Skip to content

Disable caching for wp_die() error pages (#1015)#1036

Merged
donnchawp merged 2 commits into
trunkfrom
fix/1015-wp-die-no-cache
Apr 14, 2026
Merged

Disable caching for wp_die() error pages (#1015)#1036
donnchawp merged 2 commits into
trunkfrom
fix/1015-wp-die-no-cache

Conversation

@donnchawp
Copy link
Copy Markdown
Contributor

Summary

  • Hook wp_die_handler to define DONOTCACHEPAGE whenever wp_die() is invoked, so error/interstitial pages (Redis/DB connection failures, permission errors, etc.) are never written to the cache
  • Add a wpsc_disable_cache_on_wp_die filter to opt out for sites that intentionally render cacheable content via wp_die()

Fixes #1015

The existing error_get_last() check in the output-buffer callback doesn't catch wp_die() because it isn't a PHP error. W3 Total Cache takes the same approach (Generic_Plugin.php#L896).

Test plan

  • Trigger wp_die() on a front-end request (e.g. stop Redis with Redis Object Cache active) and confirm no cache file is written for that URL
  • After restoring the underlying service, confirm the next request renders and caches the real page
  • Confirm wp-cache.log shows DONOTCACHEPAGE defined. Caching disabled. on the failing request
  • Add a filter returning false for wpsc_disable_cache_on_wp_die and confirm wp_die() output is cached again (legacy behavior)

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().
@donnchawp donnchawp merged commit 7f74328 into trunk Apr 14, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WP Super Cache incorrectly caches pages with wp_die() error messages

1 participant