: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
function wpsc_get_minimum_preload_interval() {
return apply_filters( 'wpsc_minimum_preload_interval', 10 );
function wpsc_preload_settings() {
global $wp_cache_preload_interval, $wp_cache_preload_on, $wp_cache_preload_taxonomies, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $wp_cache_preload_posts, $wpdb;
if ( isset( $_POST[ 'action' ] ) == false || $_POST[ 'action' ] != 'preload' )
if ( isset( $_POST[ 'preload_off' ] ) ) {
} elseif ( isset( $_POST[ 'preload_now' ] ) ) {
wpsc_update_idle_preload();
<div class="notice notice-warning">
<h4><?php esc_html_e( 'Preload has been activated', 'wp-super-cache' ); ?></h4>
$min_refresh_interval = wpsc_get_minimum_preload_interval();
// Set to true if the preload interval is changed, and a reschedule is required.
$force_preload_reschedule = false;
if ( isset( $_POST[ 'wp_cache_preload_interval' ] ) && ( $_POST[ 'wp_cache_preload_interval' ] == 0 || $_POST[ 'wp_cache_preload_interval' ] >= $min_refresh_interval ) ) {
$_POST[ 'wp_cache_preload_interval' ] = (int)$_POST[ 'wp_cache_preload_interval' ];
if ( $wp_cache_preload_interval != $_POST[ 'wp_cache_preload_interval' ] ) {
$force_preload_reschedule = true;
// phpcs:ignore WordPress.Security.NonceVerification.Missing
$wp_cache_preload_interval = (int) $_POST['wp_cache_preload_interval'];
wp_cache_setting( 'wp_cache_preload_interval', $wp_cache_preload_interval );
if ( $_POST[ 'wp_cache_preload_posts' ] == 'all' ) {
$wp_cache_preload_posts = 'all';
$wp_cache_preload_posts = (int)$_POST[ 'wp_cache_preload_posts' ];
wp_cache_setting( 'wp_cache_preload_posts', $wp_cache_preload_posts );
if ( isset( $_POST[ 'wp_cache_preload_email_volume' ] ) && in_array( $_POST[ 'wp_cache_preload_email_volume' ], array( 'none', 'less', 'medium', 'many' ) ) ) {
$wp_cache_preload_email_volume = $_POST[ 'wp_cache_preload_email_volume' ];
$wp_cache_preload_email_volume = 'none';
wp_cache_setting( 'wp_cache_preload_email_volume', $wp_cache_preload_email_volume );
if ( $wp_cache_preload_email_volume == 'none' )
wp_cache_setting( 'wp_cache_preload_email_me', 0 );
wp_cache_setting( 'wp_cache_preload_email_me', 1 );
if ( isset( $_POST[ 'wp_cache_preload_taxonomies' ] ) ) {
$wp_cache_preload_taxonomies = 1;
$wp_cache_preload_taxonomies = 0;
wp_cache_setting( 'wp_cache_preload_taxonomies', $wp_cache_preload_taxonomies );
if ( isset( $_POST[ 'wp_cache_preload_on' ] ) ) {
$wp_cache_preload_on = 1;
$wp_cache_preload_on = 0;
wp_cache_setting( 'wp_cache_preload_on', $wp_cache_preload_on );
// Ensure that preload settings are applied to scheduled cron.
$next_preload = wp_next_scheduled( 'wp_cache_full_preload_hook' );
$should_schedule = ( $wp_cache_preload_on === 1 && $wp_cache_preload_interval > 0 );
// If forcing a reschedule, or preload is disabled, clear the next scheduled event.
if ( $next_preload && ( ! $should_schedule || $force_preload_reschedule ) ) {
wp_cache_debug( 'Clearing old preload event' );
wpsc_reset_preload_counter();
wpsc_create_stop_preload_flag();
wp_unschedule_event( $next_preload, 'wp_cache_full_preload_hook' );
// Ensure a preload is scheduled if it should be.
if ( ! $next_preload && $should_schedule ) {
wp_cache_debug( 'Scheduling new preload event' );
wp_schedule_single_event( time() + ( $wp_cache_preload_interval * 60 ), 'wp_cache_full_preload_hook' );
function wpsc_is_preloading() {
if ( wp_next_scheduled( 'wp_cache_preload_hook' ) || wp_next_scheduled( 'wp_cache_full_preload_hook' ) ) {
function wpsc_set_default_gc( $force = false ) {
global $cache_path, $wp_cache_shutdown_gc, $cache_schedule_type;
if ( isset( $wp_cache_shutdown_gc ) && $wp_cache_shutdown_gc == 1 ) {
unset( $cache_schedule_type );
$timestamp = wp_next_scheduled( 'wp_cache_gc' );
wp_unschedule_event( $timestamp, 'wp_cache_gc' );
// set up garbage collection with some default settings
if ( false == isset( $cache_schedule_type ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) {
$cache_schedule_type = 'interval';
$cache_time_interval = 600;
$cache_schedule_interval = 'hourly';
wp_cache_setting( 'cache_schedule_type', $cache_schedule_type );
wp_cache_setting( 'cache_time_interval', $cache_time_interval );
wp_cache_setting( 'cache_max_time', $cache_max_time );
wp_cache_setting( 'cache_schedule_interval', $cache_schedule_interval );
wp_cache_setting( 'cache_gc_email_me', $cache_gc_email_me );
wp_schedule_single_event( time() + 600, 'wp_cache_gc' );
function add_mod_rewrite_rules() {
return update_mod_rewrite_rules();
function remove_mod_rewrite_rules() {
return update_mod_rewrite_rules( false );
function update_mod_rewrite_rules( $add_rules = true ) {
global $cache_path, $update_mod_rewrite_rules_error;
$update_mod_rewrite_rules_error = false;
if ( defined( "DO_NOT_UPDATE_HTACCESS" ) ) {
$update_mod_rewrite_rules_error = ".htaccess update disabled by admin: DO_NOT_UPDATE_HTACCESS defined";
if ( ! function_exists( 'get_home_path' ) ) {
include_once( ABSPATH . 'wp-admin/includes/file.php' ); // get_home_path()
include_once( ABSPATH . 'wp-admin/includes/misc.php' ); // extract_from_markers()
$home_path = trailingslashit( get_home_path() );
$home_root = parse_url( get_bloginfo( 'url' ) );
$home_root = isset( $home_root[ 'path' ] ) ? trailingslashit( $home_root[ 'path' ] ) : '/';
$home_path != $_SERVER[ 'DOCUMENT_ROOT' ]
$home_path = $_SERVER[ 'DOCUMENT_ROOT' ];
$home_path != str_replace( '//', '/', $_SERVER[ 'DOCUMENT_ROOT' ] . $home_root ) &&
is_dir( $_SERVER[ 'DOCUMENT_ROOT' ] . $home_root )
$home_path = str_replace( '//', '/', $_SERVER[ 'DOCUMENT_ROOT' ] . $home_root );
$home_path = trailingslashit( $home_path );
if ( ! file_exists( $home_path . ".htaccess" ) ) {
$update_mod_rewrite_rules_error = ".htaccess not found: {$home_path}.htaccess";
$generated_rules = wpsc_get_htaccess_info();
$existing_rules = implode( "\n", extract_from_markers( $home_path . '.htaccess', 'WPSuperCache' ) );
$rules = $add_rules ? $generated_rules[ 'rules' ] : '';
if ( $existing_rules == $rules ) {
$update_mod_rewrite_rules_error = "rules have not changed";
if ( $generated_rules[ 'wprules' ] == '' ) {
$update_mod_rewrite_rules_error = "WordPress rules empty";
return insert_with_markers( $home_path . '.htaccess', 'WPSuperCache', array() );
$url = trailingslashit( get_bloginfo( 'url' ) );
$original_page = wp_remote_get( $url, array( 'timeout' => 60, 'blocking' => true ) );
if ( is_wp_error( $original_page ) ) {
$update_mod_rewrite_rules_error = "Problem loading page";
$backup_filename = $cache_path . 'htaccess.' . mt_rand() . ".php";
$backup_file_contents = file_get_contents( $home_path . '.htaccess' );
file_put_contents( $backup_filename, "<" . "?php die(); ?" . ">" . $backup_file_contents );
$existing_gzip_rules = implode( "\n", extract_from_markers( $cache_path . '.htaccess', 'supercache' ) );
if ( $existing_gzip_rules != $generated_rules[ 'gziprules' ] ) {
insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $generated_rules[ 'gziprules' ] ) );
$wprules = extract_from_markers( $home_path . '.htaccess', 'WordPress' );
wpsc_remove_marker( $home_path . '.htaccess', 'WordPress' ); // remove original WP rules so SuperCache rules go on top
if ( insert_with_markers( $home_path . '.htaccess', 'WPSuperCache', explode( "\n", $rules ) ) && insert_with_markers( $home_path . '.htaccess', 'WordPress', $wprules ) ) {
$new_page = wp_remote_get( $url, array( 'timeout' => 60, 'blocking' => true ) );
if ( is_wp_error( $new_page ) ) {
$update_mod_rewrite_rules_error = "Error testing page with new .htaccess rules: " . $new_page->get_error_message() . ".";
wp_cache_debug( 'update_mod_rewrite_rules: failed to update rules. error fetching second page: ' . $new_page->get_error_message() );
} elseif ( $new_page[ 'body' ] != $original_page[ 'body' ] ) {
$update_mod_rewrite_rules_error = "Page test failed as pages did not match with new .htaccess rules.";
wp_cache_debug( 'update_mod_rewrite_rules: failed to update rules. page test failed as pages did not match. Files dumped in ' . $cache_path . ' for inspection.' );
wp_cache_debug( 'update_mod_rewrite_rules: original page: 1-' . md5( $original_page[ 'body' ] ) . '.txt' );
wp_cache_debug( 'update_mod_rewrite_rules: new page: 1-' . md5( $new_page[ 'body' ] ) . '.txt' );
file_put_contents( $cache_path . '1-' . md5( $original_page[ 'body' ] ) . '.txt', $original_page[ 'body' ] );
file_put_contents( $cache_path . '2-' . md5( $new_page[ 'body' ] ) . '.txt', $new_page[ 'body' ] );
file_put_contents( $home_path . '.htaccess', $backup_file_contents );
unlink( $backup_filename );
$update_mod_rewrite_rules_error .= "<br />See debug log for further details";
$update_mod_rewrite_rules_error .= "<br />Enable debug log on Debugging page for further details and try again";
file_put_contents( $home_path . '.htaccess', $backup_file_contents );
unlink( $backup_filename );
$update_mod_rewrite_rules_error = "problem inserting rules in .htaccess and original .htaccess restored";
// Delete feeds when the site is updated so that feed files are always fresh
function wpsc_feed_update( $type, $permalink ) {
$wpsc_feed_list = get_option( 'wpsc_feed_list' );
update_option( 'wpsc_feed_list', array() );
if ( is_array( $wpsc_feed_list ) && ! empty( $wpsc_feed_list ) ) {
foreach( $wpsc_feed_list as $file ) {
wp_cache_debug( "wpsc_feed_update: deleting feed: $file" );
prune_super_cache( $file, true );
prune_super_cache( dirname( $file ) . '/meta-' . basename( $file ), true );
add_action( 'gc_cache', 'wpsc_feed_update', 10, 2 );
function wpsc_get_plugin_list() {
$list = do_cacheaction( 'wpsc_filter_list' );
foreach( $list as $t => $details ) {
$key = "cache_" . $details[ 'key' ];
if ( isset( $GLOBALS[ $key ] ) && $GLOBALS[ $key ] == 1 ) {
$list[ $t ][ 'enabled' ] = true;
$list[ $t ][ 'enabled' ] = false;
$list[ $t ][ 'desc' ] = strip_tags( $list[ $t ][ 'desc' ] );
$list[ $t ][ 'title' ] = strip_tags( $list[ $t ][ 'title' ] );
function wpsc_update_plugin_list( $update ) {
$list = do_cacheaction( 'wpsc_filter_list' );
foreach( $update as $key => $enabled ) {
$plugin_toggle = "cache_{$key}";
if ( isset( $GLOBALS[ $plugin_toggle ] ) || isset( $list[ $key ] ) ) {
wp_cache_setting( $plugin_toggle, (int)$enabled );
function wpsc_add_plugin( $file ) {
if ( substr( $file, 0, strlen( ABSPATH ) ) == ABSPATH ) {
$file = substr( $file, strlen( ABSPATH ) ); // remove ABSPATH
! isset( $wpsc_plugins ) ||
! is_array( $wpsc_plugins ) ||
! in_array( $file, $wpsc_plugins )
wp_cache_setting( 'wpsc_plugins', $wpsc_plugins );
add_action( 'wpsc_add_plugin', 'wpsc_add_plugin' );
function wpsc_delete_plugin( $file ) {
if ( substr( $file, 0, strlen( ABSPATH ) ) == ABSPATH ) {
$file = substr( $file, strlen( ABSPATH ) ); // remove ABSPATH
isset( $wpsc_plugins ) &&
is_array( $wpsc_plugins ) &&
in_array( $file, $wpsc_plugins )
unset( $wpsc_plugins[ array_search( $file, $wpsc_plugins ) ] );
wp_cache_setting( 'wpsc_plugins', $wpsc_plugins );
add_action( 'wpsc_delete_plugin', 'wpsc_delete_plugin' );
function wpsc_get_plugins() {
function wpsc_add_cookie( $name ) {
! isset( $wpsc_cookies ) ||
! is_array( $wpsc_cookies ) ||
! in_array( $name, $wpsc_cookies )
wp_cache_setting( 'wpsc_cookies', $wpsc_cookies );
add_action( 'wpsc_add_cookie', 'wpsc_add_cookie' );
function wpsc_delete_cookie( $name ) {
isset( $wpsc_cookies ) &&
is_array( $wpsc_cookies ) &&
in_array( $name, $wpsc_cookies )
unset( $wpsc_cookies[ array_search( $name, $wpsc_cookies ) ] );
wp_cache_setting( 'wpsc_cookies', $wpsc_cookies );
add_action( 'wpsc_delete_cookie', 'wpsc_delete_cookie' );
function wpsc_get_cookies() {
function wpsc_get_extra_cookies() {
is_array( $wpsc_cookies ) &&
return '|' . implode( '|', $wpsc_cookies );
function wpsc_update_check() {
! isset( $wpsc_version ) ||
wp_cache_setting( 'wpsc_version', 169 );
global $wp_cache_debug_log, $cache_path;
$log_file = $cache_path . str_replace('/', '', str_replace('..', '', $wp_cache_debug_log));
if ( ! file_exists( $log_file ) ) {
wp_cache_debug( 'wpsc_update_check: Deleted old log file on plugin update.' );
add_action( 'admin_init', 'wpsc_update_check' );
* Renders a partial/template.
* The global $current_user is made available for any rendered template.
* @param string $partial - Filename under ./partials directory, with or without .php (appended if absent).
* @param array $page_vars - Variables made available for the template.
function wpsc_render_partial( $partial, array $page_vars = array() ) {
if ( ! str_ends_with( $partial, '.php' ) ) {
if ( strpos( $partial, 'partials/' ) !== 0 ) {
$partial = 'partials/' . $partial;
$path = __DIR__ . '/' . $partial;
if ( ! file_exists( $path ) ) {
foreach ( $page_vars as $key => $val ) {
function wpsc_render_header() {
<img class="wpsc-icon" src="<?php echo esc_url( plugin_dir_url( __FILE__ ) . '/assets/super-cache-icon.png' ); ?>" />
<span class="wpsc-name"><?php echo esc_html( 'WP Super Cache' ); ?></span>
function wpsc_render_footer() {
<div class="wp-super-cache-version">
<img class="wpsc-icon" src="<?php echo esc_url( plugin_dir_url( __FILE__ ) . '/assets/super-cache-icon.png' ); ?>" />
<span class="wpsc-name"><?php echo esc_html( 'WP Super Cache' ); ?></span>
<div class="automattic-airline">
<img class="wpsc-icon" src="<?php echo esc_url( plugin_dir_url( __FILE__ ) . '/assets/automattic-airline.svg' ); ?>" />