From 5dcd426d2387405b371c006fa631a72b6abfb151 Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh Date: Sun, 9 Feb 2020 17:53:41 +0000 Subject: [PATCH 01/17] Add a config loader and replace global settings. Settings will be stored in a global array, $wpsc_config. Filename of the include file copied from Simple Cache. --- includes/pre-wp-functions.php | 13 +++++ plugins/domain-mapping.php | 4 +- plugins/multisite.php | 7 ++- plugins/wptouch.php | 3 +- wp-cache-base.php | 4 +- wp-cache-phase1.php | 8 +-- wp-cache-phase2.php | 52 +++++++++---------- wp-cache.php | 97 +++++++++++++++++------------------ 8 files changed, 99 insertions(+), 89 deletions(-) create mode 100644 includes/pre-wp-functions.php diff --git a/includes/pre-wp-functions.php b/includes/pre-wp-functions.php new file mode 100644 index 00000000..8c995607 --- /dev/null +++ b/includes/pre-wp-functions.php @@ -0,0 +1,13 @@ +

' . esc_html__( 'Domain Mapping plugin detected! Please go to the Supercache plugins page and enable the domain mapping helper plugin.', 'wp-super-cache' ) . '

'; } } diff --git a/plugins/multisite.php b/plugins/multisite.php index df71f9ac..cf4f056d 100644 --- a/plugins/multisite.php +++ b/plugins/multisite.php @@ -47,14 +47,13 @@ function wp_super_cache_multisite_notice() { } function wp_super_cache_override_on_flag() { - global $cache_enabled, $super_cache_enabled; - if ( true !== $cache_enabled ) { + if ( true !== $GLOBALS['wpsc_config']['cache_enabled'] ) { return false; } if ( 1 === (int) get_option( 'wp_super_cache_disabled' ) ) { - $cache_enabled = false; - $super_cache_enabled = false; + $GLOBALS['wpsc_config']['cache_enabled'] = false; + $GLOBALS['wpsc_config']['super_cache_enabled'] = false; define( 'DONOTCACHEPAGE', 1 ); define( 'SUBMITDISABLED', 'disabled style="color: #aaa" ' ); if ( is_admin() ) { diff --git a/plugins/wptouch.php b/plugins/wptouch.php index 9f2209a6..e956c938 100644 --- a/plugins/wptouch.php +++ b/plugins/wptouch.php @@ -41,8 +41,7 @@ function wp_super_cache_wptouch_admin() { add_cacheaction( 'cache_admin_page', 'wp_super_cache_wptouch_admin' ); function wp_super_cache_wptouch_notice() { - global $cache_enabled; - if ( $cache_enabled ) { + if ( $GLOBALS['wpsc_config']['cache_enabled'] ) { echo '

' . __( 'WPTouch plugin detected! Please go to the Supercache plugins page and enable the WPTouch helper plugin.', 'wp-super-cache' ) . '

'; } } diff --git a/wp-cache-base.php b/wp-cache-base.php index df65196c..afe4de57 100644 --- a/wp-cache-base.php +++ b/wp-cache-base.php @@ -1,5 +1,5 @@

' . __( 'Mobile rewrite rules detected', 'wp-super-cache' ) . "

"; echo "

" . __( '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' ) . "

" . __( 'This will have no affect on ordinary users but mobile users will see uncached pages.', 'wp-super-cache' ) . "

"; - } elseif ( $wp_cache_mod_rewrite && $cache_enabled && $wp_cache_mobile_enabled && $scrules != '' && ( + } elseif ( $wp_cache_mod_rewrite && $GLOBALS['wpsc_config']['cache_enabled'] && $wp_cache_mobile_enabled && $scrules != '' && ( ( '' != $wp_cache_mobile_prefixes && false === strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_prefixes ), ' ' ) ) ) || ( '' != $wp_cache_mobile_browsers && false === strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) ) ) ) ) { @@ -439,14 +440,14 @@ function wp_cache_manager_error_checks() {

Update Mod_Rewrite Rules button.', 'wp-super-cache' ); ?>

__( '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 ) { @@ -474,7 +475,7 @@ function wp_cache_manager_error_checks() { } if ( isset( $disable_supercache_htaccess_warning ) == false ) $disable_supercache_htaccess_warning = false; - if ( ! $is_nginx && $dismiss_htaccess_warning == 0 && $wp_cache_mod_rewrite && $super_cache_enabled && $disable_supercache_htaccess_warning == false && get_option( 'siteurl' ) != get_option( 'home' ) ) { + if ( ! $is_nginx && $dismiss_htaccess_warning == 0 && $wp_cache_mod_rewrite && $GLOBALS['wpsc_config']['super_cache_enabled'] && $disable_supercache_htaccess_warning == false && get_option( 'siteurl' ) != get_option( 'home' ) ) { ?>

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' ); ?>

@@ -662,12 +663,12 @@ function wp_cache_manager_updates() { if ( ! defined( 'DISABLE_SUPERCACHE' ) ) { wp_cache_debug( 'DISABLE_SUPERCACHE is not set, super_cache enabled.' ); wp_super_cache_enable(); - $super_cache_enabled = true; + $GLOBALS['wpsc_config']['super_cache_enabled'] = true; } } else { wp_cache_disable(); wp_super_cache_disable(); - $super_cache_enabled = false; + $GLOBALS['wpsc_config']['super_cache_enabled'] = false; } if ( isset( $_POST[ 'wp_cache_mod_rewrite' ] ) && $_POST[ 'wp_cache_mod_rewrite' ] == 1 ) { @@ -763,7 +764,7 @@ function wp_cache_manager_updates() { add_action( 'admin_init', 'wp_cache_manager_updates' ); function wp_cache_manager() { - global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled; + global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_compression; global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_no_cache_for_get; global $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_supercache_cache_list, $cache_page_secret; global $wp_super_cache_front_page_check, $wp_cache_refresh_single_only, $wp_cache_mobile_prefixes; @@ -853,9 +854,9 @@ function toggleLayer( whichLayer ) { echo '

' . __( 'WP Super Cache Settings', 'wp-super-cache' ) . '

'; // Set a default. - if ( false === $cache_enabled && ! isset( $wp_cache_mod_rewrite ) ) { + if ( false === $GLOBALS['wpsc_config']['cache_enabled'] && ! isset( $wp_cache_mod_rewrite ) ) { $wp_cache_mod_rewrite = 0; - } elseif ( ! isset( $wp_cache_mod_rewrite ) && $cache_enabled && $super_cache_enabled ) { + } elseif ( ! isset( $wp_cache_mod_rewrite ) && $GLOBALS['wpsc_config']['cache_enabled'] && $GLOBALS['wpsc_config']['super_cache_enabled'] ) { $wp_cache_mod_rewrite = 1; } @@ -870,7 +871,7 @@ function toggleLayer( whichLayer ) { } if ( 'preload' === $curr_tab ) { - if ( true == $super_cache_enabled && ! defined( 'DISABLESUPERCACHEPRELOADING' ) ) { + if ( true == $GLOBALS['wpsc_config']['super_cache_enabled'] && ! defined( 'DISABLESUPERCACHEPRELOADING' ) ) { 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; $count = wpsc_post_count(); if ( $count > 1000 ) { @@ -961,11 +962,11 @@ function toggleLayer( whichLayer ) { wp_cache_files(); break; case 'preload': - if ( ! $cache_enabled ) { + if ( ! $GLOBALS['wpsc_config']['cache_enabled'] ) { wp_die( esc_html__( 'Caching must be enabled to use this feature', 'wp-super-cache' ) ); } echo ''; - if ( $super_cache_enabled == true && false == defined( 'DISABLESUPERCACHEPRELOADING' ) ) { + if ( $GLOBALS['wpsc_config']['super_cache_enabled'] == true && false == defined( 'DISABLESUPERCACHEPRELOADING' ) ) { echo '

' . __( 'This will cache every published post and page on your site. It will create supercache static files so unknown visitors (including bots) will hit a cached page. This will probably help your Google ranking as they are using speed as a metric when judging websites now.', 'wp-super-cache' ) . '

'; echo '

' . __( 'Preloading creates lots of files however. Caching is done from the newest post to the oldest so please consider only caching the newest if you have lots (10,000+) of posts. This is especially important on shared hosting.', 'wp-super-cache' ) . '

'; echo '

' . __( 'In ’Preload Mode’ regular garbage collection will be disabled so that old cache files are not deleted. This is a recommended setting when the cache is preloaded.', 'wp-super-cache' ) . '

'; @@ -1062,7 +1063,7 @@ function toggleLayer( whichLayer ) {
-
@@ -1147,7 +1148,7 @@ function toggleLayer( whichLayer ) {
  • strlen( ABSPATH ) && ABSPATH == substr( $cache_path, 0, strlen( ABSPATH ) ) ) { $msg = __( 'The plugin detected a bare directory index in your cache directory, which would let visitors see your cache files directly and might expose private posts.', 'wp-super-cache' ); - if ( ! $is_nginx && $super_cache_enabled && $wp_cache_mod_rewrite == 1 ) { + if ( ! $is_nginx && $GLOBALS['wpsc_config']['super_cache_enabled'] && $wp_cache_mod_rewrite == 1 ) { $msg .= ' ' . __( 'You are using expert mode to serve cache files so the plugin has added Options -Indexes to the .htaccess file in the cache directory to disable indexes. However, if that does not work, you should contact your system administrator or support and ask for them to be disabled, or use simple mode and move the cache outside of the web root.', 'wp-super-cache' ); } else { $msg .= ' ' . sprintf( __( 'index.html files have been added in key directories, but unless directory indexes are disabled, it is probably better to store the cache files outside of the web root of %s', 'wp-super-cache' ), ABSPATH ) . ''; @@ -1156,7 +1157,7 @@ function toggleLayer( whichLayer ) { } ?> - +
  • %s and update the mod_rewrite rules in the .htaccess file.', 'wp-super-cache' ), ABSPATH ); ?>
  • @@ -1209,8 +1210,8 @@ function toggleLayer( whichLayer ) {
    -
    -
    +
    +
    @@ -1224,14 +1225,14 @@ function toggleLayer( whichLayer ) {

    ' . esc_html__( 'Notice: Simple caching enabled but Supercache mod_rewrite rules from expert mode detected. Cached files will be served using those rules. If your site is working ok, please ignore this message. Otherwise, you can edit the .htaccess file in the root of your install and remove the SuperCache rules.', 'wp-super-cache' ) . '

    '; } } echo '
    '; - if ( $cache_enabled ) { + if ( $GLOBALS['wpsc_config']['cache_enabled'] ) { echo '

    ' . esc_html__( 'Cache Tester', 'wp-super-cache' ) . '

    '; echo '

    ' . esc_html__( 'Test your cached website by clicking the test button below.', 'wp-super-cache' ) . '

    '; echo '

    ' . __( 'Note: if you use Cloudflare or other transparent front-end proxy service this test may fail.

    1. If you have Cloudflare minification enabled this plugin may detect differences in the pages and report an error.
    2. Try using the development mode of Cloudflare to perform the test. You can disable development mode afterwards if the test succeeds.
    ', 'wp-super-cache' ) . '

    '; @@ -1410,7 +1411,7 @@ function wpsc_plugins_tab() { } function wpsc_admin_tabs( $current = '' ) { - global $cache_enabled, $super_cache_enabled, $wp_cache_mod_rewrite; + global $wp_cache_mod_rewrite; if ( '' === $current ) { $current = ! empty( $_GET['tab'] ) ? stripslashes( $_GET['tab'] ) : ''; // WPCS: CSRF ok, sanitization ok. @@ -1620,7 +1621,7 @@ function wpsc_update_direct_pages() { } function wp_lock_down() { - global $cached_direct_pages, $cache_enabled, $super_cache_enabled; + global $cached_direct_pages; $admin_url = admin_url( 'options-general.php?page=wpsupercache' ); $wp_lock_down = wp_update_lock_down(); @@ -1648,7 +1649,7 @@ function wp_lock_down() { echo ''; ?>

    ' . 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' ) ) . ''; } add_action( 'after_plugin_row', 'wp_cache_plugin_notice' ); @@ -3214,11 +3212,12 @@ function wp_cache_plugin_actions( $links, $file ) { add_filter( 'plugin_action_links', 'wp_cache_plugin_actions', 10, 2 ); function wp_cache_admin_notice() { - global $cache_enabled, $wp_cache_phase1_loaded; - if( substr( $_SERVER['PHP_SELF'], -11 ) == 'plugins.php' && !$cache_enabled && function_exists( 'admin_url' ) ) + global $wp_cache_phase1_loaded; + if ( substr( $_SERVER['PHP_SELF'], -11 ) == 'plugins.php' && ! $GLOBALS['wpsc_config']['cache_enabled'] && function_exists( 'admin_url' ) ) { echo '

    ' . 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' ) ) . '

    '; + } - if ( defined( 'WP_CACHE' ) && WP_CACHE == true && ( defined( 'ADVANCEDCACHEPROBLEM' ) || ( $cache_enabled && false == isset( $wp_cache_phase1_loaded ) ) ) ) { + if ( defined( 'WP_CACHE' ) && WP_CACHE == true && ( defined( 'ADVANCEDCACHEPROBLEM' ) || ( $GLOBALS['wpsc_config']['cache_enabled'] && false == isset( $wp_cache_phase1_loaded ) ) ) ) { if ( wp_cache_create_advanced_cache() ) { echo '

    ' . 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 ) . '

    '; } From ce7f9e79dd557b89fd632d9800da37a3ab1cd53c Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh Date: Sun, 9 Feb 2020 21:39:25 +0000 Subject: [PATCH 02/17] Time for $wp_cache_mod_rewrite now. Also load the configuration in the REST API using wpsc_load_config() --- rest/class.wp-super-cache-rest-get-status.php | 20 +++---- ...ss.wp-super-cache-rest-update-settings.php | 9 ++- wp-cache.php | 59 +++++++++---------- 3 files changed, 42 insertions(+), 46 deletions(-) diff --git a/rest/class.wp-super-cache-rest-get-status.php b/rest/class.wp-super-cache-rest-get-status.php index f0a4ae40..0c843b05 100644 --- a/rest/class.wp-super-cache-rest-get-status.php +++ b/rest/class.wp-super-cache-rest-get-status.php @@ -30,14 +30,13 @@ public function callback( $request ) { * @param array $status */ protected function add_preload_status( & $status ) { - global $wp_cache_config_file; - include( $wp_cache_config_file ); + wpsc_load_config(); - if ( false == $cache_enabled ) { + if ( false == $GLOBALS['wpsc_config']['cache_enabled'] ) { $status[ 'preload_disabled_cache_off' ] = true; } - if ( false == $super_cache_enabled ) { + if ( false == $GLOBALS['wpsc_config']['super_cache_enabled'] ) { $status[ 'preload_disabled_supercache_off' ] = true; } if ( true === defined( 'DISABLESUPERCACHEPRELOADING' ) ) { @@ -49,11 +48,10 @@ protected function add_preload_status( & $status ) { * @param array $status */ protected function add_php_mod_rewrite_status( & $status ) { - global $wp_cache_config_file; - include( $wp_cache_config_file ); + wpsc_load_config(); - if ( $cache_enabled && !$wp_cache_mod_rewrite ) { + if ( $GLOBALS['wpsc_config']['cache_enabled'] && ! $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] ) { $scrules = trim( implode( "\n", extract_from_markers( trailingslashit( get_home_path() ) . '.htaccess', 'WPSuperCache' ) ) ); if ( $scrules != '' ) { $status[ 'php_mod_rewrite' ] = true; @@ -87,12 +85,12 @@ protected function add_compression_status( & $status ) { * @param array $status */ protected function add_rewrite_status( & $status ) { - global $home_path, $wp_cache_config_file; + global $home_path; - include( $wp_cache_config_file ); + wpsc_load_config(); // Return if the rewrite caching is disabled. - if ( ! $cache_enabled || ! $super_cache_enabled || ! $wp_cache_mod_rewrite ) { + if ( ! $GLOBALS['wpsc_config']['cache_enabled'] || ! $GLOBALS['wpsc_config']['super_cache_enabled'] || ! $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] ) { return; } @@ -103,7 +101,7 @@ protected function add_rewrite_status( & $status ) { $status[ 'mod_rewrite_rules' ] = true; } $got_rewrite = apache_mod_loaded( 'mod_rewrite', true ); - if ( $wp_cache_mod_rewrite && false == apply_filters( 'got_rewrite', $got_rewrite ) ) { + if ( $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] && false == apply_filters( 'got_rewrite', $got_rewrite ) ) { $status[ 'mod_rewrite_missing' ] = true; } diff --git a/rest/class.wp-super-cache-rest-update-settings.php b/rest/class.wp-super-cache-rest-update-settings.php index 7d4c9f8a..d3418a64 100644 --- a/rest/class.wp-super-cache-rest-update-settings.php +++ b/rest/class.wp-super-cache-rest-update-settings.php @@ -194,7 +194,6 @@ protected function set_lock_down( $value ) { * @param mixed $value */ protected function set_super_cache_enabled( $value ) { - global $wp_cache_mod_rewrite; if ( is_numeric( $value ) == false ) { $types = array( 'wpcache' => 0, 'mod_rewrite' => 1, 'PHP' => 2 ); @@ -210,19 +209,19 @@ protected function set_super_cache_enabled( $value ) { } else { wp_super_cache_enable(); - $wp_cache_mod_rewrite = 0; // PHP recommended + $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] = 0; // PHP recommended if ( $value == 1 ) { // mod_rewrite - $wp_cache_mod_rewrite = 1; + $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] = 1; add_mod_rewrite_rules(); } elseif( $value == 2 ) { // PHP - $wp_cache_mod_rewrite = 0; + $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] = 0; remove_mod_rewrite_rules(); } - wp_cache_setting( 'wp_cache_mod_rewrite', $wp_cache_mod_rewrite ); + wp_cache_setting( 'wp_cache_mod_rewrite', $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] ); } return true; } diff --git a/wp-cache.php b/wp-cache.php index 121f31f4..58543517 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -73,7 +73,7 @@ function wpsc_init() { * It's minimal list of global variables. */ global $wpsc_config; -global $wp_cache_mod_rewrite, $wp_cache_home_path, $cache_path, $file_prefix; +global $wp_cache_home_path, $cache_path, $file_prefix; global $wp_cache_mutex_disabled, $mutex_filename, $sem_id, $wp_super_cache_late_init; global $cache_compression, $cache_max_time, $wp_cache_shutdown_gc, $cache_rebuild_files; global $wp_super_cache_debug, $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file; @@ -85,7 +85,7 @@ function wpsc_init() { global $wp_cache_config_file, $wp_cache_config_file_sample; // Check is cache config already loaded. -if ( ! isset( $GLOBALS['wpsc_config']['cache_enabled'], $GLOBALS['wpsc_config']['super_cache_enabled'], $wp_cache_mod_rewrite, $cache_path ) && +if ( ! isset( $GLOBALS['wpsc_config']['cache_enabled'], $GLOBALS['wpsc_config']['super_cache_enabled'], $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'], $cache_path ) && empty( $wp_cache_phase1_loaded ) && // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged ! @include( $wp_cache_config_file ) @@ -243,7 +243,7 @@ function wp_cache_network_pages() { add_action( 'network_admin_menu', 'wp_cache_network_pages' ); function wp_cache_manager_error_checks() { - global $wp_cache_debug, $wp_cache_cron_check, $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_mobile_enabled, $wp_cache_mod_rewrite; + global $wp_cache_debug, $wp_cache_cron_check, $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_mobile_enabled; global $dismiss_htaccess_warning, $dismiss_readable_warning, $dismiss_gc_warning, $wp_cache_shutdown_gc, $is_nginx; global $htaccess_path; @@ -339,7 +339,7 @@ function wp_cache_manager_error_checks() { if ( $GLOBALS['wpsc_config']['cache_enabled'] == true && $GLOBALS['wpsc_config']['super_cache_enabled'] == true && - $wp_cache_mod_rewrite && + $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] && ! got_mod_rewrite() && ! $is_nginx ) { @@ -422,10 +422,10 @@ function wp_cache_manager_error_checks() { $home_path = $htaccess_path; } $scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) ); - if ( $GLOBALS['wpsc_config']['cache_enabled'] && $wp_cache_mod_rewrite && !$wp_cache_mobile_enabled && strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) ) ) { + if ( $GLOBALS['wpsc_config']['cache_enabled'] && $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] && !$wp_cache_mobile_enabled && strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) ) ) { echo '

    ' . __( 'Mobile rewrite rules detected', 'wp-super-cache' ) . "

    "; echo "

    " . __( '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' ) . "

    " . __( 'This will have no affect on ordinary users but mobile users will see uncached pages.', 'wp-super-cache' ) . "

    "; - } elseif ( $wp_cache_mod_rewrite && $GLOBALS['wpsc_config']['cache_enabled'] && $wp_cache_mobile_enabled && $scrules != '' && ( + } elseif ( $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] && $GLOBALS['wpsc_config']['cache_enabled'] && $wp_cache_mobile_enabled && $scrules != '' && ( ( '' != $wp_cache_mobile_prefixes && false === strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_prefixes ), ' ' ) ) ) || ( '' != $wp_cache_mobile_browsers && false === strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) ) ) ) ) { @@ -440,14 +440,14 @@ function wp_cache_manager_error_checks() {

    Update Mod_Rewrite Rules button.', 'wp-super-cache' ); ?>

    __( '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 ) { @@ -475,7 +475,7 @@ function wp_cache_manager_error_checks() { } if ( isset( $disable_supercache_htaccess_warning ) == false ) $disable_supercache_htaccess_warning = false; - if ( ! $is_nginx && $dismiss_htaccess_warning == 0 && $wp_cache_mod_rewrite && $GLOBALS['wpsc_config']['super_cache_enabled'] && $disable_supercache_htaccess_warning == false && get_option( 'siteurl' ) != get_option( 'home' ) ) { + if ( ! $is_nginx && $dismiss_htaccess_warning == 0 && $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] && $GLOBALS['wpsc_config']['super_cache_enabled'] && $disable_supercache_htaccess_warning == false && get_option( 'siteurl' ) != get_option( 'home' ) ) { ?>

    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' ); ?>

    @@ -531,7 +531,7 @@ function admin_bar_delete_page() { } function wp_cache_manager_updates() { - global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $cache_path, $wp_cache_refresh_single_only, $cache_compression, $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get; + global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $cache_path, $wp_cache_refresh_single_only, $cache_compression, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get; global $cache_schedule_type, $cache_max_time, $cache_time_interval, $wp_cache_shutdown_gc, $wpsc_save_headers; if ( !wpsupercache_site_admin() ) @@ -672,13 +672,13 @@ function wp_cache_manager_updates() { } if ( isset( $_POST[ 'wp_cache_mod_rewrite' ] ) && $_POST[ 'wp_cache_mod_rewrite' ] == 1 ) { - $wp_cache_mod_rewrite = 1; + $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] = 1; add_mod_rewrite_rules(); } else { - $wp_cache_mod_rewrite = 0; // cache files served by PHP + $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] = 0; // cache files served by PHP remove_mod_rewrite_rules(); } - wp_cache_setting( 'wp_cache_mod_rewrite', $wp_cache_mod_rewrite ); + wp_cache_setting( 'wp_cache_mod_rewrite', $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] ); if( isset( $_POST[ 'wp_cache_clear_on_post_edit' ] ) ) { $wp_cache_clear_on_post_edit = 1; @@ -768,7 +768,7 @@ function wp_cache_manager() { global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_no_cache_for_get; global $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_supercache_cache_list, $cache_page_secret; global $wp_super_cache_front_page_check, $wp_cache_refresh_single_only, $wp_cache_mobile_prefixes; - global $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $wp_cache_disable_utf8, $wp_cache_mfunc_enabled; + global $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $wp_cache_disable_utf8, $wp_cache_mfunc_enabled; global $wp_super_cache_comments, $wp_cache_home_path, $wpsc_save_headers, $is_nginx; if ( !wpsupercache_site_admin() ) @@ -854,17 +854,17 @@ function toggleLayer( whichLayer ) { echo '

    ' . __( 'WP Super Cache Settings', 'wp-super-cache' ) . '

    '; // Set a default. - if ( false === $GLOBALS['wpsc_config']['cache_enabled'] && ! isset( $wp_cache_mod_rewrite ) ) { - $wp_cache_mod_rewrite = 0; - } elseif ( ! isset( $wp_cache_mod_rewrite ) && $GLOBALS['wpsc_config']['cache_enabled'] && $GLOBALS['wpsc_config']['super_cache_enabled'] ) { - $wp_cache_mod_rewrite = 1; + if ( false === $GLOBALS['wpsc_config']['cache_enabled'] && ! isset( $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] ) ) { + $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] = 0; + } elseif ( ! isset( $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] ) && $GLOBALS['wpsc_config']['cache_enabled'] && $GLOBALS['wpsc_config']['super_cache_enabled'] ) { + $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] = 1; } $admin_url = admin_url( 'options-general.php?page=wpsupercache' ); $curr_tab = ! empty( $_GET['tab'] ) ? sanitize_text_field( stripslashes( $_GET['tab'] ) ) : ''; // WPCS: sanitization ok. if ( empty( $curr_tab ) ) { $curr_tab = 'easy'; - if ( $wp_cache_mod_rewrite ) { + if ( $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] ) { $curr_tab = 'settings'; echo '

    ' . __( 'Notice: Expert mode caching enabled. Showing Advanced Settings Page by default.', 'wp-super-cache' ) . '

    '; } @@ -1071,8 +1071,8 @@ function toggleLayer( whichLayer ) {
    -
    -
    +
    +
    here but are not officially supported.', 'wp-super-cache' ), 'https://codex.wordpress.org/Nginx#WP_Super_Cache_Rules' ); ?> @@ -1099,15 +1099,15 @@ function toggleLayer( whichLayer ) {
    - +


    -
    -
    +
    +
    ' . esc_html__( '304 support is disabled by default because some hosts have had problems with the headers used in the past.', 'wp-super-cache' ) . '
    '; ?> -
    +
    @@ -1117,7 +1117,7 @@ function toggleLayer( whichLayer ) {
    -
    +

    ' . __( 'Mobile Browsers', 'wp-super-cache' ) . '
    ' . esc_html( $wp_cache_mobile_browsers ) . "
    " . __( 'Mobile Prefixes', 'wp-super-cache' ) . "
    " . esc_html( $wp_cache_mobile_prefixes ) . "
    "; @@ -1148,7 +1148,7 @@ function toggleLayer( whichLayer ) {
  • strlen( ABSPATH ) && ABSPATH == substr( $cache_path, 0, strlen( ABSPATH ) ) ) { $msg = __( 'The plugin detected a bare directory index in your cache directory, which would let visitors see your cache files directly and might expose private posts.', 'wp-super-cache' ); - if ( ! $is_nginx && $GLOBALS['wpsc_config']['super_cache_enabled'] && $wp_cache_mod_rewrite == 1 ) { + if ( ! $is_nginx && $GLOBALS['wpsc_config']['super_cache_enabled'] && $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] == 1 ) { $msg .= ' ' . __( 'You are using expert mode to serve cache files so the plugin has added Options -Indexes to the .htaccess file in the cache directory to disable indexes. However, if that does not work, you should contact your system administrator or support and ask for them to be disabled, or use simple mode and move the cache outside of the web root.', 'wp-super-cache' ); } else { $msg .= ' ' . sprintf( __( 'index.html files have been added in key directories, but unless directory indexes are disabled, it is probably better to store the cache files outside of the web root of %s', 'wp-super-cache' ), ABSPATH ) . ''; @@ -1157,7 +1157,7 @@ function toggleLayer( whichLayer ) { } ?> - +
  • %s and update the mod_rewrite rules in the .htaccess file.', 'wp-super-cache' ), ABSPATH ); ?>
  • @@ -1225,7 +1225,7 @@ function toggleLayer( whichLayer ) {

    ' . esc_html__( 'Notice: Simple caching enabled but Supercache mod_rewrite rules from expert mode detected. Cached files will be served using those rules. If your site is working ok, please ignore this message. Otherwise, you can edit the .htaccess file in the root of your install and remove the SuperCache rules.', 'wp-super-cache' ) . '

    '; @@ -1411,7 +1411,6 @@ function wpsc_plugins_tab() { } function wpsc_admin_tabs( $current = '' ) { - global $wp_cache_mod_rewrite; if ( '' === $current ) { $current = ! empty( $_GET['tab'] ) ? stripslashes( $_GET['tab'] ) : ''; // WPCS: CSRF ok, sanitization ok. From 43f6e69e3720ca23a85ab6a33d26e95e9fa5f636 Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh Date: Sun, 16 Feb 2020 15:45:10 +0000 Subject: [PATCH 03/17] Put $cache_path into $wpsc_config settings --- plugins/domain-mapping.php | 10 +- ...class.wp-super-cache-rest-delete-cache.php | 4 +- ...class.wp-super-cache-rest-get-settings.php | 4 +- rest/class.wp-super-cache-rest-test-cache.php | 4 +- ...ss.wp-super-cache-rest-update-settings.php | 34 ++- wp-cache-base.php | 6 +- wp-cache-phase1.php | 4 +- wp-cache-phase2.php | 100 ++++---- wp-cache.php | 221 +++++++++--------- 9 files changed, 181 insertions(+), 206 deletions(-) diff --git a/plugins/domain-mapping.php b/plugins/domain-mapping.php index 5ca79fe0..07defffc 100644 --- a/plugins/domain-mapping.php +++ b/plugins/domain-mapping.php @@ -1,8 +1,6 @@ 'UNKNOWN' ); @@ -24,7 +22,7 @@ public function callback( $request ) { $page[ $c ] = wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) ); if ( ! is_wp_error( $page[ $c ] ) ) { - $fp = fopen( $cache_path . $c . ".html", "w" ); + $fp = fopen( $GLOBALS['wpsc_config']['cache_path'] . $c . ".html", "w" ); fwrite( $fp, $page[ $c ][ 'body' ] ); fclose( $fp ); } diff --git a/rest/class.wp-super-cache-rest-update-settings.php b/rest/class.wp-super-cache-rest-update-settings.php index d3418a64..f198225f 100644 --- a/rest/class.wp-super-cache-rest-update-settings.php +++ b/rest/class.wp-super-cache-rest-update-settings.php @@ -139,9 +139,7 @@ protected function set_global( $global_name, $value ) { * @param mixed $value */ protected function set_wp_cache_location( $value ) { - global $cache_path; - - if ( $value != '' && ( ! isset( $cache_path ) || $value != $cache_path ) ) { + if ( $value != '' && ( ! isset( $GLOBALS['wpsc_config']['cache_path'] ) || $value != $GLOBALS['wpsc_config']['cache_path'] ) ) { $dir = realpath( trailingslashit( dirname( $value ) ) ); if ( $dir == false ) { $dir = WP_CONTENT_DIR . '/cache/'; @@ -159,13 +157,13 @@ protected function set_wp_cache_location( $value ) { $new_cache_path = WP_CONTENT_DIR . '/cache/'; } - if ( $new_cache_path != $cache_path ) { + if ( $new_cache_path != $GLOBALS['wpsc_config']['cache_path'] ) { if ( file_exists( $new_cache_path ) == false ) { - rename( $cache_path, $new_cache_path ); + rename( $GLOBALS['wpsc_config']['cache_path'], $new_cache_path ); } - $cache_path = $new_cache_path; - wp_cache_setting( 'cache_path', $cache_path ); + $GLOBALS['wpsc_config']['cache_path'] = $new_cache_path; + wp_cache_setting( 'cache_path', $GLOBALS['wpsc_config']['cache_path'] ); } } @@ -230,11 +228,11 @@ protected function set_super_cache_enabled( $value ) { * @param mixed $value */ protected function set_wp_cache_not_logged_in( $value ) { - global $wp_cache_not_logged_in, $cache_path; + global $wp_cache_not_logged_in; if ( 0 != $value ) { if ( 0 == $wp_cache_not_logged_in && function_exists( 'prune_super_cache' ) ) { - prune_super_cache( $cache_path, true ); + prune_super_cache( $GLOBALS['wpsc_config']['cache_path'], true ); } $wp_cache_not_logged_in = (int) $value; @@ -250,11 +248,11 @@ protected function set_wp_cache_not_logged_in( $value ) { * @param mixed $value */ protected function set_wp_cache_make_known_anon( $value ) { - global $wp_cache_make_known_anon, $cache_path; + global $wp_cache_make_known_anon; if ( 1 == $value ) { if ( $wp_cache_make_known_anon == 0 && function_exists( 'prune_super_cache' ) ) { - prune_super_cache( $cache_path, true ); + prune_super_cache( $GLOBALS['wpsc_config']['cache_path'], true ); } $wp_cache_make_known_anon = 1; @@ -270,7 +268,7 @@ protected function set_wp_cache_make_known_anon( $value ) { * @param mixed $value */ protected function set_wp_cache_object_cache( $value ) { - global $_wp_using_ext_object_cache, $wp_cache_object_cache, $cache_path; + global $_wp_using_ext_object_cache, $wp_cache_object_cache; if ( ! $_wp_using_ext_object_cache ) { return; @@ -278,7 +276,7 @@ protected function set_wp_cache_object_cache( $value ) { if ( $value == 0 ) { if ( function_exists( 'prune_super_cache' ) ) { - prune_super_cache( $cache_path, true ); + prune_super_cache( $GLOBALS['wpsc_config']['cache_path'], true ); } $wp_cache_object_cache = 1; @@ -296,7 +294,7 @@ protected function set_wp_cache_object_cache( $value ) { * @return null|string */ protected function set_cache_compression( $value ) { - global $cache_compression, $cache_path; + global $cache_compression; $new_cache_compression = 0; if ( defined( 'WPSC_DISABLE_COMPRESSION' ) ) { @@ -316,7 +314,7 @@ protected function set_cache_compression( $value ) { $cache_compression = $new_cache_compression; wp_cache_setting( 'cache_compression', $cache_compression ); if ( function_exists( 'prune_super_cache' ) ) { - prune_super_cache( $cache_path, true ); + prune_super_cache( $GLOBALS['wpsc_config']['cache_path'], true ); } delete_option( 'super_cache_meta' ); @@ -446,7 +444,7 @@ protected function set_preload_setting( $value, $name ) { * @param bool $enabled */ protected function toggle_easy_caching( $enabled = true ) { - global $cache_path, $wp_cache_shutdown_gc, $cache_schedule_type; + global $wp_cache_shutdown_gc, $cache_schedule_type; if ( $enabled ) { $settings = array( 'wp_cache_mobile_enabled' => 1, @@ -474,8 +472,8 @@ protected function toggle_easy_caching( $enabled = true ) { $this->set_value_by_key( $value, $key ); } - if ( $cache_path != WP_CONTENT_DIR . '/cache/' ) { - $this->set_value_by_key( $cache_path, 'wp_cache_location' ); + if ( $GLOBALS['wpsc_config']['cache_path'] != WP_CONTENT_DIR . '/cache/' ) { + $this->set_value_by_key( $GLOBALS['wpsc_config']['cache_path'], 'wp_cache_location' ); } $advanced_settings = array( diff --git a/wp-cache-base.php b/wp-cache-base.php index afe4de57..36c7d9e1 100644 --- a/wp-cache-base.php +++ b/wp-cache-base.php @@ -1,5 +1,5 @@ $directory ) { $protected[ $id ] = trailingslashit( wpsc_get_realpath( $directory ) ); } @@ -814,7 +811,7 @@ function wpsc_delete_files( $dir, $delete = true ) { } function get_all_supercache_filenames( $dir = '' ) { - global $wp_cache_mobile_enabled, $cache_path; + global $wp_cache_mobile_enabled; $dir = wpsc_get_realpath( $dir ); if ( ! $dir ) { @@ -953,7 +950,7 @@ function wpsc_is_caching_user_disabled() { /* returns true/false depending on location of $dir. */ function wp_cache_confirm_delete( $dir ) { - global $cache_path, $blog_cache_dir; + global $blog_cache_dir; // don't allow cache_path, blog cache dir, blog meta dir, supercache. $dir = wpsc_get_realpath( $dir ); @@ -966,10 +963,10 @@ function wp_cache_confirm_delete( $dir ) { return false; } - $rp_cache_path = wpsc_get_realpath( $cache_path ); + $rp_cache_path = wpsc_get_realpath( $GLOBALS['wpsc_config']['cache_path'] ); if ( ! $rp_cache_path ) { - wp_cache_debug( "wp_cache_confirm_delete: cache_path does not exist: $cache_path" ); + wp_cache_debug( "wp_cache_confirm_delete: cache_path does not exist: " . $GLOBALS['wpsc_config']['cache_path'] ); return false; } @@ -978,7 +975,7 @@ function wp_cache_confirm_delete( $dir ) { $dir == $rp_cache_path || $dir == wpsc_get_realpath( $blog_cache_dir ) || $dir == wpsc_get_realpath( $blog_cache_dir . "meta/" ) || - $dir == wpsc_get_realpath( $cache_path . "supercache" ) + $dir == wpsc_get_realpath( $GLOBALS['wpsc_config']['cache_path'] . "supercache" ) ) { return false; } else { @@ -999,16 +996,16 @@ function wpsc_deep_replace( $search, $subject ) { } function wpsc_get_protected_directories() { - global $cache_path, $blog_cache_dir; + global $blog_cache_dir; return apply_filters( 'wpsc_protected_directories', array( - $cache_path . '.htaccess', - $cache_path . "index.html", + $GLOBALS['wpsc_config']['cache_path'] . '.htaccess', + $GLOBALS['wpsc_config']['cache_path'] . "index.html", $blog_cache_dir, $blog_cache_dir . "index.html", $blog_cache_dir . 'meta', $blog_cache_dir . 'meta/index.html', - $cache_path . 'supercache/index.html', - $cache_path . 'supercache' ) + $GLOBALS['wpsc_config']['cache_path'] . 'supercache/index.html', + $GLOBALS['wpsc_config']['cache_path'] . 'supercache' ) ); } @@ -1021,7 +1018,7 @@ function wpsc_debug_username() { return $wp_cache_debug_username; } function wpsc_create_debug_log( $filename = '', $username = '' ) { - global $cache_path, $wp_cache_debug_username, $wp_cache_debug_log; + global $wp_cache_debug_username, $wp_cache_debug_log; if ( $filename != '' ) { $wp_cache_debug_log = $filename; } else { @@ -1034,7 +1031,7 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) { } $msg = 'die( "Please use the viewer" );' . PHP_EOL; - $fp = fopen( $cache_path . $wp_cache_debug_log, 'w' ); + $fp = fopen( $GLOBALS['wpsc_config']['cache_path'] . $wp_cache_debug_log, 'w' ); if ( $fp ) { fwrite( $fp, '<' . "?php\n" ); fwrite( $fp, $msg ); @@ -1053,7 +1050,7 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) { exit; }' . PHP_EOL; - $fp = fopen( $cache_path . 'view_' . $wp_cache_debug_log, 'w' ); + $fp = fopen( $GLOBALS['wpsc_config']['cache_path'] . 'view_' . $wp_cache_debug_log, 'w' ); if ( $fp ) { fwrite( $fp, '<' . "?php" . PHP_EOL ); $msg .= '$debug_log = file( "./' . $wp_cache_debug_log . '" ); @@ -1399,7 +1396,7 @@ function wpsc_register_post_hooks() { } function wpcache_do_rebuild( $dir ) { - global $do_rebuild_list, $cache_path, $wpsc_file_mtimes; + global $do_rebuild_list, $wpsc_file_mtimes; wp_cache_debug( "wpcache_do_rebuild: doing rebuild for $dir" ); if ( !is_dir( $dir ) ) { @@ -1958,7 +1955,7 @@ function wp_cache_maybe_dynamic( &$buffer ) { } function wp_cache_get_ob(&$buffer) { - global $cache_path, $cache_filename, $wp_start_time, $supercachedir; + global $cache_filename, $wp_start_time, $supercachedir; global $new_cache, $wp_cache_meta, $cache_compression, $wp_super_cache_query; global $wp_cache_gzip_encoding; global $gzsize, $supercacheonly; @@ -2019,13 +2016,13 @@ function wp_cache_get_ob(&$buffer) { $home_url = parse_url( trailingslashit( get_bloginfo( 'url' ) ) ); $dir = get_current_url_supercache_dir(); - $supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $home_url[ 'host' ]); + $supercachedir = $GLOBALS['wpsc_config']['cache_path'] . 'supercache/' . preg_replace('/:.*$/', '', $home_url[ 'host' ]); if ( ! empty( $_GET ) || isset( $wp_super_cache_query[ 'is_feed' ] ) || ( $GLOBALS['wpsc_config']['super_cache_enabled'] == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) ) { wp_cache_debug( 'Supercache disabled: GET or feed detected or disabled by config.', 2 ); $GLOBALS['wpsc_config']['super_cache_enabled'] = false; } - $tmp_wpcache_filename = $cache_path . uniqid( mt_rand(), true ) . '.tmp'; + $tmp_wpcache_filename = $GLOBALS['wpsc_config']['cache_path'] . uniqid( mt_rand(), true ) . '.tmp'; if ( defined( 'WPSC_SUPERCACHE_ONLY' ) ) { $supercacheonly = true; @@ -2083,8 +2080,8 @@ function wp_cache_get_ob(&$buffer) { if ( ! $supercacheonly ) { $fr = @fopen( $tmp_wpcache_filename, 'w' ); if ( ! $fr ) { - wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $cache_path ) . $cache_filename, 1 ); - wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $cache_path ) . $cache_filename ); + wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $GLOBALS['wpsc_config']['cache_path'] ) . $cache_filename, 1 ); + wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $GLOBALS['wpsc_config']['cache_path'] ) . $cache_filename ); wp_cache_writers_exit(); return wp_cache_maybe_dynamic( $buffer ); } @@ -2337,7 +2334,7 @@ function prune_super_cache( $directory, $force = false, $rename = false ) { return false; } - global $cache_max_time, $cache_path, $blog_cache_dir; + global $cache_max_time, $blog_cache_dir; static $log = 0; static $protected_directories = ''; @@ -2427,7 +2424,7 @@ function prune_super_cache( $directory, $force = false, $rename = false ) { } function wp_cache_rebuild_or_delete( $file ) { - global $cache_rebuild_files, $cache_path, $file_prefix; + global $cache_rebuild_files, $file_prefix; if ( strpos( $file, '?' ) !== false ) @@ -2489,7 +2486,7 @@ function wp_cache_rebuild_or_delete( $file ) { } function wp_cache_phase2_clean_expired( $file_prefix, $force = false ) { - global $cache_path, $cache_max_time, $blog_cache_dir, $wp_cache_preload_on; + global $cache_max_time, $blog_cache_dir, $wp_cache_preload_on; if ( $cache_max_time == 0 ) { wp_cache_debug( "wp_cache_phase2_clean_expired: disabled because GC disabled.", 2 ); @@ -2522,8 +2519,8 @@ function wp_cache_phase2_clean_expired( $file_prefix, $force = false ) { } closedir($handle); if ( false == $wp_cache_preload_on || true == $force ) { - wp_cache_debug( "Doing GC on supercache dir: {$cache_path}supercache", 2 ); - $deleted = prune_super_cache( $cache_path . 'supercache', false, false ); + wp_cache_debug( "Doing GC on supercache dir: {$GLOBALS['wpsc_config']['cache_path']}supercache", 2 ); + $deleted = prune_super_cache( $GLOBALS['wpsc_config']['cache_path'] . 'supercache', false, false ); } } @@ -2757,16 +2754,14 @@ function wp_cache_clear_cache_on_menu() { /* Clear out the cache directory. */ function wp_cache_clear_cache( $blog_id = 0 ) { - global $cache_path; - if ( $blog_id == 0 ) { wp_cache_debug( 'Clearing all cached files in wp_cache_clear_cache()', 4 ); - prune_super_cache( $cache_path . 'supercache/', true ); - prune_super_cache( $cache_path, true ); + prune_super_cache( $GLOBALS['wpsc_config']['cache_path'] . 'supercache/', true ); + prune_super_cache( $GLOBALS['wpsc_config']['cache_path'], true ); } else { wp_cache_debug( "Clearing all cached files for blog $blog_id in wp_cache_clear_cache()", 4 ); prune_super_cache( get_supercache_dir( $blog_id ), true ); - prune_super_cache( $cache_path . 'blogs/', true ); + prune_super_cache( $GLOBALS['wpsc_config']['cache_path'] . 'blogs/', true ); } do_action( 'wp_cache_cleared' ); @@ -2882,7 +2877,7 @@ function wpsc_post_transition( $new_status, $old_status, $post ) { /* check if we want to clear out all cached files on post updates, otherwise call standard wp_cache_post_change() */ function wp_cache_post_edit( $post_id ) { - global $wp_cache_clear_on_post_edit, $cache_path, $blog_cache_dir; + global $wp_cache_clear_on_post_edit, $blog_cache_dir; static $last_post_edited = -1; if ( $post_id == $last_post_edited ) { @@ -2906,7 +2901,7 @@ function wp_cache_post_edit( $post_id ) { // we want to process the post again just in case it becomes published before the second time this function is called. $last_post_edited = $post_id; if( $wp_cache_clear_on_post_edit ) { - wp_cache_debug( "wp_cache_post_edit: Clearing cache $blog_cache_dir and {$cache_path}supercache/ on post edit per config.", 2 ); + wp_cache_debug( "wp_cache_post_edit: Clearing cache $blog_cache_dir and {$GLOBALS['wpsc_config']['cache_path']}supercache/ on post edit per config.", 2 ); prune_super_cache( $blog_cache_dir, true ); prune_super_cache( get_supercache_dir(), true ); } else { @@ -2947,7 +2942,7 @@ function wp_cache_post_id_gc( $post_id, $all = 'all' ) { } function wp_cache_post_change( $post_id ) { - global $file_prefix, $cache_path, $blog_id, $blog_cache_dir, $wp_cache_refresh_single_only; + global $file_prefix, $blog_id, $blog_cache_dir, $wp_cache_refresh_single_only; static $last_processed = -1; if ( $post_id == $last_processed ) { @@ -3115,8 +3110,7 @@ function maybe_stop_gc( $flag ) { } } function get_gc_flag() { - global $cache_path; - return $cache_path . strtolower( preg_replace( '!/:.*$!', '', str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'home' ) ) ) ) ) . "_wp_cache_gc.txt"; + return $GLOBALS['wpsc_config']['cache_path'] . strtolower( preg_replace( '!/:.*$!', '', str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'home' ) ) ) ) ) . "_wp_cache_gc.txt"; } function wp_cache_gc_cron() { diff --git a/wp-cache.php b/wp-cache.php index 58543517..592b42e7 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -73,7 +73,7 @@ function wpsc_init() { * It's minimal list of global variables. */ global $wpsc_config; -global $wp_cache_home_path, $cache_path, $file_prefix; +global $file_prefix; global $wp_cache_mutex_disabled, $mutex_filename, $sem_id, $wp_super_cache_late_init; global $cache_compression, $cache_max_time, $wp_cache_shutdown_gc, $cache_rebuild_files; global $wp_super_cache_debug, $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file; @@ -85,7 +85,7 @@ function wpsc_init() { global $wp_cache_config_file, $wp_cache_config_file_sample; // Check is cache config already loaded. -if ( ! isset( $GLOBALS['wpsc_config']['cache_enabled'], $GLOBALS['wpsc_config']['super_cache_enabled'], $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'], $cache_path ) && +if ( ! isset( $GLOBALS['wpsc_config']['cache_enabled'], $GLOBALS['wpsc_config']['super_cache_enabled'], $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'], $GLOBALS['wpsc_config']['cache_path'] ) && empty( $wp_cache_phase1_loaded ) && // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged ! @include( $wp_cache_config_file ) @@ -148,7 +148,7 @@ function wpsc_remove_advanced_cache() { } function wpsupercache_uninstall() { - global $wp_cache_config_file, $cache_path; + global $wp_cache_config_file; wpsc_remove_advanced_cache(); @@ -158,10 +158,10 @@ function wpsupercache_uninstall() { wp_cache_remove_index(); - if ( ! empty( $cache_path ) ) { - @unlink( $cache_path . '.htaccess' ); - @unlink( $cache_path . 'meta' ); - @unlink( $cache_path . 'supercache' ); + if ( ! empty( $GLOBALS['wpsc_config']['cache_path'] ) ) { + @unlink( $GLOBALS['wpsc_config']['cache_path'] . '.htaccess' ); + @unlink( $GLOBALS['wpsc_config']['cache_path'] . 'meta' ); + @unlink( $GLOBALS['wpsc_config']['cache_path'] . 'supercache' ); } wp_clear_scheduled_hook( 'wp_cache_check_site_hook' ); @@ -175,16 +175,16 @@ function wpsupercache_uninstall() { } function wpsupercache_deactivate() { - global $wp_cache_config_file, $wpsc_advanced_cache_filename, $cache_path; + global $wp_cache_config_file, $wpsc_advanced_cache_filename; wpsc_remove_advanced_cache(); - if ( ! empty( $cache_path ) ) { - prune_super_cache( $cache_path, true ); + if ( ! empty( $GLOBALS['wpsc_config']['cache_path'] ) ) { + prune_super_cache( $GLOBALS['wpsc_config']['cache_path'], true ); wp_cache_remove_index(); - @unlink( $cache_path . '.htaccess' ); - @unlink( $cache_path . 'meta' ); - @unlink( $cache_path . 'supercache' ); + @unlink( $GLOBALS['wpsc_config']['cache_path'] . '.htaccess' ); + @unlink( $GLOBALS['wpsc_config']['cache_path'] . 'meta' ); + @unlink( $GLOBALS['wpsc_config']['cache_path'] . 'supercache' ); } wp_clear_scheduled_hook( 'wp_cache_check_site_hook' ); @@ -196,9 +196,8 @@ function wpsupercache_deactivate() { register_deactivation_hook( __FILE__, 'wpsupercache_deactivate' ); function wpsupercache_activate() { - global $cache_path; - if ( ! isset( $cache_path ) || $cache_path == '' ) - $cache_path = WP_CONTENT_DIR . '/cache/'; // from sample config file + if ( ! isset( $GLOBALS['wpsc_config']['cache_path'] ) || $GLOBALS['wpsc_config']['cache_path'] == '' ) + $GLOBALS['wpsc_config']['cache_path'] = WP_CONTENT_DIR . '/cache/'; // from sample config file ob_start(); wpsc_init(); @@ -531,7 +530,7 @@ function admin_bar_delete_page() { } function wp_cache_manager_updates() { - global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $cache_path, $wp_cache_refresh_single_only, $cache_compression, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get; + global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_cache_refresh_single_only, $cache_compression, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get; global $cache_schedule_type, $cache_max_time, $cache_time_interval, $wp_cache_shutdown_gc, $wpsc_save_headers; if ( !wpsupercache_site_admin() ) @@ -553,8 +552,8 @@ function wp_cache_manager_updates() { $_POST[ 'super_cache_enabled' ] = 1; $_POST[ 'cache_rebuild_files' ] = 1; unset( $_POST[ 'cache_compression' ] ); - if ( $cache_path != WP_CONTENT_DIR . '/cache/' ) - $_POST[ 'wp_cache_location' ] = $cache_path; + if ( $GLOBALS['wpsc_config']['cache_path'] != WP_CONTENT_DIR . '/cache/' ) + $_POST[ 'wp_cache_location' ] = $GLOBALS['wpsc_config']['cache_path']; // // set up garbage collection with some default settings if ( ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) { @@ -595,11 +594,11 @@ function wp_cache_manager_updates() { } else { $new_cache_path = WP_CONTENT_DIR . '/cache/'; } - if ( $new_cache_path != $cache_path ) { + if ( $new_cache_path != $GLOBALS['wpsc_config']['cache_path'] ) { if ( file_exists( $new_cache_path ) == false ) - rename( $cache_path, $new_cache_path ); - $cache_path = $new_cache_path; - wp_cache_replace_line('^ *\$cache_path', "\$cache_path = '" . $cache_path . "';", $wp_cache_config_file); + rename( $GLOBALS['wpsc_config']['cache_path'], $new_cache_path ); + $GLOBALS['wpsc_config']['cache_path'] = $new_cache_path; + wp_cache_setting( 'cache_path', $GLOBALS['wpsc_config']['cache_path'] ); } if( isset( $_POST[ 'wp_super_cache_late_init' ] ) ) { @@ -713,7 +712,7 @@ function wp_cache_manager_updates() { if ( isset( $_POST['wp_cache_not_logged_in'] ) && $_POST['wp_cache_not_logged_in'] != 0 ) { if ( $wp_cache_not_logged_in == 0 && function_exists( 'prune_super_cache' ) ) { - prune_super_cache( $cache_path, true ); + prune_super_cache( $GLOBALS['wpsc_config']['cache_path'], true ); } $wp_cache_not_logged_in = (int)$_POST['wp_cache_not_logged_in']; } else { @@ -723,7 +722,7 @@ function wp_cache_manager_updates() { if( isset( $_POST[ 'wp_cache_make_known_anon' ] ) ) { if( $wp_cache_make_known_anon == 0 && function_exists( 'prune_super_cache' ) ) - prune_super_cache ($cache_path, true); + prune_super_cache( $GLOBALS['wpsc_config']['cache_path'], true ); $wp_cache_make_known_anon = 1; } else { $wp_cache_make_known_anon = 0; @@ -753,7 +752,7 @@ function wp_cache_manager_updates() { $cache_compression = $new_cache_compression; wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file); if ( function_exists( 'prune_super_cache' ) ) - prune_super_cache( $cache_path, true ); + prune_super_cache( $GLOBALS['wpsc_config']['cache_path'], true ); delete_option( 'super_cache_meta' ); } } @@ -764,12 +763,12 @@ function wp_cache_manager_updates() { add_action( 'admin_init', 'wp_cache_manager_updates' ); function wp_cache_manager() { - global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_compression; + global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_compression; global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_no_cache_for_get; global $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_supercache_cache_list, $cache_page_secret; global $wp_super_cache_front_page_check, $wp_cache_refresh_single_only, $wp_cache_mobile_prefixes; global $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $wp_cache_disable_utf8, $wp_cache_mfunc_enabled; - global $wp_super_cache_comments, $wp_cache_home_path, $wpsc_save_headers, $is_nginx; + global $wp_super_cache_comments, $wpsc_save_headers, $is_nginx; if ( !wpsupercache_site_admin() ) return false; @@ -896,8 +895,8 @@ function toggleLayer( whichLayer ) { if ( is_array( $preload_counter ) && $preload_counter['c'] > 0 ) { $msg .= '

    ' . sprintf( esc_html__( 'Currently caching from post %d to %d.', 'wp-super-cache' ), ( $preload_counter['c'] - 100 ), $preload_counter['c'] ) . '

    '; $currently_preloading = true; - if ( @file_exists( $cache_path . 'preload_permalink.txt' ) ) { - $url = file_get_contents( $cache_path . 'preload_permalink.txt' ); + if ( @file_exists( $GLOBALS['wpsc_config']['cache_path'] . 'preload_permalink.txt' ) ) { + $url = file_get_contents( $GLOBALS['wpsc_config']['cache_path'] . 'preload_permalink.txt' ); $msg .= '

    ' . sprintf( __( 'Page last cached: %s', 'wp-super-cache' ), $url ) . '

    '; } if ( $msg != '' ) { @@ -936,11 +935,11 @@ function toggleLayer( whichLayer ) { } $home_path = parse_url( site_url() ); $home_path = trailingslashit( array_key_exists( 'path', $home_path ) ? $home_path['path'] : '' ); - if ( ! isset( $wp_cache_home_path ) ) { - $wp_cache_home_path = '/'; + if ( ! isset( $GLOBALS['wpsc_config']['wp_cache_home_path'] ) ) { + $GLOBALS['wpsc_config']['wp_cache_home_path'] = '/'; wp_cache_setting( 'wp_cache_home_path', '/' ); } - if ( "$home_path" != "$wp_cache_home_path" ) { + if ( "$home_path" != $GLOBALS['wpsc_config']['wp_cache_home_path'] ) { wp_cache_setting( 'wp_cache_home_path', $home_path ); } @@ -1140,13 +1139,13 @@ function toggleLayer( whichLayer ) {
    - + ' />

    1. - strlen( ABSPATH ) && ABSPATH == substr( $cache_path, 0, strlen( ABSPATH ) ) ) { + strlen( ABSPATH ) && ABSPATH == substr( $GLOBALS['wpsc_config']['cache_path'], 0, strlen( ABSPATH ) ) ) { $msg = __( 'The plugin detected a bare directory index in your cache directory, which would let visitors see your cache files directly and might expose private posts.', 'wp-super-cache' ); if ( ! $is_nginx && $GLOBALS['wpsc_config']['super_cache_enabled'] && $GLOBALS['wpsc_config']['wp_cache_mod_rewrite'] == 1 ) { $msg .= ' ' . __( 'You are using expert mode to serve cache files so the plugin has added Options -Indexes to the .htaccess file in the cache directory to disable indexes. However, if that does not work, you should contact your system administrator or support and ask for them to be disabled, or use simple mode and move the cache outside of the web root.', 'wp-super-cache' ); @@ -1249,7 +1248,7 @@ function toggleLayer( whichLayer ) { echo '

      ' . sprintf( $message, $url ); $page[ $c ] = wp_remote_get( $url, array( 'timeout' => 60, 'blocking' => true ) ); if ( ! is_wp_error( $page[ $c ] ) ) { - $fp = fopen( $cache_path . $c . '.html', 'w' ); + $fp = fopen( $GLOBALS['wpsc_config']['cache_path'] . $c . '.html', 'w' ); fwrite( $fp, $page[ $c ]['body'] ); fclose( $fp ); echo '' . esc_html__( 'OK', 'wp-super-cache' ) . " (" . $c . '.html)

      '; @@ -1441,7 +1440,7 @@ function wpsc_admin_tabs( $current = '' ) { } function wsc_mod_rewrite() { - global $valid_nonce, $cache_path; + global $valid_nonce; if ( $GLOBALS['is_nginx'] ) { return false; @@ -1525,7 +1524,7 @@ function comment_form_lockdown_message() { add_action( 'comment_form', 'comment_form_lockdown_message' ); function wp_update_lock_down() { - global $cache_path, $wp_cache_config_file, $valid_nonce; + global $wp_cache_config_file, $valid_nonce; if ( isset( $_POST[ 'wp_lock_down' ] ) && $valid_nonce ) { $wp_lock_down = $_POST[ 'wp_lock_down' ] == '1' ? '1' : '0'; @@ -1533,7 +1532,7 @@ function wp_update_lock_down() { if ( false == defined( 'WPLOCKDOWN' ) ) define( 'WPLOCKDOWN', $wp_lock_down ); if ( $wp_lock_down == '0' && function_exists( 'prune_super_cache' ) ) - prune_super_cache( $cache_path, true ); // clear the cache after lockdown + prune_super_cache( $GLOBALS['wpsc_config']['cache_path'], true ); // clear the cache after lockdown return $wp_lock_down; } if ( defined( 'WPLOCKDOWN' ) ) @@ -1543,7 +1542,7 @@ function wp_update_lock_down() { } function wpsc_update_direct_pages() { - global $cached_direct_pages, $valid_nonce, $cache_path, $wp_cache_config_file; + global $cached_direct_pages, $valid_nonce, $wp_cache_config_file; if ( false == isset( $cached_direct_pages ) ) $cached_direct_pages = array(); @@ -2031,7 +2030,7 @@ function wp_cache_edit_accepted() { } 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_debug, $wp_cache_debug_log, $wp_cache_debug_ip, $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; @@ -2056,13 +2055,13 @@ function wpsc_update_debug_settings() { } if ( isset( $_POST[ 'wpsc_delete_log' ] ) && $_POST[ 'wpsc_delete_log' ] == 1 && $wp_cache_debug_log != '' ) { - @unlink( $cache_path . $wp_cache_debug_log ); + @unlink( $GLOBALS['wpsc_config']['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 + } elseif ( ! file_exists( $GLOBALS['wpsc_config']['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; @@ -2112,7 +2111,7 @@ function wpsc_update_debug_settings() { } function wp_cache_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_debug, $wp_cache_debug_log, $wp_cache_debug_ip, $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; @@ -2126,7 +2125,7 @@ function wp_cache_debug_settings() { extract( wpsc_create_debug_log() ); // $wp_cache_debug_log, $wp_cache_debug_username } - $log_file_link = "$wp_cache_debug_log"; + $log_file_link = "$wp_cache_debug_log"; if ( $wp_super_cache_debug == 1 ) { echo "

      " . sprintf( __( 'Currently logging to: %s', 'wp-super-cache' ), $log_file_link ) . "

      "; @@ -2243,7 +2242,7 @@ function wp_super_cache_enable() { } function wp_super_cache_disable() { - global $cache_path, $supercachedir, $wp_cache_config_file; + global $supercachedir, $wp_cache_config_file; if ( ! $GLOBALS['wpsc_config']['super_cache_enabled'] ) { wp_cache_debug( 'wp_super_cache_disable: already disabled' ); @@ -2260,7 +2259,7 @@ function wp_super_cache_disable() { } 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 ); + prune_super_cache( $GLOBALS['wpsc_config']['cache_path'], true ); } if ( $GLOBALS['wp_cache_mod_rewrite'] === 1 ) { @@ -2287,23 +2286,22 @@ function wp_cache_is_enabled() { } function wp_cache_remove_index() { - global $cache_path; - if ( empty( $cache_path ) ) { + if ( empty( $GLOBALS['wpsc_config']['cache_path'] ) ) { return; } - @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" ); + @unlink( $GLOBALS['wpsc_config']['cache_path'] . "index.html" ); + @unlink( $GLOBALS['wpsc_config']['cache_path'] . "supercache/index.html" ); + @unlink( $GLOBALS['wpsc_config']['cache_path'] . "blogs/index.html" ); + if ( is_dir( $GLOBALS['wpsc_config']['cache_path'] . "blogs" ) ) { + $dir = new DirectoryIterator( $GLOBALS['wpsc_config']['cache_path'] . "blogs" ); foreach( $dir as $fileinfo ) { if ( $fileinfo->isDot() ) { continue; } if ( $fileinfo->isDir() ) { - $directory = $cache_path . "blogs/" . $fileinfo->getFilename(); + $directory = $GLOBALS['wpsc_config']['cache_path'] . "blogs/" . $fileinfo->getFilename(); if ( is_file( $directory . "/index.html" ) ) { unlink( $directory . "/index.html" ); } @@ -2318,15 +2316,15 @@ function wp_cache_remove_index() { } function wp_cache_index_notice() { - global $wp_version, $cache_path; + global $wp_version; if ( false == wpsupercache_site_admin() ) return false; if ( false == get_site_option( 'wp_super_cache_index_detected' ) ) return false; - if ( strlen( $cache_path ) < strlen( ABSPATH ) - || ABSPATH != substr( $cache_path, 0, strlen( ABSPATH ) ) ) + if ( strlen( $GLOBALS['wpsc_config']['cache_path'] ) < strlen( ABSPATH ) + || ABSPATH != substr( $GLOBALS['wpsc_config']['cache_path'], 0, strlen( ABSPATH ) ) ) return false; // cache stored outside web root if ( get_site_option( 'wp_super_cache_index_detected' ) == 2 ) { @@ -2423,9 +2421,9 @@ function wp_cache_logout_all() { add_action( 'admin_init', 'wp_cache_logout_all' ); function wp_cache_add_index_protection() { - global $cache_path, $blog_cache_dir; + global $blog_cache_dir; - if ( is_dir( $cache_path ) && false == is_file( "$cache_path/index.html" ) ) { + if ( is_dir( $GLOBALS['wpsc_config']['cache_path'] ) && false == is_file( $GLOBALS['wpsc_config']['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' ) @@ -2437,10 +2435,10 @@ function wp_cache_add_index_protection() { if ( ! function_exists( 'insert_with_markers' ) ) { include_once( ABSPATH . 'wp-admin/includes/misc.php' ); } - insert_with_markers( $cache_path . '.htaccess', "INDEX", array( 'Options -Indexes' ) ); + insert_with_markers( $GLOBALS['wpsc_config']['cache_path'] . '.htaccess', "INDEX", array( 'Options -Indexes' ) ); } - $directories = array( $cache_path, $cache_path . '/supercache/', $cache_path . '/blogs/', $blog_cache_dir, $blog_cache_dir . "/meta" ); + $directories = array( $GLOBALS['wpsc_config']['cache_path'], $GLOBALS['wpsc_config']['cache_path'] . '/supercache/', $GLOBALS['wpsc_config']['cache_path'] . '/blogs/', $blog_cache_dir, $blog_cache_dir . "/meta" ); foreach( $directories as $dir ) { if ( false == is_dir( $dir ) ) @mkdir( $dir ); @@ -2453,18 +2451,16 @@ function wp_cache_add_index_protection() { } function wp_cache_add_site_cache_index() { - global $cache_path; - wp_cache_add_index_protection(); // root and supercache - if ( is_dir( $cache_path . "blogs" ) ) { - $dir = new DirectoryIterator( $cache_path . "blogs" ); + if ( is_dir( $GLOBALS['wpsc_config']['cache_path'] . "blogs" ) ) { + $dir = new DirectoryIterator( $GLOBALS['wpsc_config']['cache_path'] . "blogs" ); foreach( $dir as $fileinfo ) { if ( $fileinfo->isDot() ) { continue; } if ( $fileinfo->isDir() ) { - $directory = $cache_path . "blogs/" . $fileinfo->getFilename(); + $directory = $GLOBALS['wpsc_config']['cache_path'] . "blogs/" . $fileinfo->getFilename(); if ( false == is_file( $directory . "/index.html" ) ) { $fp = @fopen( $directory . "/index.html", 'w' ); if ( $fp ) @@ -2483,27 +2479,27 @@ function wp_cache_add_site_cache_index() { } function wp_cache_verify_cache_dir() { - global $cache_path, $blog_cache_dir; + global $blog_cache_dir; - $dir = dirname($cache_path); - if ( !file_exists($cache_path) ) { - if ( !is_writeable_ACLSafe( $dir ) || !($dir = mkdir( $cache_path ) ) ) { + $dir = dirname( $GLOBALS['wpsc_config']['cache_path'] ); + if ( ! file_exists( $GLOBALS['wpsc_config']['cache_path'] ) ) { + if ( ! is_writeable_ACLSafe( $dir ) || ! ( $dir = mkdir( $GLOBALS['wpsc_config']['cache_path'] ) ) ) { echo "" . __( 'Error', 'wp-super-cache' ) . ": " . sprintf( __( 'Your cache directory (%1$s) did not exist and couldn’t be created by the web server. Check %1$s permissions.', 'wp-super-cache' ), $dir ); return false; } } - if ( !is_writeable_ACLSafe($cache_path)) { - echo "" . __( 'Error', 'wp-super-cache' ) . ": " . sprintf( __( 'Your cache directory (%1$s) or %2$s need to be writable for this plugin to work. Double-check it.', 'wp-super-cache' ), $cache_path, $dir ); + if ( ! is_writeable_ACLSafe( $GLOBALS['wpsc_config']['cache_path'] ) ) { + echo "" . __( 'Error', 'wp-super-cache' ) . ": " . sprintf( __( 'Your cache directory (%1$s) or %2$s need to be writable for this plugin to work. Double-check it.', 'wp-super-cache' ), $GLOBALS['wpsc_config']['cache_path'], $dir ); return false; } - if ( '/' != substr($cache_path, -1)) { - $cache_path .= '/'; + if ( '/' != substr( $GLOBALS['wpsc_config']['cache_path'], -1 ) ) { + $GLOBALS['wpsc_config']['cache_path'] .= '/'; } - if( false == is_dir( $blog_cache_dir ) ) { - @mkdir( $cache_path . "blogs" ); - if( $blog_cache_dir != $cache_path . "blogs/" ) + if ( false == is_dir( $blog_cache_dir ) ) { + @mkdir( $GLOBALS['wpsc_config']['cache_path'] . "blogs" ); + if ( $blog_cache_dir != $GLOBALS['wpsc_config']['cache_path'] . "blogs/" ) @mkdir( $blog_cache_dir ); } @@ -2515,7 +2511,7 @@ function wp_cache_verify_cache_dir() { } function wp_cache_verify_config_file() { - global $wp_cache_config_file, $wp_cache_config_file_sample, $sem_id, $cache_path; + global $wp_cache_config_file, $wp_cache_config_file_sample, $sem_id; global $WPSC_HTTP_HOST; $new = false; @@ -2550,8 +2546,8 @@ function wp_cache_verify_config_file() { } $new = true; } - if ( $sem_id == 5419 && $cache_path != '' && $WPSC_HTTP_HOST != '' ) { - $sem_id = crc32( $WPSC_HTTP_HOST . $cache_path ) & 0x7fffffff; + if ( $sem_id == 5419 && $GLOBALS['wpsc_config']['cache_path'] != '' && $WPSC_HTTP_HOST != '' ) { + $sem_id = crc32( $WPSC_HTTP_HOST . $GLOBALS['wpsc_config']['cache_path'] ) & 0x7fffffff; wp_cache_replace_line('sem_id', '$sem_id = ' . $sem_id . ';', $wp_cache_config_file); } if ( $new ) { @@ -2746,11 +2742,11 @@ function wp_cache_regenerate_cache_file_stats() { } function wp_cache_files() { - global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $blog_cache_dir, $cache_compression; + global $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $blog_cache_dir, $cache_compression; global $wp_cache_preload_on; - if ( '/' != substr($cache_path, -1)) { - $cache_path .= '/'; + if ( '/' != substr($GLOBALS['wpsc_config']['cache_path'], -1)) { + $GLOBALS['wpsc_config']['cache_path'] .= '/'; } if ( $valid_nonce ) { @@ -2785,7 +2781,7 @@ function wp_cache_files() { if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletesupercache' ) { $supercacheuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) ); - $supercacheuri = trailingslashit( realpath( $cache_path . 'supercache/' . $supercacheuri ) ); + $supercacheuri = trailingslashit( realpath( $GLOBALS['wpsc_config']['cache_path'] . 'supercache/' . $supercacheuri ) ); if ( wp_cache_confirm_delete( $supercacheuri ) ) { printf( __( "Deleting supercache file: %s
      ", 'wp-super-cache' ), $supercacheuri ); wpsc_delete_files( $supercacheuri ); @@ -2960,7 +2956,7 @@ function delete_cache_dashboard() { //add_action( 'dashmenu', 'delete_cache_dashboard' ); function wpsc_dirsize($directory, $sizes) { - global $cache_max_time, $cache_path, $valid_nonce, $wp_cache_preload_on, $file_prefix; + global $cache_max_time, $valid_nonce, $wp_cache_preload_on, $file_prefix; $now = time(); if (is_dir($directory)) { @@ -2990,7 +2986,7 @@ function wpsc_dirsize($directory, $sizes) { } $sizes[ $cache_type ][ $cache_status ]+=1; if ( $valid_nonce && isset( $_GET[ 'listfiles' ] ) ) { - $dir = str_replace( $cache_path . 'supercache/' , '', dirname( $directory ) ); + $dir = str_replace( $GLOBALS['wpsc_config']['cache_path'] . 'supercache/' , '', dirname( $directory ) ); $age = $now - $filem; if ( false == isset( $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ] ) ) { $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ][ 'lower_age' ] = $age; @@ -3021,12 +3017,12 @@ function wpsc_dirsize($directory, $sizes) { } function wp_cache_clean_cache( $file_prefix, $all = false ) { - global $cache_path, $supercachedir, $blog_cache_dir; + global $supercachedir, $blog_cache_dir; do_action( 'wp_cache_cleared' ); if ( $all == true && wpsupercache_site_admin() && function_exists( 'prune_super_cache' ) ) { - prune_super_cache( $cache_path, true ); + prune_super_cache( $GLOBALS['wpsc_config']['cache_path'], true ); return true; } if ( $supercachedir == '' ) @@ -3044,7 +3040,7 @@ function wp_cache_clean_cache( $file_prefix, $all = false ) { } wp_cache_clean_legacy_files( $blog_cache_dir, $file_prefix ); - wp_cache_clean_legacy_files( $cache_path, $file_prefix ); + wp_cache_clean_legacy_files( $GLOBALS['wpsc_config']['cache_path'], $file_prefix ); } @@ -3488,7 +3484,7 @@ function clear_post_supercache( $post_id ) { } 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; + global $wpdb, $wp_cache_preload_interval, $wp_cache_preload_posts, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $wp_cache_preload_taxonomies; if ( get_option( 'preload_cache_stop' ) ) { delete_option( 'preload_cache_stop' ); @@ -3496,7 +3492,7 @@ function wp_cron_preload_cache() { return true; } - $mutex = $cache_path . "preload_mutex.tmp"; + $mutex = $GLOBALS['wpsc_config']['cache_path'] . "preload_mutex.tmp"; sleep( 3 + mt_rand( 1, 5 ) ); if ( @file_exists( $mutex ) ) { if ( @filemtime( $mutex ) > ( time() - 600 ) ) { @@ -3529,11 +3525,11 @@ function wp_cron_preload_cache() { if ( $wp_cache_preload_posts == 'all' || $c < $wp_cache_preload_posts ) { wp_cache_debug( 'wp_cron_preload_cache: doing taxonomy preload.', 5 ); - $permalink_counter_msg = $cache_path . "preload_permalink.txt"; + $permalink_counter_msg = $GLOBALS['wpsc_config']['cache_path'] . "preload_permalink.txt"; if ( isset( $wp_cache_preload_taxonomies ) && $wp_cache_preload_taxonomies ) { $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"; + $taxonomy_filename = $GLOBALS['wpsc_config']['cache_path'] . "taxonomy_" . $taxonomy . ".txt"; if ( $c == 0 ) @unlink( $taxonomy_filename ); @@ -3572,10 +3568,10 @@ function wp_cron_preload_cache() { wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) ); wp_cache_debug( "wp_cron_preload_cache: fetched $url", 5 ); sleep( 1 ); - if ( @file_exists( $cache_path . "stop_preload.txt" ) ) { + if ( @file_exists( $GLOBALS['wpsc_config']['cache_path'] . "stop_preload.txt" ) ) { wp_cache_debug( 'wp_cron_preload_cache: cancelling preload. stop_preload.txt found.', 5 ); @unlink( $mutex ); - @unlink( $cache_path . "stop_preload.txt" ); + @unlink( $GLOBALS['wpsc_config']['cache_path'] . "stop_preload.txt" ); @unlink( $taxonomy_filename ); update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) ); if ( $wp_cache_preload_email_me ) @@ -3615,7 +3611,7 @@ function wp_cron_preload_cache() { wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing posts from %2$d to %3$d', 'wp-super-cache' ), home_url(), $c, ($c+100) ), ' ' ); $msg = ''; $count = $c + 1; - $permalink_counter_msg = $cache_path . "preload_permalink.txt"; + $permalink_counter_msg = $GLOBALS['wpsc_config']['cache_path'] . "preload_permalink.txt"; foreach( $posts as $post_id ) { set_time_limit( 60 ); if ( $page_on_front != 0 && ( $post_id == $page_on_front || $post_id == $page_for_posts ) ) @@ -3632,10 +3628,10 @@ function wp_cron_preload_cache() { @fwrite( $fp, $count . " " . $url ); @fclose( $fp ); } - if ( @file_exists( $cache_path . "stop_preload.txt" ) ) { + if ( @file_exists( $GLOBALS['wpsc_config']['cache_path'] . "stop_preload.txt" ) ) { wp_cache_debug( 'wp_cron_preload_cache: cancelling preload. stop_preload.txt found.', 5 ); @unlink( $mutex ); - @unlink( $cache_path . "stop_preload.txt" ); + @unlink( $GLOBALS['wpsc_config']['cache_path'] . "stop_preload.txt" ); update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) ); if ( $wp_cache_preload_email_me ) wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Stopped', 'wp-super-cache' ), home_url(), '' ), ' ' ); @@ -3864,7 +3860,6 @@ function wpsc_admin_bar_render( $wp_admin_bar ) { add_action( 'admin_bar_menu', 'wpsc_admin_bar_render', 99 ); function wpsc_cancel_preload() { - global $cache_path; $next_preload = wp_next_scheduled( 'wp_cache_preload_hook' ); if ( $next_preload ) { wp_cache_debug( 'wpsc_cancel_preload: unscheduling wp_cache_preload_hook' ); @@ -3878,14 +3873,12 @@ function wpsc_cancel_preload() { wp_unschedule_event( $next_preload, 'wp_cache_full_preload_hook' ); } wp_cache_debug( 'wpsc_cancel_preload: creating stop_preload.txt' ); - $fp = @fopen( $cache_path . "stop_preload.txt", 'w' ); + $fp = @fopen( $GLOBALS['wpsc_config']['cache_path'] . "stop_preload.txt", 'w' ); @fclose( $fp ); } function wpsc_enable_preload() { - global $cache_path; - - @unlink( $cache_path . "preload_mutex.tmp" ); + @unlink( $GLOBALS['wpsc_config']['cache_path'] . "preload_mutex.tmp" ); update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) ); wp_schedule_single_event( time() + 10, 'wp_cache_full_preload_hook' ); } @@ -4005,7 +3998,7 @@ function wpsc_is_preloading() { } function wpsc_set_default_gc( $force = false ) { - global $cache_path, $wp_cache_shutdown_gc, $cache_schedule_type; + global $wp_cache_shutdown_gc, $cache_schedule_type; if ( isset( $wp_cache_shutdown_gc ) && $wp_cache_shutdown_gc == 1 ) { return false; @@ -4048,7 +4041,7 @@ function remove_mod_rewrite_rules() { } function update_mod_rewrite_rules( $add_rules = true ) { - global $cache_path, $update_mod_rewrite_rules_error; + global $update_mod_rewrite_rules_error; $update_mod_rewrite_rules_error = false; @@ -4109,12 +4102,12 @@ function update_mod_rewrite_rules( $add_rules = true ) { return false; } - $backup_filename = $cache_path . 'htaccess.' . mt_rand() . ".php"; + $backup_filename = $GLOBALS['wpsc_config']['cache_path'] . 'htaccess.' . mt_rand() . ".php"; $backup_file_contents = file_get_contents( $home_path . '.htaccess' ); file_put_contents( $backup_filename, "<" . "?php die(); ?" . ">" . $backup_file_contents ); - $existing_gzip_rules = implode( "\n", extract_from_markers( $cache_path . '.htaccess', 'supercache' ) ); + $existing_gzip_rules = implode( "\n", extract_from_markers( $GLOBALS['wpsc_config']['cache_path'] . '.htaccess', 'supercache' ) ); if ( $existing_gzip_rules != $generated_rules[ 'gziprules' ] ) { - insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $generated_rules[ 'gziprules' ] ) ); + insert_with_markers( $GLOBALS['wpsc_config']['cache_path'] . '.htaccess', 'supercache', explode( "\n", $generated_rules[ 'gziprules' ] ) ); } $wprules = extract_from_markers( $home_path . '.htaccess', 'WordPress' ); wpsc_remove_marker( $home_path . '.htaccess', 'WordPress' ); // remove original WP rules so SuperCache rules go on top @@ -4128,11 +4121,11 @@ function update_mod_rewrite_rules( $add_rules = true ) { } elseif ( $new_page[ 'body' ] != $original_page[ 'body' ] ) { $restore_backup = true; $update_mod_rewrite_rules_error = "Page test failed as pages did not match with new .htaccess rules."; - wp_cache_debug( 'update_mod_rewrite_rules: failed to update rules. page test failed as pages did not match. Files dumped in ' . $cache_path . ' for inspection.' ); + wp_cache_debug( 'update_mod_rewrite_rules: failed to update rules. page test failed as pages did not match. Files dumped in ' . $GLOBALS['wpsc_config']['cache_path'] . ' for inspection.' ); wp_cache_debug( 'update_mod_rewrite_rules: original page: 1-' . md5( $original_page[ 'body' ] ) . '.txt' ); wp_cache_debug( 'update_mod_rewrite_rules: new page: 1-' . md5( $new_page[ 'body' ] ) . '.txt' ); - file_put_contents( $cache_path . '1-' . md5( $original_page[ 'body' ] ) . '.txt', $original_page[ 'body' ] ); - file_put_contents( $cache_path . '2-' . md5( $new_page[ 'body' ] ) . '.txt', $new_page[ 'body' ] ); + file_put_contents( $GLOBALS['wpsc_config']['cache_path'] . '1-' . md5( $original_page[ 'body' ] ) . '.txt', $original_page[ 'body' ] ); + file_put_contents( $GLOBALS['wpsc_config']['cache_path'] . '2-' . md5( $new_page[ 'body' ] ) . '.txt', $new_page[ 'body' ] ); } if ( $restore_backup ) { @@ -4290,8 +4283,8 @@ function wpsc_update_check() { $wpsc_version != 169 ) { wp_cache_setting( 'wpsc_version', 169 ); - global $wp_cache_debug_log, $cache_path; - $log_file = $cache_path . str_replace('/', '', str_replace('..', '', $wp_cache_debug_log)); + global $wp_cache_debug_log; + $log_file = $GLOBALS['wpsc_config']['cache_path'] . str_replace('/', '', str_replace('..', '', $wp_cache_debug_log)); if ( ! file_exists( $log_file ) ) { return false; } From e47270c744b2dc16e62e620938816142ac733a9d Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh Date: Sun, 16 Feb 2020 15:55:47 +0000 Subject: [PATCH 04/17] Move $file_prefix into the wpsc_config settings --- ...class.wp-super-cache-rest-delete-cache.php | 6 ++--- wp-cache-phase2.php | 24 ++++++++--------- wp-cache.php | 27 +++++++++---------- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/rest/class.wp-super-cache-rest-delete-cache.php b/rest/class.wp-super-cache-rest-delete-cache.php index 8944d45b..40f6f6a1 100644 --- a/rest/class.wp-super-cache-rest-delete-cache.php +++ b/rest/class.wp-super-cache-rest-delete-cache.php @@ -15,8 +15,7 @@ public function callback( $request ) { wpsc_delete_post_cache( $params['id'] ); } elseif ( !empty( $params['expired'] ) ) { - global $file_prefix; - wp_cache_clean_expired( $file_prefix ); + wp_cache_clean_expired( $GLOBALS['wpsc_config']['file_prefix'] ); } elseif ( isset( $params['url'] ) ) { $directory = $GLOBALS['wpsc_config']['cache_path'] . 'supercache/' . $params[ 'url' ]; @@ -24,8 +23,7 @@ public function callback( $request ) { prune_super_cache( $directory . '/page', true ); } else { - global $file_prefix; - wp_cache_clean_cache( $file_prefix, !empty( $params['all'] ) ); + wp_cache_clean_cache( $GLOBALS['wpsc_config']['file_prefix'], !empty( $params['all'] ) ); } return rest_ensure_response( array( 'Cache Cleared' => true ) ); diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index b3e095fe..b5ab5a16 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -29,21 +29,21 @@ function get_wp_cache_key( $url = false ) { } function wp_super_cache_init() { - global $wp_cache_key, $key, $blogcacheid, $file_prefix, $blog_cache_dir, $meta_file, $cache_file, $cache_filename, $meta_pathname; + global $wp_cache_key, $key, $blogcacheid, $blog_cache_dir, $meta_file, $cache_file, $cache_filename, $meta_pathname; $wp_cache_key = get_wp_cache_key(); $key = $blogcacheid . md5( $wp_cache_key ); $wp_cache_key = $blogcacheid . $wp_cache_key; - $cache_filename = $file_prefix . $key . '.php'; - $meta_file = $file_prefix . $key . '.php'; + $cache_filename = $GLOBALS['wpsc_config']['file_prefix'] . $key . '.php'; + $meta_file = $GLOBALS['wpsc_config']['file_prefix'] . $key . '.php'; $cache_file = wpsc_get_realpath( $blog_cache_dir ) . '/' . $cache_filename; $meta_pathname = wpsc_get_realpath( $blog_cache_dir . 'meta/' ) . '/' . $meta_file; return compact( 'key', 'cache_filename', 'meta_file', 'cache_file', 'meta_pathname' ); } function wp_cache_serve_cache_file() { - global $key, $blogcacheid, $wp_cache_request_uri, $file_prefix, $blog_cache_dir, $meta_file, $cache_file, $cache_filename, $meta_pathname, $wp_cache_gzip_encoding, $meta; + global $key, $blogcacheid, $wp_cache_request_uri, $blog_cache_dir, $meta_file, $cache_file, $cache_filename, $meta_pathname, $wp_cache_gzip_encoding, $meta; global $cache_compression, $wp_cache_slash_check, $wp_supercache_304, $wp_cache_no_cache_for_get; global $wp_cache_disable_utf8, $wp_cache_mfunc_enabled, $wpsc_served_header; @@ -2297,7 +2297,7 @@ function wp_cache_get_ob(&$buffer) { } } -function wp_cache_phase2_clean_cache($file_prefix) { +function wp_cache_phase2_clean_cache( $file_prefix ) { global $wpdb, $blog_cache_dir; if( !wp_cache_writers_entry() ) @@ -2424,7 +2424,7 @@ function prune_super_cache( $directory, $force = false, $rename = false ) { } function wp_cache_rebuild_or_delete( $file ) { - global $cache_rebuild_files, $file_prefix; + global $cache_rebuild_files; if ( strpos( $file, '?' ) !== false ) @@ -2452,13 +2452,13 @@ function wp_cache_rebuild_or_delete( $file ) { return false; } - if ( substr( basename( $file ), 0, mb_strlen( $file_prefix ) ) == $file_prefix ) { + if ( substr( basename( $file ), 0, mb_strlen( $GLOBALS['wpsc_config']['file_prefix'] ) ) == $GLOBALS['wpsc_config']['file_prefix'] ) { @unlink( $file ); wp_cache_debug( "rebuild_or_gc: deleted non-anonymous file: $file" ); return false; } - if ( substr( basename( $file ), 0, 5 + mb_strlen( $file_prefix ) ) == 'meta-' . $file_prefix ) { + if ( substr( basename( $file ), 0, 5 + mb_strlen( $GLOBALS['wpsc_config']['file_prefix'] ) ) == 'meta-' . $GLOBALS['wpsc_config']['file_prefix'] ) { @unlink( $file ); wp_cache_debug( "rebuild_or_gc: deleted meta file: $file" ); return false; @@ -2942,7 +2942,7 @@ function wp_cache_post_id_gc( $post_id, $all = 'all' ) { } function wp_cache_post_change( $post_id ) { - global $file_prefix, $blog_id, $blog_cache_dir, $wp_cache_refresh_single_only; + global $blog_id, $blog_cache_dir, $wp_cache_refresh_single_only; static $last_processed = -1; if ( $post_id == $last_processed ) { @@ -3029,7 +3029,7 @@ function wp_cache_post_change( $post_id ) { $supercache_files_deleted = false; if ( $handle = @opendir( $blog_cache_dir ) ) { while ( false !== ($file = readdir($handle))) { - if ( strpos( $file, $file_prefix ) !== false ) { + if ( strpos( $file, $GLOBALS['wpsc_config']['file_prefix'] ) !== false ) { if ( strpos( $file, '.html' ) ) { // delete old wpcache files immediately wp_cache_debug( "wp_cache_post_change: Deleting obsolete wpcache cache+meta files: $file" ); @@ -3114,7 +3114,7 @@ function get_gc_flag() { } function wp_cache_gc_cron() { - global $file_prefix, $cache_max_time, $cache_gc_email_me, $cache_time_interval; + global $cache_max_time, $cache_gc_email_me, $cache_time_interval; $msg = ''; if ( $cache_max_time == 0 ) { @@ -3140,7 +3140,7 @@ function wp_cache_gc_cron() { $start = time(); $num = 0; - if( false === ( $num = wp_cache_phase2_clean_expired( $file_prefix ) ) ) { + if( false === ( $num = wp_cache_phase2_clean_expired( $GLOBALS['wpsc_config']['file_prefix'] ) ) ) { wp_cache_debug( 'Cache Expiry cron job failed. Probably mutex locked.', 1 ); update_option( 'wpsupercache_gc_time', time() - ( $cache_time_interval - 10 ) ); // if GC failed then run it again in one minute $msg .= __( 'Cache expiry cron job failed. Job will run again in 10 seconds.', 'wp-super-cache' ) . "\n"; diff --git a/wp-cache.php b/wp-cache.php index 592b42e7..266b279c 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -73,7 +73,6 @@ function wpsc_init() { * It's minimal list of global variables. */ global $wpsc_config; -global $file_prefix; global $wp_cache_mutex_disabled, $mutex_filename, $sem_id, $wp_super_cache_late_init; global $cache_compression, $cache_max_time, $wp_cache_shutdown_gc, $cache_rebuild_files; global $wp_super_cache_debug, $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file; @@ -2703,7 +2702,7 @@ function wp_cache_format_fsize( $fsize ) { } function wp_cache_regenerate_cache_file_stats() { - global $cache_compression, $supercachedir, $file_prefix, $wp_cache_preload_on, $cache_max_time; + global $cache_compression, $supercachedir, $wp_cache_preload_on, $cache_max_time; if ( $supercachedir == '' ) $supercachedir = get_supercache_dir(); @@ -2742,7 +2741,7 @@ function wp_cache_regenerate_cache_file_stats() { } function wp_cache_files() { - global $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $blog_cache_dir, $cache_compression; + global $cache_max_time, $valid_nonce, $supercachedir, $blog_cache_dir, $cache_compression; global $wp_cache_preload_on; if ( '/' != substr($GLOBALS['wpsc_config']['cache_path'], -1)) { @@ -2751,15 +2750,15 @@ function wp_cache_files() { if ( $valid_nonce ) { if(isset($_REQUEST['wp_delete_cache'])) { - wp_cache_clean_cache($file_prefix); + wp_cache_clean_cache($GLOBALS['wpsc_config']['file_prefix']); $_GET[ 'action' ] = 'regenerate_cache_stats'; } if ( isset( $_REQUEST[ 'wp_delete_all_cache' ] ) ) { - wp_cache_clean_cache( $file_prefix, true ); + wp_cache_clean_cache( $GLOBALS['wpsc_config']['file_prefix'], true ); $_GET[ 'action' ] = 'regenerate_cache_stats'; } if(isset($_REQUEST['wp_delete_expired'])) { - wp_cache_clean_expired($file_prefix); + wp_cache_clean_expired($GLOBALS['wpsc_config']['file_prefix']); $_GET[ 'action' ] = 'regenerate_cache_stats'; } } @@ -2792,7 +2791,7 @@ function wp_cache_files() { } } while( false !== ( $file = readdir( $handle ) ) ) { - if ( strpos( $file, $file_prefix ) !== false && substr( $file, -4 ) == '.php' ) { + if ( strpos( $file, $GLOBALS['wpsc_config']['file_prefix'] ) !== false && substr( $file, -4 ) == '.php' ) { if ( false == file_exists( $blog_cache_dir . 'meta/' . $file ) ) { @unlink( $blog_cache_dir . $file ); continue; // meta does not exist @@ -2956,7 +2955,7 @@ function delete_cache_dashboard() { //add_action( 'dashmenu', 'delete_cache_dashboard' ); function wpsc_dirsize($directory, $sizes) { - global $cache_max_time, $valid_nonce, $wp_cache_preload_on, $file_prefix; + global $cache_max_time, $valid_nonce, $wp_cache_preload_on; $now = time(); if (is_dir($directory)) { @@ -2969,8 +2968,8 @@ function wpsc_dirsize($directory, $sizes) { closedir($dh); } } else { - if ( is_file( $directory ) && strpos( $directory, 'meta-' . $file_prefix ) === false ) { - if ( strpos( $directory, '/' . $file_prefix ) !== false ) { + if ( is_file( $directory ) && strpos( $directory, 'meta-' . $GLOBALS['wpsc_config']['file_prefix'] ) === false ) { + if ( strpos( $directory, '/' . $GLOBALS['wpsc_config']['file_prefix'] ) !== false ) { $cache_type = 'wpcache'; } else { $cache_type = 'supercache'; @@ -3090,7 +3089,7 @@ function wp_cache_clean_legacy_files( $dir, $file_prefix ) { } } -function wp_cache_clean_expired($file_prefix) { +function wp_cache_clean_expired( $file_prefix ) { global $cache_max_time, $blog_cache_dir, $wp_cache_preload_on; if ( $cache_max_time == 0 ) { @@ -3108,7 +3107,7 @@ function wp_cache_clean_expired($file_prefix) { } $_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats; } - return wp_cache_phase2_clean_expired($file_prefix); + return wp_cache_phase2_clean_expired( $file_prefix ); } $now = time(); @@ -3659,7 +3658,7 @@ function wp_cron_preload_cache() { 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; + global $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 { @@ -3669,7 +3668,7 @@ function wp_cron_preload_cache() { 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. + wp_cache_phase2_clean_expired( $GLOBALS['wpsc_config']['file_prefix'], true ); // force cleanup of old files. } } @unlink( $mutex ); From 1466e26ec1e8b40a7c11e2201ff0929c383d6a2d Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh Date: Sun, 16 Feb 2020 16:01:53 +0000 Subject: [PATCH 05/17] Put $wp_cache_mutex_disabled into the settings array. --- wp-cache-phase2.php | 12 ++++++------ wp-cache.php | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index b5ab5a16..200c61e7 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -1614,9 +1614,9 @@ function wp_cache_is_rejected($uri) { } function wp_cache_mutex_init() { - global $mutex, $wp_cache_mutex_disabled, $use_flock, $blog_cache_dir, $mutex_filename, $sem_id; + global $mutex, $use_flock, $blog_cache_dir, $mutex_filename, $sem_id; - if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) ) + if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $GLOBALS['wpsc_config']['wp_cache_mutex_disabled'] ) && $GLOBALS['wpsc_config']['wp_cache_mutex_disabled'] ) ) return true; if( !is_bool( $use_flock ) ) { @@ -1638,9 +1638,9 @@ function wp_cache_mutex_init() { } function wp_cache_writers_entry() { - global $mutex, $wp_cache_mutex_disabled, $use_flock; + global $mutex, $use_flock; - if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) ) + if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $GLOBALS['wpsc_config']['wp_cache_mutex_disabled'] ) && $GLOBALS['wpsc_config']['wp_cache_mutex_disabled'] ) ) return true; if( !$mutex ) { @@ -1660,9 +1660,9 @@ function wp_cache_writers_entry() { } function wp_cache_writers_exit() { - global $mutex, $wp_cache_mutex_disabled, $use_flock; + global $mutex, $use_flock; - if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) ) + if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $GLOBALS['wpsc_config']['wp_cache_mutex_disabled'] ) && $GLOBALS['wpsc_config']['wp_cache_mutex_disabled'] ) ) return true; if( !$mutex ) { diff --git a/wp-cache.php b/wp-cache.php index 266b279c..449a4ec0 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -73,7 +73,7 @@ function wpsc_init() { * It's minimal list of global variables. */ global $wpsc_config; -global $wp_cache_mutex_disabled, $mutex_filename, $sem_id, $wp_super_cache_late_init; +global $mutex_filename, $sem_id, $wp_super_cache_late_init; global $cache_compression, $cache_max_time, $wp_cache_shutdown_gc, $cache_rebuild_files; global $wp_super_cache_debug, $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file; global $wp_cache_debug_log, $wp_cache_debug_ip, $wp_cache_debug_username, $wp_cache_debug_email; @@ -529,7 +529,7 @@ function admin_bar_delete_page() { } function wp_cache_manager_updates() { - global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_cache_refresh_single_only, $cache_compression, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get; + global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_cache_refresh_single_only, $cache_compression, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get; global $cache_schedule_type, $cache_max_time, $cache_time_interval, $wp_cache_shutdown_gc, $wpsc_save_headers; if ( !wpsupercache_site_admin() ) @@ -700,14 +700,14 @@ function wp_cache_manager_updates() { wp_cache_replace_line('^ *\$wpsc_save_headers', "\$wpsc_save_headers = " . $wpsc_save_headers . ";", $wp_cache_config_file); if( isset( $_POST[ 'wp_cache_mutex_disabled' ] ) ) { - $wp_cache_mutex_disabled = 0; + $GLOBALS['wpsc_config']['wp_cache_mutex_disabled'] = 0; } else { - $wp_cache_mutex_disabled = 1; + $GLOBALS['wpsc_config']['wp_cache_mutex_disabled'] = 1; } if( defined( 'WPSC_DISABLE_LOCKING' ) ) { - $wp_cache_mutex_disabled = 1; + $GLOBALS['wpsc_config']['wp_cache_mutex_disabled'] = 1; } - wp_cache_replace_line('^ *\$wp_cache_mutex_disabled', "\$wp_cache_mutex_disabled = " . $wp_cache_mutex_disabled . ";", $wp_cache_config_file); + wp_cache_setting( 'wp_cache_mutex_disabled', $GLOBALS['wpsc_config']['wp_cache_mutex_disabled'] ); if ( isset( $_POST['wp_cache_not_logged_in'] ) && $_POST['wp_cache_not_logged_in'] != 0 ) { if ( $wp_cache_not_logged_in == 0 && function_exists( 'prune_super_cache' ) ) { @@ -763,7 +763,7 @@ function wp_cache_manager_updates() { function wp_cache_manager() { global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_compression; - global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_no_cache_for_get; + global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_no_cache_for_get; global $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_supercache_cache_list, $cache_page_secret; global $wp_super_cache_front_page_check, $wp_cache_refresh_single_only, $wp_cache_mobile_prefixes; global $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $wp_cache_disable_utf8, $wp_cache_mfunc_enabled; @@ -1126,7 +1126,7 @@ function toggleLayer( whichLayer ) {

      -
      +

      DO NOT CACHE PAGE secret key: %s', 'wp-super-cache' ), trailingslashit( get_bloginfo( 'url' ) ) . "?donotcachepage={$cache_page_secret}", $cache_page_secret ); ?> From 0ef3e0ed4630889965ae6a6d6304df7b5bddf256 Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh Date: Sun, 16 Feb 2020 16:04:59 +0000 Subject: [PATCH 06/17] mutex_filename doesn't have to be global. --- wp-cache-phase1.php | 1 - wp-cache-phase2.php | 3 ++- wp-cache.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wp-cache-phase1.php b/wp-cache-phase1.php index ce41cfc4..43f0801a 100644 --- a/wp-cache-phase1.php +++ b/wp-cache-phase1.php @@ -30,7 +30,6 @@ $wp_cache_phase1_loaded = true; -$mutex_filename = 'wp_cache_mutex.lock'; $new_cache = false; if ( ! isset( $wp_cache_plugins_dir ) ) { diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index 200c61e7..8169d52e 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -1614,7 +1614,8 @@ function wp_cache_is_rejected($uri) { } function wp_cache_mutex_init() { - global $mutex, $use_flock, $blog_cache_dir, $mutex_filename, $sem_id; + global $mutex, $use_flock, $blog_cache_dir, $sem_id; + $mutex_filename = 'wp_cache_mutex.lock'; if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $GLOBALS['wpsc_config']['wp_cache_mutex_disabled'] ) && $GLOBALS['wpsc_config']['wp_cache_mutex_disabled'] ) ) return true; diff --git a/wp-cache.php b/wp-cache.php index 449a4ec0..76693b5d 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -73,7 +73,7 @@ function wpsc_init() { * It's minimal list of global variables. */ global $wpsc_config; -global $mutex_filename, $sem_id, $wp_super_cache_late_init; +global $sem_id, $wp_super_cache_late_init; global $cache_compression, $cache_max_time, $wp_cache_shutdown_gc, $cache_rebuild_files; global $wp_super_cache_debug, $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file; global $wp_cache_debug_log, $wp_cache_debug_ip, $wp_cache_debug_username, $wp_cache_debug_email; From bdb6b7fa6b05f52c0ababc7de3d7fdfd18444c81 Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh Date: Sun, 16 Feb 2020 16:10:08 +0000 Subject: [PATCH 07/17] Move $sem_id into the settings array. --- wp-cache-phase2.php | 6 +++--- wp-cache.php | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index 8169d52e..ff32a9aa 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -1614,7 +1614,7 @@ function wp_cache_is_rejected($uri) { } function wp_cache_mutex_init() { - global $mutex, $use_flock, $blog_cache_dir, $sem_id; + global $mutex, $use_flock, $blog_cache_dir; $mutex_filename = 'wp_cache_mutex.lock'; if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $GLOBALS['wpsc_config']['wp_cache_mutex_disabled'] ) && $GLOBALS['wpsc_config']['wp_cache_mutex_disabled'] ) ) @@ -1633,8 +1633,8 @@ function wp_cache_mutex_init() { wp_cache_debug( "Created mutex lock on filename: {$blog_cache_dir}{$mutex_filename}", 5 ); $mutex = @fopen( $blog_cache_dir . $mutex_filename, 'w' ); } else { - wp_cache_debug( "Created mutex lock on semaphore: {$sem_id}", 5 ); - $mutex = @sem_get( $sem_id, 1, 0666, 1 ); + wp_cache_debug( "Created mutex lock on semaphore: {$GLOBALS['wpsc_config']['sem_id']}", 5 ); + $mutex = @sem_get( $GLOBALS['wpsc_config']['sem_id'], 1, 0666, 1 ); } } diff --git a/wp-cache.php b/wp-cache.php index 76693b5d..219ab5bd 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -73,7 +73,7 @@ function wpsc_init() { * It's minimal list of global variables. */ global $wpsc_config; -global $sem_id, $wp_super_cache_late_init; +global $wp_super_cache_late_init; global $cache_compression, $cache_max_time, $wp_cache_shutdown_gc, $cache_rebuild_files; global $wp_super_cache_debug, $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file; global $wp_cache_debug_log, $wp_cache_debug_ip, $wp_cache_debug_username, $wp_cache_debug_email; @@ -2510,7 +2510,7 @@ function wp_cache_verify_cache_dir() { } function wp_cache_verify_config_file() { - global $wp_cache_config_file, $wp_cache_config_file_sample, $sem_id; + global $wp_cache_config_file, $wp_cache_config_file_sample; global $WPSC_HTTP_HOST; $new = false; @@ -2545,9 +2545,9 @@ function wp_cache_verify_config_file() { } $new = true; } - if ( $sem_id == 5419 && $GLOBALS['wpsc_config']['cache_path'] != '' && $WPSC_HTTP_HOST != '' ) { - $sem_id = crc32( $WPSC_HTTP_HOST . $GLOBALS['wpsc_config']['cache_path'] ) & 0x7fffffff; - wp_cache_replace_line('sem_id', '$sem_id = ' . $sem_id . ';', $wp_cache_config_file); + if ( $GLOBALS['wpsc_config']['sem_id'] == 5419 && $GLOBALS['wpsc_config']['cache_path'] != '' && $WPSC_HTTP_HOST != '' ) { + $GLOBALS['wpsc_config']['sem_id'] = crc32( $WPSC_HTTP_HOST . $GLOBALS['wpsc_config']['cache_path'] ) & 0x7fffffff; + wp_cache_setting( 'sem_id', $GLOBALS['wpsc_config']['sem_id'] ); } if ( $new ) { require($wp_cache_config_file); From f07ea57bfbf96e9fb4bee94f82316b624a18d8b3 Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh Date: Sun, 16 Feb 2020 16:16:08 +0000 Subject: [PATCH 08/17] Add $wp_super_cache_late_init to the settings array --- wp-cache-phase1.php | 8 +++++++- wp-cache-phase2.php | 10 +++------- wp-cache.php | 13 ++++++------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/wp-cache-phase1.php b/wp-cache-phase1.php index 43f0801a..0949cc51 100644 --- a/wp-cache-phase1.php +++ b/wp-cache-phase1.php @@ -117,6 +117,12 @@ return true; } -if ( ! isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && false == $wp_super_cache_late_init ) ) { +if ( + ! isset( $GLOBALS['wpsc_config']['wp_super_cache_late_init'] ) || + ( + isset( $GLOBALS['wpsc_config']['wp_super_cache_late_init'] ) && + false == $GLOBALS['wpsc_config']['wp_super_cache_late_init'] + ) +) { wp_cache_serve_cache_file(); } diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index ff32a9aa..a6da532c 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -265,13 +265,11 @@ function wp_cache_get_legacy_cache( $cache_file ) { } function wp_cache_postload() { - global $wp_super_cache_late_init; - if ( ! $GLOBALS['wpsc_config']['cache_enabled'] ) { return true; } - if ( isset( $wp_super_cache_late_init ) && true == $wp_super_cache_late_init ) { + if ( isset( $GLOBALS['wpsc_config']['wp_super_cache_late_init'] ) && true == $GLOBALS['wpsc_config']['wp_super_cache_late_init'] ) { wp_cache_debug( 'Supercache Late Init: add wp_cache_serve_cache_file to init', 3 ); add_action( 'init', 'wp_cache_late_loader', 9999 ); } else { @@ -2052,8 +2050,7 @@ function wp_cache_get_ob(&$buffer) { wp_cache_writers_exit(); wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. Check your settings page. $cache_error" ); if ( $wp_cache_mfunc_enabled == 1 ) { - global $wp_super_cache_late_init; - if ( false == isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && $wp_super_cache_late_init == 0 ) ) + if ( false == isset( $GLOBALS['wpsc_config']['wp_super_cache_late_init'] ) || ( isset( $GLOBALS['wpsc_config']['wp_super_cache_late_init'] ) && $GLOBALS['wpsc_config']['wp_super_cache_late_init'] == 0 ) ) wp_cache_add_to_buffer( $buffer, 'Super Cache dynamic page detected but $wp_super_cache_late_init not set. See the readme.txt for further details.' ); } @@ -2143,8 +2140,7 @@ function wp_cache_get_ob(&$buffer) { wp_cache_add_to_buffer( $buffer, "Warning! Obsolete mfunc/mclude/dynamic-cached-content tags found. Please update your theme. See http://ocaoimh.ie/y/5b for more information." ); } - global $wp_super_cache_late_init; - if ( false == isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && $wp_super_cache_late_init == 0 ) ) + if ( false == isset( $GLOBALS['wpsc_config']['wp_super_cache_late_init'] ) || ( isset( $GLOBALS['wpsc_config']['wp_super_cache_late_init'] ) && $GLOBALS['wpsc_config']['wp_super_cache_late_init'] == 0 ) ) wp_cache_add_to_buffer( $buffer, 'Super Cache dynamic page detected but late init not set. See the readme.txt for further details.' ); if ( $fr ) { // wpcache caching diff --git a/wp-cache.php b/wp-cache.php index 219ab5bd..eef32985 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -73,7 +73,6 @@ function wpsc_init() { * It's minimal list of global variables. */ global $wpsc_config; -global $wp_super_cache_late_init; global $cache_compression, $cache_max_time, $wp_cache_shutdown_gc, $cache_rebuild_files; global $wp_super_cache_debug, $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file; global $wp_cache_debug_log, $wp_cache_debug_ip, $wp_cache_debug_username, $wp_cache_debug_email; @@ -529,7 +528,7 @@ function admin_bar_delete_page() { } function wp_cache_manager_updates() { - global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_cache_refresh_single_only, $cache_compression, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get; + global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_cache_refresh_single_only, $cache_compression, $wp_supercache_304, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get; global $cache_schedule_type, $cache_max_time, $cache_time_interval, $wp_cache_shutdown_gc, $wpsc_save_headers; if ( !wpsupercache_site_admin() ) @@ -601,11 +600,11 @@ function wp_cache_manager_updates() { } if( isset( $_POST[ 'wp_super_cache_late_init' ] ) ) { - $wp_super_cache_late_init = 1; + $GLOBALS['wpsc_config']['wp_super_cache_late_init'] = 1; } else { - $wp_super_cache_late_init = 0; + $GLOBALS['wpsc_config']['wp_super_cache_late_init'] = 0; } - wp_cache_replace_line('^ *\$wp_super_cache_late_init', "\$wp_super_cache_late_init = " . $wp_super_cache_late_init . ";", $wp_cache_config_file); + wp_cache_setting( 'wp_super_cache_late_init', $GLOBALS['wpsc_config']['wp_super_cache_late_init'] ); if( isset( $_POST[ 'wp_cache_disable_utf8' ] ) ) { $wp_cache_disable_utf8 = 1; @@ -766,7 +765,7 @@ function wp_cache_manager() { global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_no_cache_for_get; global $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_supercache_cache_list, $cache_page_secret; global $wp_super_cache_front_page_check, $wp_cache_refresh_single_only, $wp_cache_mobile_prefixes; - global $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $wp_cache_disable_utf8, $wp_cache_mfunc_enabled; + global $wp_supercache_304, $wp_cache_front_page_checks, $wp_cache_disable_utf8, $wp_cache_mfunc_enabled; global $wp_super_cache_comments, $wpsc_save_headers, $is_nginx; if ( !wpsupercache_site_admin() ) @@ -1128,7 +1127,7 @@ function toggleLayer( whichLayer ) {
      -
      +
      DO NOT CACHE PAGE secret key: %s', 'wp-super-cache' ), trailingslashit( get_bloginfo( 'url' ) ) . "?donotcachepage={$cache_page_secret}", $cache_page_secret ); ?>
    From 700e7590615713ae635836f9421ae9af1108117f Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh Date: Sun, 16 Feb 2020 16:22:16 +0000 Subject: [PATCH 09/17] $cache_compression --- ...ss.wp-super-cache-rest-update-settings.php | 12 ++++------ wp-cache-phase1.php | 4 ++-- wp-cache-phase2.php | 10 ++++---- wp-cache.php | 24 +++++++++---------- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/rest/class.wp-super-cache-rest-update-settings.php b/rest/class.wp-super-cache-rest-update-settings.php index f198225f..21dfe355 100644 --- a/rest/class.wp-super-cache-rest-update-settings.php +++ b/rest/class.wp-super-cache-rest-update-settings.php @@ -294,12 +294,10 @@ protected function set_wp_cache_object_cache( $value ) { * @return null|string */ protected function set_cache_compression( $value ) { - global $cache_compression; - $new_cache_compression = 0; if ( defined( 'WPSC_DISABLE_COMPRESSION' ) ) { - $cache_compression = 0; - wp_cache_setting( 'cache_compression', $cache_compression ); + $GLOBALS['wpsc_config']['cache_compression'] = 0; + wp_cache_setting( 'cache_compression', $GLOBALS['wpsc_config']['cache_compression'] ); } else { if ( 1 == $value ) { @@ -310,9 +308,9 @@ protected function set_cache_compression( $value ) { return __( "You attempted to enable compression but `zlib.output_compression` is enabled. See #21 in the Troubleshooting section of the readme file.", 'wp-super-cache' ); } - if ( $new_cache_compression != $cache_compression ) { - $cache_compression = $new_cache_compression; - wp_cache_setting( 'cache_compression', $cache_compression ); + if ( $new_cache_compression != $GLOBALS['wpsc_config']['cache_compression'] ) { + $GLOBALS['wpsc_config']['cache_compression'] = $new_cache_compression; + wp_cache_setting( 'cache_compression', $GLOBALS['wpsc_config']['cache_compression'] ); if ( function_exists( 'prune_super_cache' ) ) { prune_super_cache( $GLOBALS['wpsc_config']['cache_path'], true ); } diff --git a/wp-cache-phase1.php b/wp-cache-phase1.php index 0949cc51..971286e9 100644 --- a/wp-cache-phase1.php +++ b/wp-cache-phase1.php @@ -101,7 +101,7 @@ $gzipped = 0; $gzsize = 0; -if ( $cache_compression ) { +if ( $GLOBALS['wpsc_config']['cache_compression'] ) { $wp_cache_gzip_encoding = gzip_accepted(); } @@ -121,7 +121,7 @@ ! isset( $GLOBALS['wpsc_config']['wp_super_cache_late_init'] ) || ( isset( $GLOBALS['wpsc_config']['wp_super_cache_late_init'] ) && - false == $GLOBALS['wpsc_config']['wp_super_cache_late_init'] + false == $GLOBALS['wpsc_config']['wp_super_cache_late_init'] ) ) { wp_cache_serve_cache_file(); diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index a6da532c..4d3d9af2 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -44,7 +44,7 @@ function wp_super_cache_init() { function wp_cache_serve_cache_file() { global $key, $blogcacheid, $wp_cache_request_uri, $blog_cache_dir, $meta_file, $cache_file, $cache_filename, $meta_pathname, $wp_cache_gzip_encoding, $meta; - global $cache_compression, $wp_cache_slash_check, $wp_supercache_304, $wp_cache_no_cache_for_get; + global $wp_cache_slash_check, $wp_supercache_304, $wp_cache_no_cache_for_get; global $wp_cache_disable_utf8, $wp_cache_mfunc_enabled, $wpsc_served_header; if ( wpsc_is_backend() ) { @@ -208,7 +208,7 @@ function wp_cache_serve_cache_file() { $cache_file = do_cacheaction( 'wp_cache_served_cache_file', $cache_file ); // Sometimes the gzip headers are lost. Make sure html returned isn't compressed! - if ( $cache_compression && $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $meta[ 'headers' ] ) ) { + if ( $GLOBALS['wpsc_config']['cache_compression'] && $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $meta[ 'headers' ] ) ) { $ungzip = true; wp_cache_debug( 'GZIP headers not found. Force uncompressed output.', 1 ); } else { @@ -1955,7 +1955,7 @@ function wp_cache_maybe_dynamic( &$buffer ) { function wp_cache_get_ob(&$buffer) { global $cache_filename, $wp_start_time, $supercachedir; - global $new_cache, $wp_cache_meta, $cache_compression, $wp_super_cache_query; + global $new_cache, $wp_cache_meta, $wp_super_cache_query; global $wp_cache_gzip_encoding; global $gzsize, $supercacheonly; global $blog_cache_dir, $wp_supercache_cache_list; @@ -2104,7 +2104,7 @@ function wp_cache_get_ob(&$buffer) { wp_cache_writers_exit(); return wp_cache_maybe_dynamic( $buffer ); } elseif ( - $cache_compression && + $GLOBALS['wpsc_config']['cache_compression'] && ( ! isset( $wp_cache_mfunc_enabled ) || $wp_cache_mfunc_enabled == 0 @@ -2157,7 +2157,7 @@ function wp_cache_get_ob(&$buffer) { $buffer = do_cacheaction( 'wpsc_cachedata', $buffer ); // dynamic content for display } - if ( $cache_compression && $wp_cache_gzip_encoding ) { + if ( $GLOBALS['wpsc_config']['cache_compression'] && $wp_cache_gzip_encoding ) { wp_cache_debug( 'Gzipping dynamic buffer for display.', 5 ); wp_cache_add_to_buffer( $buffer, "Compression = gzip" ); $gzdata = gzencode( $buffer, 6, FORCE_GZIP ); diff --git a/wp-cache.php b/wp-cache.php index eef32985..6e56d7e6 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -73,7 +73,7 @@ function wpsc_init() { * It's minimal list of global variables. */ global $wpsc_config; -global $cache_compression, $cache_max_time, $wp_cache_shutdown_gc, $cache_rebuild_files; +global $cache_max_time, $wp_cache_shutdown_gc, $cache_rebuild_files; global $wp_super_cache_debug, $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file; global $wp_cache_debug_log, $wp_cache_debug_ip, $wp_cache_debug_username, $wp_cache_debug_email; global $cache_time_interval, $cache_scheduled_time, $cache_schedule_interval, $cache_schedule_type, $cache_gc_email_me; @@ -528,7 +528,7 @@ function admin_bar_delete_page() { } function wp_cache_manager_updates() { - global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_cache_refresh_single_only, $cache_compression, $wp_supercache_304, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get; + global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_cache_refresh_single_only, $wp_supercache_304, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get; global $cache_schedule_type, $cache_max_time, $cache_time_interval, $wp_cache_shutdown_gc, $wpsc_save_headers; if ( !wpsupercache_site_admin() ) @@ -735,8 +735,8 @@ function wp_cache_manager_updates() { wp_cache_setting( 'wp_cache_refresh_single_only', $wp_cache_refresh_single_only ); if ( defined( 'WPSC_DISABLE_COMPRESSION' ) ) { - $cache_compression = 0; - wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file); + $GLOBALS['wpsc_config']['cache_compression'] = 0; + wp_cache_setting( 'cache_compression', 0 ); } else { if ( isset( $_POST[ 'cache_compression' ] ) ) { $new_cache_compression = 1; @@ -746,9 +746,9 @@ function wp_cache_manager_updates() { if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) { echo '
    ' . __( "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' ) . '
    '; } else { - if ( $new_cache_compression != $cache_compression ) { - $cache_compression = $new_cache_compression; - wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file); + if ( $new_cache_compression != $GLOBALS['wpsc_config']['cache_compression'] ) { + $GLOBALS['wpsc_config']['cache_compression'] = $new_cache_compression; + wp_cache_setting( 'cache_compression', $GLOBALS['wpsc_config']['cache_compression'] ); if ( function_exists( 'prune_super_cache' ) ) prune_super_cache( $GLOBALS['wpsc_config']['cache_path'], true ); delete_option( 'super_cache_meta' ); @@ -761,7 +761,7 @@ function wp_cache_manager_updates() { add_action( 'admin_init', 'wp_cache_manager_updates' ); function wp_cache_manager() { - global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_compression; + global $wp_cache_config_file, $valid_nonce, $supercachedir; global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_no_cache_for_get; global $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_supercache_cache_list, $cache_page_secret; global $wp_super_cache_front_page_check, $wp_cache_refresh_single_only, $wp_cache_mobile_prefixes; @@ -1091,7 +1091,7 @@ function toggleLayer( whichLayer ) {
    -
    +

    @@ -2701,7 +2701,7 @@ function wp_cache_format_fsize( $fsize ) { } function wp_cache_regenerate_cache_file_stats() { - global $cache_compression, $supercachedir, $wp_cache_preload_on, $cache_max_time; + global $supercachedir, $wp_cache_preload_on, $cache_max_time; if ( $supercachedir == '' ) $supercachedir = get_supercache_dir(); @@ -2730,7 +2730,7 @@ function wp_cache_regenerate_cache_file_stats() { $sizes[ $cache_type ][ $status ] = $cached_list; } } - if ( $cache_compression ) { + if ( $GLOBALS['wpsc_config']['cache_compression'] ) { $sizes[ 'supercache' ][ 'cached' ] = intval( $sizes[ 'supercache' ][ 'cached' ] / 2 ); $sizes[ 'supercache' ][ 'expired' ] = intval( $sizes[ 'supercache' ][ 'expired' ] / 2 ); } @@ -2740,7 +2740,7 @@ function wp_cache_regenerate_cache_file_stats() { } function wp_cache_files() { - global $cache_max_time, $valid_nonce, $supercachedir, $blog_cache_dir, $cache_compression; + global $cache_max_time, $valid_nonce, $supercachedir, $blog_cache_dir; global $wp_cache_preload_on; if ( '/' != substr($GLOBALS['wpsc_config']['cache_path'], -1)) { From 4662dbc65dd968c8da64b8e36ade24a51c24bb0f Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh Date: Sun, 16 Feb 2020 16:33:23 +0000 Subject: [PATCH 10/17] $cache_max_time --- wp-cache-phase2.php | 49 ++++++++++++++++++------------------ wp-cache.php | 60 ++++++++++++++++++++++----------------------- 2 files changed, 54 insertions(+), 55 deletions(-) diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index 4d3d9af2..5a7fa19a 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -92,7 +92,6 @@ function wp_cache_serve_cache_file() { } } else { // no $cache_file global $wpsc_save_headers; - global $cache_max_time; // last chance, check if a supercache file exists. Just in case .htaccess rules don't work on this host $filename = supercache_filename(); $file = get_current_url_supercache_dir() . $filename; @@ -108,8 +107,8 @@ function wp_cache_serve_cache_file() { } elseif ( isset( $wpsc_save_headers ) && $wpsc_save_headers ) { wp_cache_debug( 'Saving headers. Cannot serve a supercache file.' ); return false; - } elseif ( $cache_max_time > 0 && ( filemtime( $file ) + $cache_max_time ) < time() ) { - wp_cache_debug( sprintf( "Cache has expired and is older than %d seconds old.", $cache_max_time ) ); + } elseif ( $GLOBALS['wpsc_config']['cache_max_time'] > 0 && ( filemtime( $file ) + $GLOBALS['wpsc_config']['cache_max_time'] ) < time() ) { + wp_cache_debug( sprintf( "Cache has expired and is older than %d seconds old.", $GLOBALS['wpsc_config']['cache_max_time'] ) ); return false; } @@ -1959,7 +1958,7 @@ function wp_cache_get_ob(&$buffer) { global $wp_cache_gzip_encoding; global $gzsize, $supercacheonly; global $blog_cache_dir, $wp_supercache_cache_list; - global $wp_cache_not_logged_in, $cache_max_time; + global $wp_cache_not_logged_in; global $wp_cache_is_home, $wp_cache_front_page_checks, $wp_cache_mfunc_enabled; if ( isset( $wp_cache_mfunc_enabled ) == false ) @@ -2331,7 +2330,7 @@ function prune_super_cache( $directory, $force = false, $rename = false ) { return false; } - global $cache_max_time, $blog_cache_dir; + global $blog_cache_dir; static $log = 0; static $protected_directories = ''; @@ -2350,8 +2349,8 @@ function prune_super_cache( $directory, $force = false, $rename = false ) { wp_cache_debug( "prune_super_cache: exiting as file/dir does not exist: $directory" ); return $log; } - if( !isset( $cache_max_time ) ) - $cache_max_time = 3600; + if( !isset( $GLOBALS['wpsc_config']['cache_max_time'] ) ) + $GLOBALS['wpsc_config']['cache_max_time'] = 3600; $now = time(); @@ -2368,7 +2367,7 @@ function prune_super_cache( $directory, $force = false, $rename = false ) { $entry = $directory . $entry; prune_super_cache( $entry, $force, $rename ); // If entry is a directory, AND it's not a protected one, AND we're either forcing the delete, OR the file is out of date, - if( is_dir( $entry ) && !in_array( $entry, $protected_directories ) && ( $force || @filemtime( $entry ) + $cache_max_time <= $now ) ) { + if( is_dir( $entry ) && !in_array( $entry, $protected_directories ) && ( $force || @filemtime( $entry ) + $GLOBALS['wpsc_config']['cache_max_time'] <= $now ) ) { // if the directory isn't empty can't delete it if( $handle = @opendir( $entry ) ) { $donotdelete = false; @@ -2388,7 +2387,7 @@ function prune_super_cache( $directory, $force = false, $rename = false ) { if ( $force ) { wp_cache_debug( "gc: deleted $entry, forced delete", 2 ); } else { - wp_cache_debug( "gc: deleted $entry, older than $cache_max_time seconds", 2 ); + wp_cache_debug( "gc: deleted $entry, older than {$GLOBALS['wpsc_config']['cache_max_time']} seconds", 2 ); } } } elseif ( in_array( $entry, $protected_directories ) ) { @@ -2397,7 +2396,7 @@ function prune_super_cache( $directory, $force = false, $rename = false ) { } closedir($dh); } - } elseif( is_file($directory) && ($force || @filemtime( $directory ) + $cache_max_time <= $now ) ) { + } elseif ( is_file($directory) && ($force || @filemtime( $directory ) + $GLOBALS['wpsc_config']['cache_max_time'] <= $now ) ) { $oktodelete = true; if ( in_array( $directory, $protected_directories ) ) { wp_cache_debug( "gc: could not delete $directory as it's protected.", 2 ); @@ -2483,9 +2482,9 @@ function wp_cache_rebuild_or_delete( $file ) { } function wp_cache_phase2_clean_expired( $file_prefix, $force = false ) { - global $cache_max_time, $blog_cache_dir, $wp_cache_preload_on; + global $blog_cache_dir, $wp_cache_preload_on; - if ( $cache_max_time == 0 ) { + if ( $GLOBALS['wpsc_config']['cache_max_time'] == 0 ) { wp_cache_debug( "wp_cache_phase2_clean_expired: disabled because GC disabled.", 2 ); return false; } @@ -2499,17 +2498,17 @@ function wp_cache_phase2_clean_expired( $file_prefix, $force = false ) { if ( ( $handle = @opendir( $blog_cache_dir ) ) ) { while ( false !== ($file = readdir($handle))) { if ( preg_match("/^$file_prefix/", $file) && - (@filemtime( $blog_cache_dir . $file) + $cache_max_time) <= $now ) { + (@filemtime( $blog_cache_dir . $file) + $GLOBALS['wpsc_config']['cache_max_time']) <= $now ) { @unlink( $blog_cache_dir . $file ); @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) ); wp_cache_debug( "wp_cache_phase2_clean_expired: Deleting obsolete wpcache cache+meta files: $file" ); continue; } if($file != '.' && $file != '..') { - if( is_dir( $blog_cache_dir . $file ) == false && (@filemtime($blog_cache_dir . $file) + $cache_max_time) <= $now ) { + if( is_dir( $blog_cache_dir . $file ) == false && (@filemtime($blog_cache_dir . $file) + $GLOBALS['wpsc_config']['cache_max_time']) <= $now ) { if ( substr( $file, -9 ) != '.htaccess' && $file != 'index.html' ) { @unlink($blog_cache_dir . $file); - wp_cache_debug( "Deleting $blog_cache_dir{$file}, older than $cache_max_time seconds", 5 ); + wp_cache_debug( "Deleting $blog_cache_dir{$file}, older than {$GLOBALS['wpsc_config']['cache_max_time']} seconds", 5 ); } } } @@ -2526,7 +2525,7 @@ function wp_cache_phase2_clean_expired( $file_prefix, $force = false ) { } function wp_cache_shutdown_callback() { - global $cache_max_time, $meta_file, $new_cache, $wp_cache_meta, $known_headers, $blog_id, $wp_cache_gzip_encoding, $supercacheonly, $blog_cache_dir; + global $meta_file, $new_cache, $wp_cache_meta, $known_headers, $blog_id, $wp_cache_gzip_encoding, $supercacheonly, $blog_cache_dir; global $wp_cache_request_uri, $wp_cache_key, $wp_cache_blog_charset, $wp_cache_not_logged_in; global $WPSC_HTTP_HOST, $wp_super_cache_query; @@ -3111,10 +3110,10 @@ function get_gc_flag() { } function wp_cache_gc_cron() { - global $cache_max_time, $cache_gc_email_me, $cache_time_interval; + global $cache_gc_email_me, $cache_time_interval; $msg = ''; - if ( $cache_max_time == 0 ) { + if ( $GLOBALS['wpsc_config']['cache_max_time'] == 0 ) { wp_cache_debug( 'Cache garbage collection disabled because cache expiry time is zero.', 5 ); return false; } @@ -3132,8 +3131,8 @@ function wp_cache_gc_cron() { wp_cache_debug( 'Cache garbage collection.', 5 ); - if( !isset( $cache_max_time ) ) - $cache_max_time = 600; + if( !isset( $GLOBALS['wpsc_config']['cache_max_time'] ) ) + $GLOBALS['wpsc_config']['cache_max_time'] = 600; $start = time(); $num = 0; @@ -3161,19 +3160,19 @@ function wp_cache_gc_cron() { } function schedule_wp_gc( $forced = 0 ) { - global $cache_schedule_type, $cache_max_time, $cache_time_interval, $cache_scheduled_time, $cache_schedule_interval; + global $cache_schedule_type, $cache_time_interval, $cache_scheduled_time, $cache_schedule_interval; if ( false == isset( $cache_time_interval ) ) $cache_time_interval = 3600; if ( false == isset( $cache_schedule_type ) ) { $cache_schedule_type = 'interval'; - $cache_schedule_interval = $cache_max_time; + $cache_schedule_interval = $GLOBALS['wpsc_config']['cache_max_time']; } if ( $cache_schedule_type == 'interval' ) { - if ( !isset( $cache_max_time ) ) - $cache_max_time = 600; - if ( $cache_max_time == 0 ) + if ( !isset( $GLOBALS['wpsc_config']['cache_max_time'] ) ) + $GLOBALS['wpsc_config']['cache_max_time'] = 600; + if ( $GLOBALS['wpsc_config']['cache_max_time'] == 0 ) return false; $last_gc = get_option( "wpsupercache_gc_time" ); diff --git a/wp-cache.php b/wp-cache.php index 6e56d7e6..ccf87e03 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -73,7 +73,7 @@ function wpsc_init() { * It's minimal list of global variables. */ global $wpsc_config; -global $cache_max_time, $wp_cache_shutdown_gc, $cache_rebuild_files; +global $wp_cache_shutdown_gc, $cache_rebuild_files; global $wp_super_cache_debug, $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file; global $wp_cache_debug_log, $wp_cache_debug_ip, $wp_cache_debug_username, $wp_cache_debug_email; global $cache_time_interval, $cache_scheduled_time, $cache_schedule_interval, $cache_schedule_type, $cache_gc_email_me; @@ -529,7 +529,7 @@ function admin_bar_delete_page() { function wp_cache_manager_updates() { global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_cache_refresh_single_only, $wp_supercache_304, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get; - global $cache_schedule_type, $cache_max_time, $cache_time_interval, $wp_cache_shutdown_gc, $wpsc_save_headers; + global $cache_schedule_type, $cache_time_interval, $wp_cache_shutdown_gc, $wpsc_save_headers; if ( !wpsupercache_site_admin() ) return false; @@ -558,10 +558,10 @@ function wp_cache_manager_updates() { if ( false == isset( $cache_schedule_type ) ) { $cache_schedule_type = 'interval'; $cache_time_interval = 600; - $cache_max_time = 1800; + $GLOBALS['wpsc_config']['cache_max_time'] = 1800; 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_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = '$cache_max_time';", $wp_cache_config_file); + wp_cache_setting( 'cache_max_time', $GLOBALS['wpsc_config']['cache_max_time'] ); } wp_schedule_single_event( time() + 600, 'wp_cache_gc' ); } @@ -1723,7 +1723,7 @@ function RecursiveFolderDelete ( $folderPath ) { // from http://www.php.net/manu } 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; + global $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 ) @@ -1739,19 +1739,20 @@ function wp_cache_time_update() { wp_cache_replace_line('^ *\$cache_scheduled_time', "\$cache_scheduled_time = '$cache_scheduled_time';", $wp_cache_config_file); } - if( !isset( $cache_max_time ) ) { - $cache_max_time = 3600; - wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file); + if( !isset( $GLOBALS['wpsc_config']['cache_max_time'] ) ) { + $GLOBALS['wpsc_config']['cache_max_time'] = 3600; + wp_cache_setting( 'cache_max_time', $GLOBALS['wpsc_config']['cache_max_time'] ); } if ( !isset( $cache_time_interval ) ) { - $cache_time_interval = $cache_max_time; + $cache_time_interval = $GLOBALS['wpsc_config']['cache_max_time']; wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file); + wp_cache_setting( 'cache_time_interval', $GLOBALS['wpsc_config']['cache_time_interval'] ); } 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); + $GLOBALS['wpsc_config']['cache_max_time'] = (int)$_POST['wp_max_time']; + wp_cache_setting( 'cache_max_time', $GLOBALS['wpsc_config']['cache_max_time'] ); // schedule gc watcher if ( false == wp_next_scheduled( 'wp_cache_gc_watcher' ) ) wp_schedule_event( time()+600, 'hourly', 'wp_cache_gc_watcher' ); @@ -1798,7 +1799,7 @@ function wp_cache_time_update() { } function wp_cache_edit_max_time() { - 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, $wp_cache_preload_on; + global $wp_cache_config_file, $valid_nonce, $cache_schedule_type, $cache_scheduled_time, $cache_schedule_interval, $cache_time_interval, $cache_gc_email_me, $wp_cache_preload_on; $admin_url = admin_url( 'options-general.php?page=wpsupercache' ); $timezone_format = _x('Y-m-d G:i:s', 'timezone date format'); @@ -1839,7 +1840,7 @@ function wp_cache_edit_max_time() { echo ''; echo ''; echo ''; - echo "\n"; + echo "\n"; echo "\n"; echo '
    " . __( "seconds", 'wp-super-cache' ) . "
    " . __( "seconds", 'wp-super-cache' ) . "
    " . __( 'How long should cached pages remain fresh? Set to 0 to disable garbage collection. A good starting point is 3600 seconds.', 'wp-super-cache' ) . "
    ' . __( 'Scheduler', 'wp-super-cache' ) . ''; echo ""; @@ -2701,7 +2702,7 @@ function wp_cache_format_fsize( $fsize ) { } function wp_cache_regenerate_cache_file_stats() { - global $supercachedir, $wp_cache_preload_on, $cache_max_time; + global $supercachedir, $wp_cache_preload_on; if ( $supercachedir == '' ) $supercachedir = get_supercache_dir(); @@ -2740,7 +2741,7 @@ function wp_cache_regenerate_cache_file_stats() { } function wp_cache_files() { - global $cache_max_time, $valid_nonce, $supercachedir, $blog_cache_dir; + global $valid_nonce, $supercachedir, $blog_cache_dir; global $wp_cache_preload_on; if ( '/' != substr($GLOBALS['wpsc_config']['cache_path'], -1)) { @@ -2812,14 +2813,14 @@ function wp_cache_files() { $meta[ 'age' ] = $age; foreach( $meta as $key => $val ) $meta[ $key ] = esc_html( $val ); - if ( $cache_max_time > 0 && $age > $cache_max_time ) { + if ( $GLOBALS['wpsc_config']['cache_max_time'] > 0 && $age > $GLOBALS['wpsc_config']['cache_max_time'] ) { $expired_list[ $age ][] = $meta; } else { $cached_list[ $age ][] = $meta; } } - if ( $cache_max_time > 0 && $age > $cache_max_time ) { + if ( $GLOBALS['wpsc_config']['cache_max_time'] > 0 && $age > $GLOBALS['wpsc_config']['cache_max_time'] ) { $expired++; } else { $count++; @@ -2904,8 +2905,8 @@ function wp_cache_files() { } else { echo "

    'wpsupercache', 'listfiles' => '1' ) ), 'wp-cache' ) . "#listfiles'>" . __( 'List all cached files', 'wp-super-cache' ) . "

    "; } - if ( $cache_max_time > 0 ) - echo "

    " . sprintf( __( 'Expired files are files older than %s seconds. They are still used by the plugin and are deleted periodically.', 'wp-super-cache' ), $cache_max_time ) . "

    "; + if ( $GLOBALS['wpsc_config']['cache_max_time'] > 0 ) + echo "

    " . sprintf( __( 'Expired files are files older than %s seconds. They are still used by the plugin and are deleted periodically.', 'wp-super-cache' ), $GLOBALS['wpsc_config']['cache_max_time'] ) . "

    "; if ( $wp_cache_preload_on ) echo "

    " . __( 'Preload mode is enabled. Supercache files will never be expired.', 'wp-super-cache' ) . "

    "; } // cache_stats @@ -2954,7 +2955,7 @@ function delete_cache_dashboard() { //add_action( 'dashmenu', 'delete_cache_dashboard' ); function wpsc_dirsize($directory, $sizes) { - global $cache_max_time, $valid_nonce, $wp_cache_preload_on; + global $valid_nonce, $wp_cache_preload_on; $now = time(); if (is_dir($directory)) { @@ -2977,7 +2978,7 @@ function wpsc_dirsize($directory, $sizes) { if ( $cache_type == 'supercache' && $wp_cache_preload_on ) $keep_fresh = true; $filem = filemtime( $directory ); - if ( $keep_fresh == false && $cache_max_time > 0 && $filem + $cache_max_time <= $now ) { + if ( $keep_fresh == false && $GLOBALS['wpsc_config']['cache_max_time'] > 0 && $filem + $GLOBALS['wpsc_config']['cache_max_time'] <= $now ) { $cache_status = 'expired'; } else { $cache_status = 'cached'; @@ -3089,9 +3090,9 @@ function wp_cache_clean_legacy_files( $dir, $file_prefix ) { } function wp_cache_clean_expired( $file_prefix ) { - global $cache_max_time, $blog_cache_dir, $wp_cache_preload_on; + global $blog_cache_dir, $wp_cache_preload_on; - if ( $cache_max_time == 0 ) { + if ( $GLOBALS['wpsc_config']['cache_max_time'] == 0 ) { return false; } @@ -3116,7 +3117,7 @@ function wp_cache_clean_expired( $file_prefix ) { if ( strpos( $file, '.html' ) ) { @unlink( $blog_cache_dir . $file); @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) ); - } elseif ( ( filemtime( $blog_cache_dir . $file ) + $cache_max_time ) <= $now ) { + } elseif ( ( filemtime( $blog_cache_dir . $file ) + $GLOBALS['wpsc_config']['cache_max_time'] ) <= $now ) { @unlink( $blog_cache_dir . $file ); @unlink( $blog_cache_dir . 'meta/' . $file ); } @@ -3657,15 +3658,14 @@ function wp_cron_preload_cache() { 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 $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 + $GLOBALS['wpsc_config']['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 + $GLOBALS['wpsc_config']['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 + if ( $GLOBALS['wpsc_config']['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( $GLOBALS['wpsc_config']['file_prefix'], true ); // force cleanup of old files. } @@ -4014,12 +4014,12 @@ function wpsc_set_default_gc( $force = false ) { if ( false == isset( $cache_schedule_type ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) { $cache_schedule_type = 'interval'; $cache_time_interval = 600; - $cache_max_time = 1800; + $GLOBALS['wpsc_config']['cache_max_time'] = 1800; $cache_schedule_interval = 'hourly'; $cache_gc_email_me = 0; wp_cache_setting( 'cache_schedule_type', $cache_schedule_type ); wp_cache_setting( 'cache_time_interval', $cache_time_interval ); - wp_cache_setting( 'cache_max_time', $cache_max_time ); + wp_cache_setting( 'cache_max_time', $GLOBALS['wpsc_config']['cache_max_time'] ); wp_cache_setting( 'cache_schedule_interval', $cache_schedule_interval ); wp_cache_setting( 'cache_gc_email_me', $cache_gc_email_me ); From 669a7205c3def15c79e99d08b4d5efdf4f22518c Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh Date: Sun, 16 Feb 2020 16:37:21 +0000 Subject: [PATCH 11/17] $wp_cache_shutdown_gc --- rest/class.wp-super-cache-rest-update-settings.php | 2 +- wp-cache-phase2.php | 3 +-- wp-cache.php | 14 +++++++------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/rest/class.wp-super-cache-rest-update-settings.php b/rest/class.wp-super-cache-rest-update-settings.php index 21dfe355..1adf6dd9 100644 --- a/rest/class.wp-super-cache-rest-update-settings.php +++ b/rest/class.wp-super-cache-rest-update-settings.php @@ -442,7 +442,7 @@ protected function set_preload_setting( $value, $name ) { * @param bool $enabled */ protected function toggle_easy_caching( $enabled = true ) { - global $wp_cache_shutdown_gc, $cache_schedule_type; + global $cache_schedule_type; if ( $enabled ) { $settings = array( 'wp_cache_mobile_enabled' => 1, diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index 5a7fa19a..155d6d3b 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -3181,8 +3181,7 @@ function schedule_wp_gc( $forced = 0 ) { $last_gc = get_option( "wpsupercache_gc_time" ); } if ( $forced || ( $last_gc < ( time() - 60 ) ) ) { // Allow up to 60 seconds for the previous job to run - global $wp_cache_shutdown_gc; - if ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) { + if ( !isset( $GLOBALS['wpsc_config']['wp_cache_shutdown_gc'] ) || $GLOBALS['wpsc_config']['wp_cache_shutdown_gc'] == 0 ) { if ( !($t = wp_next_scheduled( 'wp_cache_gc' ) ) ) { wp_clear_scheduled_hook( 'wp_cache_gc' ); wp_schedule_single_event( time() + $cache_time_interval, 'wp_cache_gc' ); diff --git a/wp-cache.php b/wp-cache.php index ccf87e03..020458fa 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -73,7 +73,7 @@ function wpsc_init() { * It's minimal list of global variables. */ global $wpsc_config; -global $wp_cache_shutdown_gc, $cache_rebuild_files; +global $cache_rebuild_files; global $wp_super_cache_debug, $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file; global $wp_cache_debug_log, $wp_cache_debug_ip, $wp_cache_debug_username, $wp_cache_debug_email; global $cache_time_interval, $cache_scheduled_time, $cache_schedule_interval, $cache_schedule_type, $cache_gc_email_me; @@ -241,7 +241,7 @@ function wp_cache_network_pages() { function wp_cache_manager_error_checks() { global $wp_cache_debug, $wp_cache_cron_check, $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_mobile_enabled; - global $dismiss_htaccess_warning, $dismiss_readable_warning, $dismiss_gc_warning, $wp_cache_shutdown_gc, $is_nginx; + global $dismiss_htaccess_warning, $dismiss_readable_warning, $dismiss_gc_warning, $is_nginx; global $htaccess_path; if ( ! wpsupercache_site_admin() ) { @@ -366,7 +366,7 @@ function wp_cache_manager_error_checks() { } elseif ( !isset( $dismiss_gc_warning ) ) { $dismiss_gc_warning = 0; } - if ( $GLOBALS['wpsc_config']['cache_enabled'] && ( ! isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && function_exists( 'get_gc_flag' ) ) { + if ( $GLOBALS['wpsc_config']['cache_enabled'] && ( ! isset( $GLOBALS['wpsc_config']['wp_cache_shutdown_gc'] ) || $GLOBALS['wpsc_config']['wp_cache_shutdown_gc'] == 0 ) && function_exists( 'get_gc_flag' ) ) { $gc_flag = get_gc_flag(); if ( $dismiss_gc_warning == 0 ) { if ( false == maybe_stop_gc( $gc_flag ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) { @@ -529,7 +529,7 @@ function admin_bar_delete_page() { function wp_cache_manager_updates() { global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_cache_refresh_single_only, $wp_supercache_304, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get; - global $cache_schedule_type, $cache_time_interval, $wp_cache_shutdown_gc, $wpsc_save_headers; + global $cache_schedule_type, $cache_time_interval, $wpsc_save_headers; if ( !wpsupercache_site_admin() ) return false; @@ -554,7 +554,7 @@ function wp_cache_manager_updates() { $_POST[ 'wp_cache_location' ] = $GLOBALS['wpsc_config']['cache_path']; // // set up garbage collection with some default settings - if ( ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) { + if ( ( !isset( $GLOBALS['wpsc_config']['wp_cache_shutdown_gc'] ) || $GLOBALS['wpsc_config']['wp_cache_shutdown_gc'] == 0 ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) { if ( false == isset( $cache_schedule_type ) ) { $cache_schedule_type = 'interval'; $cache_time_interval = 600; @@ -3996,9 +3996,9 @@ function wpsc_is_preloading() { } function wpsc_set_default_gc( $force = false ) { - global $wp_cache_shutdown_gc, $cache_schedule_type; + global $cache_schedule_type; - if ( isset( $wp_cache_shutdown_gc ) && $wp_cache_shutdown_gc == 1 ) { + if ( isset( $GLOBALS['wpsc_config']['wp_cache_shutdown_gc'] ) && $GLOBALS['wpsc_config']['wp_cache_shutdown_gc'] == 1 ) { return false; } From ba7d2bc81c3df43d59aa4fb4b75e9fb7599ac87c Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh Date: Sun, 16 Feb 2020 16:40:36 +0000 Subject: [PATCH 12/17] $cache_rebuild_files --- wp-cache-phase2.php | 9 +++------ wp-cache.php | 17 ++++++++--------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index 155d6d3b..062abbe8 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -1282,7 +1282,7 @@ function wpsc_shutdown_message() { } function wp_cache_phase2() { - global $wp_cache_gzip_encoding, $cache_rebuild_files, $wp_cache_gmt_offset, $wp_cache_blog_charset; + global $wp_cache_gzip_encoding, $wp_cache_gmt_offset, $wp_cache_blog_charset; if ( $GLOBALS['wpsc_config']['cache_enabled'] == false ) { wp_cache_debug( 'wp_cache_phase2: Caching disabled! Exit' ); @@ -1337,7 +1337,7 @@ function wp_cache_phase2() { wp_cache_debug( 'Created output buffer', 4 ); // restore old supercache file temporarily - if ( ( $_SERVER['REQUEST_METHOD'] !== 'POST' && empty( $_POST ) ) && $GLOBALS['wpsc_config']['super_cache_enabled'] && $cache_rebuild_files ) { + if ( ( $_SERVER['REQUEST_METHOD'] !== 'POST' && empty( $_POST ) ) && $GLOBALS['wpsc_config']['super_cache_enabled'] && $GLOBALS['wpsc_config']['cache_rebuild_files'] ) { $user_info = wp_cache_get_cookies_values(); if( empty( $user_info ) @@ -2420,9 +2420,6 @@ function prune_super_cache( $directory, $force = false, $rename = false ) { } function wp_cache_rebuild_or_delete( $file ) { - global $cache_rebuild_files; - - if ( strpos( $file, '?' ) !== false ) $file = substr( $file, 0, strpos( $file, '?' ) ); @@ -2464,7 +2461,7 @@ function wp_cache_rebuild_or_delete( $file ) { wp_cache_debug( "rebuild_or_gc: file has disappeared: $file" ); return false; } - if( $cache_rebuild_files && substr( $file, -14 ) != '.needs-rebuild' ) { + if ( $GLOBALS['wpsc_config']['cache_rebuild_files'] && substr( $file, -14 ) != '.needs-rebuild' ) { if( @rename($file, $file . '.needs-rebuild') ) { @touch( $file . '.needs-rebuild' ); wp_cache_debug( "rebuild_or_gc: rename file to {$file}.needs-rebuild", 2 ); diff --git a/wp-cache.php b/wp-cache.php index 020458fa..969c16b2 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -73,7 +73,6 @@ function wpsc_init() { * It's minimal list of global variables. */ global $wpsc_config; -global $cache_rebuild_files; global $wp_super_cache_debug, $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file; global $wp_cache_debug_log, $wp_cache_debug_ip, $wp_cache_debug_username, $wp_cache_debug_email; global $cache_time_interval, $cache_scheduled_time, $cache_schedule_interval, $cache_schedule_type, $cache_gc_email_me; @@ -528,7 +527,7 @@ function admin_bar_delete_page() { } function wp_cache_manager_updates() { - global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_cache_refresh_single_only, $wp_supercache_304, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get; + global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_clear_on_post_edit, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_cache_refresh_single_only, $wp_supercache_304, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get; global $cache_schedule_type, $cache_time_interval, $wpsc_save_headers; if ( !wpsupercache_site_admin() ) @@ -685,11 +684,11 @@ function wp_cache_manager_updates() { wp_cache_replace_line('^ *\$wp_cache_clear_on_post_edit', "\$wp_cache_clear_on_post_edit = " . $wp_cache_clear_on_post_edit . ";", $wp_cache_config_file); if( isset( $_POST[ 'cache_rebuild_files' ] ) ) { - $cache_rebuild_files = 1; + $GLOBALS['wpsc_config']['cache_rebuild_files'] = 1; } else { - $cache_rebuild_files = 0; + $GLOBALS['wpsc_config']['cache_rebuild_files'] = 0; } - wp_cache_replace_line('^ *\$cache_rebuild_files', "\$cache_rebuild_files = " . $cache_rebuild_files . ";", $wp_cache_config_file); + wp_cache_setting( 'cache_rebuild_files', $GLOBALS['wpsc_config']['cache_rebuild_files'] ); if ( isset( $_POST[ 'wpsc_save_headers' ] ) ) { $wpsc_save_headers = 1; @@ -762,7 +761,7 @@ function wp_cache_manager_updates() { function wp_cache_manager() { global $wp_cache_config_file, $valid_nonce, $supercachedir; - global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_no_cache_for_get; + global $wp_cache_clear_on_post_edit, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_no_cache_for_get; global $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_supercache_cache_list, $cache_page_secret; global $wp_super_cache_front_page_check, $wp_cache_refresh_single_only, $wp_cache_mobile_prefixes; global $wp_supercache_304, $wp_cache_front_page_checks, $wp_cache_disable_utf8, $wp_cache_mfunc_enabled; @@ -804,8 +803,8 @@ function wp_cache_manager() { $supercachedir = get_supercache_dir(); if( get_option( 'gzipcompression' ) == 1 ) update_option( 'gzipcompression', 0 ); - if( !isset( $cache_rebuild_files ) ) - $cache_rebuild_files = 0; + if( !isset( $GLOBALS['wpsc_config']['cache_rebuild_files'] ) ) + $GLOBALS['wpsc_config']['cache_rebuild_files'] = 0; $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false; /* http://www.netlobo.com/div_hiding.html */ @@ -1095,7 +1094,7 @@ function toggleLayer( whichLayer ) {
    -
    +

    From 65c2dd03f9529f6f0d63c3600a7a6801bd41bd4a Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh Date: Sun, 16 Feb 2020 16:52:36 +0000 Subject: [PATCH 13/17] $wp_super_cache_debug --- wp-cache-phase2.php | 14 ++++++-------- wp-cache.php | 12 ++++++------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index 062abbe8..800f2162 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -523,7 +523,7 @@ function wp_cache_check_mobile( $cache_key ) { * @param $level int */ function wp_cache_debug( $message, $level = 1 ) { - global $wp_cache_debug_log, $wp_cache_debug_ip, $wp_super_cache_debug; + global $wp_cache_debug_log, $wp_cache_debug_ip; static $last_message = ''; if ( $last_message == $message ) { @@ -532,13 +532,11 @@ function wp_cache_debug( $message, $level = 1 ) { $last_message = $message; // If either of the debug or log globals aren't set, then we can stop - if ( !isset($wp_super_cache_debug) - || !isset($wp_cache_debug_log) ) + if ( ! isset( $GLOBALS['wpsc_config']['wp_super_cache_debug'] ) || ! isset( $wp_cache_debug_log ) ) return false; // If either the debug or log globals are false or empty, we can stop - if ( $wp_super_cache_debug == false - || $wp_cache_debug_log == '' ) + if ( $GLOBALS['wpsc_config']['wp_super_cache_debug'] == false || $wp_cache_debug_log == '' ) return false; // If the debug_ip has been set, but it doesn't match the ip of the requester @@ -1971,7 +1969,7 @@ function wp_cache_get_ob(&$buffer) { * we avoid caching incomplete files */ if ( $buffer == '' ) { $new_cache = false; - if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) { + if ( isset( $GLOBALS['wpsc_config']['wp_super_cache_debug'] ) && $GLOBALS['wpsc_config']['wp_super_cache_debug'] ) { wp_cache_debug( "Buffer is blank. Output buffer may have been corrupted by another plugin or this is a redirected URL. Look for text 'ob_start' in the files of your plugins directory.", 2 ); wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. Blank Page. Check output buffer usage by plugins." ); } @@ -1979,7 +1977,7 @@ function wp_cache_get_ob(&$buffer) { if ( isset( $wp_super_cache_query[ 'is_404' ] ) && false == apply_filters( 'wpsupercache_404', false ) ) { $new_cache = false; - if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) { + if ( isset( $GLOBALS['wpsc_config']['wp_super_cache_debug'] ) && $GLOBALS['wpsc_config']['wp_super_cache_debug'] ) { wp_cache_debug( '404 file not found not cached', 2 ); wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. 404." ); } @@ -1987,7 +1985,7 @@ function wp_cache_get_ob(&$buffer) { if ( !preg_match( apply_filters( 'wp_cache_eof_tags', '/(<\/html>|<\/rss>|<\/feed>|<\/urlset|<\?xml)/i' ), $buffer ) ) { $new_cache = false; - if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) { + if ( isset( $GLOBALS['wpsc_config']['wp_super_cache_debug'] ) && $GLOBALS['wpsc_config']['wp_super_cache_debug'] ) { wp_cache_debug( 'No closing html tag. Not caching.', 2 ); wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. No closing HTML tag. Check your theme." ); } diff --git a/wp-cache.php b/wp-cache.php index 969c16b2..18c37114 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -2039,7 +2039,7 @@ function wpsc_update_debug_settings() { if ( false == $valid_nonce ) { return array ( - 'wp_super_cache_debug' => $wp_super_cache_debug, + 'wp_super_cache_debug' => $GLOBALS['wpsc_config']['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, @@ -2062,8 +2062,8 @@ function wpsc_update_debug_settings() { } elseif ( ! file_exists( $GLOBALS['wpsc_config']['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 ); + $GLOBALS['wpsc_config']['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', $GLOBALS['wpsc_config']['wp_super_cache_debug'] ); if ( isset( $_POST[ 'wp_cache_debug' ] ) ) { wp_cache_setting( 'wp_cache_debug_username', $wp_cache_debug_username ); @@ -2095,7 +2095,7 @@ function wpsc_update_debug_settings() { } return array ( - 'wp_super_cache_debug' => $wp_super_cache_debug, + 'wp_super_cache_debug' => $GLOBALS['wpsc_config']['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, @@ -2125,7 +2125,7 @@ function wp_cache_debug_settings() { $log_file_link = "$wp_cache_debug_log"; - if ( $wp_super_cache_debug == 1 ) { + if ( $GLOBALS['wpsc_config']['wp_super_cache_debug'] == 1 ) { echo "

    " . sprintf( __( 'Currently logging to: %s', 'wp-super-cache' ), $log_file_link ) . "

    "; } else { echo "

    " . sprintf( __( 'Last Logged to: %s', 'wp-super-cache' ), $log_file_link ) . "

    "; @@ -2139,7 +2139,7 @@ function wp_cache_debug_settings() { echo ""; echo '
    '; - if ( ! isset( $wp_super_cache_debug ) || $wp_super_cache_debug == 0 ) { + if ( ! isset( $GLOBALS['wpsc_config']['wp_super_cache_debug'] ) || $GLOBALS['wpsc_config']['wp_super_cache_debug'] == 0 ) { $debug_status_message = __( 'Enable Logging', 'wp-super-cache' ); $not_status = 1; } else { From 05c3d1e6faf17edbeb7e8302dccf7ef1e90a6415 Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh Date: Sun, 16 Feb 2020 18:03:20 +0000 Subject: [PATCH 14/17] Remove these global $wp_super_cache_debug --- wp-cache.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wp-cache.php b/wp-cache.php index 18c37114..813715cf 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -73,7 +73,7 @@ function wpsc_init() { * It's minimal list of global variables. */ global $wpsc_config; -global $wp_super_cache_debug, $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file; +global $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file; global $wp_cache_debug_log, $wp_cache_debug_ip, $wp_cache_debug_username, $wp_cache_debug_email; global $cache_time_interval, $cache_scheduled_time, $cache_schedule_interval, $cache_schedule_type, $cache_gc_email_me; global $wp_cache_preload_on, $wp_cache_preload_interval, $wp_cache_preload_posts, $wp_cache_preload_taxonomies; @@ -2028,7 +2028,7 @@ function wp_cache_edit_accepted() { } function wpsc_update_debug_settings() { - global $wp_super_cache_debug, $wp_cache_debug_log, $wp_cache_debug_ip, $valid_nonce, $wp_cache_config_file, $wp_super_cache_comments; + global $wp_cache_debug_log, $wp_cache_debug_ip, $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; @@ -2109,7 +2109,7 @@ function wpsc_update_debug_settings() { } function wp_cache_debug_settings() { - global $wp_super_cache_debug, $wp_cache_debug_log, $wp_cache_debug_ip, $valid_nonce, $wp_cache_config_file, $wp_super_cache_comments; + global $wp_cache_debug_log, $wp_cache_debug_ip, $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; From 73fc2e250351da4e9fed72ba1143c4a59b3225ec Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh Date: Sun, 16 Feb 2020 18:17:52 +0000 Subject: [PATCH 15/17] $wp_cache_debug_log --- wp-cache-phase2.php | 26 +++++++++++++------------- wp-cache.php | 28 ++++++++++++++-------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index 800f2162..ff95f9b5 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -523,7 +523,7 @@ function wp_cache_check_mobile( $cache_key ) { * @param $level int */ function wp_cache_debug( $message, $level = 1 ) { - global $wp_cache_debug_log, $wp_cache_debug_ip; + global $wp_cache_debug_ip; static $last_message = ''; if ( $last_message == $message ) { @@ -532,11 +532,11 @@ function wp_cache_debug( $message, $level = 1 ) { $last_message = $message; // If either of the debug or log globals aren't set, then we can stop - if ( ! isset( $GLOBALS['wpsc_config']['wp_super_cache_debug'] ) || ! isset( $wp_cache_debug_log ) ) + if ( ! isset( $GLOBALS['wpsc_config']['wp_super_cache_debug'] ) || ! isset( $GLOBALS['wpsc_config']['wp_cache_debug_log'] ) ) return false; // If either the debug or log globals are false or empty, we can stop - if ( $GLOBALS['wpsc_config']['wp_super_cache_debug'] == false || $wp_cache_debug_log == '' ) + if ( $GLOBALS['wpsc_config']['wp_super_cache_debug'] == false || $GLOBALS['wpsc_config']['wp_cache_debug_log'] == '' ) return false; // If the debug_ip has been set, but it doesn't match the ip of the requester @@ -549,7 +549,7 @@ function wp_cache_debug( $message, $level = 1 ) { // Log message: Date URI Message $log_message = date('H:i:s') . " " . getmypid() . " {$_SERVER['REQUEST_URI']} {$message}" . PHP_EOL; // path to the log file in the cache folder - $log_file = $GLOBALS['wpsc_config']['cache_path'] . str_replace('/', '', str_replace('..', '', $wp_cache_debug_log)); + $log_file = $GLOBALS['wpsc_config']['cache_path'] . str_replace( '/', '', str_replace( '..', '', $GLOBALS['wpsc_config']['wp_cache_debug_log'] ) ); if ( ! file_exists( $log_file ) && function_exists( 'wpsc_create_debug_log' ) ) { global $wp_cache_debug_username; @@ -557,7 +557,7 @@ function wp_cache_debug( $message, $level = 1 ) { $wp_cache_debug_username = ''; } - wpsc_create_debug_log( $wp_cache_debug_log, $wp_cache_debug_username ); + wpsc_create_debug_log( $GLOBALS['wpsc_config']['wp_cache_debug_log'], $wp_cache_debug_username ); } error_log( $log_message, 3, $log_file ); @@ -1013,11 +1013,11 @@ function wpsc_debug_username() { return $wp_cache_debug_username; } function wpsc_create_debug_log( $filename = '', $username = '' ) { - global $wp_cache_debug_username, $wp_cache_debug_log; + global $wp_cache_debug_username; if ( $filename != '' ) { - $wp_cache_debug_log = $filename; + $GLOBALS['wpsc_config']['wp_cache_debug_log'] = $filename; } else { - $wp_cache_debug_log = md5( time() + mt_rand() ) . ".php"; + $GLOBALS['wpsc_config']['wp_cache_debug_log'] = md5( time() + mt_rand() ) . ".php"; } if ( $username != '' ) { $wp_cache_debug_username = $username; @@ -1026,14 +1026,14 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) { } $msg = 'die( "Please use the viewer" );' . PHP_EOL; - $fp = fopen( $GLOBALS['wpsc_config']['cache_path'] . $wp_cache_debug_log, 'w' ); + $fp = fopen( $GLOBALS['wpsc_config']['cache_path'] . $GLOBALS['wpsc_config']['wp_cache_debug_log'], 'w' ); if ( $fp ) { fwrite( $fp, '<' . "?php\n" ); fwrite( $fp, $msg ); fwrite( $fp, '?' . ">
    " . PHP_EOL );
     		fwrite( $fp, '<' . '?php // END HEADER ?' . '>' . PHP_EOL );
     		fclose( $fp );
    -		wp_cache_setting( 'wp_cache_debug_log', $wp_cache_debug_log );
    +		wp_cache_setting( 'wp_cache_debug_log', $GLOBALS['wpsc_config']['wp_cache_debug_log'] );
     		wp_cache_setting( 'wp_cache_debug_username', $wp_cache_debug_username );
     	}
     
    @@ -1045,10 +1045,10 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) {
     	exit;
     }' . PHP_EOL;
     
    -	$fp = fopen( $GLOBALS['wpsc_config']['cache_path'] . 'view_' . $wp_cache_debug_log, 'w' );
    +	$fp = fopen( $GLOBALS['wpsc_config']['cache_path'] . 'view_' . $GLOBALS['wpsc_config']['wp_cache_debug_log'], 'w' );
     	if ( $fp ) {
     		fwrite( $fp, '<' . "?php" . PHP_EOL );
    -		$msg .= '$debug_log = file( "./' . $wp_cache_debug_log . '" );
    +		$msg .= '$debug_log = file( "./' . $GLOBALS['wpsc_config']['wp_cache_debug_log'] . '" );
     $start_log = 1 + array_search( "<" . "?php // END HEADER ?" . ">" . PHP_EOL, $debug_log );
     if ( $start_log > 1 ) {
     	$debug_log = array_slice( $debug_log, $start_log );
    @@ -1112,7 +1112,7 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) {
     		fclose( $fp );
     	}
     
    -	return array( 'wp_cache_debug_log' => $wp_cache_debug_log, 'wp_cache_debug_username' => $wp_cache_debug_username );
    +	return array( 'wp_cache_debug_log' => $GLOBALS['wpsc_config']['wp_cache_debug_log'], 'wp_cache_debug_username' => $wp_cache_debug_username );
     }
     
     function wpsc_delete_url_cache( $url ) {
    diff --git a/wp-cache.php b/wp-cache.php
    index 813715cf..3c399c1b 100644
    --- a/wp-cache.php
    +++ b/wp-cache.php
    @@ -74,7 +74,7 @@ function wpsc_init() {
      */
     global $wpsc_config;
     global $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file;
    -global $wp_cache_debug_log, $wp_cache_debug_ip, $wp_cache_debug_username, $wp_cache_debug_email;
    +global $wp_cache_debug_ip, $wp_cache_debug_username, $wp_cache_debug_email;
     global $cache_time_interval, $cache_scheduled_time, $cache_schedule_interval, $cache_schedule_type, $cache_gc_email_me;
     global $wp_cache_preload_on, $wp_cache_preload_interval, $wp_cache_preload_posts, $wp_cache_preload_taxonomies;
     global $wp_cache_preload_email_me, $wp_cache_preload_email_volume;
    @@ -2028,7 +2028,7 @@ function wp_cache_edit_accepted() {
     }
     
     function wpsc_update_debug_settings() {
    -	global $wp_cache_debug_log, $wp_cache_debug_ip, $valid_nonce, $wp_cache_config_file, $wp_super_cache_comments;
    +	global $wp_cache_debug_ip, $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;
     
    @@ -2040,7 +2040,7 @@ function wpsc_update_debug_settings() {
     	if ( false == $valid_nonce ) {
     		return array (
     			'wp_super_cache_debug' => $GLOBALS['wpsc_config']['wp_super_cache_debug'],
    -			'wp_cache_debug_log' => $wp_cache_debug_log,
    +			'wp_cache_debug_log' => $GLOBALS['wpsc_config']['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,
    @@ -2052,22 +2052,22 @@ function wpsc_update_debug_settings() {
     		);
     	}
     
    -	if ( isset( $_POST[ 'wpsc_delete_log' ] ) && $_POST[ 'wpsc_delete_log' ] == 1 && $wp_cache_debug_log != '' ) {
    -		@unlink( $GLOBALS['wpsc_config']['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( $_POST[ 'wpsc_delete_log' ] ) && $_POST[ 'wpsc_delete_log' ] == 1 && $GLOBALS['wpsc_config']['wp_cache_debug_log'] != '' ) {
    +		@unlink( $GLOBALS['wpsc_config']['cache_path'] . $GLOBALS['wpsc_config']['wp_cache_debug_log'] );
    +		extract( wpsc_create_debug_log( $GLOBALS['wpsc_config']['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 == '' ) {
    +	if ( ! isset( $GLOBALS['wpsc_config']['wp_cache_debug_log'] ) || $GLOBALS['wpsc_config']['wp_cache_debug_log'] == '' ) {
     		extract( wpsc_create_debug_log() ); // $wp_cache_debug_log, $wp_cache_debug_username
    -	} elseif ( ! file_exists( $GLOBALS['wpsc_config']['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
    +	} elseif ( ! file_exists( $GLOBALS['wpsc_config']['cache_path'] . $GLOBALS['wpsc_config']['wp_cache_debug_log'] ) ) { // make sure debug log exists before toggling debugging
    +		extract( wpsc_create_debug_log( $GLOBALS['wpsc_config']['wp_cache_debug_log'], $wp_cache_debug_username ) ); // $wp_cache_debug_log, $wp_cache_debug_username
     	}
     	$GLOBALS['wpsc_config']['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', $GLOBALS['wpsc_config']['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_cache_setting( 'wp_cache_debug_log', $GLOBALS['wpsc_config']['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' ] ) ) {
    @@ -2096,7 +2096,7 @@ function wpsc_update_debug_settings() {
     
     	return array (
     		'wp_super_cache_debug' => $GLOBALS['wpsc_config']['wp_super_cache_debug'],
    -		'wp_cache_debug_log' => $wp_cache_debug_log,
    +		'wp_cache_debug_log' => $GLOBALS['wpsc_config']['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,
    @@ -2119,11 +2119,11 @@ function wp_cache_debug_settings() {
     	echo '';
     	echo '
    '; echo '

    ' . __( 'Fix problems with the plugin by debugging it here. It will log to a file in your cache directory.', 'wp-super-cache' ) . '

    '; - if ( ! isset( $wp_cache_debug_log ) || $wp_cache_debug_log == '' ) { + if ( ! isset( $GLOBALS['wpsc_config']['wp_cache_debug_log'] ) || $GLOBALS['wpsc_config']['wp_cache_debug_log'] == '' ) { extract( wpsc_create_debug_log() ); // $wp_cache_debug_log, $wp_cache_debug_username } - $log_file_link = "$wp_cache_debug_log"; + $log_file_link = "{$GLOBALS['wpsc_config']['wp_cache_debug_log']}"; if ( $GLOBALS['wpsc_config']['wp_super_cache_debug'] == 1 ) { echo "

    " . sprintf( __( 'Currently logging to: %s', 'wp-super-cache' ), $log_file_link ) . "

    "; @@ -4281,7 +4281,7 @@ function wpsc_update_check() { ) { wp_cache_setting( 'wpsc_version', 169 ); global $wp_cache_debug_log; - $log_file = $GLOBALS['wpsc_config']['cache_path'] . str_replace('/', '', str_replace('..', '', $wp_cache_debug_log)); + $log_file = $GLOBALS['wpsc_config']['cache_path'] . str_replace( '/', '', str_replace( '..', '', $GLOBALS['wpsc_config']['wp_cache_debug_log'] ) ); if ( ! file_exists( $log_file ) ) { return false; } From 27409fd2919d8e31ed6a56f77cdaf38dd4130ffb Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh Date: Sun, 16 Feb 2020 18:29:39 +0000 Subject: [PATCH 16/17] $wp_cache_debug_username and remove extract() calls --- wp-cache-phase2.php | 27 ++++++++++++--------------- wp-cache.php | 20 +++++++++----------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index ff95f9b5..56359690 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -552,12 +552,11 @@ function wp_cache_debug( $message, $level = 1 ) { $log_file = $GLOBALS['wpsc_config']['cache_path'] . str_replace( '/', '', str_replace( '..', '', $GLOBALS['wpsc_config']['wp_cache_debug_log'] ) ); if ( ! file_exists( $log_file ) && function_exists( 'wpsc_create_debug_log' ) ) { - global $wp_cache_debug_username; - if ( ! isset( $wp_cache_debug_username ) ) { - $wp_cache_debug_username = ''; + if ( ! isset( $GLOBALS['wpsc_config']['wp_cache_debug_username'] ) ) { + $GLOBALS['wpsc_config']['wp_cache_debug_username'] = ''; } - wpsc_create_debug_log( $GLOBALS['wpsc_config']['wp_cache_debug_log'], $wp_cache_debug_username ); + wpsc_create_debug_log( $GLOBALS['wpsc_config']['wp_cache_debug_log'], $GLOBALS['wpsc_config']['wp_cache_debug_username'] ); } error_log( $log_message, 3, $log_file ); @@ -1005,24 +1004,22 @@ function wpsc_get_protected_directories() { } function wpsc_debug_username() { - global $wp_cache_debug_username; - if ( ! isset( $wp_cache_debug_username ) || $wp_cache_debug_username == '' ) { - $wp_cache_debug_username = md5( time() + mt_rand() ); - wp_cache_setting( 'wp_cache_debug_username', $wp_cache_debug_username ); + if ( ! isset( $GLOBALS['wpsc_config']['wp_cache_debug_username'] ) || $GLOBALS['wpsc_config']['wp_cache_debug_username'] == '' ) { + $GLOBALS['wpsc_config']['wp_cache_debug_username'] = md5( time() + mt_rand() ); + wp_cache_setting( 'wp_cache_debug_username', $GLOBALS['wpsc_config']['wp_cache_debug_username'] ); } - return $wp_cache_debug_username; + return $GLOBALS['wpsc_config']['wp_cache_debug_username']; } function wpsc_create_debug_log( $filename = '', $username = '' ) { - global $wp_cache_debug_username; if ( $filename != '' ) { $GLOBALS['wpsc_config']['wp_cache_debug_log'] = $filename; } else { $GLOBALS['wpsc_config']['wp_cache_debug_log'] = md5( time() + mt_rand() ) . ".php"; } if ( $username != '' ) { - $wp_cache_debug_username = $username; + $GLOBALS['wpsc_config']['wp_cache_debug_username'] = $username; } else { - $wp_cache_debug_username = wpsc_debug_username(); + $GLOBALS['wpsc_config']['wp_cache_debug_username'] = wpsc_debug_username(); } $msg = 'die( "Please use the viewer" );' . PHP_EOL; @@ -1034,11 +1031,11 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) { fwrite( $fp, '<' . '?php // END HEADER ?' . '>' . PHP_EOL ); fclose( $fp ); wp_cache_setting( 'wp_cache_debug_log', $GLOBALS['wpsc_config']['wp_cache_debug_log'] ); - wp_cache_setting( 'wp_cache_debug_username', $wp_cache_debug_username ); + wp_cache_setting( 'wp_cache_debug_username', $GLOBALS['wpsc_config']['wp_cache_debug_username'] ); } $msg = ' -if ( !isset( $_SERVER[ "PHP_AUTH_USER" ] ) || ( $_SERVER[ "PHP_AUTH_USER" ] != "' . $wp_cache_debug_username . '" && $_SERVER[ "PHP_AUTH_PW" ] != "' . $wp_cache_debug_username . '" ) ) { +if ( !isset( $_SERVER[ "PHP_AUTH_USER" ] ) || ( $_SERVER[ "PHP_AUTH_USER" ] != "' . $GLOBALS['wpsc_config']['wp_cache_debug_username'] . '" && $_SERVER[ "PHP_AUTH_PW" ] != "' . $GLOBALS['wpsc_config']['wp_cache_debug_username'] . '" ) ) { header( "WWW-Authenticate: Basic realm=\"WP-Super-Cache Debug Log\"" ); header( $_SERVER[ "SERVER_PROTOCOL" ] . " 401 Unauthorized" ); echo "You must login to view the debug log"; @@ -1112,7 +1109,7 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) { fclose( $fp ); } - return array( 'wp_cache_debug_log' => $GLOBALS['wpsc_config']['wp_cache_debug_log'], 'wp_cache_debug_username' => $wp_cache_debug_username ); + return array( 'wp_cache_debug_log' => $GLOBALS['wpsc_config']['wp_cache_debug_log'], 'wp_cache_debug_username' => $GLOBALS['wpsc_config']['wp_cache_debug_username'] ); } function wpsc_delete_url_cache( $url ) { diff --git a/wp-cache.php b/wp-cache.php index 3c399c1b..ab9263fc 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -74,7 +74,7 @@ function wpsc_init() { */ global $wpsc_config; global $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file; -global $wp_cache_debug_ip, $wp_cache_debug_username, $wp_cache_debug_email; +global $wp_cache_debug_ip, $wp_cache_debug_email; global $cache_time_interval, $cache_scheduled_time, $cache_schedule_interval, $cache_schedule_type, $cache_gc_email_me; global $wp_cache_preload_on, $wp_cache_preload_interval, $wp_cache_preload_posts, $wp_cache_preload_taxonomies; global $wp_cache_preload_email_me, $wp_cache_preload_email_volume; @@ -2030,7 +2030,6 @@ function wp_cache_edit_accepted() { function wpsc_update_debug_settings() { global $wp_cache_debug_ip, $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". @@ -2048,25 +2047,25 @@ function wpsc_update_debug_settings() { '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, + 'wp_cache_debug_username' => $GLOBALS['wpsc_config']['wp_cache_debug_username'], ); } if ( isset( $_POST[ 'wpsc_delete_log' ] ) && $_POST[ 'wpsc_delete_log' ] == 1 && $GLOBALS['wpsc_config']['wp_cache_debug_log'] != '' ) { @unlink( $GLOBALS['wpsc_config']['cache_path'] . $GLOBALS['wpsc_config']['wp_cache_debug_log'] ); - extract( wpsc_create_debug_log( $GLOBALS['wpsc_config']['wp_cache_debug_log'], $wp_cache_debug_username ) ); // $wp_cache_debug_log, $wp_cache_debug_username + wpsc_create_debug_log( $GLOBALS['wpsc_config']['wp_cache_debug_log'], $GLOBALS['wpsc_config']['wp_cache_debug_username'] ); } if ( ! isset( $GLOBALS['wpsc_config']['wp_cache_debug_log'] ) || $GLOBALS['wpsc_config']['wp_cache_debug_log'] == '' ) { - extract( wpsc_create_debug_log() ); // $wp_cache_debug_log, $wp_cache_debug_username + wpsc_create_debug_log(); } elseif ( ! file_exists( $GLOBALS['wpsc_config']['cache_path'] . $GLOBALS['wpsc_config']['wp_cache_debug_log'] ) ) { // make sure debug log exists before toggling debugging - extract( wpsc_create_debug_log( $GLOBALS['wpsc_config']['wp_cache_debug_log'], $wp_cache_debug_username ) ); // $wp_cache_debug_log, $wp_cache_debug_username + wpsc_create_debug_log( $GLOBALS['wpsc_config']['wp_cache_debug_log'], $GLOBALS['wpsc_config']['wp_cache_debug_username'] ); } $GLOBALS['wpsc_config']['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', $GLOBALS['wpsc_config']['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_username', $GLOBALS['wpsc_config']['wp_cache_debug_username'] ); wp_cache_setting( 'wp_cache_debug_log', $GLOBALS['wpsc_config']['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 ); @@ -2104,14 +2103,13 @@ function wpsc_update_debug_settings() { '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, + 'wp_cache_debug_username' => $GLOBALS['wpsc_config']['wp_cache_debug_username'], ); } function wp_cache_debug_settings() { global $wp_cache_debug_log, $wp_cache_debug_ip, $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; extract( wpsc_update_debug_settings() ); // $wp_super_cache_debug, $wp_cache_debug_log, $wp_cache_debug_ip, $wp_super_cache_comments, $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, $wp_cache_debug_username $admin_url = admin_url( 'options-general.php?page=wpsupercache' ); @@ -2120,7 +2118,7 @@ function wp_cache_debug_settings() { echo '
    '; echo '

    ' . __( 'Fix problems with the plugin by debugging it here. It will log to a file in your cache directory.', 'wp-super-cache' ) . '

    '; if ( ! isset( $GLOBALS['wpsc_config']['wp_cache_debug_log'] ) || $GLOBALS['wpsc_config']['wp_cache_debug_log'] == '' ) { - extract( wpsc_create_debug_log() ); // $wp_cache_debug_log, $wp_cache_debug_username + wpsc_create_debug_log(); } $log_file_link = "{$GLOBALS['wpsc_config']['wp_cache_debug_log']}"; @@ -2130,7 +2128,7 @@ function wp_cache_debug_settings() { } else { echo "

    " . sprintf( __( 'Last Logged to: %s', 'wp-super-cache' ), $log_file_link ) . "

    "; } - echo "

    " . sprintf( __( 'Username/Password: %s', 'wp-super-cache' ), $wp_cache_debug_username ) . "

    "; + echo "

    " . sprintf( __( 'Username/Password: %s', 'wp-super-cache' ), $GLOBALS['wpsc_config']['wp_cache_debug_username'] ) . "

    "; echo ''; wp_nonce_field('wp-cache'); From c3185261da13690a03a95b20307661eb160b4e89 Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh Date: Sun, 2 Aug 2020 10:33:18 +0000 Subject: [PATCH 17/17] When no config file make sure we load phase1 This loads the function wpsc_load_config.php That function will now read from the sample config file if the final config file does not exist. --- includes/pre-wp-functions.php | 9 ++++++--- wp-cache-phase1.php | 2 +- wp-cache.php | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/includes/pre-wp-functions.php b/includes/pre-wp-functions.php index 8c995607..2535e343 100644 --- a/includes/pre-wp-functions.php +++ b/includes/pre-wp-functions.php @@ -1,11 +1,14 @@
    " . __( "seconds", 'wp-super-cache' ) . '
    ' . __( 'Check for stale cached files every interval seconds.', 'wp-super-cache' ) . "