: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$details = explode( "\n", $out );
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$details = explode( "\n", file_get_contents( $taxonomy_filename ) );
if ( count( $details ) > 0 && $details[0] !== '' ) {
$rows = array_splice( $details, 0, WPSC_PRELOAD_POST_COUNT );
if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume === 'many' ) {
// translators: 1: Site URL, 2: Taxonomy name, 3: Number of posts done, 4: Number of posts to preload
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing %2$s taxonomy from %3$d to %4$d', 'wp-super-cache' ), home_url(), $taxonomy, $c, ( $c + WPSC_PRELOAD_POST_COUNT ) ), 'Refreshing: ' . print_r( $rows, 1 ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
foreach ( (array) $rows as $url ) {
$url_info = wp_parse_url( $url );
$dir = get_supercache_dir() . $url_info['path'];
wp_cache_debug( "wp_cron_preload_cache: delete $dir" );
wpsc_delete_files( $dir );
prune_super_cache( trailingslashit( $dir ) . 'feed/', true );
prune_super_cache( trailingslashit( $dir ) . 'page/', true );
wpsc_update_active_preload( 'taxonomies', $taxonomy, $url );
wp_cache_debug( "wp_cron_preload_cache: fetched $url" );
sleep( WPSC_PRELOAD_POST_INTERVAL );
if ( ! wpsc_is_preload_active() ) {
wp_cache_debug( 'wp_cron_preload_cache: cancelling preload process.' );
wpsc_reset_preload_settings();
if ( $wp_cache_preload_email_me ) {
// translators: Home URL of website
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Stopped', 'wp-super-cache' ), home_url(), '' ), ' ' );
wpsc_update_idle_preload( time() );
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen
$fp = fopen( $taxonomy_filename, 'w' );
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite
fwrite( $fp, implode( "\n", $details ) );
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
$preload_more_taxonomies === false &&
$preload_more_taxonomies = true;
if ( $preload_more_taxonomies === true ) {
wpsc_schedule_next_preload();
sleep( WPSC_PRELOAD_LOOP_INTERVAL );
} elseif ( $c === 0 && $wp_cache_preload_email_me ) {
// translators: Home URL of website
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Started', 'wp-super-cache' ), home_url(), '' ), ' ' );
* The preload_cache_counter has two values:
* c = the number of posts we've preloaded after this loop.
* t = the time we started preloading in the current loop.
* $c is set to the value of preload_cache_counter['c'] at the start of the function
* before it is incremented by WPSC_PRELOAD_POST_COUNT here.
* The time is used to check if preloading has stalled in check_up_on_preloading().
'c' => ( $c + WPSC_PRELOAD_POST_COUNT ),
if ( $wp_cache_preload_posts == 'all' || $c < $wp_cache_preload_posts ) {
$types = wpsc_get_post_types();
$posts = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE ( post_type IN ( $types ) ) AND post_status = 'publish' ORDER BY ID DESC LIMIT %d," . WPSC_PRELOAD_POST_COUNT, $c ) ); // phpcs:ignore
wp_cache_debug( 'wp_cron_preload_cache: got ' . WPSC_PRELOAD_POST_COUNT . ' posts from position ' . $c );
wp_cache_debug( "wp_cron_preload_cache: no more posts to get. Limit ($wp_cache_preload_posts) reached.", 5 );
if ( !isset( $wp_cache_preload_email_volume ) )
$wp_cache_preload_email_volume = 'medium';
if ( get_option( 'show_on_front' ) == 'page' ) {
$page_on_front = get_option( 'page_on_front' );
$page_for_posts = get_option( 'page_for_posts' );
$page_on_front = $page_for_posts = 0;
if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume === 'many' ) {
/* translators: 1: home url, 2: start post id, 3: end post id */
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing posts from %2$d to %3$d', 'wp-super-cache' ), home_url(), $c, ( $c + WPSC_PRELOAD_POST_COUNT ) ), ' ' );
foreach( $posts as $post_id ) {
if ( $page_on_front != 0 && ( $post_id == $page_on_front || $post_id == $page_for_posts ) )
$url = get_permalink( $post_id );
if ( ! is_string( $url ) ) {
wp_cache_debug( "wp_cron_preload_cache: skipped $post_id. Expected a URL, received: " . gettype( $url ) );
if ( wp_cache_is_rejected( $url ) ) {
wp_cache_debug( "wp_cron_preload_cache: skipped $url per rejected strings setting" );
clear_post_supercache( $post_id );
wpsc_update_active_preload( 'posts', $count, $url );
if ( ! wpsc_is_preload_active() ) {
wp_cache_debug( 'wp_cron_preload_cache: cancelling preload process.' );
wpsc_reset_preload_settings();
if ( $wp_cache_preload_email_me ) {
// translators: Home URL of website
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Stopped', 'wp-super-cache' ), home_url(), '' ), ' ' );
wpsc_update_idle_preload( time() );
wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
wp_cache_debug( "wp_cron_preload_cache: fetched $url", 5 );
sleep( WPSC_PRELOAD_POST_INTERVAL );
if ( $wp_cache_preload_email_me && ( $wp_cache_preload_email_volume === 'medium' || $wp_cache_preload_email_volume === 'many' ) ) {
// translators: 1: home url, 2: number of posts refreshed
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] %2$d posts refreshed', 'wp-super-cache' ), home_url(), ( $c + WPSC_PRELOAD_POST_COUNT ) ), __( 'Refreshed the following posts:', 'wp-super-cache' ) . "\n$msg" );
wpsc_schedule_next_preload();
wpsc_delete_files( get_supercache_dir() );
sleep( WPSC_PRELOAD_LOOP_INTERVAL );
wpsc_reset_preload_counter();
if ( (int)$wp_cache_preload_interval && defined( 'DOING_CRON' ) ) {
if ( $wp_cache_preload_email_me )
$msg = sprintf( __( 'Scheduling next preload refresh in %d minutes.', 'wp-super-cache' ), (int)$wp_cache_preload_interval );
wp_cache_debug( "wp_cron_preload_cache: no more posts. scheduling next preload in $wp_cache_preload_interval minutes.", 5 );
wp_schedule_single_event( time() + ( (int)$wp_cache_preload_interval * 60 ), 'wp_cache_full_preload_hook' );
global $file_prefix, $cache_max_time;
if ( $wp_cache_preload_interval > 0 ) {
$cache_max_time = (int)$wp_cache_preload_interval * 60; // fool the GC into expiring really old files
$cache_max_time = 86400; // fool the GC into expiring really old files
if ( $wp_cache_preload_email_me )
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Cache Preload Completed', 'wp-super-cache' ), home_url() ), __( "Cleaning up old supercache files.", 'wp-super-cache' ) . "\n" . $msg );
if ( $cache_max_time > 0 ) { // GC is NOT disabled
wp_cache_debug( "wp_cron_preload_cache: clean expired cache files older than $cache_max_time seconds.", 5 );
wp_cache_phase2_clean_expired( $file_prefix, true ); // force cleanup of old files.
wpsc_reset_preload_settings();
wpsc_update_idle_preload( time() );
add_action( 'wp_cache_preload_hook', 'wp_cron_preload_cache' );
add_action( 'wp_cache_full_preload_hook', 'wp_cron_preload_cache' );
* Schedule the next preload event without resetting the preload counter.
* This happens when the next loop of an active preload is scheduled.
function wpsc_schedule_next_preload() {
* Edge case: If preload is not active, don't schedule the next preload.
* This can happen if the preload is cancelled by the user right after a loop finishes.
if ( ! wpsc_is_preload_active() ) {
wpsc_reset_preload_settings();
wp_cache_debug( 'wpsc_schedule_next_preload: preload is not active. not scheduling next preload.' );
if ( defined( 'DOING_CRON' ) ) {
wp_cache_debug( 'wp_cron_preload_cache: scheduling the next preload in 3 seconds.' );
wp_schedule_single_event( time() + 3, 'wp_cache_preload_hook' );
// we always want to delete the mutex file, even if we're not using cron
$mutex = $cache_path . 'preload_mutex.tmp';
wp_delete_file( $mutex );
function option_preload_cache_counter( $value ) {
if ( false == is_array( $value ) ) {
add_filter( 'option_preload_cache_counter', 'option_preload_cache_counter' );
function check_up_on_preloading() {
$value = get_option( 'preload_cache_counter' );
if ( is_array( $value ) && $value['c'] > 0 && ( time() - $value['t'] ) > 3600 && false === wp_next_scheduled( 'wp_cache_preload_hook' ) ) {
wp_schedule_single_event( time() + 5, 'wp_cache_preload_hook' );
add_action( 'init', 'check_up_on_preloading' ); // sometimes preloading stops working. Kickstart it.
function wp_cache_disable_plugin( $delete_config_file = true ) {
if ( file_exists( ABSPATH . 'wp-config.php') ) {
$global_config_file = ABSPATH . 'wp-config.php';
$global_config_file = dirname(ABSPATH) . '/wp-config.php';
if ( apply_filters( 'wpsc_enable_wp_config_edit', true ) ) {
$line = 'define(\'WP_CACHE\', true);';
strpos( file_get_contents( $global_config_file ), $line ) &&
! is_writeable_ACLSafe( $global_config_file ) ||
! wp_cache_replace_line( 'define*\(*\'WP_CACHE\'', '', $global_config_file )
wp_die( "Could not remove WP_CACHE define from $global_config_file. Please edit that file and remove the line containing the text 'WP_CACHE'. Then refresh this page." );
$line = 'define( \'WPCACHEHOME\',';
strpos( file_get_contents( $global_config_file ), $line ) &&
! is_writeable_ACLSafe( $global_config_file ) ||
! wp_cache_replace_line( 'define *\( *\'WPCACHEHOME\'', '', $global_config_file )
wp_die( "Could not remove WPCACHEHOME define from $global_config_file. Please edit that file and remove the line containing the text 'WPCACHEHOME'. Then refresh this page." );
} elseif ( function_exists( 'wp_cache_debug' ) ) {
wp_cache_debug( 'wp_cache_disable_plugin: not allowed to edit wp-config.php per configuration.' );
uninstall_supercache( WP_CONTENT_DIR . '/cache' );
$file_not_deleted = array();
wpsc_remove_advanced_cache();
if ( @file_exists( WP_CONTENT_DIR . "/advanced-cache.php" ) ) {
$file_not_deleted[] = WP_CONTENT_DIR . '/advanced-cache.php';
if ( $delete_config_file && @file_exists( WPCACHECONFIGPATH . "/wp-cache-config.php" ) ) {
if ( false == unlink( WPCACHECONFIGPATH . "/wp-cache-config.php" ) )
$file_not_deleted[] = WPCACHECONFIGPATH . '/wp-cache-config.php';
if ( ! empty( $file_not_deleted ) ) {
$msg = __( "Dear User,\n\nWP Super Cache was removed from your blog or deactivated but some files could\nnot be deleted.\n\n", 'wp-super-cache' );
foreach( (array)$file_not_deleted as $path ) {
$msg .= sprintf( __( "You should delete these files manually.\nYou may need to change the permissions of the files or parent directory.\nYou can read more about this in the Codex at\n%s\n\nThank you.", 'wp-super-cache' ), 'https://codex.wordpress.org/Changing_File_Permissions#About_Chmod' );
if ( apply_filters( 'wpsc_send_uninstall_errors', 1 ) ) {
wp_mail( get_option( 'admin_email' ), __( 'WP Super Cache: could not delete files', 'wp-super-cache' ), $msg );
extract( wpsc_get_htaccess_info() ); // $document_root, $apache_root, $home_path, $home_root, $home_root_lc, $inst_root, $wprules, $scrules, $condition_rules, $rules, $gziprules
if ( $scrules != '' && insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', array() ) ) {
$wp_rewrite->flush_rules();
} elseif( $scrules != '' ) {
wp_mail( get_option( 'admin_email' ), __( 'Supercache Uninstall Problems', 'wp-super-cache' ), sprintf( __( "Dear User,\n\nWP Super Cache was removed from your blog but the mod_rewrite rules\nin your .htaccess were not.\n\nPlease edit the following file and remove the code\nbetween 'BEGIN WPSuperCache' and 'END WPSuperCache'. Please backup the file first!\n\n%s\n\nRegards,\nWP Super Cache Plugin\nhttps://wordpress.org/plugins/wp-super-cache/", 'wp-super-cache' ), ABSPATH . '/.htaccess' ) );
function uninstall_supercache( $folderPath ) { // from http://www.php.net/manual/en/function.rmdir.php
if ( trailingslashit( constant( 'ABSPATH' ) ) == trailingslashit( $folderPath ) )
if ( @is_dir ( $folderPath ) ) {
$dh = @opendir($folderPath);
while( false !== ( $value = @readdir( $dh ) ) ) {
if ( $value != "." && $value != ".." ) {
$value = $folderPath . "/" . $value;
if ( @is_dir ( $value ) ) {
uninstall_supercache( $value );
return @rmdir( $folderPath );
function supercache_admin_bar_render() {
if ( function_exists( '_deprecated_function' ) ) {
_deprecated_function( __FUNCTION__, 'WP Super Cache 1.6.4' );
wpsc_admin_bar_render( $wp_admin_bar );
* returns true if preload is active
function wpsc_is_preload_active() {
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
if ( @file_exists( $cache_path . 'stop_preload.txt' ) ) {
if ( file_exists( $cache_path . 'preload_mutex.tmp' ) ) {
// check taxonomy preload loop
$taxonomies = apply_filters(
'wp_cache_preload_taxonomies',
'category' => 'category',
foreach ( $taxonomies as $taxonomy => $path ) {
$taxonomy_filename = $cache_path . 'taxonomy_' . $taxonomy . '.txt';
if ( file_exists( $taxonomy_filename ) ) {
// check post preload loop
$preload_cache_counter = get_option( 'preload_cache_counter' );
is_array( $preload_cache_counter )
&& isset( $preload_cache_counter['c'] )
&& $preload_cache_counter['c'] > 0
* This function will reset the preload cache counter
function wpsc_reset_preload_counter() {
* This function will reset all preload settings
function wpsc_reset_preload_settings() {
$mutex = $cache_path . 'preload_mutex.tmp';
wp_delete_file( $mutex );
wp_delete_file( $cache_path . 'stop_preload.txt' );
wpsc_reset_preload_counter();
$taxonomies = apply_filters(
'wp_cache_preload_taxonomies',
'category' => 'category',
foreach ( $taxonomies as $taxonomy => $path ) {
$taxonomy_filename = $cache_path . 'taxonomy_' . $taxonomy . '.txt';
wp_delete_file( $taxonomy_filename );
function wpsc_cancel_preload() {
$next_preload = wp_next_scheduled( 'wp_cache_preload_hook' );
$next_full_preload = wp_next_scheduled( 'wp_cache_full_preload_hook' );
if ( $next_preload || $next_full_preload ) {
wp_cache_debug( 'wpsc_cancel_preload: reset preload settings' );
wpsc_reset_preload_settings();
wp_cache_debug( 'wpsc_cancel_preload: unscheduling wp_cache_preload_hook' );
wp_unschedule_event( $next_preload, 'wp_cache_preload_hook' );
if ( $next_full_preload ) {
wp_cache_debug( 'wpsc_cancel_preload: unscheduling wp_cache_full_preload_hook' );
wp_unschedule_event( $next_full_preload, 'wp_cache_full_preload_hook' );
wp_cache_debug( 'wpsc_cancel_preload: creating stop_preload.txt' );
* Reset the preload settings, but also create the stop_preload.txt file to
* prevent the preload from starting again.
* By creating the stop_preload.txt file, we can be sure the preload will cancel.
wpsc_reset_preload_settings();
wpsc_create_stop_preload_flag();
wpsc_update_idle_preload( time() );
* The preload process checks for a file called stop_preload.txt and will stop if found.
* This function creates that file.
function wpsc_create_stop_preload_flag() {
// phpcs:ignore -- WordPress.WP.AlternativeFunctions.file_system_read_fopen WordPress.PHP.NoSilencedErrors.Discouraged
$fp = @fopen( $cache_path . 'stop_preload.txt', 'w' );
// phpcs:ignore -- WordPress.WP.AlternativeFunctions.file_system_operations_fclose WordPress.PHP.NoSilencedErrors.Discouraged
function wpsc_enable_preload() {
wpsc_reset_preload_settings();
wp_schedule_single_event( time() + 10, 'wp_cache_full_preload_hook' );
function wpsc_get_post_types() {
$preload_type_args = apply_filters( 'wpsc_preload_post_types_args', array(
'publicly_queryable' => true
$post_types = (array) apply_filters( 'wpsc_preload_post_types', get_post_types( $preload_type_args, 'names', 'or' ));
return "'" . implode( "', '", array_map( 'esc_sql', $post_types ) ) . "'";
function wpsc_post_count() {
$post_type_list = wpsc_get_post_types();
$count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type IN ( $post_type_list ) AND post_status = 'publish'" );
* Get the minimum interval in minutes between preload refreshes.
* Filter the default value of 10 minutes using the `wpsc_minimum_preload_interval` filter.