diff --git a/wp-content/plugins/wp-super-cache/readme.txt b/wp-content/plugins/wp-super-cache/readme.txt index 24f4fa0e576542c2225e5d1ec450b0a54bd545ca..81ddec620a8fd4ebc9fb66f8c8afbf40d569f6d9 100644 --- a/wp-content/plugins/wp-super-cache/readme.txt +++ b/wp-content/plugins/wp-super-cache/readme.txt @@ -1,8 +1,8 @@ # WP Super Cache # * Contributors: donncha, automattic, kraftbj * Tags: performance, caching, wp-cache, wp-super-cache, cache -* Tested up to: 5.1.1 -* Stable tag: 1.6.5 +* Tested up to: 5.2.2 +* Stable tag: 1.6.9 * Requires at least: 3.1 * Requires PHP: 5.2.4 * License: GPLv2 or later @@ -266,6 +266,29 @@ Your theme is probably responsive which means it resizes the page to suit whatev ## Changelog ## +### 1.6.9 ### +* Improve the variables and messaging used by advanced-cache.php code. #687 +* Add a warning message to the debug log viewer. #688 +* Disable raw viewing of the debug log. #691 +* Clean up the debug log. #692 #694 +* Added wpsc_update_check() in 9659af156344a77ae247dc582d52053d95c79b93. + +### 1.6.8 ### +* Added new constants, WPSC_SERVE_DISABLED (disable serving of cached files) and WPSC_SUPERCACHE_ONLY (only serve supercache cache files). #682 and #672 +* Hide get_post() warning on some sites. #684 +* Check if WPCACHEHOME is set correctly before maybe updating it. #683 +* Remove object cache support as it never worked properly. #681 +* Add "logged in users" to the "do not cache for users" setting and rename that setting to "Cache Restrictions" #657 + +### 1.6.7 ### +* wp_cache_setting() can now save boolean values since many of the settings are bools. #676 +* Check if $super_cache_enabled is true in a less strict way because it might be '1' rather than true. #677 + +### 1.6.6 ### +* Fix problems with saving settings. Returns false ONLY when there's an issue with the config file, not when the setting isn't changed. Change other code to cope with that, including updating WPCACHEHOME (#670) +* When saving settings rename the temporary config file correctly, and delete wp-admin/.php if it exists. (#673) +* Fix adding WPCACHEHOME to wp-config.php when advanced-cache.php is not found and wp-config.php is RO. (#674) + ### 1.6.5 ### * Check advanced-cache.php was created by the plugin before modifying/deleting it. (#666) * When saving settings, save blank lines. Fixes problems with WP_CACHE and WPCACHEHOME in wp-config.php. Related to #652. (#667) @@ -713,4 +736,4 @@ Your theme is probably responsive which means it resizes the page to suit whatev ## Upgrade Notice ## -Many bug fixes +Fix security issue with debug log. diff --git a/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-rest-update-settings.php b/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-rest-update-settings.php index 76f2d48a36c867b2eb8fa8608c8e16b97538581c..7d4c9f8a40b394e004cc459fb618fc0ca8523300 100644 --- a/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-rest-update-settings.php +++ b/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-rest-update-settings.php @@ -233,12 +233,12 @@ class WP_Super_Cache_Rest_Update_Settings extends WP_REST_Controller { protected function set_wp_cache_not_logged_in( $value ) { global $wp_cache_not_logged_in, $cache_path; - if ( 1 == $value ) { + if ( 0 != $value ) { if ( 0 == $wp_cache_not_logged_in && function_exists( 'prune_super_cache' ) ) { prune_super_cache( $cache_path, true ); } - $wp_cache_not_logged_in = 1; + $wp_cache_not_logged_in = (int) $value; } else { $wp_cache_not_logged_in = 0; @@ -454,6 +454,7 @@ class WP_Super_Cache_Rest_Update_Settings extends WP_REST_Controller { 'is_cache_enabled' => 1, 'cache_rebuild_files' => 1, 'cache_compression' => 0, + 'wp_cache_not_logged_in' => 2, ); wp_cache_enable(); if ( ! defined( 'DISABLE_SUPERCACHE' ) ) { @@ -489,7 +490,6 @@ class WP_Super_Cache_Rest_Update_Settings extends WP_REST_Controller { 'wp_supercache_cache_list', 'wp_cache_hello_world', 'wp_cache_clear_on_post_edit', - 'wp_cache_not_logged_in', 'wp_cache_make_known_anon', 'wp_cache_object_cache', 'wp_cache_refresh_single_only', diff --git a/wp-content/plugins/wp-super-cache/wp-cache-config-sample.php b/wp-content/plugins/wp-super-cache/wp-cache-config-sample.php index 0112ad06ba63a3837cffc6730ce9ed2674b29387..87ed823ae5dbff160ef209da667e53adf93d3520 100644 --- a/wp-content/plugins/wp-super-cache/wp-cache-config-sample.php +++ b/wp-content/plugins/wp-super-cache/wp-cache-config-sample.php @@ -54,7 +54,6 @@ $wp_super_cache_front_page_clear = 0; $wp_super_cache_front_page_check = 0; $wp_super_cache_front_page_notification = '0'; -$wp_cache_object_cache = 0; $wp_cache_anon_only = 0; $wp_supercache_cache_list = 0; $wp_cache_debug_to_file = 0; @@ -76,6 +75,7 @@ $wp_cache_pages[ "author" ] = 0; $wp_cache_hide_donation = 0; $wp_cache_not_logged_in = 0; $wp_cache_clear_on_post_edit = 0; +$wp_cache_hello_world = 0; $wp_cache_mobile_enabled = 0; $wp_cache_cron_check = 0; $wp_cache_mfunc_enabled = 0; @@ -101,4 +101,5 @@ $cache_gc_email_me = 0; $wpsc_save_headers = 0; $cache_schedule_interval = 'daily'; $wp_super_cache_comments = 1; +$wpsc_version = 169; ?> diff --git a/wp-content/plugins/wp-super-cache/wp-cache-phase1.php b/wp-content/plugins/wp-super-cache/wp-cache-phase1.php index 3a3e047ff5f65419f54e9aa128853d5dda56a3c2..d638f351a4093bf386843188ae7e1b34cc5529cf 100644 --- a/wp-content/plugins/wp-super-cache/wp-cache-phase1.php +++ b/wp-content/plugins/wp-super-cache/wp-cache-phase1.php @@ -73,7 +73,11 @@ if ( $wp_start_time = microtime(); -if ( $wp_cache_not_logged_in && wp_cache_get_cookies_values() ) { +if ( wpsc_is_backend() ) { + return true; +} + +if ( wpsc_is_caching_user_disabled() ) { wp_cache_debug( 'Caching disabled for logged in users on settings page.' ); return true; } @@ -84,7 +88,6 @@ if ( isset( $wp_cache_make_known_anon ) && $wp_cache_make_known_anon ) { do_cacheaction( 'cache_init' ); - if ( ! $cache_enabled || ( isset( $_SERVER['REQUEST_METHOD'] ) && in_array( $_SERVER['REQUEST_METHOD'], array( 'POST', 'PUT', 'DELETE' ) ) ) || isset( $_GET['customize_changeset_uuid'] ) ) { return true; } @@ -108,18 +111,6 @@ if ( function_exists( 'add_filter' ) ) { // loaded since WordPress 4.6 $wp_cache_request_uri = $_SERVER['REQUEST_URI']; // Cache this in case any plugin modifies it. -if ( $wp_cache_object_cache ) { - if ( ! include_once WP_CONTENT_DIR . '/object-cache.php' ) { - return; - } - - wp_cache_init(); // Note: wp-settings.php calls wp_cache_init() which clobbers the object made here. - - if ( ! is_object( $wp_object_cache ) ) { - return; - } -} - if ( defined( 'DOING_CRON' ) ) { extract( wp_super_cache_init() ); // $key, $cache_filename, $meta_file, $cache_file, $meta_pathname return true; diff --git a/wp-content/plugins/wp-super-cache/wp-cache-phase2.php b/wp-content/plugins/wp-super-cache/wp-cache-phase2.php index a81da50ac8147e420d63cbfa14da73225cbff370..3aacf331ea62903c6ee5a2f4b78acdde884fa0d9 100644 --- a/wp-content/plugins/wp-super-cache/wp-cache-phase2.php +++ b/wp-content/plugins/wp-super-cache/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, $file_prefix, $blog_cache_dir, $meta_file, $cache_file, $cache_filename, $meta_pathname, $wp_cache_gzip_encoding, $meta; - global $wp_cache_object_cache, $cache_compression, $wp_cache_slash_check, $wp_supercache_304, $wp_cache_home_path, $wp_cache_no_cache_for_get; + global $cache_compression, $wp_cache_slash_check, $wp_supercache_304, $wp_cache_home_path, $wp_cache_no_cache_for_get; global $wp_cache_disable_utf8, $wp_cache_mfunc_enabled, $wpsc_served_header; if ( wpsc_is_backend() ) { @@ -57,27 +57,20 @@ function wp_cache_serve_cache_file() { return false; } - extract( wp_super_cache_init() ); // $key, $cache_filename, $meta_file, $cache_file, $meta_pathname + if ( defined( 'WPSC_SERVE_DISABLED' ) ) { + wp_cache_debug( 'wp_cache_serve_cache_file: WPSC_SERVE_DISABLED defined. Not serving cached files.' ); + return false; + } - if ( $wp_cache_object_cache && wp_cache_get_cookies_values() == '' ) { - if ( !empty( $_GET ) ) { - wp_cache_debug( 'Non empty GET request. Not serving request from object cache. ' . wpsc_dump_get_request(), 1 ); - return false; - } + extract( wp_super_cache_init() ); // $key, $cache_filename, $meta_file, $cache_file, $meta_pathname - $oc_key = get_oc_key(); - $meta_filename = $oc_key . ".meta"; - if ( gzip_accepted() ) { - $oc_key .= ".gz"; - $meta_filename .= ".gz"; - } - $cache = wp_cache_get( $oc_key, 'supercache' ); - $meta = json_decode( wp_cache_get( $meta_filename, 'supercache' ), true ); - if ( is_array( $meta ) == false ) { - wp_cache_debug( 'Meta array from object cache corrupt. Ignoring cache.', 1 ); - return true; - } - } elseif ( ( $cache_file && file_exists( $cache_file ) ) || file_exists( get_current_url_supercache_dir() . 'meta-' . $cache_filename ) ) { + if ( + ! defined( 'WPSC_SUPERCACHE_ONLY' ) && + ( + ( $cache_file && file_exists( $cache_file ) ) || + file_exists( get_current_url_supercache_dir() . 'meta-' . $cache_filename ) + ) + ) { if ( file_exists( get_current_url_supercache_dir() . 'meta-' . $cache_filename ) ) { $cache_file = get_current_url_supercache_dir() . $cache_filename; $meta_pathname = get_current_url_supercache_dir() . 'meta-' . $cache_filename; @@ -221,7 +214,7 @@ function wp_cache_serve_cache_file() { } else { $ungzip = false; } - foreach ( $meta['headers'] as $t => $header ) { + foreach ( $meta[ 'headers' ] as $t => $header) { // godaddy fix, via http://blog.gneu.org/2008/05/wp-supercache-on-godaddy/ and http://www.littleredrails.com/blog/2007/09/08/using-wp-cache-on-godaddy-500-error/ if ( strpos( $header, 'Last-Modified:' ) === false ) { header( $header ); @@ -230,64 +223,41 @@ function wp_cache_serve_cache_file() { if ( isset( $wpsc_served_header ) && $wpsc_served_header ) { header( 'X-WP-Super-Cache: Served WPCache cache file' ); } - if ( $wp_cache_object_cache ) { - if ( $cache ) { - if ( $ungzip ) { - // attempt to uncompress the cached file just in case it's gzipped - $uncompressed = gzuncompress( $cache ); - if ( $uncompressed ) { - wp_cache_debug( 'Uncompressed gzipped cache file from object cache', 1 ); - $cache = $uncompressed; - unset( $uncompressed ); - } - } - if ( isset( $meta[ 'dynamic' ] ) && $meta[ 'dynamic' ] ) { - wp_cache_debug( 'Serving wp-cache dynamic file from object cache', 5 ); - echo do_cacheaction( 'wpsc_cachedata', $cache ); + if ( isset( $meta[ 'dynamic' ] ) ) { + wp_cache_debug( 'Serving wp-cache dynamic file', 5 ); + if ( $ungzip ) { + // attempt to uncompress the cached file just in case it's gzipped + $cache = wp_cache_get_legacy_cache( $cache_file ); + $uncompressed = @gzuncompress( $cache ); + if ( $uncompressed ) { + wp_cache_debug( 'Uncompressed gzipped cache file from wp-cache', 1 ); + unset( $cache ); + echo do_cacheaction( 'wpsc_cachedata', $uncompressed ); } else { - wp_cache_debug( 'Serving wp-cache static file from object cache', 5 ); - echo $cache; + echo do_cacheaction( 'wpsc_cachedata', $cache ); } - wp_cache_debug( 'exit request', 5 ); - die(); + } else { + echo do_cacheaction( 'wpsc_cachedata', wp_cache_get_legacy_cache( $cache_file ) ); } } else { - if ( isset( $meta[ 'dynamic' ] ) ) { - wp_cache_debug( 'Serving wp-cache dynamic file', 5 ); - if ( $ungzip ) { - // attempt to uncompress the cached file just in case it's gzipped - $cache = wp_cache_get_legacy_cache( $cache_file ); - $uncompressed = @gzuncompress( $cache ); - if ( $uncompressed ) { - wp_cache_debug( 'Uncompressed gzipped cache file from wp-cache', 1 ); - unset( $cache ); - echo do_cacheaction( 'wpsc_cachedata', $uncompressed ); - } else { - echo do_cacheaction( 'wpsc_cachedata', $cache ); - } + wp_cache_debug( 'Serving wp-cache static file', 5 ); + if ( $ungzip ) { + $cache = wp_cache_get_legacy_cache( $cache_file ); + $uncompressed = gzuncompress( $cache ); + if ( $uncompressed ) { + wp_cache_debug( 'Uncompressed gzipped cache file from wp-cache', 1 ); + echo $uncompressed; } else { - echo do_cacheaction( 'wpsc_cachedata', wp_cache_get_legacy_cache( $cache_file ) ); + wp_cache_debug( 'Compressed gzipped cache file from wp-cache', 1 ); + echo $cache; } } else { - wp_cache_debug( 'Serving wp-cache static file', 5 ); - if ( $ungzip ) { - $cache = wp_cache_get_legacy_cache( $cache_file ); - $uncompressed = gzuncompress( $cache ); - if ( $uncompressed ) { - wp_cache_debug( 'Uncompressed gzipped cache file from wp-cache', 1 ); - echo $uncompressed; - } else { - wp_cache_debug( 'Compressed gzipped cache file from wp-cache', 1 ); - echo $cache; - } - } else { - wp_cache_debug( 'Getting legacy cache file ' . $cache_file, 1 ); - echo( wp_cache_get_legacy_cache( $cache_file ) ); - } + wp_cache_debug( 'Getting legacy cache file ' . $cache_file, 1 ); + echo( wp_cache_get_legacy_cache( $cache_file ) ); } - wp_cache_debug( 'exit request', 5 ); - die(); } + wp_cache_debug( 'exit request', 5 ); + die(); } function wp_cache_get_legacy_cache( $cache_file ) { @@ -315,6 +285,91 @@ function wp_cache_late_loader() { wp_cache_phase2(); } +function wpsc_get_auth_cookies() { + static $cached_cookies; + + if ( isset( $cached_cookies ) && is_array( $cached_cookies ) ) { + return $cached_cookies; + } + + $cookies = array_keys( $_COOKIE ); + if ( empty( $cookies ) ) { + return array(); + } + + $auth_cookies = array(); + $duplicate_cookies = array(); + + $wp_cookies = array( + 'AUTH_COOKIE' => 'wordpress_', + 'SECURE_AUTH_COOKIE' => 'wordpress_sec_', + 'LOGGED_IN_COOKIE' => 'wordpress_logged_in_', + ); + + foreach ( $wp_cookies as $cookie_const => $cookie_prefix ) { + $cookie_key = strtolower( $cookie_const ); + + if ( defined( $cookie_const ) ) { + if ( in_array( constant( $cookie_const ), $cookies, true ) ) { + $auth_cookies[ $cookie_key ] = constant( $cookie_const ); + } + + continue; + } + + $found_cookies = preg_grep( '`^' . preg_quote( $cookie_prefix, '`' ) . '([0-9a-f]+)$`', $cookies ); + + if ( count( $found_cookies ) === 1 ) { + $auth_cookies[ $cookie_key ] = reset( $found_cookies ); + } elseif ( count( $found_cookies ) > 1 ) { + $duplicate_cookies = array_merge( $duplicate_cookies, $found_cookies ); + $auth_cookies[ $cookie_key ] = $found_cookies; + } + } + + $cookie_hash = defined( 'COOKIEHASH' ) ? COOKIEHASH : ''; + $other_cookies = array( + 'comment_cookie' => 'comment_author_', + 'postpass_cookie' => 'wp-postpass_', + ); + + foreach ( $other_cookies as $cookie_key => $cookie_prefix ) { + + if ( $cookie_hash ) { + if ( in_array( $cookie_prefix . $cookie_hash, $cookies, true ) ) { + $auth_cookies[ $cookie_key ] = $cookie_prefix . $cookie_hash; + } + + continue; + } + + $found_cookies = preg_grep( '`^' . preg_quote( $cookie_prefix, '`' ) . '([0-9a-f]+)$`', $cookies ); + + if ( count( $found_cookies ) === 1 ) { + $auth_cookies[ $cookie_key ] = reset( $found_cookies ); + } elseif ( count( $found_cookies ) > 1 ) { + $duplicate_cookies = array_merge( $duplicate_cookies, $found_cookies ); + $auth_cookies[ $cookie_key ] = $found_cookies; + } + } + + if ( ! $duplicate_cookies ) { + $cached_cookies = $auth_cookies; + } + + if ( empty( $auth_cookies ) ) { + wp_cache_debug( 'wpsc_get_auth_cookies: no auth cookies detected', 5 ); + } else { + if ( $duplicate_cookies ) { + wp_cache_debug( 'wpsc_get_auth_cookies: duplicate cookies detected( ' . implode( ', ', $duplicate_cookies ) . ' )', 5 ); + } else { + wp_cache_debug( 'wpsc_get_auth_cookies: cookies detected: ' . implode( ', ', $auth_cookies ), 5 ); + } + } + + return $auth_cookies; +} + function wp_cache_get_cookies_values() { global $wpsc_cookies; static $string = ''; @@ -336,7 +391,7 @@ function wp_cache_get_cookies_values() { $regex .= "/"; while ($key = key($_COOKIE)) { if ( preg_match( $regex, $key ) ) { - wp_cache_debug( "wp_cache_get_cookies_values: $regex Cookie detected: $key", 5 ); + wp_cache_debug( "wp_cache_get_cookies_values: Login/postpass cookie detected" ); $string .= $_COOKIE[ $key ] . ","; } next($_COOKIE); @@ -433,7 +488,7 @@ function wp_cache_check_mobile( $cache_key ) { $user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); foreach ($browsers as $browser) { if ( strstr( $user_agent, trim( strtolower( $browser ) ) ) ) { - wp_cache_debug( 'mobile browser detected: ' . $_SERVER['HTTP_USER_AGENT'], 5 ); + wp_cache_debug( 'mobile browser detected: ' . $browser ); return $cache_key . '-' . wp_cache_mobile_group( $user_agent ); } } @@ -446,7 +501,7 @@ function wp_cache_check_mobile( $cache_key ) { $browsers = explode( ',', $wp_cache_mobile_prefixes ); foreach ($browsers as $browser_prefix) { if ( substr($user_agent, 0, 4) == $browser_prefix ) { - wp_cache_debug( 'mobile browser (prefix) detected: ' . $_SERVER['HTTP_USER_AGENT'], 5 ); + wp_cache_debug( 'mobile browser (prefix) detected: ' . $browser_prefix ); return $cache_key . '-' . $browser_prefix; } } @@ -471,6 +526,12 @@ function wp_cache_check_mobile( $cache_key ) { */ function wp_cache_debug( $message, $level = 1 ) { global $wp_cache_debug_log, $cache_path, $wp_cache_debug_ip, $wp_super_cache_debug; + static $last_message = ''; + + if ( $last_message == $message ) { + return false; + } + $last_message = $message; // If either of the debug or log globals aren't set, then we can stop if ( !isset($wp_super_cache_debug) @@ -829,28 +890,52 @@ function get_oc_key( $url = false ) { } function wp_supercache_cache_for_admins() { - if ( isset( $_GET[ 'preview' ] ) || function_exists( "is_admin" ) && is_admin() || defined( 'DOING_AJAX' ) ) - return true; - if ( false == do_cacheaction( 'wp_supercache_remove_cookies', true ) ) + // Don't remove cookies for some requests. + if ( + wpsc_is_backend() || + $_SERVER['REQUEST_METHOD'] !== 'GET' || + isset( $_GET['preview'], $_GET['customize_changeset_uuid'] ) || // WPCS: CSRF ok. + strpos( stripslashes( $_SERVER['REQUEST_URI'] ), '/wp-json/' ) !== false // WPCS: sanitization ok. + ) { return true; + } - if ( $_SERVER[ "REQUEST_METHOD" ] != 'GET' || strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-json/' ) !== false ) + if ( false === do_cacheaction( 'wp_supercache_remove_cookies', true ) ) { return true; + } - $cookie_keys = array( 'wordpress_logged_in', 'comment_author_' ); - if ( defined( 'LOGGED_IN_COOKIE' ) ) - $cookie_keys[] = constant( 'LOGGED_IN_COOKIE' ); - reset( $_COOKIE ); - foreach( $_COOKIE as $cookie => $val ) { - reset( $cookie_keys ); - foreach( $cookie_keys as $key ) { - if ( strpos( $cookie, $key ) !== FALSE ) { - wp_cache_debug( 'Removing auth from $_COOKIE to allow caching for logged in user (' . $cookie . ')', 5 ); - unset( $_COOKIE[ $cookie ] ); - } + $removed_cookies = array(); + foreach ( wpsc_get_auth_cookies() as $cookie ) { + + $cookies = is_array( $cookie ) ? $cookie : array( $cookie ); + + foreach ( $cookies as $cookie_key ) { + unset( $_COOKIE[ $cookie_key ] ); + $removed_cookies[] = $cookie_key; } } + + if ( ! empty( $removed_cookies ) ) { + wp_cache_debug( 'Removing auth from $_COOKIE to allow caching for logged in user ( ' . implode( ', ', $removed_cookies ) . ' )', 5 ); + } +} + +/* + * Check if caching is disabled for the current visitor based on their cookies + */ +function wpsc_is_caching_user_disabled() { + global $wp_cache_not_logged_in; + if ( $wp_cache_not_logged_in == 2 && wpsc_get_auth_cookies() ) { + wp_cache_debug( 'wpsc_is_caching_user_disabled: true because logged in' ); + return true; + } elseif ( $wp_cache_not_logged_in == 1 && ! empty( $_COOKIE ) ) { + wp_cache_debug( 'wpsc_is_caching_user_disabled: true because cookie found' ); + return true; + } else { + wp_cache_debug( 'wpsc_is_caching_user_disabled: false' ); + return false; + } } /* returns true/false depending on location of $dir. */ @@ -935,13 +1020,7 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) { $wp_cache_debug_username = wpsc_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 . '" ) ) { - 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"; - exit; -}' . PHP_EOL; + $msg = 'die( "Please use the viewer" );' . PHP_EOL; $fp = fopen( $cache_path . $wp_cache_debug_log, 'w' ); if ( $fp ) { fwrite( $fp, '<' . "?php\n" ); @@ -952,6 +1031,15 @@ if ( !isset( $_SERVER[ "PHP_AUTH_USER" ] ) || ( $_SERVER[ "PHP_AUTH_USER" ] != " wp_cache_setting( 'wp_cache_debug_log', $wp_cache_debug_log ); wp_cache_setting( 'wp_cache_debug_username', $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 . '" ) ) { + 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"; + exit; +}' . PHP_EOL; + $fp = fopen( $cache_path . 'view_' . $wp_cache_debug_log, 'w' ); if ( $fp ) { fwrite( $fp, '<' . "?php" . PHP_EOL ); @@ -979,6 +1067,10 @@ if ( isset( $_GET[ "filter" ] ) ) { unset( $checks[1] ); // exclude_filter ?' . '> +<h2>WP Super Cache Log Viewer</h2> +<h3>Warning! Do not copy and paste this log file to a public website!</h3> +<p>This log file contains sensitive information about your website such as cookies and directories.</p> +<p>If you must share it please remove any cookies and remove any directories such as ' . ABSPATH . '.</p> Exclude requests: <br /> <' . '?php foreach ( $checks as $check ) { ?> <label><input type="checkbox" name="<' . '?php echo $check; ?' . '>" value="1" <' . '?php if ( $$check ) { echo "checked"; } ?' . '> /> <' . '?php echo $check; ?' . '></label><br /> @@ -991,7 +1083,10 @@ Text to filter by: <input type="submit" value="Submit" /> </form> <' . '?php +$path_to_site = "' . ABSPATH . '"; foreach ( $debug_log as $t => $line ) { + $line = str_replace( $path_to_site, "ABSPATH/", $line ); + $debug_log[ $t ] = $line; foreach( $checks as $check ) { if ( $$check && false !== strpos( $line, " /$check/" ) ) { unset( $debug_log[ $t ] ); @@ -1006,7 +1101,7 @@ foreach ( $debug_log as $t => $line ) { } } foreach( $debug_log as $line ) { - echo $line . "<br />"; + echo htmlspecialchars( $line ) . "<br />"; }'; fwrite( $fp, $msg ); fclose( $fp ); @@ -1060,13 +1155,16 @@ function wp_cache_setting( $field, $value ) { $GLOBALS[ $field ] = $value; if ( is_numeric( $value ) ) { - wp_cache_replace_line( '^ *\$' . $field, "\$$field = $value;", $wp_cache_config_file ); + return wp_cache_replace_line( '^ *\$' . $field, "\$$field = $value;", $wp_cache_config_file ); + } elseif ( is_bool( $value ) ) { + $output_value = $value === true ? 'true' : 'false'; + return wp_cache_replace_line( '^ *\$' . $field, "\$$field = $output_value;", $wp_cache_config_file ); } elseif ( is_object( $value ) || is_array( $value ) ) { $text = var_export( $value, true ); $text = preg_replace( '/[\s]+/', ' ', $text ); - wp_cache_replace_line( '^ *\$' . $field, "\$$field = $text;", $wp_cache_config_file ); + return wp_cache_replace_line( '^ *\$' . $field, "\$$field = $text;", $wp_cache_config_file ); } else { - wp_cache_replace_line( '^ *\$' . $field, "\$$field = '$value';", $wp_cache_config_file ); + return wp_cache_replace_line( '^ *\$' . $field, "\$$field = '$value';", $wp_cache_config_file ); } } @@ -1110,7 +1208,7 @@ function wp_cache_replace_line( $old, $new, $my_file ) { trim( $new ) == trim( $line ) ) { wp_cache_debug( "wp_cache_replace_line: setting not changed - $new" ); - return false; + return true; } elseif ( preg_match( "/$old/", $line ) ) { wp_cache_debug( "wp_cache_replace_line: changing line " . trim( $line ) . " to *$new*" ); $found = true; @@ -1118,7 +1216,7 @@ function wp_cache_replace_line( $old, $new, $my_file ) { } $tmp_config_filename = tempnam( $GLOBALS['cache_path'], 'wpsc' ); - rename( $tmp_config_filename, $tmp_wpcache_filename . ".php" ); + rename( $tmp_config_filename, $tmp_config_filename . ".php" ); $tmp_config_filename .= ".php"; wp_cache_debug( 'wp_cache_replace_line: writing to ' . $tmp_config_filename ); $fd = fopen( $tmp_config_filename, 'w' ); @@ -1160,11 +1258,29 @@ function wp_cache_replace_line( $old, $new, $my_file ) { return true; } +function wpsc_shutdown_message() { + static $did_wp_footer = false; + global $wp_super_cache_comments; + + if ( ! defined( 'WPSCSHUTDOWNMESSAGE' ) || ( isset( $wp_super_cache_comments) && ! $wp_super_cache_comments ) ) { + return; + } + + if ( ! $did_wp_footer ) { + $did_wp_footer = true; + register_shutdown_function( 'wpsc_shutdown_message' ); + } else { + echo PHP_EOL . '<!-- WP Super Cache: ' . esc_html( constant( 'WPSCSHUTDOWNMESSAGE' ) ) . ' -->' . PHP_EOL; + } +} + function wp_cache_phase2() { global $wp_cache_gzip_encoding, $super_cache_enabled, $cache_rebuild_files, $cache_enabled, $wp_cache_gmt_offset, $wp_cache_blog_charset; if ( $cache_enabled == false ) { - wp_cache_debug( 'Caching disabled! quiting!', 1 ); + wp_cache_debug( 'wp_cache_phase2: Caching disabled! Exit' ); + define( 'WPSCSHUTDOWNMESSAGE', __( 'Caching disabled. Page not cached.', 'wp-super-cache' ) ); + add_action( 'wp_footer', 'wpsc_shutdown_message' ); return false; } @@ -1210,6 +1326,20 @@ function wp_cache_phase2() { header( 'Vary: Accept-Encoding, Cookie' ); } + if ( wpsc_is_caching_user_disabled() ) { + wp_cache_debug( 'wp_cache_phase2: Caching disabled for known user! Exit.' ); + define( 'WPSCSHUTDOWNMESSAGE', __( 'Caching disabled for known user. User logged in or cookie found.', 'wp-super-cache' ) ); + add_action( 'wp_footer', 'wpsc_shutdown_message' ); + return false; + } + + if ( wp_cache_user_agent_is_rejected() ) { + define( 'WPSCSHUTDOWNMESSAGE', __( 'Caching disabled because user agent was rejected.', 'wp-super-cache' ) ); + wp_cache_debug( 'wp_cache_phase2: No caching to do as user agent rejected.' ); + add_action( 'wp_footer', 'wpsc_shutdown_message' ); + return false; + } + ob_start( 'wp_cache_ob_callback' ); wp_cache_debug( 'Created output buffer', 4 ); @@ -1643,7 +1773,7 @@ function wpsc_is_fatal_error() { } function wp_cache_ob_callback( $buffer ) { - global $wp_cache_pages, $wp_query, $wp_super_cache_query, $cache_acceptable_files, $wp_cache_no_cache_for_get, $wp_cache_object_cache, $wp_cache_request_uri, $do_rebuild_list, $wpsc_file_mtimes, $wpsc_save_headers, $super_cache_enabled; + global $wp_cache_pages, $wp_query, $wp_super_cache_query, $cache_acceptable_files, $wp_cache_no_cache_for_get, $wp_cache_request_uri, $do_rebuild_list, $wpsc_file_mtimes, $wpsc_save_headers, $super_cache_enabled; $script = basename( $_SERVER[ 'PHP_SELF' ] ); // All the things that can stop a page being cached @@ -1675,9 +1805,6 @@ function wp_cache_ob_callback( $buffer ) { } elseif ( $_SERVER["REQUEST_METHOD"] == 'DELETE' ) { wp_cache_debug( 'Not caching DELETE request.', 5 ); $cache_this_page = false; - } elseif ( $wp_cache_object_cache && !empty( $_GET ) ) { - wp_cache_debug( 'Not caching GET request while object cache storage enabled.', 5 ); - $cache_this_page = false; } elseif ( isset( $_GET[ 'preview' ] ) ) { wp_cache_debug( 'Not caching preview post.', 2 ); $cache_this_page = false; @@ -1832,7 +1959,7 @@ function wp_cache_get_ob(&$buffer) { global $wp_cache_gzip_encoding, $super_cache_enabled; global $gzsize, $supercacheonly; global $blog_cache_dir, $wp_supercache_cache_list; - global $wp_cache_not_logged_in, $wp_cache_object_cache, $cache_max_time; + global $wp_cache_not_logged_in, $cache_max_time; global $wp_cache_is_home, $wp_cache_front_page_checks, $wp_cache_mfunc_enabled; if ( isset( $wp_cache_mfunc_enabled ) == false ) @@ -1896,7 +2023,13 @@ function wp_cache_get_ob(&$buffer) { $tmp_wpcache_filename = $cache_path . uniqid( mt_rand(), true ) . '.tmp'; - $supercacheonly = false; + if ( defined( 'WPSC_SUPERCACHE_ONLY' ) ) { + $supercacheonly = true; + wp_cache_debug( 'wp_cache_get_ob: WPSC_SUPERCACHE_ONLY defined. Only creating supercache files.' ); + } else { + $supercacheonly = false; + } + if( $super_cache_enabled ) { if ( wp_cache_get_cookies_values() == '' && empty( $_GET ) ) { wp_cache_debug( 'Anonymous user detected. Only creating Supercache file.', 3 ); @@ -1905,23 +2038,13 @@ function wp_cache_get_ob(&$buffer) { } $cache_error = ''; - if ( $wp_cache_not_logged_in && wp_cache_get_cookies_values() != '' ) { + if ( wpsc_is_caching_user_disabled() ) { $super_cache_enabled = false; $cache_enabled = false; $cache_error = 'Not caching requests by known users. (See Advanced Settings page)'; wp_cache_debug( 'Not caching for known user.', 5 ); } - if ( $wp_cache_object_cache ) { // half on mode when using the object cache - if ( wp_cache_get_cookies_values() != '' ) { - $cache_enabled = false; - $cache_error = 'Known User and using object. Only anonymous users cached.'; - } - $super_cache_enabled = false; - $supercacheonly = false; - wp_cache_init(); // PHP5 destroys objects during shutdown - } - if ( !$cache_enabled ) { wp_cache_debug( 'Cache is not enabled. Sending buffer to browser.', 5 ); wp_cache_writers_exit(); @@ -1953,42 +2076,51 @@ function wp_cache_get_ob(&$buffer) { $fr = $fr2 = $gz = false; // Open wp-cache cache file - if ( false == $wp_cache_object_cache ) { - 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 ); + 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_writers_exit(); + return wp_cache_maybe_dynamic( $buffer ); + } + } else { + $user_info = wp_cache_get_cookies_values(); + $do_cache = apply_filters( 'do_createsupercache', $user_info ); + if ( + $super_cache_enabled && + ( + $user_info == '' || + $do_cache === true + ) + ) { + $cache_fname = $dir . supercache_filename(); + $tmp_cache_filename = $dir . uniqid( mt_rand(), true ) . '.tmp'; + $fr2 = @fopen( $tmp_cache_filename, 'w' ); + if ( !$fr2 ) { + wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $tmp_cache_filename ), 1 ); + wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) ); + @fclose( $fr ); + @unlink( $tmp_wpcache_filename ); wp_cache_writers_exit(); return wp_cache_maybe_dynamic( $buffer ); - } - } else { - $user_info = wp_cache_get_cookies_values(); - $do_cache = apply_filters( 'do_createsupercache', $user_info ); - if ( $super_cache_enabled && ( $user_info == '' || $do_cache === true ) ) { - - $cache_fname = $dir . supercache_filename(); - $tmp_cache_filename = $dir . uniqid( mt_rand(), true ) . '.tmp'; - $fr2 = @fopen( $tmp_cache_filename, 'w' ); - if ( !$fr2 ) { - wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $tmp_cache_filename ), 1 ); - wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) ); + } elseif ( + $cache_compression && + ( + ! isset( $wp_cache_mfunc_enabled ) || + $wp_cache_mfunc_enabled == 0 + ) + ) { // don't want to store compressed files if using dynamic content + $gz = @fopen( $tmp_cache_filename . ".gz", 'w'); + if ( !$gz ) { + wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz", 1 ); + wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz" ); @fclose( $fr ); @unlink( $tmp_wpcache_filename ); + @fclose( $fr2 ); + @unlink( $tmp_cache_filename ); wp_cache_writers_exit(); return wp_cache_maybe_dynamic( $buffer ); - } elseif ( ( !isset( $wp_cache_mfunc_enabled ) || $wp_cache_mfunc_enabled == 0 ) && $cache_compression ) { // don't want to store compressed files if using dynamic content - $gz = @fopen( $tmp_cache_filename . ".gz", 'w'); - if (!$gz) { - wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz", 1 ); - wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz" ); - @fclose( $fr ); - @unlink( $tmp_wpcache_filename ); - @fclose( $fr2 ); - @unlink( $tmp_cache_filename ); - wp_cache_writers_exit(); - return wp_cache_maybe_dynamic( $buffer ); - } } } } @@ -2021,8 +2153,6 @@ function wp_cache_get_ob(&$buffer) { wp_cache_debug( 'Writing dynamic buffer to supercache file.' ); wp_cache_add_to_buffer( $buffer, "Dynamic Super Cache" ); fputs( $fr2, $buffer ); - } elseif ( true == $wp_cache_object_cache ) { - wp_cache_set( $oc_key, $buffer, 'supercache', $cache_max_time ); } $wp_cache_meta[ 'dynamic' ] = true; if ( $wp_cache_mfunc_enabled == 1 && do_cacheaction( 'wpsc_cachedata_safety', 0 ) === 1 ) { @@ -2059,15 +2189,9 @@ function wp_cache_get_ob(&$buffer) { if ( $fr ) { wp_cache_debug( 'Writing gzipped buffer to wp-cache cache file.', 5 ); fputs($fr, '<?php die(); ?>' . $gzdata); - } elseif ( $cache_enabled && $wp_cache_object_cache ) { - wp_cache_set( $oc_key . ".gz", $gzdata, 'supercache', $cache_max_time ); - $added_cache = 1; } } else { // no compression - if ( $cache_enabled && $wp_cache_object_cache ) { - wp_cache_set( $oc_key, $buffer, 'supercache', $cache_max_time ); - $added_cache = 1; - } elseif ( $fr ) { + if ( $fr ) { wp_cache_debug( 'Writing non-gzipped buffer to wp-cache cache file.' ); fputs($fr, '<?php die(); ?>' . $buffer); } @@ -2084,61 +2208,62 @@ function wp_cache_get_ob(&$buffer) { } $new_cache = true; - if ( false == $wp_cache_object_cache ) { - if( $fr ) { - $supercacheonly = false; - fclose($fr); - if ( filesize( $tmp_wpcache_filename ) == 0 ) { - wp_cache_debug( "Warning! The file $tmp_wpcache_filename was empty. Did not rename to {$dir}{$cache_filename}", 5 ); - @unlink( $tmp_wpcache_filename ); - } else { - if ( !@rename( $tmp_wpcache_filename, $dir . $cache_filename ) ) { - if ( false == is_dir( $dir ) ) - @wp_mkdir_p( $dir ); - @unlink( $dir . $cache_filename ); - @rename( $tmp_wpcache_filename, $dir . $cache_filename ); - } - if ( file_exists( $dir . $cache_filename ) ) { - wp_cache_debug( "Renamed temp wp-cache file to {$dir}{$cache_filename}", 5 ); - } else { - wp_cache_debug( "FAILED to rename temp wp-cache file to {$dir}{$cache_filename}", 5 ); + if ( $fr ) { + $supercacheonly = false; + fclose( $fr ); + if ( filesize( $tmp_wpcache_filename ) == 0 ) { + wp_cache_debug( "Warning! The file $tmp_wpcache_filename was empty. Did not rename to {$dir}{$cache_filename}", 5 ); + @unlink( $tmp_wpcache_filename ); + } else { + if ( ! @rename( $tmp_wpcache_filename, $dir . $cache_filename ) ) { + if ( false == is_dir( $dir ) ) { + @wp_mkdir_p( $dir ); } - $added_cache = 1; + @unlink( $dir . $cache_filename ); + @rename( $tmp_wpcache_filename, $dir . $cache_filename ); } - } - if( $fr2 ) { - fclose($fr2); - if ( $wp_cache_front_page_checks && $cache_fname == $supercachedir . $home_url[ 'path' ] . supercache_filename() && !( $wp_cache_is_home ) ) { - wp_cache_writers_exit(); - wp_cache_debug( 'Warning! Not writing another page to front page cache.', 1 ); - return $buffer; - } elseif ( filesize( $tmp_cache_filename ) == 0 ) { - wp_cache_debug( "Warning! The file $tmp_cache_filename was empty. Did not rename to {$cache_fname}", 5 ); - @unlink( $tmp_cache_filename ); + if ( file_exists( $dir . $cache_filename ) ) { + wp_cache_debug( "Renamed temp wp-cache file to {$dir}{$cache_filename}", 5 ); } else { - if ( !@rename( $tmp_cache_filename, $cache_fname ) ) { - @unlink( $cache_fname ); - @rename( $tmp_cache_filename, $cache_fname ); - } - wp_cache_debug( "Renamed temp supercache file to $cache_fname", 5 ); - $added_cache = 1; + wp_cache_debug( "FAILED to rename temp wp-cache file to {$dir}{$cache_filename}", 5 ); } + $added_cache = 1; } - if( $gz ) { - fclose($gz); - if ( filesize( $tmp_cache_filename . '.gz' ) == 0 ) { - wp_cache_debug( "Warning! The file {$tmp_cache_filename}.gz was empty. Did not rename to {$cache_fname}.gz", 5 ); - @unlink( $tmp_cache_filename . '.gz' ); - } else { - if ( !@rename( $tmp_cache_filename . '.gz', $cache_fname . '.gz' ) ) { - @unlink( $cache_fname . '.gz' ); - @rename( $tmp_cache_filename . '.gz', $cache_fname . '.gz' ); - } - wp_cache_debug( "Renamed temp supercache gz file to {$cache_fname}.gz", 5 ); - $added_cache = 1; + } + + if ( $fr2 ) { + fclose( $fr2 ); + if ( $wp_cache_front_page_checks && $cache_fname == $supercachedir . $home_url[ 'path' ] . supercache_filename() && !( $wp_cache_is_home ) ) { + wp_cache_writers_exit(); + wp_cache_debug( 'Warning! Not writing another page to front page cache.', 1 ); + return $buffer; + } elseif ( filesize( $tmp_cache_filename ) == 0 ) { + wp_cache_debug( "Warning! The file $tmp_cache_filename was empty. Did not rename to {$cache_fname}", 5 ); + @unlink( $tmp_cache_filename ); + } else { + if ( ! @rename( $tmp_cache_filename, $cache_fname ) ) { + @unlink( $cache_fname ); + @rename( $tmp_cache_filename, $cache_fname ); + } + wp_cache_debug( "Renamed temp supercache file to $cache_fname", 5 ); + $added_cache = 1; + } + } + if ( $gz ) { + fclose( $gz ); + if ( filesize( $tmp_cache_filename . '.gz' ) == 0 ) { + wp_cache_debug( "Warning! The file {$tmp_cache_filename}.gz was empty. Did not rename to {$cache_fname}.gz", 5 ); + @unlink( $tmp_cache_filename . '.gz' ); + } else { + if ( ! @rename( $tmp_cache_filename . '.gz', $cache_fname . '.gz' ) ) { + @unlink( $cache_fname . '.gz' ); + @rename( $tmp_cache_filename . '.gz', $cache_fname . '.gz' ); } + wp_cache_debug( "Renamed temp supercache gz file to {$cache_fname}.gz", 5 ); + $added_cache = 1; } } + if ( $added_cache && isset( $wp_supercache_cache_list ) && $wp_supercache_cache_list ) { update_option( 'wpsupercache_count', ( get_option( 'wpsupercache_count' ) + 1 ) ); $last_urls = (array)get_option( 'supercache_last_cached' ); @@ -2404,7 +2529,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 $wp_cache_request_uri, $wp_cache_key, $wp_cache_object_cache, $cache_enabled, $wp_cache_blog_charset, $wp_cache_not_logged_in; + global $wp_cache_request_uri, $wp_cache_key, $cache_enabled, $wp_cache_blog_charset, $wp_cache_not_logged_in; global $WPSC_HTTP_HOST, $wp_super_cache_query; if ( ! function_exists( 'wpsc_init' ) ) { @@ -2515,26 +2640,20 @@ function wp_cache_shutdown_callback() { if( wp_cache_writers_entry() ) { wp_cache_debug( "Writing meta file: {$dir}meta-{$meta_file}", 2 ); - if ( false == $wp_cache_object_cache ) { - $tmp_meta_filename = $dir . uniqid( mt_rand(), true ) . '.tmp'; - $final_meta_filename = $dir . "meta-" . $meta_file; - $fr = @fopen( $tmp_meta_filename, 'w'); - if ( $fr ) { - fputs($fr, $serial); - fclose($fr); - @chmod( $tmp_meta_filename, 0666 & ~umask()); - if( !@rename( $tmp_meta_filename, $final_meta_filename ) ) { - @unlink( $dir . $final_meta_filename ); - @rename( $tmp_meta_filename, $final_meta_filename ); - } - } else { - wp_cache_debug( "Problem writing meta file: {$final_meta_filename}" ); + + $tmp_meta_filename = $dir . uniqid( mt_rand(), true ) . '.tmp'; + $final_meta_filename = $dir . "meta-" . $meta_file; + $fr = @fopen( $tmp_meta_filename, 'w'); + if ( $fr ) { + fputs($fr, $serial); + fclose($fr); + @chmod( $tmp_meta_filename, 0666 & ~umask()); + if( !@rename( $tmp_meta_filename, $final_meta_filename ) ) { + @unlink( $dir . $final_meta_filename ); + @rename( $tmp_meta_filename, $final_meta_filename ); } - } elseif ( $cache_enabled ) { - $oc_key = get_oc_key() . ".meta"; - if ( gzip_accepted() ) - $oc_key .= ".gz"; - wp_cache_set( $oc_key, $serial, 'supercache', $cache_max_time ); + } else { + wp_cache_debug( "Problem writing meta file: {$final_meta_filename}" ); } wp_cache_writers_exit(); @@ -2549,7 +2668,7 @@ function wp_cache_shutdown_callback() { } } } else { - wp_cache_debug( "Did not write meta file: meta-{$meta_file} *$supercacheonly* *$wp_cache_not_logged_in* *$new_cache*", 2 ); + wp_cache_debug( "Did not write meta file: meta-{$meta_file}\nsupercacheonly: $supercacheonly\nwp_cache_not_logged_in: $wp_cache_not_logged_in\nnew_cache:$new_cache" ); } global $time_to_gc_cache; if( isset( $time_to_gc_cache ) && $time_to_gc_cache == 1 ) { @@ -2634,25 +2753,23 @@ function wp_cache_clear_cache_on_menu() { /* Clear out the cache directory. */ function wp_cache_clear_cache( $blog_id = 0 ) { - global $cache_path, $wp_cache_object_cache; - if ( $wp_cache_object_cache ) { - reset_oc_version(); + 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 ); } else { - 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 ); - } 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 ); - } + 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 ); } + do_action( 'wp_cache_cleared' ); } function wpsc_delete_post_archives( $post ) { - $post = get_post( $post ); + $post = @get_post( $post ); if ( ! is_object( $post ) ) { return; } @@ -2761,7 +2878,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, $wp_cache_object_cache; + global $wp_cache_clear_on_post_edit, $cache_path, $blog_cache_dir; static $last_post_edited = -1; if ( $post_id == $last_post_edited ) { @@ -2786,12 +2903,8 @@ function wp_cache_post_edit( $post_id ) { $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 ); - if ( $wp_cache_object_cache ) { - reset_oc_version(); - } else { - prune_super_cache( $blog_cache_dir, true ); - prune_super_cache( get_supercache_dir(), true ); - } + prune_super_cache( $blog_cache_dir, true ); + prune_super_cache( get_supercache_dir(), true ); } else { $action = current_filter(); wp_cache_debug( "wp_cache_post_edit: Clearing cache for post $post_id on ${action}", 2 ); @@ -2801,10 +2914,6 @@ function wp_cache_post_edit( $post_id ) { } function wp_cache_post_id_gc( $post_id, $all = 'all' ) { - global $wp_cache_object_cache; - - if ( $wp_cache_object_cache ) - reset_oc_version(); $post_id = intval( $post_id ); if( $post_id == 0 ) @@ -2834,7 +2943,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, $super_cache_enabled, $blog_cache_dir, $wp_cache_refresh_single_only, $wp_cache_object_cache; + global $file_prefix, $cache_path, $blog_id, $super_cache_enabled, $blog_cache_dir, $wp_cache_refresh_single_only; static $last_processed = -1; if ( $post_id == $last_processed ) { @@ -2886,9 +2995,6 @@ function wp_cache_post_change( $post_id ) { if ( $all != $all_backup ) wp_cache_debug( 'wp_cache_post_change: $all changed by wpsc_delete_related_pages_on_edit filter: ' . intval( $all ) ); - if ( $wp_cache_object_cache ) - reset_oc_version(); - // Delete supercache files whenever a post change event occurs, even if supercache is currently disabled. $dir = get_supercache_dir(); // make sure the front page has a rebuild file diff --git a/wp-content/plugins/wp-super-cache/wp-cache.php b/wp-content/plugins/wp-super-cache/wp-cache.php index 4457f50665b84ca580b57a40559cf98c4a875046..f5ba6ed4806457a767b59ec946467e1ae5ef35d0 100644 --- a/wp-content/plugins/wp-super-cache/wp-cache.php +++ b/wp-content/plugins/wp-super-cache/wp-cache.php @@ -3,7 +3,7 @@ Plugin Name: WP Super Cache Plugin URI: https://wordpress.org/plugins/wp-super-cache/ Description: Very fast caching plugin for WordPress. -Version: 1.6.5 +Version: 1.6.9 Author: Automattic Author URI: https://automattic.com/ License: GPL2+ @@ -41,25 +41,25 @@ if ( ! defined( 'PHP_VERSION_ID' ) ) { } function wpsc_init() { - global $wp_cache_config_file, $wp_cache_config_file_sample, $wp_cache_file, $wp_cache_check_wp_config, $wp_cache_link; + global $wp_cache_config_file, $wp_cache_config_file_sample, $wpsc_advanced_cache_dist_filename, $wp_cache_check_wp_config, $wpsc_advanced_cache_filename; $wp_cache_config_file = WP_CONTENT_DIR . '/wp-cache-config.php'; if ( !defined( 'WPCACHEHOME' ) ) { define( 'WPCACHEHOME', dirname( __FILE__ ) . '/' ); $wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php'; - $wp_cache_file = WPCACHEHOME . 'advanced-cache.php'; + $wpsc_advanced_cache_dist_filename = WPCACHEHOME . 'advanced-cache.php'; } elseif ( realpath( WPCACHEHOME ) != realpath( dirname( __FILE__ ) ) ) { $wp_cache_config_file_sample = dirname( __FILE__ ) . '/wp-cache-config-sample.php'; - $wp_cache_file = dirname( __FILE__ ) . '/advanced-cache.php'; + $wpsc_advanced_cache_dist_filename = dirname( __FILE__ ) . '/advanced-cache.php'; if ( ! defined( 'ADVANCEDCACHEPROBLEM' ) ) { define( 'ADVANCEDCACHEPROBLEM', 1 ); // force an update of WPCACHEHOME } } else { $wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php'; - $wp_cache_file = WPCACHEHOME . 'advanced-cache.php'; + $wpsc_advanced_cache_dist_filename = WPCACHEHOME . 'advanced-cache.php'; } - $wp_cache_link = WP_CONTENT_DIR . '/advanced-cache.php'; + $wpsc_advanced_cache_filename = WP_CONTENT_DIR . '/advanced-cache.php'; if ( !defined( 'WP_CACHE' ) || ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) ) { $wp_cache_check_wp_config = true; @@ -102,7 +102,6 @@ function wp_super_cache_init_action() { load_plugin_textdomain( 'wp-super-cache', false, basename( dirname( __FILE__ ) ) . '/languages' ); wpsc_register_post_hooks(); - } add_action( 'init', 'wp_super_cache_init_action' ); @@ -135,14 +134,14 @@ function get_wpcachehome() { } function wpsc_remove_advanced_cache() { - global $wp_cache_link; - if ( file_exists( $wp_cache_link ) ) { - $file = file_get_contents( $wp_cache_link ); + global $wpsc_advanced_cache_filename; + if ( file_exists( $wpsc_advanced_cache_filename ) ) { + $file = file_get_contents( $wpsc_advanced_cache_filename ); if ( strpos( $file, "WP SUPER CACHE 0.8.9.1" ) || strpos( $file, "WP SUPER CACHE 1.2" ) ) { - unlink( $wp_cache_link ); + unlink( $wpsc_advanced_cache_filename ); } } } @@ -175,7 +174,7 @@ if ( is_admin() ) { } function wpsupercache_deactivate() { - global $wp_cache_config_file, $wp_cache_link, $cache_path; + global $wp_cache_config_file, $wpsc_advanced_cache_filename, $cache_path; wpsc_remove_advanced_cache(); @@ -203,9 +202,11 @@ function wpsupercache_activate() { ob_start(); wpsc_init(); - if ( !wp_cache_check_link() || - !wp_cache_verify_config_file() || - !wp_cache_verify_cache_dir() ) { + if ( + ! wpsc_check_advanced_cache() || + ! wp_cache_verify_config_file() || + ! wp_cache_verify_cache_dir() + ) { $text = ob_get_contents(); ob_end_clean(); return false; @@ -309,9 +310,11 @@ function wp_cache_manager_error_checks() { } } - if ( !wp_cache_check_link() || - !wp_cache_verify_config_file() || - !wp_cache_verify_cache_dir() ) { + if ( + ! wpsc_check_advanced_cache() || + ! wp_cache_verify_config_file() || + ! wp_cache_verify_cache_dir() + ) { echo '<p>' . __( "Cannot continue... fix previous problems and retry.", 'wp-super-cache' ) . '</p>'; return false; } @@ -527,7 +530,7 @@ if ( 'delcachepage' === filter_input( INPUT_GET, 'action' ) ) { } 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_object_cache, $_wp_using_ext_object_cache, $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_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 $cache_schedule_type, $cache_max_time, $cache_time_interval, $wp_cache_shutdown_gc, $wpsc_save_headers; if ( !wpsupercache_site_admin() ) @@ -572,12 +575,13 @@ function wp_cache_manager_updates() { wp_clear_scheduled_hook( 'wp_cache_gc' ); wp_clear_scheduled_hook( 'wp_cache_gc_watcher' ); } - $advanced_settings = array( 'wp_super_cache_late_init', 'wp_cache_disable_utf8', 'wp_cache_no_cache_for_get', 'wp_supercache_304', 'wp_cache_mfunc_enabled', 'wp_cache_mobile_enabled', 'wp_cache_front_page_checks', 'wp_supercache_cache_list', 'wp_cache_clear_on_post_edit', 'wp_cache_not_logged_in', 'wp_cache_make_known_anon','wp_cache_object_cache', 'wp_cache_refresh_single_only', 'cache_compression' ); + $advanced_settings = array( 'wp_super_cache_late_init', 'wp_cache_disable_utf8', 'wp_cache_no_cache_for_get', 'wp_supercache_304', 'wp_cache_mfunc_enabled', 'wp_cache_mobile_enabled', 'wp_cache_front_page_checks', 'wp_supercache_cache_list', 'wp_cache_clear_on_post_edit', 'wp_cache_make_known_anon', 'wp_cache_refresh_single_only', 'cache_compression' ); foreach( $advanced_settings as $setting ) { if ( isset( $GLOBALS[ $setting ] ) && $GLOBALS[ $setting ] == 1 ) { $_POST[ $setting ] = 1; } } + $_POST['wp_cache_not_logged_in'] = 2; } if( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'scupdates' ) { @@ -707,10 +711,11 @@ function wp_cache_manager_updates() { } wp_cache_replace_line('^ *\$wp_cache_mutex_disabled', "\$wp_cache_mutex_disabled = " . $wp_cache_mutex_disabled . ";", $wp_cache_config_file); - if( isset( $_POST[ 'wp_cache_not_logged_in' ] ) ) { - if( $wp_cache_not_logged_in == 0 && function_exists( 'prune_super_cache' ) ) - prune_super_cache ($cache_path, true); - $wp_cache_not_logged_in = 1; + 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 ); + } + $wp_cache_not_logged_in = (int)$_POST['wp_cache_not_logged_in']; } else { $wp_cache_not_logged_in = 0; } @@ -725,15 +730,6 @@ function wp_cache_manager_updates() { } wp_cache_replace_line('^ *\$wp_cache_make_known_anon', "\$wp_cache_make_known_anon = " . $wp_cache_make_known_anon . ";", $wp_cache_config_file); - if( $_wp_using_ext_object_cache && isset( $_POST[ 'wp_cache_object_cache' ] ) ) { - if( $wp_cache_object_cache == 0 && function_exists( 'prune_super_cache' ) ) - prune_super_cache( $cache_path, true ); - $wp_cache_object_cache = 1; - } else { - $wp_cache_object_cache = 0; - } - wp_cache_replace_line('^ *\$wp_cache_object_cache', "\$wp_cache_object_cache = " . $wp_cache_object_cache . ";", $wp_cache_config_file); - if( isset( $_POST[ 'wp_cache_refresh_single_only' ] ) ) { $wp_cache_refresh_single_only = 1; } else { @@ -771,7 +767,7 @@ function wp_cache_manager() { global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled; 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_object_cache, $_wp_using_ext_object_cache, $wp_cache_refresh_single_only, $wp_cache_mobile_prefixes; + 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_super_cache_comments, $wp_cache_home_path, $wpsc_save_headers, $is_nginx; @@ -875,7 +871,7 @@ table.wpsc-settings-table { } if ( 'preload' === $curr_tab ) { - if ( true === $super_cache_enabled && ! defined( 'DISABLESUPERCACHEPRELOADING' ) ) { + if ( true == $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 ) { @@ -1089,7 +1085,10 @@ table.wpsc-settings-table { <td> <fieldset> <legend class="hidden">Miscellaneous</legend> - <label><input type='checkbox' name='wp_cache_not_logged_in' <?php checked( $wp_cache_not_logged_in ); ?> value='1'> <?php echo __( 'Don’t cache pages for <acronym title="Logged in users and those that comment">known users</acronym>.', 'wp-super-cache' ) . ' <em>(' . esc_html__( 'Recommended', 'wp-super-cache' ) . ')</em>'; ?></label><br /> + <strong><?php echo __( 'Cache Restrictions', 'wp-super-cache' ); ?></strong><br /> + <label><input type='radio' name='wp_cache_not_logged_in' <?php checked( $wp_cache_not_logged_in, 0 ); ?> value='0'> <?php echo __( 'Enable caching for all visitors.', 'wp-super-cache' ); ?></label><br /> + <label><input type='radio' name='wp_cache_not_logged_in' <?php checked( $wp_cache_not_logged_in, 1 ); ?> value='1'> <?php echo __( 'Disable caching for visitors who have a cookie set in their browser.', 'wp-super-cache' ); ?></label><br /> + <label><input type='radio' name='wp_cache_not_logged_in' <?php checked( $wp_cache_not_logged_in, 2 ); ?> value='2'> <?php echo __( 'Disable caching for logged in visitors.', 'wp-super-cache' ) . ' <em>(' . esc_html__( 'Recommended', 'wp-super-cache' ) . ')</em>'; ?></label><br /><br /> <label><input type='checkbox' name='wp_cache_no_cache_for_get' <?php checked( $wp_cache_no_cache_for_get ); ?> value='1'> <?php _e( 'Don’t cache pages with GET parameters. (?x=y at the end of a url)', 'wp-super-cache' ); ?></label><br /> <?php if ( ! defined( 'WPSC_DISABLE_COMPRESSION' ) ) : ?> <?php if ( ! function_exists( 'gzencode' ) ) : ?> @@ -1141,9 +1140,6 @@ table.wpsc-settings-table { <label><input type='checkbox' name='wp_cache_mutex_disabled' <?php if( !$wp_cache_mutex_disabled ) echo "checked"; ?> value='0'> <?php _e( 'Coarse file locking. You do not need this as it will slow down your website.', 'wp-super-cache' ); ?></label><br /> <?php } ?> <label><input type='checkbox' name='wp_super_cache_late_init' <?php if( $wp_super_cache_late_init ) echo "checked"; ?> value='1'> <?php _e( 'Late init. Display cached files after WordPress has loaded.', 'wp-super-cache' ); ?></label><br /> - <?php if ( $_wp_using_ext_object_cache ) { - ?><label><input type='checkbox' name='wp_cache_object_cache' <?php if( $wp_cache_object_cache ) echo "checked"; ?> value='1'> <?php echo __( 'Use object cache to store cached files.', 'wp-super-cache' ) . ' ' . __( '(Experimental)', 'wp-super-cache' ); ?></label><?php - }?> <?php printf( __( '<strong>DO NOT CACHE PAGE</strong> secret key: <a href="%s">%s</a>', 'wp-super-cache' ), trailingslashit( get_bloginfo( 'url' ) ) . "?donotcachepage={$cache_page_secret}", $cache_page_secret ); ?> </fieldset> </td> @@ -2130,12 +2126,13 @@ function wp_cache_debug_settings() { if ( ! isset( $wp_cache_debug_log ) || $wp_cache_debug_log == '' ) { extract( wpsc_create_debug_log() ); // $wp_cache_debug_log, $wp_cache_debug_username } - $log_file_link = "<a href='" . site_url( str_replace( ABSPATH, '', "{$cache_path}view_{$wp_cache_debug_log}" ) ) . "'>$wp_cache_debug_log</a>"; - $raw_log_file_link = "<a href='" . site_url( str_replace( ABSPATH, '', "{$cache_path}{$wp_cache_debug_log}" ) ) . "'>" . __( 'RAW', 'wp-super-cache' ) . "</a>"; + + $log_file_link = "<a href='" . site_url( str_replace( ABSPATH, '', "{$cache_path}view_{$wp_cache_debug_log}?wp-admin=1&wp-json=1&filter=" ) ) . "'>$wp_cache_debug_log</a>"; + if ( $wp_super_cache_debug == 1 ) { - echo "<p>" . sprintf( __( 'Currently logging to: %s (%s)', 'wp-super-cache' ), $log_file_link, $raw_log_file_link ) . "</p>"; + echo "<p>" . sprintf( __( 'Currently logging to: %s', 'wp-super-cache' ), $log_file_link ) . "</p>"; } else { - echo "<p>" . sprintf( __( 'Last Logged to: %s (%s)', 'wp-super-cache' ), $log_file_link, $raw_log_file_link ) . "</p>"; + echo "<p>" . sprintf( __( 'Last Logged to: %s', 'wp-super-cache' ), $log_file_link ) . "</p>"; } echo "<p>" . sprintf( __( 'Username/Password: %s', 'wp-super-cache' ), $wp_cache_debug_username ) . "</p>"; @@ -2188,10 +2185,14 @@ function wp_cache_debug_settings() { function wp_cache_enable() { global $wp_cache_config_file, $cache_enabled; - if ( ! wp_cache_replace_line( '^\s*\$cache_enabled\s*=', '$cache_enabled = true;', $wp_cache_config_file ) ) { - return; + if ( $cache_enabled ) { + wp_cache_debug( 'wp_cache_enable: already enabled' ); + return true; } + wp_cache_setting( 'cache_enabled', true ); + wp_cache_debug( 'wp_cache_enable: enable cache' ); + $cache_enabled = true; if ( wpsc_set_default_gc() ) { @@ -2206,10 +2207,14 @@ function wp_cache_enable() { function wp_cache_disable() { global $wp_cache_config_file, $cache_enabled; - if ( ! wp_cache_replace_line( '^\s*\$cache_enabled\s*=', '$cache_enabled = false;', $wp_cache_config_file ) ) { - return; + if ( ! $cache_enabled ) { + wp_cache_debug( 'wp_cache_disable: already disabled' ); + return true; } + wp_cache_setting( 'cache_enabled', false ); + wp_cache_debug( 'wp_cache_disable: disable cache' ); + $cache_enabled = false; wp_clear_scheduled_hook( 'wp_cache_check_site_hook' ); @@ -2220,10 +2225,14 @@ function wp_cache_disable() { function wp_super_cache_enable() { global $supercachedir, $wp_cache_config_file, $super_cache_enabled; - if ( ! wp_cache_replace_line( '^\s*\$super_cache_enabled\s*=', '$super_cache_enabled = true;', $wp_cache_config_file ) ) { - return; + if ( $super_cache_enabled ) { + wp_cache_debug( 'wp_super_cache_enable: already enabled' ); + return true; } + wp_cache_setting( 'super_cache_enabled', true ); + wp_cache_debug( 'wp_super_cache_enable: enable cache' ); + $super_cache_enabled = true; if ( is_dir( $supercachedir . '.disabled' ) ) { @@ -2239,10 +2248,14 @@ function wp_super_cache_enable() { function wp_super_cache_disable() { global $cache_path, $supercachedir, $wp_cache_config_file, $super_cache_enabled; - if ( ! wp_cache_replace_line('^\s*\$super_cache_enabled\s*=', '$super_cache_enabled = false;', $wp_cache_config_file ) ) { - return; + if ( ! $super_cache_enabled ) { + wp_cache_debug( 'wp_super_cache_disable: already disabled' ); + return true; } + wp_cache_setting( 'super_cache_enabled', false ); + wp_cache_debug( 'wp_super_cache_disable: disable cache' ); + $super_cache_enabled = false; if ( is_dir( $supercachedir ) ) { @@ -2552,7 +2565,7 @@ function wp_cache_verify_config_file() { } function wp_cache_create_advanced_cache() { - global $wp_cache_link, $wp_cache_file; + global $wpsc_advanced_cache_filename, $wpsc_advanced_cache_dist_filename; if ( file_exists( ABSPATH . 'wp-config.php') ) { $global_config_file = ABSPATH . 'wp-config.php'; } else { @@ -2566,24 +2579,41 @@ function wp_cache_create_advanced_cache() { return false; } - if ( !is_writeable_ACLSafe($global_config_file) || !wp_cache_replace_line('define *\( *\'WPCACHEHOME\'', $line, $global_config_file ) ) { - echo '<div class="notice notice-error"><h4>' . __( 'Warning', 'wp-super-cache' ) . "! <em>" . sprintf( __( 'Could not update %s!</em> WPCACHEHOME must be set in config file.', 'wp-super-cache' ), $global_config_file ) . "</h4></div>"; - return false; + if ( + ! strpos( file_get_contents( $global_config_file ), "WPCACHEHOME" ) || + ( + defined( 'WPCACHEHOME' ) && + ( + constant( 'WPCACHEHOME' ) == '' || + ( + constant( 'WPCACHEHOME' ) != '' && + ! file_exists( constant( 'WPCACHEHOME' ) . '/wp-cache.php' ) + ) + ) + ) + ) { + if ( + ! is_writeable_ACLSafe( $global_config_file ) || + ! wp_cache_replace_line( 'define *\( *\'WPCACHEHOME\'', $line, $global_config_file ) + ) { + echo '<div class="notice notice-error"><h4>' . __( 'Warning', 'wp-super-cache' ) . "! <em>" . sprintf( __( 'Could not update %s!</em> WPCACHEHOME must be set in config file.', 'wp-super-cache' ), $global_config_file ) . "</h4></div>"; + return false; + } } $ret = true; - if ( file_exists( $wp_cache_link ) ) { - $file = file_get_contents( $wp_cache_link ); + if ( file_exists( $wpsc_advanced_cache_filename ) ) { + $file = file_get_contents( $wpsc_advanced_cache_filename ); if ( ! strpos( $file, "WP SUPER CACHE 0.8.9.1" ) && ! strpos( $file, "WP SUPER CACHE 1.2" ) ) { - wp_die( '<div class="notice notice-error"><h4>' . __( 'Warning!', 'wp-super-cache' ) . "</h4><p>" . sprintf( __( 'The file %s already exists. Please manually delete it before using this plugin.', 'wp-super-cache' ), $wp_cache_link ) . "</p></div>" ); + wp_die( '<div class="notice notice-error"><h4>' . __( 'Warning!', 'wp-super-cache' ) . "</h4><p>" . sprintf( __( 'The file %s already exists. Please manually delete it before using this plugin. If you continue to see this message after deleting it please contact your hosting support.', 'wp-super-cache' ), $wpsc_advanced_cache_filename ) . "</p></div>" ); } } - $file = file_get_contents( $wp_cache_file ); - $fp = @fopen( $wp_cache_link, 'w' ); + $file = file_get_contents( $wpsc_advanced_cache_dist_filename ); + $fp = @fopen( $wpsc_advanced_cache_filename, 'w' ); if( $fp ) { fputs( $fp, $file ); fclose( $fp ); @@ -2593,12 +2623,12 @@ function wp_cache_create_advanced_cache() { return $ret; } -function wp_cache_check_link() { - global $wp_cache_link, $wp_cache_file; +function wpsc_check_advanced_cache() { + global $wpsc_advanced_cache_filename; $ret = true; - if( file_exists($wp_cache_link) ) { - $file = file_get_contents( $wp_cache_link ); + if ( file_exists( $wpsc_advanced_cache_filename ) ) { + $file = file_get_contents( $wpsc_advanced_cache_filename ); if( strpos( $file, "WP SUPER CACHE 0.8.9.1" ) || strpos( $file, "WP SUPER CACHE 1.2" ) ) { return true; } else { @@ -2614,7 +2644,6 @@ function wp_cache_check_link() { echo "<li>" . sprintf( __( 'Make %1$s writable using the chmod command through your ftp or server software. (<em>chmod 777 %1$s</em>) and refresh this page. This is only a temporary measure and you’ll have to make it read only afterwards again. (Change 777 to 755 in the previous command)', 'wp-super-cache' ), WP_CONTENT_DIR ) . "</li>"; echo "<li>" . sprintf( __( 'Refresh this page to update <em>%s/advanced-cache.php</em>', 'wp-super-cache' ), WP_CONTENT_DIR ) . "</li></ol>"; echo sprintf( __( 'If that doesn’t work, make sure the file <em>%s/advanced-cache.php</em> doesn’t exist:', 'wp-super-cache' ), WP_CONTENT_DIR ) . "<ol>"; - printf( __( '<li>Open <em>%1$s</em> in a text editor.</li><li>Change the text <em>CACHEHOME</em> to <em>%2$s</em></li><li> Save the file and copy it to <em>%3$s</em> and refresh this page.</li>', 'wp-super-cache' ), $wp_cache_file, WPCACHEHOME, $wp_cache_link ); echo "</ol>"; echo "</div>"; return false; @@ -2630,18 +2659,21 @@ function wp_cache_check_global_config() { if ( file_exists( ABSPATH . 'wp-config.php') ) { - $global = ABSPATH . 'wp-config.php'; + $global_config_file = ABSPATH . 'wp-config.php'; } else { - $global = dirname(ABSPATH) . '/wp-config.php'; + $global_config_file = dirname( ABSPATH ) . '/wp-config.php'; } $line = 'define(\'WP_CACHE\', true);'; - if (!is_writeable_ACLSafe($global) || !wp_cache_replace_line('define *\( *\'WP_CACHE\'', $line, $global) ) { + if ( + ! is_writeable_ACLSafe( $global_config_file ) || + ! wp_cache_replace_line( 'define *\( *\'WP_CACHE\'', $line, $global_config_file ) + ) { if ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) { echo '<div class="notice notice-error">' . __( "<h4>WP_CACHE constant set to false</h4><p>The WP_CACHE constant is used by WordPress to load the code that serves cached pages. Unfortunately, it is set to false. Please edit your wp-config.php and add or edit the following line above the final require_once command:<br /><br /><code>define('WP_CACHE', true);</code></p>", 'wp-super-cache' ) . "</div>"; } else { echo '<div class="notice notice-error"><p>' . __( "<strong>Error: WP_CACHE is not enabled</strong> in your <code>wp-config.php</code> file and I couldn’t modify it.", 'wp-super-cache' ) . "</p>"; - echo "<p>" . sprintf( __( "Edit <code>%s</code> and add the following line:<br /> <code>define('WP_CACHE', true);</code><br />Otherwise, <strong>WP-Cache will not be executed</strong> by WordPress core. ", 'wp-super-cache' ), $global ) . "</p></div>"; + echo "<p>" . sprintf( __( "Edit <code>%s</code> and add the following line:<br /> <code>define('WP_CACHE', true);</code><br />Otherwise, <strong>WP-Cache will not be executed</strong> by WordPress core. ", 'wp-super-cache' ), $global_config_file ) . "</p></div>"; } return false; } else { @@ -2718,7 +2750,7 @@ function wp_cache_regenerate_cache_file_stats() { function wp_cache_files() { global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $super_cache_enabled, $blog_cache_dir, $cache_compression; - global $wp_cache_object_cache, $wp_cache_preload_on; + global $wp_cache_preload_on; if ( '/' != substr($cache_path, -1)) { $cache_path .= '/'; @@ -2741,13 +2773,6 @@ function wp_cache_files() { echo "<a name='listfiles'></a>"; echo '<fieldset class="options" id="show-this-fieldset"><h4>' . __( 'Cache Contents', 'wp-super-cache' ) . '</h4>'; - if ( $wp_cache_object_cache ) { - echo "<p>" . __( "Object cache in use. No cache listing available.", 'wp-super-cache' ) . "</p>"; - wp_cache_delete_buttons(); - echo "</fieldset>"; - return false; - } - $cache_stats = get_option( 'supercache_stats' ); if ( !is_array( $cache_stats ) || ( isset( $_GET[ 'listfiles' ] ) ) || ( $valid_nonce && array_key_exists('action', $_GET) && $_GET[ 'action' ] == 'regenerate_cache_stats' ) ) { $count = 0; @@ -2999,13 +3024,10 @@ function wpsc_dirsize($directory, $sizes) { } function wp_cache_clean_cache( $file_prefix, $all = false ) { - global $cache_path, $supercachedir, $blog_cache_dir, $wp_cache_object_cache; + global $cache_path, $supercachedir, $blog_cache_dir; do_action( 'wp_cache_cleared' ); - if ( $wp_cache_object_cache && function_exists( "reset_oc_version" ) ) - reset_oc_version(); - if ( $all == true && wpsupercache_site_admin() && function_exists( 'prune_super_cache' ) ) { prune_super_cache( $cache_path, true ); return true; @@ -3725,11 +3747,23 @@ function wp_cache_disable_plugin( $delete_config_file = true ) { if ( apply_filters( 'wpsc_enable_wp_config_edit', true ) ) { $line = 'define(\'WP_CACHE\', true);'; - if ( strpos( file_get_contents( $global_config_file ), $line ) && ( !is_writeable_ACLSafe( $global_config_file ) || !wp_cache_replace_line( 'define *\( *\'WP_CACHE\'', '', $global_config_file ) ) ) { + if ( + strpos( file_get_contents( $global_config_file ), $line ) && + ( + ! is_writeable_ACLSafe( $global_config_file ) || + ! wp_cache_replace_line( 'define*\(*\'WP_CACHE\'', '', $global_config_file ) + ) + ) { wp_die( "Could not remove WP_CACHE define from $global_config_file. Please edit that file and remove the line containing the text 'WP_CACHE'. Then refresh this page." ); } $line = 'define( \'WPCACHEHOME\','; - if ( strpos( file_get_contents( $global_config_file ), $line ) && ( !is_writeable_ACLSafe( $global_config_file ) || !wp_cache_replace_line( 'define *\( *\'WPCACHEHOME\'', '', $global_config_file ) ) ) { + if ( + strpos( file_get_contents( $global_config_file ), $line ) && + ( + ! is_writeable_ACLSafe( $global_config_file ) || + ! wp_cache_replace_line( 'define *\( *\'WPCACHEHOME\'', '', $global_config_file ) + ) + ) { wp_die( "Could not remove WPCACHEHOME define from $global_config_file. Please edit that file and remove the line containing the text 'WPCACHEHOME'. Then refresh this page." ); } } elseif ( function_exists( 'wp_cache_debug' ) ) { @@ -4250,3 +4284,22 @@ function wpsc_get_extra_cookies() { return ''; } } + +function wpsc_update_check() { + global $wpsc_version; + + if ( + ! isset( $wpsc_version ) || + $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)); + if ( ! file_exists( $log_file ) ) { + return false; + } + @unlink( $log_file ); + wp_cache_debug( 'wpsc_update_check: Deleted old log file on plugin update.' ); + } +} +add_action( 'admin_init', 'wpsc_update_check' );