Skip to content

Commit

Permalink
Super Cache: don't show the migration notice if already using Boost C…
Browse files Browse the repository at this point in the history
…ache (#38005)

* Identify if Boost Cache used and do not show migrate notice

Fixes #38002

* changelog

* Return 'NONE' if no advanced-cache.php, not false.

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

Upstream-Ref: Automattic/jetpack@82da40e
  • Loading branch information
dilirity authored and matticbot committed Jun 25, 2024
1 parent 567495c commit 4915dba
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This is an alpha version! The changes listed here are not final.
### 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: do not show migration notice if already using Boost Cache
- Super Cache: fixed a PHP warning when deactivating the plugin.
- Super Cache: make sure plugins links is an array before using it.
- Super Cache: remove the preload interval based on the post count. Preload as often as you want.
Expand Down
5 changes: 5 additions & 0 deletions inc/boost.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ function wpsc_jetpack_boost_notice() {
return;
}

// hide the admin notice if Jetpack Boost Cache is already used.
if ( 'BOOST' === wpsc_identify_advanced_cache() ) {
return;
}

// Don't show the banner if the banner has been dismissed.
$is_dismissed = '1' === get_user_option( 'wpsc_dismissed_boost_admin_notice' );
if ( $is_dismissed ) {
Expand Down
40 changes: 33 additions & 7 deletions wp-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2318,19 +2318,45 @@ function wp_cache_create_advanced_cache() {
return $ret;
}

/**
* Identify the advanced cache plugin used
*
* @return string The name of the advanced cache plugin, BOOST, WPSC or OTHER.
*/
function wpsc_identify_advanced_cache() {
global $wpsc_advanced_cache_filename;
if ( ! file_exists( $wpsc_advanced_cache_filename ) ) {
return 'NONE';
}
$contents = file_get_contents( $wpsc_advanced_cache_filename ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents

if ( false !== str_contains( $contents, 'Boost Cache Plugin' ) ) {
return 'BOOST';
}

if ( str_contains( $contents, 'WP SUPER CACHE 0.8.9.1' ) || str_contains( $contents, 'WP SUPER CACHE 1.2' ) ) {
return 'WPSC';
}

return 'OTHER';
}

function wpsc_check_advanced_cache() {
global $wpsc_advanced_cache_filename;

$ret = false;
$other_advanced_cache = false;
if ( file_exists( $wpsc_advanced_cache_filename ) ) {
$file = file_get_contents( $wpsc_advanced_cache_filename );
if ( strpos( $file, "WP SUPER CACHE 0.8.9.1" ) || strpos( $file, "WP SUPER CACHE 1.2" ) ) {
return true;
} elseif ( strpos( $file, 'Boost Cache Plugin' ) !== false ) {
$other_advanced_cache = 'BOOST';
} else {
$other_advanced_cache = true;
$cache_type = wpsc_identify_advanced_cache();
switch ( $cache_type ) {
case 'WPSC':
return true;
case 'BOOST':
$other_advanced_cache = 'BOOST';
break;
default:
$other_advanced_cache = true;
break;
}
} else {
$ret = wp_cache_create_advanced_cache();
Expand Down

0 comments on commit 4915dba

Please sign in to comment.