" . __( 'A custom url or permalink structure is required for this plugin to work correctly. Please go to the Permalinks Options Page to configure your permalinks.', 'wp-super-cache' ) . "
Troubleshooting section of the readme.txt', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-super-cache/faq/' ); ?>
' . __( "Cannot continue... fix previous problems and retry.", 'wp-super-cache' ) . '';
return false;
}
if ( false == function_exists( 'wpsc_deep_replace' ) ) {
$msg = __( 'Warning! You must set WP_CACHE and WPCACHEHOME in your wp-config.php for this plugin to work correctly:' ) . ' ';
$msg .= "define( 'WP_CACHE', true ); ";
$msg .= "define( 'WPCACHEHOME', '" . __DIR__ . "/' ); ";
wp_die( $msg );
}
if (!wp_cache_check_global_config()) {
return false;
}
if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) {
?>
this page for instructions on modifying your php.ini.', 'wp-super-cache' ); ?>
%s/wp-cache-config.php and cannot be modified. That file must be writeable by the web server to make any changes.', 'wp-super-cache' ), WPCACHECONFIGPATH ); ?>
This page explains how to change file permissions.', 'wp-super-cache' ); ?>
' . esc_html__( 'For best performance you should enable "Mobile device support" or delete the mobile rewrite rules in your .htaccess. Look for the 2 lines with the text "2.0\ MMP|240x320" and delete those.', 'wp-super-cache' ) . '
' . esc_html__( 'This will have no affect on ordinary users but mobile users will see uncached pages.', 'wp-super-cache' ) . '
# BEGIN WPSuperCache and # END WPSuperCache and let the plugin regenerate them by reloading this page.', 'wp-super-cache' ), $home_path ); ?>
# BEGIN WPSuperCache and # END WPSuperCache. There are two sections that look very similar. Just below the line %%{HTTP:Cookie} !^.*(comment_author_|%s|wp-postpass_).*$ add these lines: (do it twice, once for each section)', 'wp-super-cache' ), $home_path, wpsc_get_logged_in_cookie() ); ?>
__( 'Required to serve compressed supercache files properly.', 'wp-super-cache' ), 'mod_headers' => __( 'Required to set caching information on supercache pages. IE7 users will see old pages without this module.', 'wp-super-cache' ), 'mod_expires' => __( 'Set the expiry date on supercached pages. Visitors may not see new pages when they refresh or leave comments without this module.', 'wp-super-cache' ) );
foreach( $required_modules as $req => $desc ) {
if( !in_array( $req, $mods ) ) {
$missing_mods[ $req ] = $desc;
}
}
if( isset( $missing_mods) && is_array( $missing_mods ) ) {
?>
here. Unfortunately, WordPress writes to the .htaccess in the install directory, not where your site is served from. When you update the rewrite rules in this plugin you will have to copy the file to where your site is hosted. This will be fixed in the future.', 'wp-super-cache' ); ?>
' . __( "Warning! You attempted to enable compression but zlib.output_compression is enabled. See #21 in the Troubleshooting section of the readme file.", 'wp-super-cache' ) . '
support forum.', 'wp-super-cache' ),
'https://wordpress.org/support/plugin/wp-super-cache/'
)
);
?>
development version for the latest fixes (changelog).', 'wp-super-cache' ), 'https://odd.blog/y/2o', 'https://plugins.trac.wordpress.org/log/wp-super-cache/' ); ?>
rate us and give feedback.', 'wp-super-cache' ), 'https://wordpress.org/support/plugin/wp-super-cache/reviews?rate=5#new-post' ); ?>
' . esc_html__( 'Cache plugins are PHP scripts you\'ll find in a dedicated folder inside the WP Super Cache folder (wp-super-cache/plugins/). They load at the same time as WP Super Cache, and before regular WordPress plugins.', 'wp-super-cache' ) . '
';
echo '
' . esc_html__( 'Keep in mind that cache plugins are for advanced users only. To create and manage them, you\'ll need extensive knowledge of both PHP and WordPress actions.', 'wp-super-cache' ) . '
';
echo '
' . sprintf( __( 'Warning! Due to the way WordPress upgrades plugins, the ones you upload to the WP Super Cache folder (wp-super-cache/plugins/) will be deleted when you upgrade WP Super Cache. To avoid this loss, load your cache plugins from a different location. When you set $wp_cache_plugins_dir to the new location in wp-config.php, WP Super Cache will look there instead. You can find additional details in the developer documentation.', 'wp-super-cache' ), 'https://odd.blog/wp-super-cache-developers/' ) . '
' . __( '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' ) . '
';
echo "
";
_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' );
echo "
' . __( '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' ) . '
';
} else {
echo '
' . __( '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' ) . '
' . __( 'Warning', 'wp-super-cache' ) . "! " . sprintf( __( 'Could not update %s! WPCACHEHOME must be set in config file.', 'wp-super-cache' ), $global_config_file ) . "
";
return false;
}
}
$ret = true;
if ( file_exists( $wpsc_advanced_cache_filename ) ) {
$file = file_get_contents( $wpsc_advanced_cache_filename );
if (
! strpos( $file, "WP SUPER CACHE 0.8.9.1" ) &&
! strpos( $file, "WP SUPER CACHE 1.2" )
) {
return false;
}
}
$file = file_get_contents( $wpsc_advanced_cache_dist_filename );
$fp = @fopen( $wpsc_advanced_cache_filename, 'w' );
if( $fp ) {
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite
fwrite( $fp, $file );
fclose( $fp );
do_action( 'wpsc_created_advanced_cache' );
} else {
$ret = false;
}
return $ret;
}
/**
* 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 ) ) {
return 'NONE';
}
$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' ) ) {
return 'BOOST';
}
if ( str_contains( $contents, 'WP SUPER CACHE 0.8.9.1' ) || str_contains( $contents, 'WP SUPER CACHE 1.2' ) ) {
return 'WPSC';
}
return 'OTHER';
}
function wpsc_check_advanced_cache() {
global $wpsc_advanced_cache_filename;
$ret = false;
$other_advanced_cache = false;
if ( file_exists( $wpsc_advanced_cache_filename ) ) {
$cache_type = wpsc_identify_advanced_cache();
switch ( $cache_type ) {
case 'WPSC':
return true;
case 'BOOST':
$other_advanced_cache = 'BOOST';
break;
default:
$other_advanced_cache = true;
break;
}
} else {
$ret = wp_cache_create_advanced_cache();
}
if ( false == $ret ) {
if ( $other_advanced_cache === 'BOOST' ) {
wpsc_deactivate_boost_cache_notice();
} elseif ( $other_advanced_cache ) {
echo '
' . __( 'Warning! You may not be allowed to use this plugin on your site.', 'wp-super-cache' ) . "
";
echo '
' .
sprintf(
__( '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
) .
'
';
echo '
' .
__( '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' ),
'
';
echo '
' .
__( 'If you need support for this problem contact your hosting provider.', 'wp-super-cache' ),
'
" .
sprintf(
__( 'Make %1$s writable using the chmod command through your ftp or server software. (chmod 777 %1$s) 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' ),
WP_CONTENT_DIR
) .
"
";
echo "
" . sprintf( __( 'Refresh this page to update %s/advanced-cache.php', 'wp-super-cache' ), WP_CONTENT_DIR ) . "
";
echo sprintf( __( 'If that doesn’t work, make sure the file %s/advanced-cache.php doesn’t exist:', 'wp-super-cache' ), WP_CONTENT_DIR ) . "";
echo "";
echo '
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:
define('WP_CACHE', true);
", 'wp-super-cache' ) . "";
} else {
echo '
' . __( "Error: WP_CACHE is not enabled in your wp-config.php file and I couldn’t modify it.", 'wp-super-cache' ) . "
";
echo "
" . sprintf( __( "Edit %s and add the following line: define('WP_CACHE', true); Otherwise, WP-Cache will not be executed by WordPress core. ", 'wp-super-cache' ), $global_config_file ) . "
";
}
return false;
} else {
echo "
" . __( '
WP_CACHE constant added to wp-config.php
If you continue to see this warning message please see point 5 of the Troubleshooting Guide. The WP_CACHE line must be moved up.', 'wp-super-cache' ) . "
' . sprintf( __( 'WP Super Cache must be configured. Go to the admin page to enable and configure the plugin.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '
' . sprintf( __('WP Super Cache is disabled. Please go to the plugin admin page to enable caching.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '
' . sprintf( __( 'Warning! WP Super Cache caching was broken but has been fixed! The script advanced-cache.php could not load wp-cache-phase1.php.
The file %1$s/advanced-cache.php has been recreated and WPCACHEHOME fixed in your wp-config.php. Reload to hide this message.', 'wp-super-cache' ), WP_CONTENT_DIR ) . '
';
}
}
}
add_action( 'admin_notices', 'wp_cache_admin_notice' );
function wp_cache_check_site() {
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, $wpdb;
if ( !isset( $wp_super_cache_front_page_check ) || ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 0 ) ) {
return false;
}
if ( function_exists( "wp_remote_get" ) == false ) {
return false;
}
$front_page = wp_remote_get( site_url(), array('timeout' => 60, 'blocking' => true ) );
if( is_array( $front_page ) ) {
// Check for gzipped front page
if ( $front_page[ 'headers' ][ 'content-type' ] == 'application/x-gzip' ) {
if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) {
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Please clear cache!', 'wp-super-cache' ), home_url() ), sprintf( __( "Please visit %s to clear the cache as the front page of your site is now downloading!", 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) );
} else {
wp_cache_clear_cache( $wpdb->blogid );
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Cache Cleared!', 'wp-super-cache' ), home_url() ), sprintf( __( "The cache on your blog has been cleared because the front page of your site is now downloading. Please visit %s to verify the cache has been cleared.", 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) );
}
}
// Check for broken front page
if (
! empty( $wp_super_cache_front_page_text )
&& ! str_contains( $front_page['body'], $wp_super_cache_front_page_text )
) {
if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) {
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Please clear cache!', 'wp-super-cache' ), home_url() ), sprintf( __( 'Please visit %1$s to clear the cache as the front page of your site is not correct and missing the text, "%2$s"!', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ), $wp_super_cache_front_page_text ) );
} else {
wp_cache_clear_cache( $wpdb->blogid );
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Cache Cleared!', 'wp-super-cache' ), home_url() ), sprintf( __( 'The cache on your blog has been cleared because the front page of your site is missing the text "%2$s". Please visit %1$s to verify the cache has been cleared.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ), $wp_super_cache_front_page_text ) );
}
}
}
if ( isset( $wp_super_cache_front_page_notification ) && $wp_super_cache_front_page_notification == 1 ) {
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page check!', 'wp-super-cache' ), home_url() ), sprintf( __( "WP Super Cache has checked the front page of your blog. Please visit %s if you would like to disable this.", 'wp-super-cache' ) . "\n\n", admin_url( 'options-general.php?page=wpsupercache' ) ) );
}
if ( !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.', 2 );
}
}
add_action( 'wp_cache_check_site_hook', 'wp_cache_check_site' );
function update_cached_mobile_ua_list( $mobile_browsers, $mobile_prefixes = 0, $mobile_groups = 0 ) {
global $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_groups;
wp_cache_setting( 'wp_cache_mobile_browsers', $mobile_browsers );
wp_cache_setting( 'wp_cache_mobile_prefixes', $mobile_prefixes );
if ( is_array( $mobile_groups ) ) {
$wp_cache_mobile_groups = $mobile_groups;
wp_cache_replace_line('^ *\$wp_cache_mobile_groups', "\$wp_cache_mobile_groups = '" . implode( ', ', $mobile_groups ) . "';", $wp_cache_config_file);
}
return true;
}
function wpsc_update_htaccess() {
extract( wpsc_get_htaccess_info() ); // $document_root, $apache_root, $home_path, $home_root, $home_root_lc, $inst_root, $wprules, $scrules, $condition_rules, $rules, $gziprules
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', explode( "\n", $wprules ) ) ) {
return true;
} else {
return false;
}
}
function wpsc_update_htaccess_form( $short_form = true ) {
global $wpmu_version;
$admin_url = admin_url( 'options-general.php?page=wpsupercache' );
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( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) {
echo "
" . sprintf( __( 'The file %s.htaccess cannot be modified by the web server. Please correct this using the chmod command or your ftp client.', 'wp-super-cache' ), $home_path ) . "
" . __( 'Refresh this page when the file permissions have been modified.' ) . "
" . sprintf( __( 'Alternatively, you can edit your %s.htaccess file manually and add the following code (before any WordPress rules):', 'wp-super-cache' ), $home_path ) . "
";
echo "
# BEGIN WPSuperCache\n" . esc_html( $rules ) . "# END WPSuperCache
";
} else {
if ( $short_form == false ) {
echo "
" . sprintf( __( 'To serve static html files your server must have the correct mod_rewrite rules added to a file called %s.htaccess', 'wp-super-cache' ), $home_path ) . " ";
_e( "You can edit the file yourself. Add the following rules.", 'wp-super-cache' );
echo __( " Make sure they appear before any existing WordPress rules. ", 'wp-super-cache' ) . "
";
echo "
";
echo "
# BEGIN WPSuperCache\n" . esc_html( $rules ) . "# END WPSuperCache
";
echo "
";
echo "
" . sprintf( __( 'Rules must be added to %s too:', 'wp-super-cache' ), WP_CONTENT_DIR . "/cache/.htaccess" ) . "
";
echo "
";
echo "
# BEGIN supercache\n" . esc_html( $gziprules ) . "# END supercache
";
echo "
";
}
if ( !isset( $wpmu_version ) || $wpmu_version == '' ) {
echo '\n";
}
}
}
/*
* Return LOGGED_IN_COOKIE if it doesn't begin with wordpress_logged_in
* to avoid having people update their .htaccess file
*/
function wpsc_get_logged_in_cookie() {
$logged_in_cookie = 'wordpress_logged_in';
if ( defined( 'LOGGED_IN_COOKIE' ) && substr( constant( 'LOGGED_IN_COOKIE' ), 0, 19 ) != 'wordpress_logged_in' )
$logged_in_cookie = constant( 'LOGGED_IN_COOKIE' );
return $logged_in_cookie;
}
function wpsc_get_htaccess_info() {
global $wp_cache_mobile_enabled, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_disable_utf8;
global $htaccess_path;
if ( isset( $_SERVER[ "PHP_DOCUMENT_ROOT" ] ) ) {
$document_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
$apache_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
} else {
$document_root = $_SERVER[ "DOCUMENT_ROOT" ];
$apache_root = '%{DOCUMENT_ROOT}';
}
$content_dir_root = $document_root;
if ( strpos( $document_root, '/kunden/homepages/' ) === 0 ) {
// https://wordpress.org/support/topic/plugin-wp-super-cache-how-to-get-mod_rewrite-working-on-1and1-shared-hosting?replies=1
// On 1and1, PHP's directory structure starts with '/homepages'. The
// Apache directory structure has an extra '/kunden' before it.
// Also 1and1 does not support the %{DOCUMENT_ROOT} variable in
// .htaccess files.
// This prevents the $inst_root from being calculated correctly and
// means that the $apache_root is wrong.
//
// e.g. This is an example of how Apache and PHP see the directory
// structure on 1and1:
// Apache: /kunden/homepages/xx/dxxxxxxxx/htdocs/site1/index.html
// PHP: /homepages/xx/dxxxxxxxx/htdocs/site1/index.html
// Here we fix up the paths to make mode_rewrite work on 1and1 shared hosting.
$content_dir_root = substr( $content_dir_root, 7 );
$apache_root = $document_root;
}
$home_path = get_home_path();
$home_root = parse_url(get_bloginfo('url'));
$home_root = isset( $home_root[ 'path' ] ) ? trailingslashit( $home_root[ 'path' ] ) : '/';
if ( isset( $htaccess_path ) ) {
$home_path = $htaccess_path;
} elseif (
$home_root == '/' &&
$home_path != $_SERVER[ 'DOCUMENT_ROOT' ]
) {
$home_path = $_SERVER[ 'DOCUMENT_ROOT' ];
} elseif (
$home_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 );
$home_root_lc = str_replace( '//', '/', strtolower( $home_root ) );
$inst_root = str_replace( '//', '/', '/' . trailingslashit( str_replace( $content_dir_root, '', str_replace( '\\', '/', WP_CONTENT_DIR ) ) ) );
$wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
$wprules = str_replace( "RewriteEngine On\n", '', $wprules );
$wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
$scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
if( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
$condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*[^/]$";
$condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*//.*$";
}
$condition_rules[] = "RewriteCond %{REQUEST_METHOD} !POST";
$condition_rules[] = "RewriteCond %{QUERY_STRING} ^$";
$condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|" . wpsc_get_logged_in_cookie() . wpsc_get_extra_cookies() . "|wp-postpass_).*$";
$condition_rules[] = "RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\\\"]+ [NC]";
$condition_rules[] = "RewriteCond %{HTTP:Profile} !^[a-z0-9\\\"]+ [NC]";
if ( $wp_cache_mobile_enabled ) {
if ( isset( $wp_cache_mobile_browsers ) && "" != $wp_cache_mobile_browsers )
$condition_rules[] = "RewriteCond %{HTTP_USER_AGENT} !^.*(" . addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) . ").* [NC]";
if ( isset( $wp_cache_mobile_prefixes ) && "" != $wp_cache_mobile_prefixes )
$condition_rules[] = "RewriteCond %{HTTP_USER_AGENT} !^(" . addcslashes( str_replace( ', ', '|', $wp_cache_mobile_prefixes ), ' ' ) . ").* [NC]";
}
$condition_rules = apply_filters( 'supercacherewriteconditions', $condition_rules );
$rules = "\n";
$rules .= "RewriteEngine On\n";
$rules .= "RewriteBase $home_root\n"; // props Chris Messina
$rules .= "#If you serve pages from behind a proxy you may want to change 'RewriteCond %{HTTPS} on' to something more sensible\n";
if ( isset( $wp_cache_disable_utf8 ) == false || $wp_cache_disable_utf8 == 0 ) {
$charset = get_option('blog_charset') == '' ? 'UTF-8' : get_option('blog_charset');
$rules .= "AddDefaultCharset {$charset}\n";
}
$rules .= "CONDITION_RULES";
$rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
$rules .= "RewriteCond %{HTTPS} on\n";
$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html.gz -f\n";
$rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html.gz\" [L]\n\n";
$rules .= "CONDITION_RULES";
$rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
$rules .= "RewriteCond %{HTTPS} !on\n";
$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html.gz -f\n";
$rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html.gz\" [L]\n\n";
$rules .= "CONDITION_RULES";
$rules .= "RewriteCond %{HTTPS} on\n";
$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html -f\n";
$rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html\" [L]\n\n";
$rules .= "CONDITION_RULES";
$rules .= "RewriteCond %{HTTPS} !on\n";
$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html -f\n";
$rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html\" [L]\n";
$rules .= "\n";
$rules = apply_filters( 'supercacherewriterules', $rules );
$rules = str_replace( "CONDITION_RULES", implode( "\n", $condition_rules ) . "\n", $rules );
$gziprules = "\n \n ForceType text/html\n FileETag None\n \n AddEncoding gzip .gz\n AddType text/html .gz\n\n";
$gziprules .= "\n SetEnvIfNoCase Request_URI \.gz$ no-gzip\n\n";
// Default headers.
$headers = array(
'Vary' => 'Accept-Encoding, Cookie',
'Cache-Control' => 'max-age=3, must-revalidate',
);
// Allow users to override the Vary header with WPSC_VARY_HEADER.
if ( defined( 'WPSC_VARY_HEADER' ) && ! empty( WPSC_VARY_HEADER ) ) {
$headers['Vary'] = WPSC_VARY_HEADER;
}
// Allow users to override Cache-control header with WPSC_CACHE_CONTROL_HEADER
if ( defined( 'WPSC_CACHE_CONTROL_HEADER' ) && ! empty( WPSC_CACHE_CONTROL_HEADER ) ) {
$headers['Cache-Control'] = WPSC_CACHE_CONTROL_HEADER;
}
// Allow overriding headers with a filter.
$headers = apply_filters( 'wpsc_htaccess_mod_headers', $headers );
// Combine headers into a block of text.
$headers_text = implode(
"\n",
array_map(
function ( $key, $value ) {
return " Header set $key '" . addcslashes( $value, "'" ) . "'";
},
array_keys( $headers ),
array_values( $headers )
)
);
// Pack headers into gziprules (for historic reasons) - TODO refactor the values
// returned to better reflect the blocks being written.
if ( $headers_text != '' ) {
$gziprules .= "\n$headers_text\n\n";
}
// Deafult mod_expires rules.
$expires_rules = array(
'ExpiresActive On',
'ExpiresByType text/html A3',
);
// Allow overriding mod_expires rules with a filter.
$expires_rules = apply_filters( 'wpsc_htaccess_mod_expires', $expires_rules );
$gziprules .= "\n";
$gziprules .= implode(
"\n",
array_map(
function ( $line ) {
return " $line";
},
$expires_rules
)
);
$gziprules .= "\n\n";
$gziprules .= "Options -Indexes\n";
return array(
'document_root' => $document_root,
'apache_root' => $apache_root,
'home_path' => $home_path,
'home_root' => $home_root,
'home_root_lc' => $home_root_lc,
'inst_root' => $inst_root,
'wprules' => $wprules,
'scrules' => $scrules,
'condition_rules' => $condition_rules,
'rules' => $rules,
'gziprules' => $gziprules,
);
}
function clear_post_supercache( $post_id ) {
$dir = get_current_url_supercache_dir( $post_id );
if ( false == @is_dir( $dir ) )
return false;
if ( get_supercache_dir() == $dir ) {
wp_cache_debug( "clear_post_supercache: not deleting post_id $post_id as it points at homepage: $dir" );
return false;
}
wp_cache_debug( "clear_post_supercache: post_id: $post_id. deleting files in $dir" );
if ( get_post_type( $post_id ) != 'page') { // don't delete child pages if they exist
prune_super_cache( $dir, true );
} else {
wpsc_delete_files( $dir );
}
}
/**
* Serves an AJAX endpoint to return the current state of the preload process.
*/
function wpsc_ajax_get_preload_status() {
$preload_status = wpsc_get_preload_status( true );
wp_send_json_success( $preload_status );
}
add_action( 'wp_ajax_wpsc_get_preload_status', 'wpsc_ajax_get_preload_status' );
/**
* Returns the location of the preload status file.
*/
function wpsc_get_preload_status_file_path() {
global $cache_path;
return $cache_path . 'preload_permalink.txt';
}
/**
* Get the timestamp of the next preload.
*/
function wpsc_get_next_preload_time() {
$next = wp_next_scheduled( 'wp_cache_preload_hook' );
if ( ! $next ) {
$next = wp_next_scheduled( 'wp_cache_full_preload_hook' );
}
return $next;
}
/**
* Read the preload status. Caches the result in a static variable.
*/
function wpsc_get_preload_status( $include_next = false ) {
$status = array(
'running' => false,
'history' => array(),
'next' => false,
'previous' => null,
);
$filename = wpsc_get_preload_status_file_path();
if ( file_exists( $filename ) ) {
$data = wp_json_file_decode( $filename, array( 'associative' => true ) );
if ( is_array( $data ) ) {
$status = $data;
}
}
if ( $include_next ) {
$status['next'] = wpsc_get_next_preload_time();
}
return $status;
}
/**
* Update the preload status file during a preload.
*/
function wpsc_update_active_preload( $group = null, $progress = null, $url = null ) {
$preload_status = wpsc_get_preload_status();
$preload_status['running'] = true;
// Add the new entry to the history.
array_unshift(
$preload_status['history'],
array(
'group' => $group,
'progress' => $progress,
'url' => $url,
)
);
// Limit to 5 in the history.
$preload_status['history'] = array_slice( $preload_status['history'], 0, 5 );
$filename = wpsc_get_preload_status_file_path();
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
if ( false === file_put_contents( $filename, wp_json_encode( $preload_status ) ) ) {
wp_cache_debug( "wpsc_update_active_preload: failed to write to $filename" );
}
}
/**
* Update the preload status to indicate it is idle. If a finish time is specified, store it.
*/
function wpsc_update_idle_preload( $finish_time = null ) {
$preload_status = wpsc_get_preload_status();
$preload_status['running'] = false;
$preload_status['history'] = array();
if ( ! empty( $finish_time ) ) {
$preload_status['previous'] = $finish_time;
}
$filename = wpsc_get_preload_status_file_path();
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
if ( false === file_put_contents( $filename, wp_json_encode( $preload_status ) ) ) {
wp_cache_debug( "wpsc_update_idle_preload: failed to write to $filename" );
}
}
function wp_cron_preload_cache() {
global $wpdb, $wp_cache_preload_interval, $wp_cache_preload_posts, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $cache_path, $wp_cache_preload_taxonomies;
// check if stop_preload.txt exists and preload should be stopped.
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
if ( @file_exists( $cache_path . 'stop_preload.txt' ) ) {
wp_cache_debug( 'wp_cron_preload_cache: preload cancelled. Aborting preload.' );
wpsc_reset_preload_settings();
return true;
}
/*
* The mutex file is used to prevent multiple preload processes from running at the same time.
* If the mutex file is found, the preload process will wait 3-8 seconds and then check again.
* If the mutex file is still found, the preload process will abort.
* If the mutex file is not found, the preload process will create the mutex file and continue.
* The mutex file is deleted at the end of the preload process.
* The mutex file is deleted if it is more than 10 minutes old.
* The mutex file should only be deleted by the preload process that created it.
* If the mutex file is deleted by another process, another preload process may start.
*/
$mutex = $cache_path . "preload_mutex.tmp";
if ( @file_exists( $mutex ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
sleep( 3 + wp_rand( 1, 5 ) );
// check again just in case another preload process is still running.
if ( @file_exists( $mutex ) && @filemtime( $mutex ) > ( time() - 600 ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
wp_cache_debug( 'wp_cron_preload_cache: preload mutex found and less than 600 seconds old. Aborting preload.', 1 );
return true;
} else {
wp_cache_debug( 'wp_cron_preload_cache: old preload mutex found and deleted. Preload continues.', 1 );
@unlink( $mutex );
}
}
$fp = @fopen( $mutex, 'w' );
@fclose( $fp );
$counter = get_option( 'preload_cache_counter' );
$c = $counter[ 'c' ];
if ( $wp_cache_preload_email_volume == 'none' && $wp_cache_preload_email_me == 1 ) {
$wp_cache_preload_email_me = 0;
wp_cache_setting( 'wp_cache_preload_email_me', 0 );
}
$just_started_preloading = false;
/*
* Preload taxonomies first.
*
*/
if ( isset( $wp_cache_preload_taxonomies ) && $wp_cache_preload_taxonomies ) {
wp_cache_debug( 'wp_cron_preload_cache: doing taxonomy preload.', 5 );
$taxonomies = apply_filters(
'wp_cache_preload_taxonomies',
array(
'post_tag' => 'tag',
'category' => 'category',
)
);
$preload_more_taxonomies = false;
foreach ( $taxonomies as $taxonomy => $path ) {
$taxonomy_filename = $cache_path . 'taxonomy_' . $taxonomy . '.txt';
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
if ( false === @file_exists( $taxonomy_filename ) ) {
if ( ! $just_started_preloading && $wp_cache_preload_email_me ) {
// translators: 1: site url
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Started', 'wp-super-cache' ), home_url(), '' ), ' ' );
}
$just_started_preloading = true;
$out = '';
$records = get_terms( $taxonomy );
foreach ( $records as $term ) {
$out .= get_term_link( $term ) . "\n";
}
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen
$fp = fopen( $taxonomy_filename, 'w' );
if ( $fp ) {
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite
fwrite( $fp, $out );
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
fclose( $fp );
}
$details = explode( "\n", $out );
} else {
// 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 ) {
set_time_limit( 60 );
if ( $url === '' ) {
continue;
}
$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_remote_get(
$url,
array(
'timeout' => 60,
'blocking' => true,
)
);
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() );
return true;
}
}
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen
$fp = fopen( $taxonomy_filename, 'w' );
if ( $fp ) {
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite
fwrite( $fp, implode( "\n", $details ) );
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
fclose( $fp );
}
}
if (
$preload_more_taxonomies === false &&
count( $details ) > 0 &&
$details[0] !== ''
) {
$preload_more_taxonomies = true;
}
}
if ( $preload_more_taxonomies === true ) {
wpsc_schedule_next_preload();
sleep( WPSC_PRELOAD_LOOP_INTERVAL );
return true;
}
} 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(), '' ), ' ' );
}
/*
*
* Preload posts now.
*
* 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().
*/
update_option(
'preload_cache_counter',
array(
'c' => ( $c + WPSC_PRELOAD_POST_COUNT ),
't' => time(),
)
);
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 );
} else {
wp_cache_debug( "wp_cron_preload_cache: no more posts to get. Limit ($wp_cache_preload_posts) reached.", 5 );
$posts = false;
}
if ( !isset( $wp_cache_preload_email_volume ) )
$wp_cache_preload_email_volume = 'medium';
if ( $posts ) {
if ( get_option( 'show_on_front' ) == 'page' ) {
$page_on_front = get_option( 'page_on_front' );
$page_for_posts = get_option( 'page_for_posts' );
} else {
$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 ) ), ' ' );
}
$msg = '';
$count = $c + 1;
foreach( $posts as $post_id ) {
set_time_limit( 60 );
if ( $page_on_front != 0 && ( $post_id == $page_on_front || $post_id == $page_for_posts ) )
continue;
$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 ) );
continue;
}
if ( wp_cache_is_rejected( $url ) ) {
wp_cache_debug( "wp_cron_preload_cache: skipped $url per rejected strings setting" );
continue;
}
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() );
return true;
}
$msg .= "$url\n";
wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
wp_cache_debug( "wp_cron_preload_cache: fetched $url", 5 );
++$count;
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 );
} else {
$msg = '';
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
} else {
$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() );
}
@unlink( $mutex );
}
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() {
global $cache_path;
/*
* 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.' );
return;
}
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 ) ) {
return array(
'c' => 0,
't' => time(),
);
} else {
return $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 ) {
global $wp_rewrite;
if ( file_exists( ABSPATH . 'wp-config.php') ) {
$global_config_file = ABSPATH . 'wp-config.php';
} else {
$global_config_file = dirname(ABSPATH) . '/wp-config.php';
}
if ( apply_filters( 'wpsc_enable_wp_config_edit', true ) ) {
$line = 'define(\'WP_CACHE\', true);';
if (
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\',';
if (
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 .= "{$path}\n";
}
$msg .= "\n";
$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 ) )
return false;
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 );
} else {
@unlink( $value );
}
}
}
return @rmdir( $folderPath );
} else {
return false;
}
}
function supercache_admin_bar_render() {
global $wp_admin_bar;
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() {
global $cache_path;
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
if ( @file_exists( $cache_path . 'stop_preload.txt' ) ) {
return false;
}
if ( file_exists( $cache_path . 'preload_mutex.tmp' ) ) {
return true;
}
// check taxonomy preload loop
$taxonomies = apply_filters(
'wp_cache_preload_taxonomies',
array(
'post_tag' => 'tag',
'category' => 'category',
)
);
foreach ( $taxonomies as $taxonomy => $path ) {
$taxonomy_filename = $cache_path . 'taxonomy_' . $taxonomy . '.txt';
if ( file_exists( $taxonomy_filename ) ) {
return true;
}
}
// check post preload loop
$preload_cache_counter = get_option( 'preload_cache_counter' );
if (
is_array( $preload_cache_counter )
&& isset( $preload_cache_counter['c'] )
&& $preload_cache_counter['c'] > 0
) {
return true;
}
return false;
}
/*
* This function will reset the preload cache counter
*/
function wpsc_reset_preload_counter() {
update_option(
'preload_cache_counter',
array(
'c' => 0,
't' => time(),
)
);
}
/*
* This function will reset all preload settings
*/
function wpsc_reset_preload_settings() {
global $cache_path;
$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',
array(
'post_tag' => 'tag',
'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();
}
if ( $next_preload ) {
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() {
global $cache_path;
// 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
@fclose( $fp );
}
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(
'public' => true,
'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() {
global $wpdb;
static $count;
if ( isset( $count ) ) {
return $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'" );
return $count;
}
/**
* Get the minimum interval in minutes between preload refreshes.
* Filter the default value of 10 minutes using the `wpsc_minimum_preload_interval` filter.
*
* @return int
*/
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' )
return;
if ( isset( $_POST[ 'preload_off' ] ) ) {
wpsc_cancel_preload();
return;
} elseif ( isset( $_POST[ 'preload_now' ] ) ) {
wpsc_enable_preload();
wpsc_update_idle_preload();
?>