Skip to content

Commit

Permalink
Super Cache & Boost: detect WP_CACHE when it's set using "const" in w…
Browse files Browse the repository at this point in the history
…p-config.php (#38022)

* Detect "const WP_CACHE =" in wp-config.php too

* changelog

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/9658574624

Upstream-Ref: Automattic/jetpack@2fee08f
  • Loading branch information
dilirity authored and matticbot committed Jun 25, 2024
1 parent 98a6a0e commit 567495c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This is an alpha version! The changes listed here are not final.
- WP Super Cache: Updated banner designs, added auto-install Jetpack Boost buttons

### Fixed
- Detect when WP_CACHE is defined with "const" in wp-config.php
- Super Cache: Align detection of Boost installs with activation of that plugin
- Super Cache: fixed a PHP warning when deactivating the plugin.
- Super Cache: make sure plugins links is an array before using it.
Expand Down
13 changes: 13 additions & 0 deletions wp-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2385,6 +2385,19 @@ function wp_cache_check_global_config() {
$global_config_file = dirname( ABSPATH ) . '/wp-config.php';
}

if ( preg_match( '#^\s*(define\s*\(\s*[\'"]WP_CACHE[\'"]|const\s+WP_CACHE\s*=)#m', file_get_contents( $global_config_file ) ) === 1 ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
if ( defined( 'WP_CACHE' ) && ! constant( 'WP_CACHE' ) ) {
?>
<div class="notice notice-error"><h4><?php esc_html_e( 'WP_CACHE constant set to false', 'wp-super-cache' ); ?></h4>
<p><?php esc_html_e( 'The WP_CACHE constant is used by WordPress to load the code that serves cached pages. Unfortunately, it is set to false. Please edit your wp-config.php and add or edit the following line above the final require_once command:', 'wp-super-cache' ); ?></p>
<p><code>define('WP_CACHE', true);</code></p></div>
<?php
return false;
} else {
return true;
}
}

$line = 'define(\'WP_CACHE\', true);';
if (
! is_writeable_ACLSafe( $global_config_file ) ||
Expand Down

0 comments on commit 567495c

Please sign in to comment.