: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Plugin Name: WP Super Cache
* Plugin URI: https://wordpress.org/plugins/wp-super-cache/
* Description: Very fast caching plugin for WordPress.
* Author URI: https://automattic.com/
* License URI: https://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: wp-super-cache
Copyright Automattic and many other contributors.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
define( 'WPSC_VERSION_ID', '1.12.1' );
require_once( __DIR__. '/inc/delete-cache-button.php');
require_once( __DIR__. '/inc/preload-notification.php');
require_once __DIR__ . '/inc/boost.php';
if ( ! function_exists( 'wp_cache_phase2' ) ) {
require_once( __DIR__. '/wp-cache-phase2.php');
if ( ! defined( 'PHP_VERSION_ID' ) ) {
// For versions of PHP below 5.2.7, this constant doesn't exist.
$wpsc_php_version = explode( '.', PHP_VERSION );
define( 'PHP_VERSION_ID', intval( $wpsc_php_version[0] * 10000 + $wpsc_php_version[1] * 100 + $wpsc_php_version[2] ) );
unset( $wpsc_php_version );
* Defines how many posts to preload per loop.
if ( ! defined( 'WPSC_PRELOAD_POST_COUNT' ) ) {
define( 'WPSC_PRELOAD_POST_COUNT', 10 );
* Defines the interval in seconds between preloading pages.
if ( ! defined( 'WPSC_PRELOAD_POST_INTERVAL' ) ) {
define( 'WPSC_PRELOAD_POST_INTERVAL', 1 );
* Defines the interval in seconds between preloading loops.
if ( ! defined( 'WPSC_PRELOAD_LOOP_INTERVAL' ) ) {
define( 'WPSC_PRELOAD_LOOP_INTERVAL', 0 );
global $wp_cache_config_file, $wp_cache_config_file_sample, $wpsc_advanced_cache_dist_filename, $wp_cache_check_wp_config, $wpsc_advanced_cache_filename, $wpsc_promo_links;
if ( ! defined( 'WPCACHECONFIGPATH' ) ) {
define( 'WPCACHECONFIGPATH', WP_CONTENT_DIR );
$wp_cache_config_file = WPCACHECONFIGPATH . '/wp-cache-config.php';
// Centralise the promotional links to other products
$wpsc_promo_links = array(
'boost' => 'https://jetpack.com/boost/?utm_source=wporg&utm_medium=plugin&utm_campaign=wp-super-cache&utm_id=wp-super-cache',
'photon' => 'https://jetpack.com/features/design/content-delivery-network/?utm_source=wporg&utm_medium=plugin&utm_campaign=wp-super-cache&utm_id=wp-super-cache',
'videopress' => 'https://jetpack.com/videopress/?utm_source=wporg&utm_medium=plugin&utm_campaign=wp-super-cache&utm_id=wp-super-cache',
'crowdsignal' => 'https://crowdsignal.com/?utm_source=wporg&utm_medium=plugin&utm_campaign=wp-super-cache&utm_id=wp-super-cache',
'jetpack' => 'https://jetpack.com/?utm_source=wporg&utm_medium=plugin&utm_campaign=wp-super-cache&utm_id=wp-super-cache',
if ( !defined( 'WPCACHEHOME' ) ) {
define( 'WPCACHEHOME', __DIR__ . '/' );
$wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
$wpsc_advanced_cache_dist_filename = WPCACHEHOME . 'advanced-cache.php';
} elseif ( realpath( WPCACHEHOME ) != realpath( __DIR__ ) ) {
$wp_cache_config_file_sample = __DIR__. '/wp-cache-config-sample.php';
$wpsc_advanced_cache_dist_filename = __DIR__. '/advanced-cache.php';
if ( ! defined( 'ADVANCEDCACHEPROBLEM' ) ) {
define( 'ADVANCEDCACHEPROBLEM', 1 ); // force an update of WPCACHEHOME
$wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
$wpsc_advanced_cache_dist_filename = WPCACHEHOME . 'advanced-cache.php';
$wpsc_advanced_cache_filename = WP_CONTENT_DIR . '/advanced-cache.php';
if ( !defined( 'WP_CACHE' ) || ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) ) {
$wp_cache_check_wp_config = true;
* WP-CLI requires explicit declaration of global variables.
* It's minimal list of global variables.
global $super_cache_enabled, $cache_enabled, $wp_cache_mod_rewrite, $wp_cache_home_path, $cache_path, $file_prefix;
global $wp_cache_mutex_disabled, $mutex_filename, $sem_id, $wp_super_cache_late_init;
global $cache_compression, $cache_max_time, $wp_cache_shutdown_gc, $cache_rebuild_files;
global $wp_super_cache_debug, $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file;
global $wp_cache_debug_log, $wp_cache_debug_ip, $wp_cache_debug_username, $wp_cache_debug_email;
global $cache_time_interval, $cache_scheduled_time, $cache_schedule_interval, $cache_schedule_type, $cache_gc_email_me;
global $wp_cache_preload_on, $wp_cache_preload_interval, $wp_cache_preload_posts, $wp_cache_preload_taxonomies;
// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- these are used by various functions but the linter complains.
global $wp_cache_preload_email_me, $wp_cache_preload_email_volume;
global $wp_cache_mobile, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes;
global $wp_cache_config_file, $wp_cache_config_file_sample;
// Check is cache config already loaded.
if ( ! isset( $cache_enabled, $super_cache_enabled, $wp_cache_mod_rewrite, $cache_path ) &&
empty( $wp_cache_phase1_loaded ) &&
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
! @include( $wp_cache_config_file )
@include $wp_cache_config_file_sample; // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
include(WPCACHEHOME . 'wp-cache-base.php');
if ( class_exists( 'WP_REST_Controller' ) ) {
include( __DIR__. '/rest/load.php' );
function wp_super_cache_init_action() {
load_plugin_textdomain( 'wp-super-cache', false, basename( __DIR__ ) . '/languages' );
wpsc_register_post_hooks();
add_action( 'init', 'wp_super_cache_init_action' );
function wp_cache_set_home() {
global $wp_cache_is_home;
$wp_cache_is_home = ( is_front_page() || is_home() );
if ( $wp_cache_is_home && is_paged() )
$wp_cache_is_home = false;
add_action( 'template_redirect', 'wp_cache_set_home' );
function wpsc_enqueue_styles() {
plugins_url( 'styling/dashboard.css', __FILE__ ),
filemtime( plugin_dir_path( __FILE__ ) . 'styling/dashboard.css' )
// Check for the page parameter to see if we're on a WPSC page.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['page'] ) && $_GET['page'] === 'wpsupercache' ) {
add_action( 'admin_enqueue_scripts', 'wpsc_enqueue_styles' );
// OSSDL CDN plugin (https://wordpress.org/plugins/ossdl-cdn-off-linker/)
include_once( WPCACHEHOME . 'ossdl-cdn.php' );
function get_wpcachehome() {
if ( function_exists( '_deprecated_function' ) ) {
_deprecated_function( __FUNCTION__, 'WP Super Cache 1.6.5' );
if ( ! defined( 'WPCACHEHOME' ) ) {
if ( is_file( __DIR__ . '/wp-cache-config-sample.php' ) ) {
define( 'WPCACHEHOME', trailingslashit( __DIR__ ) );
} elseif ( is_file( __DIR__ . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
define( 'WPCACHEHOME', __DIR__ . '/wp-super-cache/' );
die( sprintf( esc_html__( 'Please create %s/wp-cache-config.php from wp-super-cache/wp-cache-config-sample.php', 'wp-super-cache' ), esc_attr( WPCACHECONFIGPATH ) ) );
function wpsc_remove_advanced_cache() {
global $wpsc_advanced_cache_filename;
if ( file_exists( $wpsc_advanced_cache_filename ) ) {
$file = file_get_contents( $wpsc_advanced_cache_filename );
strpos( $file, "WP SUPER CACHE 0.8.9.1" ) ||
strpos( $file, "WP SUPER CACHE 1.2" )
unlink( $wpsc_advanced_cache_filename );
function wpsupercache_uninstall() {
global $wp_cache_config_file, $cache_path;
wpsc_remove_advanced_cache();
if ( file_exists( $wp_cache_config_file ) ) {
unlink( $wp_cache_config_file );
if ( ! empty( $cache_path ) ) {
@unlink( $cache_path . '.htaccess' );
@unlink( $cache_path . 'meta' );
@unlink( $cache_path . 'supercache' );
wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
wp_clear_scheduled_hook( 'wp_cache_gc' );
wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
wp_cache_disable_plugin();
delete_site_option( 'wp_super_cache_index_detected' );
register_uninstall_hook( __FILE__, 'wpsupercache_uninstall' );
function wpsupercache_deactivate() {
global $wp_cache_config_file, $wpsc_advanced_cache_filename, $cache_path;
wpsc_remove_advanced_cache();
if ( ! empty( $cache_path ) ) {
prune_super_cache( $cache_path, true );
@unlink( $cache_path . '.htaccess' );
@unlink( $cache_path . 'meta' );
@unlink( $cache_path . 'supercache' );
wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
wp_clear_scheduled_hook( 'wp_cache_gc' );
wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file);
wp_cache_disable_plugin( false ); // don't delete configuration file
delete_user_option( get_current_user_id(), 'wpsc_dismissed_boost_banner' );
register_deactivation_hook( __FILE__, 'wpsupercache_deactivate' );
function wpsupercache_activate() {
if ( ! isset( $cache_path ) || $cache_path == '' )
$cache_path = WP_CONTENT_DIR . '/cache/'; // from sample config file
! wp_cache_verify_cache_dir() ||
! wpsc_check_advanced_cache() ||
! wp_cache_verify_config_file()
$text = ob_get_contents();
$text = ob_get_contents();
wp_cache_check_global_config();
wp_schedule_single_event( time() + 10, 'wp_cache_add_site_cache_index' );
register_activation_hook( __FILE__, 'wpsupercache_activate' );
function wpsupercache_site_admin() {
if ( version_compare( $wp_version, '4.8', '>=' ) ) {
return current_user_can( 'setup_network' );
function wp_cache_add_pages() {
if ( wpsupercache_site_admin() ) {
// In single or MS mode add this menu item too, but only for superadmins in MS mode.
add_options_page( 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager' );
add_action( 'admin_menu', 'wp_cache_add_pages' );
function wp_cache_network_pages() {
add_submenu_page( 'settings.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager' );
add_action( 'network_admin_menu', 'wp_cache_network_pages' );
* Load JavaScript on admin pages.
function wp_super_cache_admin_enqueue_scripts( $hook ) {
if ( 'settings_page_wpsupercache' !== $hook ) {
trailingslashit( plugin_dir_url( __FILE__ ) ) . 'js/admin.js',
'boostNoticeDismissNonce' => wp_create_nonce( 'wpsc_dismiss_boost_notice' ),
'boostDismissNonce' => wp_create_nonce( 'wpsc_dismiss_boost_banner' ),
'boostInstallNonce' => wp_create_nonce( 'updates' ),
'boostActivateNonce' => wp_create_nonce( 'activate-boost' ),
add_action( 'admin_enqueue_scripts', 'wp_super_cache_admin_enqueue_scripts' );
* Use the standard WordPress plugin installation ajax handler.
add_action( 'wp_ajax_wpsc_install_plugin', 'wp_ajax_install_plugin' );
* Check if Jetpack Boost has been installed.
function wpsc_is_boost_installed() {
$plugins = array_keys( get_plugins() );
foreach ( $plugins as $plugin ) {
if ( str_contains( $plugin, 'jetpack-boost/jetpack-boost.php' ) ) {
* Check if Jetpack Boost is active.
function wpsc_is_boost_active() {
return class_exists( '\Automattic\Jetpack_Boost\Jetpack_Boost' );
* Admin ajax action: hide the Boost Banner.
function wpsc_hide_boost_banner() {
check_ajax_referer( 'wpsc_dismiss_boost_banner', 'nonce' );
update_user_option( get_current_user_id(), 'wpsc_dismissed_boost_banner', '1' );
add_action( 'wp_ajax_wpsc-hide-boost-banner', 'wpsc_hide_boost_banner' );
* Admin ajax action: activate Jetpack Boost.
function wpsc_ajax_activate_boost() {
check_ajax_referer( 'activate-boost' );
if ( ! isset( $_POST['source'] ) ) {
wp_send_json_error( 'no source specified' );
$source = sanitize_text_field( wp_unslash( $_POST['source'] ) );
$result = activate_plugin( 'jetpack-boost/jetpack-boost.php' );
if ( is_wp_error( $result ) ) {
wp_send_json_error( $result->get_error_message() );
wpsc_notify_migration_to_boost( $source );
add_action( 'wp_ajax_wpsc_activate_boost', 'wpsc_ajax_activate_boost' );
* Show a Jetpack Boost installation banner (unless dismissed or installed)
function wpsc_jetpack_boost_install_banner() {
if ( ! wpsc_is_boost_current() ) {
// Don't show the banner if Boost is installed, or the banner has been dismissed.
$is_dismissed = '1' === get_user_option( 'wpsc_dismissed_boost_banner' );
if ( wpsc_is_boost_active() || $is_dismissed ) {
$config = wpsc_get_boost_migration_config();
$button_url = $config['is_installed'] ? $config['activate_url'] : $config['install_url'];
$button_label = $config['is_installed'] ? __( 'Set up Jetpack Boost', 'wp-super-cache' ) : __( 'Install Jetpack Boost', 'wp-super-cache' );
$button_class = $config['is_installed'] ? 'wpsc-activate-boost-button' : 'wpsc-install-boost-button';
$plugin_url = plugin_dir_url( __FILE__ );
<div class="wpsc-boost-banner">
<div class="wpsc-boost-banner-inner">
<div class="wpsc-boost-banner-content">
<img style="width:282px" src="<?php echo esc_url( $plugin_url . '/assets/jetpack-logo.svg' ); ?>" height="36" />
<?php esc_html_e( 'Speed up your site with our top‑rated performance tool', 'wp-super-cache' ); ?>
<p id="wpsc-install-invitation">
'Caching is a great start, but there is more to maximize your site speed. Find out how much your cache speeds up your site and make it blazing fast with Jetpack Boost, the easiest WordPress speed optimization plugin developed by WP Super Cache engineers.',
<div class="wpsc-boost-migration-error" style="display:none; color:red; margin-bottom: 20px;"></div>
<div style="display: flex; gap: 24px;">
<a style="font-weight: 500; line-height: 1; padding: 10px 20px 15px;" data-source='banner' href="<?php echo esc_url( $button_url ); ?>" class="wpsc-boost-migration-button button button-primary <?php echo esc_attr( $button_class ); ?>">
<div class='spinner' style='display:none; margin-top: 8px'></div>
<label><?php echo esc_html( $button_label ); ?></label>
<a style="display: flex; align-items: center; font-weight: 500; color: #000; " href="https://jetpack.com/blog/discover-how-to-improve-your-site-performance-with-jetpack-boost/">
<div class="wpsc-boost-banner-image-container">
src="<?php echo esc_url( $plugin_url . 'assets/boost-install-card-main.png' ); ?>"
title="<?php esc_attr_e( 'Check how your web site performance scores for desktop and mobile.', 'wp-super-cache' ); ?>"
alt="<?php esc_attr_e( 'An image showing the Jetpack Boost dashboard.', 'wp-super-cache' ); ?>"
srcset="<?php echo esc_url( $plugin_url . 'assets/boost-install-card-main.png' ); ?> 400w, <?php echo esc_url( $plugin_url . 'assets/boost-install-card-main-2x.png' ); ?> 800w"
sizes="(max-width: 782px) 350px, 700px"
<span class="wpsc-boost-dismiss dashicons dashicons-dismiss"></span>
function wp_cache_manager_error_checks() {
global $wp_cache_debug, $wp_cache_cron_check, $cache_enabled, $super_cache_enabled, $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_mobile_enabled, $wp_cache_mod_rewrite;
global $dismiss_htaccess_warning, $dismiss_readable_warning, $dismiss_gc_warning, $wp_cache_shutdown_gc, $is_nginx;
if ( ! wpsupercache_site_admin() ) {
if ( PHP_VERSION_ID < 50300 && ( ini_get( 'safe_mode' ) === '1' || strtolower( ini_get( 'safe_mode' ) ) === 'on' ) ) { // @codingStandardsIgnoreLine
echo '<div class="notice notice-error"><h4>' . esc_html__( 'Warning! PHP Safe Mode Enabled!', 'wp-super-cache' ) . '</h4>';
echo '<p>' . esc_html__( 'You may experience problems running this plugin because SAFE MODE is enabled.', 'wp-super-cache' ) . '<br />';
if ( ! ini_get( 'safe_mode_gid' ) ) { // @codingStandardsIgnoreLine
esc_html_e( 'Your server is set up to check the owner of PHP scripts before allowing them to read and write files.', 'wp-super-cache' );
printf( __( 'You or an administrator may be able to make it work by changing the group owner of the plugin scripts to match that of the web server user. The group owner of the %s/cache/ directory must also be changed. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details.', 'wp-super-cache' ), esc_attr( WP_CONTENT_DIR ) );
_e( 'You or an administrator must disable this. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details. This cannot be disabled in a .htaccess file unfortunately. It must be done in the php.ini config file.', 'wp-super-cache' );
if ( '' == get_option( 'permalink_structure' ) ) {
echo '<div class="notice notice-error"><h4>' . __( 'Permlink Structure Error', 'wp-super-cache' ) . '</h4>';
echo "<p>" . __( 'A custom url or permalink structure is required for this plugin to work correctly. Please go to the <a href="options-permalink.php">Permalinks Options Page</a> to configure your permalinks.', 'wp-super-cache' ) . "</p>";
if ( $wp_cache_debug || ! $wp_cache_cron_check ) {
if ( defined( 'DISABLE_WP_CRON' ) && constant( 'DISABLE_WP_CRON' ) ) {
<div class="notice notice-error"><h4><?php _e( 'CRON System Disabled', 'wp-super-cache' ); ?></h4>
<p><?php _e( 'The WordPress CRON jobs system is disabled. This means the garbage collection system will not work unless you run the CRON system manually.', 'wp-super-cache' ); ?></p>
} elseif ( function_exists( "wp_remote_get" ) == false ) {
$hostname = str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'siteurl' ) ) );
if( strpos( $hostname, '/' ) )
$hostname = substr( $hostname, 0, strpos( $hostname, '/' ) );