From 4915dba7f969fc7d90170b55ae9f588269e370d9 Mon Sep 17 00:00:00 2001 From: dilirity Date: Tue, 25 Jun 2024 08:33:16 +0000 Subject: [PATCH] Super Cache: don't show the migration notice if already using Boost Cache (#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@82da40eefb4313d60f12ca1d2cf2b9957e15b322 --- CHANGELOG.md | 1 + inc/boost.php | 5 +++++ wp-cache.php | 40 +++++++++++++++++++++++++++++++++------- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e311fa54..07f98a6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/inc/boost.php b/inc/boost.php index d5054b2f..9df030ac 100644 --- a/inc/boost.php +++ b/inc/boost.php @@ -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 ) { diff --git a/wp-cache.php b/wp-cache.php index ddd92060..1e3e3366 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -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();