From 8be3c4bfec39673d73483cfb10e3fd143d5731ff Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh <5656673+donnchawp@users.noreply.github.com> Date: Tue, 14 Apr 2026 14:52:44 +0100 Subject: [PATCH 1/2] Disable caching for wp_die() error pages Fixes #1015 Hook wp_die_handler to define DONOTCACHEPAGE when wp_die() is invoked, preventing error/interstitial pages (e.g. "Error establishing a Redis connection") from being cached and served to subsequent visitors. A wpsc_disable_cache_on_wp_die filter preserves the legacy behavior for sites that intentionally render cacheable content via wp_die(). --- wp-cache.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/wp-cache.php b/wp-cache.php index 0b3e067d..240941b9 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -157,6 +157,29 @@ function wp_super_cache_init_action() { } add_action( 'init', 'wp_super_cache_init_action' ); +/** + * Disable caching for pages rendered via wp_die(). + * + * wp_die() is used to render error and interstitial pages (e.g. "Error + * establishing a database connection"); caching them causes the error to + * persist for subsequent visitors even after the underlying issue is resolved. + * + * @param callable $handler The registered wp_die handler, returned unchanged. + * @return callable + */ +function wpsc_wp_die_disable_cache( $handler ) { + /** + * Filters whether to disable caching when wp_die() is invoked. + * + * @param bool $disable Whether to set DONOTCACHEPAGE. Default true. + */ + if ( apply_filters( 'wpsc_disable_cache_on_wp_die', true ) && ! defined( 'DONOTCACHEPAGE' ) ) { + define( 'DONOTCACHEPAGE', true ); + } + return $handler; +} +add_filter( 'wp_die_handler', 'wpsc_wp_die_disable_cache' ); + function wp_cache_set_home() { global $wp_cache_is_home; $wp_cache_is_home = ( is_front_page() || is_home() ); From ade43e552b6f5bc7721842d1138fe1980f4d3003 Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh <5656673+donnchawp@users.noreply.github.com> Date: Tue, 14 Apr 2026 15:03:51 +0100 Subject: [PATCH 2/2] Linting warning fix --- wp-cache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-cache.php b/wp-cache.php index 240941b9..25f01685 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -160,8 +160,8 @@ function wp_super_cache_init_action() { /** * Disable caching for pages rendered via wp_die(). * - * wp_die() is used to render error and interstitial pages (e.g. "Error - * establishing a database connection"); caching them causes the error to + * The function wp_die() is used to render error and interstitial pages (e.g. + * "Error establishing a database connection"); caching them causes the error to * persist for subsequent visitors even after the underlying issue is resolved. * * @param callable $handler The registered wp_die handler, returned unchanged.