: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
unlink( $directory . "/index.html" );
if ( is_dir( $directory . "/meta" ) ) {
if ( is_file( $directory . "/meta/index.html" ) ) {
unlink( $directory . "/meta/index.html" );
function wp_cache_index_notice() {
global $wp_version, $cache_path;
if ( false == wpsupercache_site_admin() )
if ( false == get_site_option( 'wp_super_cache_index_detected' ) )
if ( strlen( $cache_path ) < strlen( ABSPATH )
|| ABSPATH != substr( $cache_path, 0, strlen( ABSPATH ) ) )
return false; // cache stored outside web root
if ( get_site_option( 'wp_super_cache_index_detected' ) == 2 ) {
update_site_option( 'wp_super_cache_index_detected', 3 );
echo "<div class='error' style='padding: 10px 10px 50px 10px'>";
echo "<h2>" . __( 'WP Super Cache Warning!', 'wp-super-cache' ) . '</h2>';
echo '<p>' . __( 'All users of this site have been logged out to refresh their login cookies.', 'wp-super-cache' ) . '</p>';
} elseif ( get_site_option( 'wp_super_cache_index_detected' ) != 3 ) {
echo "<div id='wpsc-index-warning' class='error notice' style='padding: 10px 10px 50px 10px'>";
echo "<h2>" . __( 'WP Super Cache Warning!', 'wp-super-cache' ) . '</h2>';
echo '<p>' . __( 'Your server is configured to show files and directories, which may expose sensitive data such as login cookies to attackers in the cache directories. That has been fixed by adding a file named index.html to each directory. If you use simple caching, consider moving the location of the cache directory on the Advanced Settings page.', 'wp-super-cache' ) . '</p>';
_e( 'If you just installed WP Super Cache for the first time, you can dismiss this message. Otherwise, you should probably refresh the login cookies of all logged in WordPress users here by clicking the logout link below.', 'wp-super-cache' );
if ( -1 == version_compare( $wp_version, '4.0' ) ) {
echo '<p>' . __( 'Your site is using a very old version of WordPress. When you update to the latest version everyone will be logged out and cookie information updated.', 'wp-super-cache' ) . '</p>';
echo '<p>' . __( 'The logout link will log out all WordPress users on this site except you. Your authentication cookie will be updated, but you will not be logged out.', 'wp-super-cache' ) . '</p>';
echo "<a id='wpsc-dismiss' href='#'>" . __( 'Dismiss', 'wp-super-cache' ) . "</a>";
if ( 1 == version_compare( $wp_version, '4.0' ) ) {
echo " | <a href='" . wp_nonce_url( admin_url( '?action=wpsclogout' ), 'wpsc_logout' ) . "'>" . __( 'Logout', 'wp-super-cache' ) . "</a>";
<script type='text/javascript'>
jQuery(document).ready(function(){
jQuery('#wpsc-dismiss').on("click",function() {
type: "post",url: "admin-ajax.php",data: { action: 'wpsc-index-dismiss', _ajax_nonce: '<?php echo wp_create_nonce( 'wpsc-index-dismiss' ); ?>' },
beforeSend: function() {jQuery("#wpsc-index-warning").fadeOut('slow');},
add_action( 'admin_notices', 'wp_cache_index_notice' );
function wpsc_config_file_notices() {
global $wp_cache_config_file;
if ( ! isset( $_GET['page'] ) || $_GET['page'] != 'wpsupercache' ) {
$notice = get_transient( 'wpsc_config_error' );
case 'error_move_tmp_config_file':
$msg = sprintf( __( 'Error: Could not rename temporary file to configuration file. Please make sure %s is writeable by the webserver.' ), $wp_cache_config_file );
$msg = sprintf( __( 'Error: Configuration file is read only. Please make sure %s is writeable by the webserver.' ), $wp_cache_config_file );
$msg = sprintf( __( 'Error: The directory containing the configuration file %s is read only. Please make sure it is writeable by the webserver.' ), $wp_cache_config_file );
case 'config_file_not_loaded':
$msg = sprintf( __( 'Error: Configuration file %s could not be loaded. Please reload the page.' ), $wp_cache_config_file );
case 'config_file_missing':
$msg = sprintf( __( 'Error: Configuration file %s is missing. Please reload the page.' ), $wp_cache_config_file );
echo '<div class="error"><p><strong>' . $msg . '</strong></p></div>';
add_action( 'admin_notices', 'wpsc_config_file_notices' );
function wpsc_dismiss_indexhtml_warning() {
check_ajax_referer( "wpsc-index-dismiss" );
update_site_option( 'wp_super_cache_index_detected', 3 );
add_action( 'wp_ajax_wpsc-index-dismiss', 'wpsc_dismiss_indexhtml_warning' );
function wp_cache_logout_all() {
if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'wpsclogout' && wp_verify_nonce( $_GET[ '_wpnonce' ], 'wpsc_logout' ) ) {
$user_id = $current_user->ID;
WP_Session_Tokens::destroy_all_for_all_users();
wp_set_auth_cookie( $user_id, false, is_ssl() );
update_site_option( 'wp_super_cache_index_detected', 2 );
wp_redirect( admin_url() );
if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'wpsclogout' )
add_action( 'admin_init', 'wp_cache_logout_all' );
function wp_cache_add_index_protection() {
global $cache_path, $blog_cache_dir;
if ( is_dir( $cache_path ) && false == is_file( "$cache_path/index.html" ) ) {
$page = wp_remote_get( home_url( "/wp-content/cache/" ) );
if ( false == is_wp_error( $page ) ) {
if ( false == get_site_option( 'wp_super_cache_index_detected' )
&& $page[ 'response' ][ 'code' ] == 200
&& stripos( $page[ 'body' ], 'index of' ) ) {
add_site_option( 'wp_super_cache_index_detected', 1 ); // only show this once
if ( ! function_exists( 'insert_with_markers' ) ) {
include_once( ABSPATH . 'wp-admin/includes/misc.php' );
insert_with_markers( $cache_path . '.htaccess', "INDEX", array( 'Options -Indexes' ) );
$directories = array( $cache_path, $cache_path . '/supercache/', $cache_path . '/blogs/', $blog_cache_dir, $blog_cache_dir . "/meta" );
foreach( $directories as $dir ) {
if ( false == is_dir( $dir ) )
if ( is_dir( $dir ) && false == is_file( "$dir/index.html" ) ) {
$fp = @fopen( "$dir/index.html", 'w' );
function wp_cache_add_site_cache_index() {
wp_cache_add_index_protection(); // root and supercache
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 ( false == is_file( $directory . "/index.html" ) ) {
$fp = @fopen( $directory . "/index.html", 'w' );
if ( is_dir( $directory . "/meta" ) ) {
if ( false == is_file( $directory . "/meta/index.html" ) ) {
$fp = @fopen( $directory . "/meta/index.html", 'w' );
function wp_cache_verify_cache_dir() {
global $cache_path, $blog_cache_dir;
$dir = dirname($cache_path);
if ( !file_exists($cache_path) ) {
if ( !is_writeable_ACLSafe( $dir ) || !($dir = mkdir( $cache_path ) ) ) {
echo "<strong>" . __( 'Error', 'wp-super-cache' ) . ":</strong> " . sprintf( __( 'Your cache directory (<strong>%1$s</strong>) did not exist and couldn’t be created by the web server. Check %1$s permissions.', 'wp-super-cache' ), $dir );
if ( !is_writeable_ACLSafe($cache_path)) {
echo "<strong>" . __( 'Error', 'wp-super-cache' ) . ":</strong> " . sprintf( __( 'Your cache directory (<strong>%1$s</strong>) or <strong>%2$s</strong> need to be writable for this plugin to work. Double-check it.', 'wp-super-cache' ), $cache_path, $dir );
if ( '/' != substr($cache_path, -1)) {
if( false == is_dir( $blog_cache_dir ) ) {
@mkdir( $cache_path . "blogs" );
if( $blog_cache_dir != $cache_path . "blogs/" )
@mkdir( $blog_cache_dir );
if( false == is_dir( $blog_cache_dir . 'meta' ) )
@mkdir( $blog_cache_dir . 'meta' );
wp_cache_add_index_protection();
function wp_cache_verify_config_file() {
global $wp_cache_config_file, $wp_cache_config_file_sample, $sem_id, $cache_path;
$dir = dirname($wp_cache_config_file);
if ( file_exists($wp_cache_config_file) ) {
$lines = implode( ' ', file( $wp_cache_config_file ) );
if ( ! str_contains( $lines, 'WPCACHEHOME' ) ) {
if( is_writeable_ACLSafe( $wp_cache_config_file ) ) {
@unlink( $wp_cache_config_file );
echo "<strong>" . __( 'Error', 'wp-super-cache' ) . ":</strong> " . sprintf( __( 'Your WP-Cache config file (<strong>%s</strong>) is out of date and not writable by the Web server. Please delete it and refresh this page.', 'wp-super-cache' ), $wp_cache_config_file );
} elseif( !is_writeable_ACLSafe($dir)) {
echo "<strong>" . __( 'Error', 'wp-super-cache' ) . ":</strong> " . sprintf( __( 'Configuration file missing and %1$s directory (<strong>%2$s</strong>) is not writable by the web server. Check its permissions.', 'wp-super-cache' ), WP_CONTENT_DIR, $dir );
if ( !file_exists($wp_cache_config_file) ) {
if ( !file_exists($wp_cache_config_file_sample) ) {
echo "<strong>" . __( 'Error', 'wp-super-cache' ) . ":</strong> " . sprintf( __( 'Sample WP-Cache config file (<strong>%s</strong>) does not exist. Verify your installation.', 'wp-super-cache' ), $wp_cache_config_file_sample );
copy($wp_cache_config_file_sample, $wp_cache_config_file);
$dir = str_replace( str_replace( '\\', '/', WP_CONTENT_DIR ), '', str_replace( '\\', '/', __DIR__ ) );
if ( is_file( __DIR__ . '/wp-cache-config-sample.php' ) ) {
wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/\" );", $wp_cache_config_file);
} elseif ( is_file( __DIR__ . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/wp-super-cache/\" );", $wp_cache_config_file);
if ( $sem_id == 5419 && $cache_path != '' && $WPSC_HTTP_HOST != '' ) {
$sem_id = crc32( $WPSC_HTTP_HOST . $cache_path ) & 0x7fffffff;
wp_cache_replace_line('sem_id', '$sem_id = ' . $sem_id . ';', $wp_cache_config_file);
require($wp_cache_config_file);
wpsc_set_default_gc( true );
function wp_cache_create_advanced_cache() {
global $wpsc_advanced_cache_filename, $wpsc_advanced_cache_dist_filename;
if ( file_exists( ABSPATH . 'wp-config.php') ) {
$global_config_file = ABSPATH . 'wp-config.php';
} elseif ( file_exists( dirname( ABSPATH ) . '/wp-config.php' ) ) {
$global_config_file = dirname( ABSPATH ) . '/wp-config.php';
} elseif ( defined( 'DEBIAN_FILE' ) && file_exists( DEBIAN_FILE ) ) {
$global_config_file = DEBIAN_FILE;
die('Cannot locate wp-config.php');
$line = 'define( \'WPCACHEHOME\', \'' . __DIR__ . '/\' );';
if ( ! apply_filters( 'wpsc_enable_wp_config_edit', true ) ) {
echo '<div class="notice notice-error"><h4>' . __( 'Warning', 'wp-super-cache' ) . "! " . sprintf( __( 'Not allowed to edit %s per configuration.', 'wp-super-cache' ), $global_config_file ) . "</h4></div>";
! strpos( file_get_contents( $global_config_file ), "WPCACHEHOME" ) ||
defined( 'WPCACHEHOME' ) &&
constant( 'WPCACHEHOME' ) == '' ||
constant( 'WPCACHEHOME' ) != '' &&
! file_exists( constant( 'WPCACHEHOME' ) . '/wp-cache.php' )
! is_writeable_ACLSafe( $global_config_file ) ||
! wp_cache_replace_line( 'define *\( *\'WPCACHEHOME\'', $line, $global_config_file )
echo '<div class="notice notice-error"><h4>' . __( 'Warning', 'wp-super-cache' ) . "! <em>" . sprintf( __( 'Could not update %s!</em> WPCACHEHOME must be set in config file.', 'wp-super-cache' ), $global_config_file ) . "</h4></div>";
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" )
$file = file_get_contents( $wpsc_advanced_cache_dist_filename );
$fp = @fopen( $wpsc_advanced_cache_filename, 'w' );
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite
do_action( 'wpsc_created_advanced_cache' );
* 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 ) ) {
$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' ) ) {
if ( str_contains( $contents, 'WP SUPER CACHE 0.8.9.1' ) || str_contains( $contents, 'WP SUPER CACHE 1.2' ) ) {
function wpsc_check_advanced_cache() {
global $wpsc_advanced_cache_filename;
$other_advanced_cache = false;
if ( file_exists( $wpsc_advanced_cache_filename ) ) {
$cache_type = wpsc_identify_advanced_cache();
$other_advanced_cache = 'BOOST';
$other_advanced_cache = true;
$ret = wp_cache_create_advanced_cache();
if ( $other_advanced_cache === 'BOOST' ) {
wpsc_deactivate_boost_cache_notice();
} elseif ( $other_advanced_cache ) {
echo '<div style="width: 50%" class="notice notice-error"><h2>' . __( 'Warning! You may not be allowed to use this plugin on your site.', 'wp-super-cache' ) . "</h2>";
__( 'The file %s was created by another plugin or by your system administrator. Please examine the file carefully by FTP or SSH and consult your hosting documentation. ', 'wp-super-cache' ),
$wpsc_advanced_cache_filename
__( 'If it was created by another caching plugin please uninstall that plugin first before activating WP Super Cache. If the file is not removed by that action you should delete the file manually.', 'wp-super-cache' ),
__( 'If you need support for this problem contact your hosting provider.', 'wp-super-cache' ),
} elseif ( ! is_writeable_ACLSafe( $wpsc_advanced_cache_filename ) ) {
echo '<div class="notice notice-error"><h2>' . __( 'Warning', 'wp-super-cache' ) . "! <em>" . sprintf( __( '%s/advanced-cache.php</em> cannot be updated.', 'wp-super-cache' ), WP_CONTENT_DIR ) . "</h2>";
__( 'Make %1$s writable using the chmod command through your ftp or server software. (<em>chmod 777 %1$s</em>) and refresh this page. This is only a temporary measure and you’ll have to make it read only afterwards again. (Change 777 to 755 in the previous command)', 'wp-super-cache' ),
echo "<li>" . sprintf( __( 'Refresh this page to update <em>%s/advanced-cache.php</em>', 'wp-super-cache' ), WP_CONTENT_DIR ) . "</li></ol>";
echo sprintf( __( 'If that doesn’t work, make sure the file <em>%s/advanced-cache.php</em> doesn’t exist:', 'wp-super-cache' ), WP_CONTENT_DIR ) . "<ol>";
function wp_cache_check_global_config() {
global $wp_cache_check_wp_config;
if ( !isset( $wp_cache_check_wp_config ) )
if ( file_exists( ABSPATH . 'wp-config.php') ) {
$global_config_file = ABSPATH . 'wp-config.php';
$global_config_file = dirname( ABSPATH ) . '/wp-config.php';
if ( preg_match( '#^\s*(define\s*\(\s*[\'"]WP_CACHE[\'"]|const\s+WP_CACHE\s*=)#m', file_get_contents( $global_config_file ) ) === 1 ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
if ( defined( 'WP_CACHE' ) && ! constant( 'WP_CACHE' ) ) {
<div class="notice notice-error"><h4><?php esc_html_e( 'WP_CACHE constant set to false', 'wp-super-cache' ); ?></h4>
<p><?php esc_html_e( 'The WP_CACHE constant is used by WordPress to load the code that serves cached pages. Unfortunately, it is set to false. Please edit your wp-config.php and add or edit the following line above the final require_once command:', 'wp-super-cache' ); ?></p>
<p><code>define('WP_CACHE', true);</code></p></div>
$line = 'define(\'WP_CACHE\', true);';
! is_writeable_ACLSafe( $global_config_file ) ||
! wp_cache_replace_line( 'define *\( *\'WP_CACHE\'', $line, $global_config_file )
if ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) {
echo '<div class="notice notice-error">' . __( "<h4>WP_CACHE constant set to false</h4><p>The WP_CACHE constant is used by WordPress to load the code that serves cached pages. Unfortunately, it is set to false. Please edit your wp-config.php and add or edit the following line above the final require_once command:<br /><br /><code>define('WP_CACHE', true);</code></p>", 'wp-super-cache' ) . "</div>";
echo '<div class="notice notice-error"><p>' . __( "<strong>Error: WP_CACHE is not enabled</strong> in your <code>wp-config.php</code> file and I couldn’t modify it.", 'wp-super-cache' ) . "</p>";
echo "<p>" . sprintf( __( "Edit <code>%s</code> and add the following line:<br /> <code>define('WP_CACHE', true);</code><br />Otherwise, <strong>WP-Cache will not be executed</strong> by WordPress core. ", 'wp-super-cache' ), $global_config_file ) . "</p></div>";
echo "<div class='notice notice-warning'>" . __( '<h4>WP_CACHE constant added to wp-config.php</h4><p>If you continue to see this warning message please see point 5 of the <a href="https://wordpress.org/plugins/wp-super-cache/faq/">Troubleshooting Guide</a>. The WP_CACHE line must be moved up.', 'wp-super-cache' ) . "</p></div>";
function wpsc_generate_sizes_array() {
$cache_types = apply_filters( 'wpsc_cache_types', array( 'supercache', 'wpcache' ) );
$cache_states = apply_filters( 'wpsc_cache_state', array( 'expired', 'cached' ) );
foreach( $cache_types as $type ) {
foreach( $cache_states as $state ) {
$sizes[ $type ][ $state ] = 0;
$sizes[ $type ][ 'fsize' ] = 0;
$sizes[ $type ][ 'cached_list' ] = array();
$sizes[ $type ][ 'expired_list' ] = array();
function wp_cache_format_fsize( $fsize ) {
$fsize = number_format( $fsize / 1024, 2 ) . "MB";
} elseif ( $fsize != 0 ) {
$fsize = number_format( $fsize, 2 ) . "KB";
function wp_cache_regenerate_cache_file_stats() {
global $cache_compression, $supercachedir, $file_prefix, $wp_cache_preload_on, $cache_max_time;
if ( $supercachedir == '' )
$supercachedir = get_supercache_dir();
$sizes = wpsc_generate_sizes_array();
if (is_dir( $supercachedir ) ) {
if ( $dh = opendir( $supercachedir ) ) {
while ( ( $entry = readdir( $dh ) ) !== false ) {
if ( $entry != '.' && $entry != '..' ) {
$sizes = wpsc_dirsize( trailingslashit( $supercachedir ) . $entry, $sizes );
foreach( $sizes as $cache_type => $list ) {
foreach( array( 'cached_list', 'expired_list' ) as $status ) {
foreach( $list[ $status ] as $dir => $details ) {
if ( $details[ 'files' ] == 2 && !isset( $details[ 'upper_age' ] ) ) {
$cached_list[ $dir ] = $details;
$sizes[ $cache_type ][ $status ] = $cached_list;