Disable caching for wp_die() error pages (#1015)#1036
Merged
Conversation
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().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
wp_die_handlerto defineDONOTCACHEPAGEwheneverwp_die()is invoked, so error/interstitial pages (Redis/DB connection failures, permission errors, etc.) are never written to the cachewpsc_disable_cache_on_wp_diefilter to opt out for sites that intentionally render cacheable content viawp_die()Fixes #1015
The existing
error_get_last()check in the output-buffer callback doesn't catchwp_die()because it isn't a PHP error. W3 Total Cache takes the same approach (Generic_Plugin.php#L896).Test plan
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 URLwp-cache.logshowsDONOTCACHEPAGE defined. Caching disabled.on the failing requestfalseforwpsc_disable_cache_on_wp_dieand confirmwp_die()output is cached again (legacy behavior)