: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if ( false == isset( $cached_direct_pages ) )
$cached_direct_pages = array();
if ( $valid_nonce && array_key_exists('new_direct_page', $_POST) && $_POST[ 'new_direct_page' ] && '' != $_POST[ 'new_direct_page' ] ) {
$page = str_replace( get_option( 'siteurl' ), '', $_POST[ 'new_direct_page' ] );
$page = str_replace( '..', '', preg_replace( '/[ <>\'\"\r\n\t\(\)\$\[\];#]/', '', $page ) );
if ( substr( $page, 0, 1 ) != '/' )
if ( $page != '/' || false == is_array( $cached_direct_pages ) || in_array( $page, $cached_direct_pages ) == false ) {
$cached_direct_pages[] = $page;
@unlink( trailingslashit( ABSPATH . $page ) . "index.html" );
wpsc_delete_files( get_supercache_dir() . $page );
$out = substr( $out, 0, -2 );
$out = '$cached_direct_pages = array( ' . $out . ' );';
wp_cache_replace_line('^ *\$cached_direct_pages', "$out", $wp_cache_config_file);
if ( !empty( $expiredfiles ) ) {
foreach( $expiredfiles as $file ) {
$firstfolder = explode( '/', $file );
$firstfolder = ABSPATH . $firstfolder[1];
$file = realpath( str_replace( '..', '', preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', $file ) ) );
@unlink( trailingslashit( $file ) . "index.html" );
@unlink( trailingslashit( $file ) . "index.html.gz" );
RecursiveFolderDelete( trailingslashit( $firstfolder ) );
if ( $valid_nonce && array_key_exists('deletepage', $_POST) && $_POST[ 'deletepage' ] ) {
$page = str_replace( '..', '', preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', $_POST['deletepage'] ) ) . '/';
$pagefile = realpath( ABSPATH . $page . 'index.html' );
if ( substr( $pagefile, 0, strlen( ABSPATH ) ) != ABSPATH || false == wp_cache_confirm_delete( ABSPATH . $page ) ) {
die( __( 'Cannot delete directory', 'wp-super-cache' ) );
$firstfolder = explode( '/', $page );
$firstfolder = ABSPATH . $firstfolder[1];
if( is_file( $pagefile ) && is_writeable_ACLSafe( $pagefile ) && is_writeable_ACLSafe( $firstfolder ) ) {
@unlink( $pagefile . '.gz' );
RecursiveFolderDelete( $firstfolder );
return $cached_direct_pages;
function wpsc_lockdown() {
global $cached_direct_pages, $cache_enabled, $super_cache_enabled;
$admin_url = admin_url( 'options-general.php?page=wpsupercache' );
$wp_lock_down = wp_update_lock_down();
compact( 'cached_direct_pages', 'cache_enabled', 'super_cache_enabled', 'admin_url', 'wp_lock_down' )
function RecursiveFolderDelete ( $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 ) ) {
RecursiveFolderDelete ( $value );
return @rmdir ( $folderPath );
function wp_cache_time_update() {
global $cache_max_time, $wp_cache_config_file, $valid_nonce, $cache_schedule_type, $cache_scheduled_time, $cache_schedule_interval, $cache_time_interval, $cache_gc_email_me;
if ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'expirytime' ) {
if ( false == $valid_nonce )
if( !isset( $cache_schedule_type ) ) {
$cache_schedule_type = 'interval';
wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
if( !isset( $cache_scheduled_time ) ) {
$cache_scheduled_time = '00:00';
wp_cache_replace_line('^ *\$cache_scheduled_time', "\$cache_scheduled_time = '$cache_scheduled_time';", $wp_cache_config_file);
if( !isset( $cache_max_time ) ) {
wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
if ( !isset( $cache_time_interval ) ) {
$cache_time_interval = $cache_max_time;
wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file);
if ( isset( $_POST['wp_max_time'] ) ) {
$cache_max_time = (int)$_POST['wp_max_time'];
wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
if ( false == wp_next_scheduled( 'wp_cache_gc_watcher' ) )
wp_schedule_event( time()+600, 'hourly', 'wp_cache_gc_watcher' );
if ( isset( $_POST[ 'cache_gc_email_me' ] ) ) {
wp_cache_replace_line('^ *\$cache_gc_email_me', "\$cache_gc_email_me = $cache_gc_email_me;", $wp_cache_config_file);
wp_cache_replace_line('^ *\$cache_gc_email_me', "\$cache_gc_email_me = $cache_gc_email_me;", $wp_cache_config_file);
if ( isset( $_POST[ 'cache_schedule_type' ] ) && $_POST[ 'cache_schedule_type' ] == 'interval' && isset( $_POST['cache_time_interval'] ) ) {
wp_clear_scheduled_hook( 'wp_cache_gc' );
$cache_schedule_type = 'interval';
if ( (int)$_POST[ 'cache_time_interval' ] == 0 )
$_POST[ 'cache_time_interval' ] = 600;
$cache_time_interval = (int)$_POST[ 'cache_time_interval' ];
wp_schedule_single_event( time() + $cache_time_interval, 'wp_cache_gc' );
wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file);
wp_clear_scheduled_hook( 'wp_cache_gc' );
$cache_schedule_type = 'time';
if ( !isset( $_POST[ 'cache_scheduled_time' ] ) ||
$_POST[ 'cache_scheduled_time' ] == '' ||
5 != strlen( $_POST[ 'cache_scheduled_time' ] ) ||
":" != substr( $_POST[ 'cache_scheduled_time' ], 2, 1 )
$_POST[ 'cache_scheduled_time' ] = '00:00';
$cache_scheduled_time = $_POST[ 'cache_scheduled_time' ];
if ( ! preg_match( '/[0-9][0-9]:[0-9][0-9]/', $cache_scheduled_time ) ) {
$cache_scheduled_time = '00:00';
$schedules = wp_get_schedules();
if ( !isset( $cache_schedule_interval ) )
$cache_schedule_interval = 'daily';
if ( isset( $_POST[ 'cache_schedule_interval' ] ) && isset( $schedules[ $_POST[ 'cache_schedule_interval' ] ] ) )
$cache_schedule_interval = $_POST[ 'cache_schedule_interval' ];
wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
wp_cache_replace_line('^ *\$cache_schedule_interval', "\$cache_schedule_interval = '{$cache_schedule_interval}';", $wp_cache_config_file);
wp_cache_replace_line('^ *\$cache_scheduled_time', "\$cache_scheduled_time = '$cache_scheduled_time';", $wp_cache_config_file);
wp_schedule_event( strtotime( $cache_scheduled_time ), $cache_schedule_interval, 'wp_cache_gc' );
function wp_cache_sanitize_value($text, & $array) {
$text = esc_html(strip_tags($text));
$array = preg_split( '/[\s,]+/', rtrim( $text ) );
$text = var_export($array, true);
$text = preg_replace('/[\s]+/', ' ', $text);
function wp_cache_update_rejected_ua() {
global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce;
if ( !function_exists( 'apache_request_headers' ) ) return;
if ( isset( $_POST[ 'wp_rejected_user_agent' ] ) && $valid_nonce ) {
$_POST[ 'wp_rejected_user_agent' ] = str_replace( ' ', '___', $_POST[ 'wp_rejected_user_agent' ] );
$text = str_replace( '___', ' ', wp_cache_sanitize_value( $_POST[ 'wp_rejected_user_agent' ], $cache_rejected_user_agent ) );
wp_cache_replace_line( '^ *\$cache_rejected_user_agent', "\$cache_rejected_user_agent = $text;", $wp_cache_config_file );
foreach( $cache_rejected_user_agent as $k => $ua ) {
$cache_rejected_user_agent[ $k ] = str_replace( '___', ' ', $ua );
reset( $cache_rejected_user_agent );
function wpsc_edit_rejected_ua() {
global $cache_rejected_user_agent;
if ( ! function_exists( 'apache_request_headers' ) ) {
$admin_url = admin_url( 'options-general.php?page=wpsupercache' );
wp_cache_update_rejected_ua();
compact( 'cache_rejected_user_agent', 'admin_url' )
function wp_cache_update_rejected_pages() {
global $wp_cache_config_file, $valid_nonce, $wp_cache_pages;
if ( isset( $_POST[ 'wp_edit_rejected_pages' ] ) && $valid_nonce ) {
$pages = array( 'single', 'pages', 'archives', 'tag', 'frontpage', 'home', 'category', 'feed', 'author', 'search' );
foreach( $pages as $page ) {
if ( isset( $_POST[ 'wp_cache_pages' ][ $page ] ) ) {
wp_cache_replace_line('^ *\$wp_cache_pages\[ "' . $page . '" \]', "\$wp_cache_pages[ \"{$page}\" ] = $value;", $wp_cache_config_file);
$wp_cache_pages[ $page ] = $value;
function wpsc_update_tracking_parameters() {
global $wpsc_tracking_parameters, $valid_nonce, $wp_cache_config_file;
if ( isset( $_POST['tracking_parameters'] ) && $valid_nonce ) {
$text = wp_cache_sanitize_value( str_replace( '\\\\', '\\', $_POST['tracking_parameters'] ), $wpsc_tracking_parameters );
wp_cache_replace_line( '^ *\$wpsc_tracking_parameters', "\$wpsc_tracking_parameters = $text;", $wp_cache_config_file );
wp_cache_setting( 'wpsc_ignore_tracking_parameters', isset( $_POST['wpsc_ignore_tracking_parameters'] ) ? 1 : 0 );
function wpsc_edit_tracking_parameters() {
global $wpsc_tracking_parameters, $wpsc_ignore_tracking_parameters;
$admin_url = admin_url( 'options-general.php?page=wpsupercache' );
wpsc_update_tracking_parameters();
if ( ! isset( $wpsc_tracking_parameters ) ) {
$wpsc_tracking_parameters = array( 'fbclid', 'ref', 'gclid', 'fb_source', 'mc_cid', 'mc_eid', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'utm_expid', 'mtm_source', 'mtm_medium', 'mtm_campaign', 'mtm_keyword', 'mtm_content', 'mtm_cid', 'mtm_group', 'mtm_placement' );
if ( ! isset( $wpsc_ignore_tracking_parameters ) ) {
$wpsc_ignore_tracking_parameters = 0;
compact( 'wpsc_ignore_tracking_parameters', 'wpsc_tracking_parameters', 'admin_url' )
function wp_cache_update_rejected_cookies() {
global $wpsc_rejected_cookies, $wp_cache_config_file, $valid_nonce;
if ( isset( $_POST['wp_rejected_cookies'] ) && $valid_nonce ) {
$text = wp_cache_sanitize_value( str_replace( '\\\\', '\\', $_POST['wp_rejected_cookies'] ), $wpsc_rejected_cookies );
wp_cache_replace_line( '^ *\$wpsc_rejected_cookies', "\$wpsc_rejected_cookies = $text;", $wp_cache_config_file );
function wp_cache_update_rejected_strings() {
global $cache_rejected_uri, $wp_cache_config_file, $valid_nonce;
if ( isset($_REQUEST['wp_rejected_uri']) && $valid_nonce ) {
$text = wp_cache_sanitize_value( str_replace( '\\\\', '\\', $_REQUEST['wp_rejected_uri'] ), $cache_rejected_uri );
wp_cache_replace_line('^ *\$cache_rejected_uri', "\$cache_rejected_uri = $text;", $wp_cache_config_file);
function wp_cache_update_accepted_strings() {
global $cache_acceptable_files, $wp_cache_config_file, $valid_nonce;
if ( isset( $_REQUEST[ 'wp_accepted_files' ] ) && $valid_nonce ) {
$text = wp_cache_sanitize_value( $_REQUEST[ 'wp_accepted_files' ], $cache_acceptable_files );
wp_cache_replace_line( '^ *\$cache_acceptable_files', "\$cache_acceptable_files = $text;", $wp_cache_config_file );
function wpsc_update_debug_settings() {
global $wp_super_cache_debug, $wp_cache_debug_log, $wp_cache_debug_ip, $cache_path, $valid_nonce, $wp_cache_config_file, $wp_super_cache_comments;
global $wp_super_cache_front_page_check, $wp_super_cache_front_page_clear, $wp_super_cache_front_page_text, $wp_super_cache_front_page_notification, $wp_super_cache_advanced_debug;
global $wp_cache_debug_username;
if ( ! isset( $wp_super_cache_comments ) ) {
$wp_super_cache_comments = 1; // defaults to "enabled".
wp_cache_setting( 'wp_super_cache_comments', $wp_super_cache_comments );
if ( false == $valid_nonce ) {
'wp_super_cache_debug' => $wp_super_cache_debug,
'wp_cache_debug_log' => $wp_cache_debug_log,
'wp_cache_debug_ip' => $wp_cache_debug_ip,
'wp_super_cache_comments' => $wp_super_cache_comments,
'wp_super_cache_front_page_check' => $wp_super_cache_front_page_check,
'wp_super_cache_front_page_clear' => $wp_super_cache_front_page_clear,
'wp_super_cache_front_page_text' => $wp_super_cache_front_page_text,
'wp_super_cache_front_page_notification' => $wp_super_cache_front_page_notification,
'wp_super_cache_advanced_debug' => $wp_super_cache_advanced_debug,
'wp_cache_debug_username' => $wp_cache_debug_username,
if ( isset( $_POST[ 'wpsc_delete_log' ] ) && $_POST[ 'wpsc_delete_log' ] == 1 && $wp_cache_debug_log != '' ) {
@unlink( $cache_path . $wp_cache_debug_log );
extract( wpsc_create_debug_log( $wp_cache_debug_log, $wp_cache_debug_username ) ); // $wp_cache_debug_log, $wp_cache_debug_username
if ( ! isset( $wp_cache_debug_log ) || $wp_cache_debug_log == '' ) {
extract( wpsc_create_debug_log() ); // $wp_cache_debug_log, $wp_cache_debug_username
} elseif ( ! file_exists( $cache_path . $wp_cache_debug_log ) ) { // make sure debug log exists before toggling debugging
extract( wpsc_create_debug_log( $wp_cache_debug_log, $wp_cache_debug_username ) ); // $wp_cache_debug_log, $wp_cache_debug_username
$wp_super_cache_debug = ( isset( $_POST[ 'wp_super_cache_debug' ] ) && $_POST[ 'wp_super_cache_debug' ] == 1 ) ? 1 : 0;
wp_cache_setting( 'wp_super_cache_debug', $wp_super_cache_debug );
if ( isset( $_POST[ 'wp_cache_debug' ] ) ) {
wp_cache_setting( 'wp_cache_debug_username', $wp_cache_debug_username );
wp_cache_setting( 'wp_cache_debug_log', $wp_cache_debug_log );
$wp_super_cache_comments = isset( $_POST[ 'wp_super_cache_comments' ] ) ? 1 : 0;
wp_cache_setting( 'wp_super_cache_comments', $wp_super_cache_comments );
if ( isset( $_POST[ 'wp_cache_debug_ip' ] ) && filter_var( $_POST[ 'wp_cache_debug_ip' ], FILTER_VALIDATE_IP ) ) {
$wp_cache_debug_ip = esc_html( preg_replace( '/[ <>\'\"\r\n\t\(\)\$\[\];#]/', '', $_POST[ 'wp_cache_debug_ip' ] ) );
wp_cache_setting( 'wp_cache_debug_ip', $wp_cache_debug_ip );
$wp_super_cache_front_page_check = isset( $_POST[ 'wp_super_cache_front_page_check' ] ) ? 1 : 0;
wp_cache_setting( 'wp_super_cache_front_page_check', $wp_super_cache_front_page_check );
$wp_super_cache_front_page_clear = isset( $_POST[ 'wp_super_cache_front_page_clear' ] ) ? 1 : 0;
wp_cache_setting( 'wp_super_cache_front_page_clear', $wp_super_cache_front_page_clear );
if ( isset( $_POST[ 'wp_super_cache_front_page_text' ] ) ) {
$wp_super_cache_front_page_text = esc_html( preg_replace( '/[ <>\'\"\r\n\t\(\)\$\[\];#]/', '', $_POST[ 'wp_super_cache_front_page_text' ] ) );
$wp_super_cache_front_page_text = '';
wp_cache_setting( 'wp_super_cache_front_page_text', $wp_super_cache_front_page_text );
$wp_super_cache_front_page_notification = isset( $_POST[ 'wp_super_cache_front_page_notification' ] ) ? 1 : 0;
wp_cache_setting( 'wp_super_cache_front_page_notification', $wp_super_cache_front_page_notification );
if ( $wp_super_cache_front_page_check == 1 && !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
wp_cache_debug( 'scheduled wp_cache_check_site_hook for 360 seconds time.' );
'wp_super_cache_debug' => $wp_super_cache_debug,
'wp_cache_debug_log' => $wp_cache_debug_log,
'wp_cache_debug_ip' => $wp_cache_debug_ip,
'wp_super_cache_comments' => $wp_super_cache_comments,
'wp_super_cache_front_page_check' => $wp_super_cache_front_page_check,
'wp_super_cache_front_page_clear' => $wp_super_cache_front_page_clear,
'wp_super_cache_front_page_text' => $wp_super_cache_front_page_text,
'wp_super_cache_front_page_notification' => $wp_super_cache_front_page_notification,
'wp_super_cache_advanced_debug' => $wp_super_cache_advanced_debug,
'wp_cache_debug_username' => $wp_cache_debug_username,
function wp_cache_enable() {
global $wp_cache_config_file, $cache_enabled;
wp_cache_debug( 'wp_cache_enable: already enabled' );
wp_cache_setting( 'cache_enabled', true );
wp_cache_debug( 'wp_cache_enable: enable cache' );
if ( wpsc_set_default_gc() ) {
// gc might not be scheduled, check and schedule
$timestamp = wp_next_scheduled( 'wp_cache_gc' );
if ( false == $timestamp ) {
wp_schedule_single_event( time() + 600, 'wp_cache_gc' );
function wp_cache_disable() {
global $wp_cache_config_file, $cache_enabled;
if ( ! $cache_enabled ) {
wp_cache_debug( 'wp_cache_disable: already disabled' );
wp_cache_setting( 'cache_enabled', false );
wp_cache_debug( 'wp_cache_disable: disable cache' );
wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
wp_clear_scheduled_hook( 'wp_cache_gc' );
wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
function wp_super_cache_enable() {
global $supercachedir, $wp_cache_config_file, $super_cache_enabled;
if ( $super_cache_enabled ) {
wp_cache_debug( 'wp_super_cache_enable: already enabled' );
wp_cache_setting( 'super_cache_enabled', true );
wp_cache_debug( 'wp_super_cache_enable: enable cache' );
$super_cache_enabled = true;
if ( ! $supercachedir ) {
$supercachedir = get_supercache_dir();
if ( is_dir( $supercachedir . '.disabled' ) ) {
if ( is_dir( $supercachedir ) ) {
prune_super_cache( $supercachedir . '.disabled', true );
@unlink( $supercachedir . '.disabled' );
@rename( $supercachedir . '.disabled', $supercachedir );
function wp_super_cache_disable() {
global $cache_path, $supercachedir, $wp_cache_config_file, $super_cache_enabled;
if ( ! $super_cache_enabled ) {
wp_cache_debug( 'wp_super_cache_disable: already disabled' );
wp_cache_setting( 'super_cache_enabled', false );
wp_cache_debug( 'wp_super_cache_disable: disable cache' );
$super_cache_enabled = false;
if ( ! $supercachedir ) {
$supercachedir = get_supercache_dir();
if ( is_dir( $supercachedir ) ) {
@rename( $supercachedir, $supercachedir . '.disabled' );
sleep( 1 ); // allow existing processes to write to the supercachedir and then delete it
if ( function_exists( 'prune_super_cache' ) && is_dir( $supercachedir ) ) {
prune_super_cache( $cache_path, true );
if ( $GLOBALS['wp_cache_mod_rewrite'] === 1 ) {
remove_mod_rewrite_rules();
function wp_cache_is_enabled() {
global $wp_cache_config_file;
if ( get_option( 'gzipcompression' ) ) {
echo '<strong>' . __( 'Warning', 'wp-super-cache' ) . '</strong>: ' . __( 'GZIP compression is enabled in WordPress, wp-cache will be bypassed until you disable gzip compression.', 'wp-super-cache' );
$lines = file( $wp_cache_config_file );
foreach ( $lines as $line ) {
if ( preg_match( '/^\s*\$cache_enabled\s*=\s*true\s*;/', $line ) ) {
function wp_cache_remove_index() {
if ( empty( $cache_path ) ) {
@unlink( $cache_path . "index.html" );
@unlink( $cache_path . "supercache/index.html" );
@unlink( $cache_path . "blogs/index.html" );
if ( is_dir( $cache_path . "blogs" ) ) {
$dir = new DirectoryIterator( $cache_path . "blogs" );
foreach( $dir as $fileinfo ) {
if ( $fileinfo->isDot() ) {
if ( $fileinfo->isDir() ) {
$directory = $cache_path . "blogs/" . $fileinfo->getFilename();
if ( is_file( $directory . "/index.html" ) ) {