Skip to content

Commit

Permalink
WP Super Cache: don't define DONOTCACHEPAGE without checking if it's …
Browse files Browse the repository at this point in the history
…defined (#36423)

* Check if DONOTCACHEPAGE is defined before setting it.

ref:
https://wordpress.org/support/topic/warning-constant-donotcachepage-already-defined/

* changelog

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/8319226494
  • Loading branch information
thingalon authored and matticbot committed Mar 18, 2024
1 parent 327496f commit 49e2960
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ This is an alpha version! The changes listed here are not final.
### Changed
- Updated package dependencies.

### Fixed
- WP Super Cache: do not define DONOTCACHEPAGE if it is already defined

## [1.12.0] - 2024-03-11
### Added
- Setup: Detect Jetpack Boost cache and suggest troubleshooting steps [#36018]
Expand Down
28 changes: 21 additions & 7 deletions wp-cache-phase1.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
if ( '/' === $cache_path || empty( $cache_path ) ) {
define( 'WPSCSHUTDOWNMESSAGE', 'WARNING! Caching disabled. Configuration corrupted. Reset configuration on Advanced Settings page.' );
add_action( 'wp_footer', 'wpsc_shutdown_message' );
define( 'DONOTCACHEPAGE', 1 );
if ( ! defined( 'DONOTCACHEPAGE' ) ) {
define( 'DONOTCACHEPAGE', 1 );
}
return;
}

Expand All @@ -55,7 +57,9 @@
// from the secret shown on the Advanced settings page.
if ( isset( $_GET['donotcachepage'] ) && isset( $cache_page_secret ) && $_GET['donotcachepage'] == $cache_page_secret ) {
$cache_enabled = false;
define( 'DONOTCACHEPAGE', 1 );
if ( ! defined( 'DONOTCACHEPAGE' ) ) {
define( 'DONOTCACHEPAGE', 1 );
}
}

// Load wp-super-cache plugins
Expand Down Expand Up @@ -109,21 +113,27 @@

// don't cache in wp-admin
if ( wpsc_is_backend() ) {
define( 'DONOTCACHEPAGE', 1 );
if ( ! defined( 'DONOTCACHEPAGE' ) ) {
define( 'DONOTCACHEPAGE', 1 );
}
return true;
}

// if a cookie is found that we don't like then don't serve/cache the page
if ( wpsc_is_rejected_cookie() ) {
define( 'DONOTCACHEPAGE', 1 );
if ( ! defined( 'DONOTCACHEPAGE' ) ) {
define( 'DONOTCACHEPAGE', 1 );
}
$cache_enabled = false;
wp_cache_debug( 'Caching disabled because rejected cookie found.' );
return true;
}

if ( wpsc_is_caching_user_disabled() ) {
wp_cache_debug( 'Caching disabled for logged in users on settings page.' );
define( 'DONOTCACHEPAGE', 1 );
if ( ! defined( 'DONOTCACHEPAGE' ) ) {
define( 'DONOTCACHEPAGE', 1 );
}
return true;
}

Expand All @@ -142,13 +152,17 @@
// don't cache or serve cached files for various URLs, including the Customizer.
if ( isset( $_SERVER['REQUEST_METHOD'] ) && in_array( $_SERVER['REQUEST_METHOD'], array( 'POST', 'PUT', 'DELETE' ), true ) ) {
wp_cache_debug( 'Caching disabled for non GET request.' );
define( 'DONOTCACHEPAGE', 1 );
if ( ! defined( 'DONOTCACHEPAGE' ) ) {
define( 'DONOTCACHEPAGE', 1 );
}
return true;
}

if ( isset( $_GET['customize_changeset_uuid'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
wp_cache_debug( 'Caching disabled for customizer.' );
define( 'DONOTCACHEPAGE', 1 );
if ( ! defined( 'DONOTCACHEPAGE' ) ) {
define( 'DONOTCACHEPAGE', 1 );
}
return true;
}

Expand Down

0 comments on commit 49e2960

Please sign in to comment.