diff --git a/wp-content/plugins/wp-super-cache/plugins/jetpack.php b/wp-content/plugins/wp-super-cache/plugins/jetpack.php index e66e71be512b87fcb65eb17e04c63850b0c880cf..c473a27c4a09271ade990232965c81cea34243ee 100644 --- a/wp-content/plugins/wp-super-cache/plugins/jetpack.php +++ b/wp-content/plugins/wp-super-cache/plugins/jetpack.php @@ -64,6 +64,14 @@ function wp_super_cache_jetpack_cookie_check( $cache_key ) { } } + if ( isset ( $_COOKIE['akm_mobile'] ) ) { + if ( $_COOKIE['akm_mobile'] == 'true' ) { + return 'mobile'; + } elseif ( $_COOKIE['akm_mobile'] == 'false' ) { + return 'normal'; + } + } + if ( function_exists( 'jetpack_is_mobile' ) ) { if ( jetpack_is_mobile() ) { return 'mobile'; diff --git a/wp-content/plugins/wp-super-cache/plugins/multisite.php b/wp-content/plugins/wp-super-cache/plugins/multisite.php index 1f09b99ca7fa31339e5d13233db060c82b93f260..6306a160e5952b1ace343c82265a31edd38771b2 100644 --- a/wp-content/plugins/wp-super-cache/plugins/multisite.php +++ b/wp-content/plugins/wp-super-cache/plugins/multisite.php @@ -7,7 +7,7 @@ if ( ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) === t function wp_super_cache_multisite_init() { add_filter( 'wpmu_blogs_columns', 'wp_super_cache_blogs_col' ); add_action( 'manage_sites_custom_column', 'wp_super_cache_blogs_field', 10, 2 ); - add_action( 'init', 'wp_super_cache_override_on_flag' ); + add_action( 'init', 'wp_super_cache_override_on_flag', 9 ); } function wp_super_cache_blogs_col( $col ) { @@ -20,18 +20,20 @@ function wp_super_cache_blogs_field( $name, $blog_id ) { return false; } + $blog_id = (int) $blog_id; + if ( isset( $_GET['id'], $_GET['action'], $_GET['_wpnonce'] ) - && $blog_id === intval( $_GET['id'] ) + && $blog_id === filter_input( INPUT_GET, 'id', FILTER_VALIDATE_INT ) && wp_verify_nonce( $_GET['_wpnonce'], 'wp-cache' . $blog_id ) ) { - if ( 'disable_cache' === $_GET['action'] ) { - add_blog_option( $_GET['id'], 'wp_super_cache_disabled', 1 ); - } elseif ( 'enable_cache' === $_GET['action'] ) { - delete_blog_option( $_GET['id'], 'wp_super_cache_disabled' ); + if ( 'disable_cache' === filter_input( INPUT_GET, 'action' ) ) { + add_blog_option( $blog_id, 'wp_super_cache_disabled', 1 ); + } elseif ( 'enable_cache' === filter_input( INPUT_GET, 'action' ) ) { + delete_blog_option( $blog_id, 'wp_super_cache_disabled' ); } } - if ( get_blog_option( $blog_id, 'wp_super_cache_disabled' ) === 1 ) { + if ( 1 === (int) get_blog_option( $blog_id, 'wp_super_cache_disabled' ) ) { echo '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'enable_cache', 'id' => $blog_id ) ), 'wp-cache' . $blog_id ) . '">' . __( 'Enable', 'wp-super-cache' ) . '</a>'; } else { echo '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'disable_cache', 'id' => $blog_id ) ), 'wp-cache' . $blog_id ) . '">' . __( 'Disable', 'wp-super-cache' ) . '</a>'; @@ -39,7 +41,7 @@ function wp_super_cache_blogs_field( $name, $blog_id ) { } function wp_super_cache_multisite_notice() { - if ( isset( $_GET['page'] ) && 'wpsupercache' === $_GET['page'] ) { + if ( 'wpsupercache' === filter_input( INPUT_GET, 'page' ) ) { echo '<div class="error"><p><strong>' . __( 'Caching has been disabled on this blog on the Network Admin Sites page.', 'wp-super-cache' ) . '</strong></p></div>'; } } @@ -50,7 +52,7 @@ function wp_super_cache_override_on_flag() { return false; } - if ( get_option( 'wp_super_cache_disabled' ) ) { + if ( 1 === (int) get_option( 'wp_super_cache_disabled' ) ) { $cache_enabled = false; $super_cache_enabled = false; define( 'DONOTCACHEPAGE', 1 ); diff --git a/wp-content/plugins/wp-super-cache/readme.txt b/wp-content/plugins/wp-super-cache/readme.txt index 4c96603556fd47f9755afe4a45a0bf75e00d253a..92c9c776c2d8f62b034a85a5c8b3ecfdcd7dc093 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: 4.9.1 -* Stable tag: 1.5.9 +* Tested up to: 4.9.6 +* Stable tag: 1.6.2 * Requires at least: 3.0 * Requires PHP: 5.2.4 * License: GPLv2 or later @@ -89,7 +89,7 @@ There is one regular WordPress filter too. Use the "do_createsupercache" filter to customize the checks made before caching. The filter accepts one parameter. The output of WP-Cache's wp_cache_get_cookies_values() function. -See plugins/searchengine.php as an example I use for my [No Adverts for Friends](https://odd.blog/no-adverts-for-friends/) plugin. +See [plugins/searchengine.php](https://github.com/Automattic/wp-super-cache/blob/4cda5c0f2218e40e118232b5bf22d227fb3206b7/plugins/searchengine.php) as an example I use for my [No Adverts for Friends](https://odd.blog/no-adverts-for-friends/) plugin. ### Troubleshooting ### If things don't work when you installed the plugin here are a few things to check: @@ -136,7 +136,7 @@ If that doesn't work, add this line to your wp-config.php: 27. Use [Cron View](https://wordpress.org/plugins/cron-view/) to help diagnose garbage collection and preload problems. Use the plugin to make sure jobs are scheduled and for what time. Look for the wp_cache_gc and wp_cache_full_preload_hook jobs. 18. The error message, "WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory." appears at the end of every page. You can delete wp-content/advanced-cache.php and reload the plugin settings page or edit wp-config.php and look for WPCACHEHOME and make sure it points at the wp-super-cache folder. This will normally be wp-content/plugins/wp-super-cache/ but you'll likely need the full path to that file (so it's easier to let the settings page fix it). If it is not correct the caching engine will not load. 19. If your server is running into trouble because of the number of semaphores used by the plugin it's because your users are using file locking which is not recommended (but is needed by a small number of users). You can globally disable file locking by defining the constant WPSC_DISABLE_LOCKING, or defining the constant WPSC_REMOVE_SEMAPHORE so that sem_remove() is called after every page is cached but that seems to cause problems for other processes requesting the same semaphore. Best to disable it. - +20. Set the variable $htaccess_path in wp-config.php or wp-cache-config.php to the path of your global .htaccess if the plugin is looking for that file in the wrong directory. This might happen if you have WordPress installed in an unusual way. ## Installation ## Install like any other plugin, directly from your plugins page but make sure you have custom permalinks enabled. Go to the plugin settings page at Settings->WP Super Cache and enable caching. @@ -261,6 +261,41 @@ Your theme is probably responsive which means it resizes the page to suit whatev ## Changelog ## +### 1.6.2 ### +* Fixed serving expired supercache files (#562) +* Write directly to the config file to avoid permission problems with wp-content. (#563) +* Correctly set the .htaccess rules on the main site of a multisite. (#557) +* Check if set_transient() exists before using it. (#565) +* Removed searchengine.php example plugin as it sets a cookie to track users. Still available [here](https://github.com/Automattic/wp-super-cache/blob/4cda5c0f2218e40e118232b5bf22d227fb3206b7/plugins/searchengine.php). (#567) +* For advanced users only. Change the vary and cache control headers. See https://github.com/Automattic/wp-super-cache/pull/555 (#555) + +### 1.6.1 ### +* Fix the name of the WP Crontrol plugin. (#549) +* Handle errors during deactivation/uninstall by email rather than exiting. (#551) +* Add a notice when settings can't be updated. (#552 and #553) + +### 1.6.0 ### +* Fix issues in multisite plugin (#501) +* Fixes wp-cli plugin deactivate/activate (#499) +* Cleanup - change quotes. (#495) +* $htaccess_path defines the path to the global .htacess file. (#507) +* Fix 'cannot redeclare gzip_accepted()' (#511) +* Correct the renaming of tmp_wpcache_filename (removed unnecessary slash in path) which caused renaming to fail. (#516) +* Add check for Jetpack mobile theme cookie (#515) +* Optimize wp_cache_phase2 and create wpsc_register_post_hooks (#508) +* WPCACHEHOME has a trailing slash (#513) +* Cleanup cache enable/disable and update_mod_rewrite_rules (#500) +* Post Update now clears category cache (#519) +* Various fixes for saving the debug page form (#542) +* Expert-caching and empty parameters, like ?amp, should not serve cached page (#533) +* Tiny Yslow description fix (#527) +* Add ipad to mobile list (#525) +* Hide opcache_invalidate() warnings since it's disabled some places. (#543) +* Check that HTTP_REFERER exists before checking it. (#544) +* Replace Cron View" with WP Crontrol because it's still updated. (#546) +* adding hook (wp_cache_cleared) for full cache purges (#537) + + ### 1.5.9 ### * Fixed fatal error if the debug log was deleted while debugging was enabled and a visitor came to the site. * Fixed the dynamic caching test plugin because of PHP7 changes. Dynamic cache mode must be enabled now. @@ -628,4 +663,4 @@ Your theme is probably responsive which means it resizes the page to suit whatev ## Upgrade Notice ## -Fixes rare fatal error when using debug log +Fix problems writing to the config file for some users. diff --git a/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-rest-get-settings.php b/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-rest-get-settings.php index c9c704e590c4393f19fed9a370e5cfdfb1560dab..af708f94618b8ab3b3ac91f01f12ef7361a8ea1d 100644 --- a/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-rest-get-settings.php +++ b/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-rest-get-settings.php @@ -23,7 +23,7 @@ class WP_Super_Cache_Rest_Get_Settings extends WP_REST_Controller { } if ( function_exists( "opcache_invalidate" ) ) { - opcache_invalidate( $wp_cache_config_file ); + @opcache_invalidate( $wp_cache_config_file ); } include( $wp_cache_config_file ); @@ -78,7 +78,7 @@ class WP_Super_Cache_Rest_Get_Settings extends WP_REST_Controller { public function get_cache_type() { global $wp_cache_config_file; if ( function_exists( "opcache_invalidate" ) ) { - opcache_invalidate( $wp_cache_config_file ); + @opcache_invalidate( $wp_cache_config_file ); } include( $wp_cache_config_file ); 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 d2f2f89b468714db70ede0f72667b4880453e000..76f2d48a36c867b2eb8fa8608c8e16b97538581c 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 @@ -87,7 +87,11 @@ class WP_Super_Cache_Rest_Update_Settings extends WP_REST_Controller { $set_method = method_exists( $this, 'set_' . $map['global'] ) ? 'set_' . $map['global'] : 'set_global'; - $has_error = call_user_func( array( $this, $set_method ), $value ); + if ( $set_method == 'set_global' ) { + $has_error = call_user_func( array( $this, $set_method ), $key, $value ); + } else { + $has_error = call_user_func( array( $this, $set_method ), $value ); + } } if ( ! empty( $has_error ) ) { @@ -604,7 +608,7 @@ class WP_Super_Cache_Rest_Update_Settings extends WP_REST_Controller { wp_cache_setting( 'cache_page_secret', $cache_page_secret ); if ( function_exists( "opcache_invalidate" ) ) { - opcache_invalidate( $wp_cache_config_file ); + @opcache_invalidate( $wp_cache_config_file ); } } wpsc_set_default_gc( true ); @@ -637,6 +641,9 @@ class WP_Super_Cache_Rest_Update_Settings extends WP_REST_Controller { } $_POST[ 'wp_cache_debug' ] = 1; } else { + if ( ! isset( $GLOBALS[ $setting ] ) ) { + $GLOBALS[ $setting ] = 0; + } $_POST[ $setting ] = $GLOBALS[ $setting ]; } } diff --git a/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-settings-map.php b/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-settings-map.php index 9e8ed0644688492ee0199cb7506628e23aca1e11..4eec197c35ddcd26e4c29eae54c886b88eaa2989 100644 --- a/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-settings-map.php +++ b/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-settings-map.php @@ -236,7 +236,7 @@ class WP_Super_Cache_Settings_Map { 'global' => 'wp_super_cache_debug', ), 'wp_cache_debug_username' => array( - 'global' => 'wp_cache_debug_username', + 'get' => 'wpsc_debug_username', ), 'wp_cache_debug_log' => array( 'global' => 'wp_cache_debug_log', diff --git a/wp-content/plugins/wp-super-cache/rest/load.php b/wp-content/plugins/wp-super-cache/rest/load.php index 32007432b2f4547679171e9e795d4ffb3dee3db0..8f2f171b2122bf17b9a7605138e6d9b6546bc130 100644 --- a/wp-content/plugins/wp-super-cache/rest/load.php +++ b/wp-content/plugins/wp-super-cache/rest/load.php @@ -35,7 +35,7 @@ class WP_Super_Cache_Router { $preload_cache = new WP_Super_Cache_Rest_Preload(); $get_status = new WP_Super_Cache_Rest_Get_Status(); $get_plugins = new WP_Super_Cache_Rest_Get_Plugins(); - $update_plugins = new WP_Super_Cache_Rest_Update_plugins(); + $update_plugins = new WP_Super_Cache_Rest_Update_Plugins(); register_rest_route( $namespace, '/settings', array( array( 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 7880e9eb3e2f75ed0d1a2ce83ba78661c2cef98e..d5291f3c2012fb109862155f7f0dabf46c19c1a5 100644 --- a/wp-content/plugins/wp-super-cache/wp-cache-phase1.php +++ b/wp-content/plugins/wp-super-cache/wp-cache-phase1.php @@ -1,6 +1,8 @@ <?php -require_once dirname( __FILE__ ) . '/wp-cache-phase2.php'; +if ( ! function_exists( 'wp_cache_phase2' ) ) { + require_once dirname( __FILE__ ) . '/wp-cache-phase2.php'; +} // error_reporting(E_ERROR | E_PARSE); // uncomment to debug this file! if ( ! @include WP_CONTENT_DIR . '/wp-cache-config.php' ) { 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 32b6a62570136a2132c1e2e993d28fed264d57a5..95449bf106d61cb76645d5d5f94a06ae8c82e91a 100644 --- a/wp-content/plugins/wp-super-cache/wp-cache-phase2.php +++ b/wp-content/plugins/wp-super-cache/wp-cache-phase2.php @@ -53,12 +53,12 @@ function wp_cache_serve_cache_file() { } if ( wp_cache_user_agent_is_rejected() ) { - wp_cache_debug( "No wp-cache file served as user agent rejected.", 5 ); + wp_cache_debug( 'No wp-cache file served as user agent rejected.', 5 ); return false; } if ( $wp_cache_no_cache_for_get && false == empty( $_GET ) ) { - wp_cache_debug( "Non empty GET request. Caching disabled on settings page. " . wpsc_dump_get_request(), 1 ); + wp_cache_debug( 'Non empty GET request. Caching disabled on settings page. ' . wpsc_dump_get_request(), 1 ); return false; } @@ -66,7 +66,7 @@ function wp_cache_serve_cache_file() { 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 ); + wp_cache_debug( 'Non empty GET request. Not serving request from object cache. ' . wpsc_dump_get_request(), 1 ); return false; } @@ -79,7 +79,7 @@ function wp_cache_serve_cache_file() { $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 ); + 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 ) ) { @@ -87,7 +87,7 @@ function wp_cache_serve_cache_file() { $cache_file = get_current_url_supercache_dir() . $cache_filename; $meta_pathname = get_current_url_supercache_dir() . 'meta-' . $cache_filename; } elseif ( !file_exists( $cache_file ) ) { - wp_cache_debug( "wp_cache_serve_cache_file: found cache file but then it disappeared!" ); + wp_cache_debug( 'wp_cache_serve_cache_file: found cache file but then it disappeared!' ); return false; } @@ -104,6 +104,7 @@ 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; @@ -111,13 +112,16 @@ function wp_cache_serve_cache_file() { wp_cache_debug( "No Super Cache file found for current URL: $file" ); return false; } elseif ( false == empty( $_GET ) ) { - wp_cache_debug( "GET array not empty. Cannot serve a supercache file. " . wpsc_dump_get_request() ); + wp_cache_debug( 'GET array not empty. Cannot serve a supercache file. ' . wpsc_dump_get_request() ); return false; } elseif ( wp_cache_get_cookies_values() != '' ) { - wp_cache_debug( "Cookies found. Cannot serve a supercache file. " . wp_cache_get_cookies_values() ); + wp_cache_debug( 'Cookies found. Cannot serve a supercache file. ' . wp_cache_get_cookies_values() ); return false; } elseif ( isset( $wpsc_save_headers ) && $wpsc_save_headers ) { - wp_cache_debug( "Saving headers. Cannot serve a supercache file." ); + wp_cache_debug( 'Saving headers. Cannot serve a supercache file.' ); + return false; + } elseif ( ( filemtime( $file ) + $cache_max_time ) < time() ) { + wp_cache_debug( sprintf( "Cache has expired and is older than %d seconds old.", $cache_max_time ) ); return false; } @@ -158,8 +162,20 @@ function wp_cache_serve_cache_file() { if ( isset( $wp_cache_disable_utf8 ) == false || $wp_cache_disable_utf8 == 0 ) header( "Content-type: text/html; charset=UTF-8" ); - header( "Vary: Accept-Encoding, Cookie" ); - header( "Cache-Control: max-age=3, must-revalidate" ); + if ( defined( 'WPSC_VARY_HEADER' ) ) { + if ( WPSC_VARY_HEADER != '' ) { + header( "Vary: " . WPSC_VARY_HEADER ); + } + } else { + header( "Vary: Accept-Encoding, Cookie" ); + } + if ( defined( 'WPSC_CACHE_CONTROL_HEADER' ) ) { + if ( WPSC_CACHE_CONTROL_HEADER != '' ) { + header( "Cache-Control: " . WPSC_CACHE_CONTROL_HEADER ); + } + } else { + header( "Cache-Control: max-age=3, must-revalidate" ); + } $size = function_exists( 'mb_strlen' ) ? mb_strlen( $cachefiledata, '8bit' ) : strlen( $cachefiledata ); if ( $wp_cache_gzip_encoding ) { if ( isset( $wpsc_served_header ) && $wpsc_served_header ) { @@ -199,7 +215,7 @@ function wp_cache_serve_cache_file() { echo $cachefiledata; exit(); } else { - wp_cache_debug( "No wp-cache file exists. Must generate a new one." ); + wp_cache_debug( 'No wp-cache file exists. Must generate a new one.' ); return false; } } @@ -208,7 +224,7 @@ function wp_cache_serve_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' ] ) ) { $ungzip = true; - wp_cache_debug( "GZIP headers not found. Force uncompressed output.", 1 ); + wp_cache_debug( 'GZIP headers not found. Force uncompressed output.', 1 ); } else { $ungzip = false; } @@ -226,30 +242,30 @@ function wp_cache_serve_cache_file() { // 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 ); + 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 ); + wp_cache_debug( 'Serving wp-cache dynamic file from object cache', 5 ); echo do_cacheaction( 'wpsc_cachedata', $cache ); } else { - wp_cache_debug( "Serving wp-cache static file from object cache", 5 ); + wp_cache_debug( 'Serving wp-cache static file from object cache', 5 ); echo $cache; } - wp_cache_debug( "exit request", 5 ); + wp_cache_debug( 'exit request', 5 ); die(); } } else { if ( isset( $meta[ 'dynamic' ] ) ) { - wp_cache_debug( "Serving wp-cache dynamic file", 5 ); + 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 ); + wp_cache_debug( 'Uncompressed gzipped cache file from wp-cache', 1 ); unset( $cache ); echo do_cacheaction( 'wpsc_cachedata', $uncompressed ); } else { @@ -259,21 +275,23 @@ function wp_cache_serve_cache_file() { echo do_cacheaction( 'wpsc_cachedata', wp_cache_get_legacy_cache( $cache_file ) ); } } else { - wp_cache_debug( "Serving wp-cache static file", 5 ); + 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 ); + 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( "exit request", 5 ); + wp_cache_debug( 'exit request', 5 ); die(); } } @@ -289,7 +307,7 @@ function wp_cache_postload() { return true; if ( isset( $wp_super_cache_late_init ) && true == $wp_super_cache_late_init ) { - wp_cache_debug( "Supercache Late Init: add wp_cache_serve_cache_file to init", 3 ); + wp_cache_debug( 'Supercache Late Init: add wp_cache_serve_cache_file to init', 3 ); add_action( 'init', 'wp_cache_late_loader', 9999 ); } else { wp_super_cache_init(); @@ -298,7 +316,7 @@ function wp_cache_postload() { } function wp_cache_late_loader() { - wp_cache_debug( "Supercache Late Loader running on init", 3 ); + wp_cache_debug( 'Supercache Late Loader running on init', 3 ); wp_cache_serve_cache_file(); wp_cache_phase2(); } @@ -384,11 +402,11 @@ function wp_cache_check_mobile( $cache_key ) { // allow plugins to short circuit mobile check. Cookie, extra UA checks? switch( do_cacheaction( 'wp_cache_check_mobile', $cache_key ) ) { case "normal": - wp_cache_debug( "wp_cache_check_mobile: desktop user agent detected by wp_cache_check_mobile action" ); + wp_cache_debug( 'wp_cache_check_mobile: desktop user agent detected by wp_cache_check_mobile action' ); return $cache_key; break; case "mobile": - wp_cache_debug( "wp_cache_check_mobile: mobile user agent detected by wp_cache_check_mobile action" ); + wp_cache_debug( 'wp_cache_check_mobile: mobile user agent detected by wp_cache_check_mobile action' ); return $cache_key . "-mobile"; break; } @@ -398,7 +416,7 @@ function wp_cache_check_mobile( $cache_key ) { } if ( do_cacheaction( 'disable_mobile_check', false ) ) { - wp_cache_debug( "wp_cache_check_mobile: disable_mobile_check disabled mobile check" ); + wp_cache_debug( 'wp_cache_check_mobile: disable_mobile_check disabled mobile check' ); return $cache_key; } @@ -406,7 +424,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: ' . $_SERVER['HTTP_USER_AGENT'], 5 ); return $cache_key . '-' . wp_cache_mobile_group( $user_agent ); } } @@ -419,7 +437,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: ' . $_SERVER['HTTP_USER_AGENT'], 5 ); return $cache_key . '-' . $browser_prefix; } } @@ -631,12 +649,12 @@ function wpsc_is_in_cache_directory( $directory ) { static $rp_cache_path = ''; if ( $directory == '' ) { - wp_cache_debug( "wpsc_is_in_cache_directory: exiting as directory is blank" ); + wp_cache_debug( 'wpsc_is_in_cache_directory: exiting as directory is blank' ); return false; } if ( $cache_path == '' ) { - wp_cache_debug( "wpsc_is_in_cache_directory: exiting as cache_path is blank" ); + wp_cache_debug( 'wpsc_is_in_cache_directory: exiting as cache_path is blank' ); return false; } @@ -645,14 +663,14 @@ function wpsc_is_in_cache_directory( $directory ) { } if ( ! $rp_cache_path ) { - wp_cache_debug( "wpsc_is_in_cache_directory: exiting as cache_path directory does not exist" ); + wp_cache_debug( 'wpsc_is_in_cache_directory: exiting as cache_path directory does not exist' ); return false; } $directory = wpsc_get_realpath( $directory ); if ( ! $directory ) { - wp_cache_debug( "wpsc_is_in_cache_directory: directory does not exist" ); + wp_cache_debug( 'wpsc_is_in_cache_directory: directory does not exist' ); return false; } @@ -668,7 +686,7 @@ function wpsc_delete_files( $dir, $delete = true ) { static $protected = ''; if ( $dir == '' ) { - wp_cache_debug( "wpsc_delete_files: directory is blank" ); + wp_cache_debug( 'wpsc_delete_files: directory is blank' ); return false; } @@ -682,7 +700,7 @@ function wpsc_delete_files( $dir, $delete = true ) { $dir = wpsc_get_realpath( $dir ); if ( ! $dir ) { - wp_cache_debug( "wpsc_delete_files: directory does not exist: " . $dir ); + wp_cache_debug( 'wpsc_delete_files: directory does not exist: ' . $dir ); return false; } @@ -716,7 +734,7 @@ function get_all_supercache_filenames( $dir = '' ) { $dir = wpsc_get_realpath( $dir ); if ( ! $dir ) { - wp_cache_debug( "get_all_supercache_filenames: directory does not exist" ); + wp_cache_debug( 'get_all_supercache_filenames: directory does not exist' ); return array(); } @@ -832,7 +850,7 @@ function wp_cache_confirm_delete( $dir ) { $dir = wpsc_get_realpath( $dir ); if ( ! $dir ) { - wp_cache_debug( "wp_cache_confirm_delete: directory does not exist" ); + wp_cache_debug( 'wp_cache_confirm_delete: directory does not exist' ); return false; } @@ -886,6 +904,14 @@ 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 ); + } + return $wp_cache_debug_username; +} function wpsc_create_debug_log( $filename = '', $username = '' ) { global $cache_path, $wp_cache_debug_username, $wp_cache_debug_log; if ( $filename != '' ) { @@ -896,7 +922,7 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) { if ( $username != '' ) { $wp_cache_debug_username = $username; } else { - $wp_cache_debug_username = md5( time() + mt_rand() ); + $wp_cache_debug_username = wpsc_debug_username(); } $msg = ' @@ -1036,9 +1062,15 @@ function wp_cache_setting( $field, $value ) { function wp_cache_replace_line( $old, $new, $my_file ) { if ( @is_file( $my_file ) == false ) { + if ( function_exists( 'set_transient' ) ) { + set_transient( 'wpsc_config_error', 'config_file_missing', 10 ); + } return false; } if (!is_writeable_ACLSafe($my_file)) { + if ( function_exists( 'set_transient' ) ) { + set_transient( 'wpsc_config_error', 'config_file_ro', 10 ); + } trigger_error( "Error: file $my_file is not writable." ); return false; } @@ -1054,6 +1086,9 @@ function wp_cache_replace_line( $old, $new, $my_file ) { } else { $c++; if ( $c > 100 ) { + if ( function_exists( 'set_transient' ) ) { + set_transient( 'wpsc_config_error', 'config_file_not_loaded', 10 ); + } trigger_error( "wp_cache_replace_line: Error - file $my_file could not be loaded." ); return false; } @@ -1066,10 +1101,12 @@ function wp_cache_replace_line( $old, $new, $my_file ) { } } - $tmp_file = dirname( $my_file ) . '/' . mt_rand() . '.php'; - $fd = fopen( $tmp_file, 'w' ); + $fd = fopen( $my_file, 'w' ); if ( ! $fd ) { - trigger_error( "wp_cache_replace_line: Error - could not write to $tmp_file" ); + if ( function_exists( 'set_transient' ) ) { + set_transient( 'wpsc_config_error', 'config_file_ro', 10 ); + } + trigger_error( "wp_cache_replace_line: Error - could not write to $my_file" ); return false; } if ( $found ) { @@ -1093,10 +1130,9 @@ function wp_cache_replace_line( $old, $new, $my_file ) { } } fclose( $fd ); - @rename( $tmp_file, $my_file ); if ( function_exists( "opcache_invalidate" ) ) { - opcache_invalidate( $my_file ); + @opcache_invalidate( $my_file ); } return true; @@ -1106,7 +1142,7 @@ 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( 'Caching disabled! quiting!', 1 ); return false; } @@ -1116,34 +1152,15 @@ function wp_cache_phase2() { $wp_cache_blog_charset = get_option( 'blog_charset' ); wp_cache_mutex_init(); - if(function_exists('add_action') && ( !defined( 'WPLOCKDOWN' ) || ( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) == '0' ) ) ) { + if ( function_exists( 'add_action' ) && ( ! defined( 'WPLOCKDOWN' ) || constant( 'WPLOCKDOWN' ) == '0' ) ) { wp_cache_debug( 'Setting up WordPress actions', 5 ); add_action( 'template_redirect', 'wp_super_cache_query_vars' ); add_filter( 'wp_redirect_status', 'wpsc_catch_http_status_code' ); add_filter( 'status_header', 'wpsc_catch_status_header', 10, 2 ); - - // Post ID is received - add_action('wp_trash_post', 'wp_cache_post_edit', 0); - add_action('publish_post', 'wp_cache_post_edit', 0); - add_action('edit_post', 'wp_cache_post_change', 0); // leaving a comment called edit_post - add_action('delete_post', 'wp_cache_post_edit', 0); - add_action('publish_phone', 'wp_cache_post_edit', 0); - // Coment ID is received - add_action('trackback_post', 'wp_cache_get_postid_from_comment', 99); - add_action('pingback_post', 'wp_cache_get_postid_from_comment', 99); - add_action('comment_post', 'wp_cache_get_postid_from_comment', 99); - add_action('edit_comment', 'wp_cache_get_postid_from_comment', 99); - add_action('wp_set_comment_status', 'wp_cache_get_postid_from_comment', 99, 2); - // No post_id is available - add_action('switch_theme', 'wp_cache_no_postid', 99); - add_action('edit_user_profile_update', 'wp_cache_no_postid', 99); - add_action( 'wp_update_nav_menu', 'wp_cache_clear_cache_on_menu' ); - add_action('wp_cache_gc','wp_cache_gc_cron'); - add_action( 'clean_post_cache', 'wp_cache_post_edit' ); add_filter( 'supercache_filename_str', 'wp_cache_check_mobile' ); - add_action( 'wp_cache_gc_watcher', 'wp_cache_gc_watcher' ); - add_action( 'transition_post_status', 'wpsc_post_transition', 10, 3 ); + + wpsc_register_post_hooks(); do_cacheaction( 'add_cacheaction' ); } @@ -1158,24 +1175,73 @@ function wp_cache_phase2() { $super_cache_enabled = false; } - if($wp_cache_gzip_encoding) - header('Vary: Accept-Encoding, Cookie'); - else - header('Vary: Cookie'); + if ( defined( 'WPSC_VARY_HEADER' ) ) { + if ( WPSC_VARY_HEADER != '' ) { + header( 'Vary: ' . WPSC_VARY_HEADER ); + } + } else { + header( 'Vary: Accept-Encoding, Cookie' ); + } + ob_start( 'wp_cache_ob_callback' ); wp_cache_debug( 'Created output buffer', 4 ); // restore old supercache file temporarily - if ( ( $_SERVER["REQUEST_METHOD"] != 'POST' && empty( $_POST ) ) && $super_cache_enabled && $cache_rebuild_files ) { + if ( ( $_SERVER['REQUEST_METHOD'] !== 'POST' && empty( $_POST ) ) && $super_cache_enabled && $cache_rebuild_files ) { $user_info = wp_cache_get_cookies_values(); - $do_cache = apply_filters( 'do_createsupercache', $user_info ); - if( $user_info == '' || $do_cache === true ) + + if( empty( $user_info ) + || true === apply_filters( 'do_createsupercache', $user_info ) + ) { wpcache_do_rebuild( get_current_url_supercache_dir() ); + } } schedule_wp_gc(); } +function wpsc_register_post_hooks() { + static $done = false; + + if ( $done ) { + return; + } + + if ( false === $GLOBALS['cache_enabled'] + || ( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) != '0' ) + ) { + $done = true; + return; + } + + // Post ID is received + add_action( 'wp_trash_post', 'wp_cache_post_edit', 0 ); + add_action( 'publish_post', 'wp_cache_post_edit', 0 ); + add_action( 'edit_post', 'wp_cache_post_change', 0 ); // leaving a comment called edit_post + add_action( 'delete_post', 'wp_cache_post_edit', 0 ); + add_action( 'publish_phone', 'wp_cache_post_edit', 0 ); + + // Coment ID is received + add_action( 'trackback_post', 'wp_cache_get_postid_from_comment', 99 ); + add_action( 'pingback_post', 'wp_cache_get_postid_from_comment', 99 ); + add_action( 'comment_post', 'wp_cache_get_postid_from_comment', 99 ); + add_action( 'edit_comment', 'wp_cache_get_postid_from_comment', 99 ); + add_action( 'wp_set_comment_status', 'wp_cache_get_postid_from_comment', 99, 2 ); + + // No post_id is available + add_action( 'switch_theme', 'wp_cache_no_postid', 99 ); + add_action( 'edit_user_profile_update', 'wp_cache_no_postid', 99 ); + add_action( 'wp_update_nav_menu', 'wp_cache_clear_cache_on_menu' ); + add_action( 'clean_post_cache', 'wp_cache_post_edit' ); + add_action( 'transition_post_status', 'wpsc_post_transition', 10, 3 ); + + // Cron hooks + add_action( 'wp_cache_gc','wp_cache_gc_cron' ); + add_action( 'wp_cache_gc_watcher', 'wp_cache_gc_watcher' ); + + $done = true; +} + function wpcache_do_rebuild( $dir ) { global $do_rebuild_list, $cache_path, $wpsc_file_mtimes; wp_cache_debug( "wpcache_do_rebuild: doing rebuild for $dir" ); @@ -1187,7 +1253,7 @@ function wpcache_do_rebuild( $dir ) { $dir = wpsc_get_realpath( $dir ); if ( ! $dir ) { - wp_cache_debug( "wpcache_do_rebuild: exiting as directory does not exist." ); + wp_cache_debug( 'wpcache_do_rebuild: exiting as directory does not exist.' ); return false; } @@ -1415,15 +1481,15 @@ function wp_cache_writers_entry() { return true; if( !$mutex ) { - wp_cache_debug( "(writers entry) mutex lock not created. not caching.", 2 ); + wp_cache_debug( '(writers entry) mutex lock not created. not caching.', 2 ); return false; } if ( $use_flock ) { - wp_cache_debug( "grabbing lock using flock()", 5 ); + wp_cache_debug( 'grabbing lock using flock()', 5 ); flock($mutex, LOCK_EX); } else { - wp_cache_debug( "grabbing lock using sem_acquire()", 5 ); + wp_cache_debug( 'grabbing lock using sem_acquire()', 5 ); @sem_acquire($mutex); } @@ -1437,15 +1503,15 @@ function wp_cache_writers_exit() { return true; if( !$mutex ) { - wp_cache_debug( "(writers exit) mutex lock not created. not caching.", 2 ); + wp_cache_debug( '(writers exit) mutex lock not created. not caching.', 2 ); return false; } if ( $use_flock ) { - wp_cache_debug( "releasing lock using flock()", 5 ); + wp_cache_debug( 'releasing lock using flock()', 5 ); flock( $mutex, LOCK_UN ); } else { - wp_cache_debug( "releasing lock using sem_release() and sem_remove()", 5 ); + wp_cache_debug( 'releasing lock using sem_release() and sem_remove()', 5 ); @sem_release( $mutex ); if ( defined( "WPSC_REMOVE_SEMAPHORE" ) ) @sem_remove( $mutex ); @@ -1561,7 +1627,7 @@ function wp_cache_ob_callback( $buffer ) { wp_cache_debug( 'DONOTCACHEPAGE defined. Caching disabled.', 2 ); $cache_this_page = false; } elseif ( $wp_cache_no_cache_for_get && ! empty( $_GET ) ) { - wp_cache_debug( "Non empty GET request. Caching disabled on settings page. " . wpsc_dump_get_request(), 1 ); + wp_cache_debug( 'Non empty GET request. Caching disabled on settings page. ' . wpsc_dump_get_request(), 1 ); $cache_this_page = false; } elseif ( $_SERVER["REQUEST_METHOD"] == 'POST' || !empty( $_POST ) || get_option( 'gzipcompression' ) ) { wp_cache_debug( 'Not caching POST request.', 5 ); @@ -1751,7 +1817,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' ] ) { - wp_cache_debug( "404 file not found not cached", 2 ); + wp_cache_debug( '404 file not found not cached', 2 ); wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. 404." ); } } @@ -1759,7 +1825,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' ] ) { - wp_cache_debug( "No closing html tag. Not caching.", 2 ); + 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." ); } } @@ -1773,12 +1839,12 @@ function wp_cache_get_ob(&$buffer) { if( !wp_cache_writers_entry() ) { wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. Could not get mutex lock." ); - wp_cache_debug( "Could not get mutex lock. Not caching.", 1 ); + wp_cache_debug( 'Could not get mutex lock. Not caching.', 1 ); return wp_cache_maybe_dynamic( $buffer ); } if ( $wp_cache_not_logged_in && isset( $wp_super_cache_query[ 'is_feed' ] ) ) { - wp_cache_debug( "Feed detected. Writing wpcache cache files.", 5 ); + wp_cache_debug( 'Feed detected. Writing wpcache cache files.', 5 ); $wp_cache_not_logged_in = false; } @@ -1787,7 +1853,7 @@ function wp_cache_get_ob(&$buffer) { $dir = get_current_url_supercache_dir(); $supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $home_url[ 'host' ]); if ( ! empty( $_GET ) || isset( $wp_super_cache_query[ 'is_feed' ] ) || ( $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 ); + wp_cache_debug( 'Supercache disabled: GET or feed detected or disabled by config.', 2 ); $super_cache_enabled = false; } @@ -1796,7 +1862,7 @@ function wp_cache_get_ob(&$buffer) { $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 ); + wp_cache_debug( 'Anonymous user detected. Only creating Supercache file.', 3 ); $supercacheonly = true; } } @@ -1837,7 +1903,7 @@ function wp_cache_get_ob(&$buffer) { $dir = wpsc_get_realpath( $dir ); if ( ! $dir ) { - wp_cache_debug( "wp_cache_get_ob: not caching as directory does not exist." ); + wp_cache_debug( 'wp_cache_get_ob: not caching as directory does not exist.' ); return $buffer; } @@ -1854,7 +1920,7 @@ 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_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 ); @@ -1868,7 +1934,7 @@ function wp_cache_get_ob(&$buffer) { $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_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 ); @@ -1877,7 +1943,7 @@ function wp_cache_get_ob(&$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_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 ); @@ -1902,7 +1968,7 @@ function wp_cache_get_ob(&$buffer) { */ if ( $wp_cache_mfunc_enabled == 1 ) { if ( preg_match( '/<!--mclude|<!--mfunc|<!--dynamic-cached-content-->/', $buffer ) ) { //Dynamic content - wp_cache_debug( "mfunc/mclude/dynamic-cached-content tags have been retired. Please update your theme. See docs for updates." ); + wp_cache_debug( 'mfunc/mclude/dynamic-cached-content tags have been retired. Please update your theme. See docs for updates.' ); 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." ); } @@ -1911,11 +1977,11 @@ function wp_cache_get_ob(&$buffer) { 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 - wp_cache_debug( "Writing dynamic buffer to wpcache file." ); + wp_cache_debug( 'Writing dynamic buffer to wpcache file.' ); wp_cache_add_to_buffer( $buffer, "Dynamic WPCache Super Cache" ); fputs( $fr, '<?php die(); ?>' . $buffer ); } elseif ( isset( $fr2 ) ) { // supercache active - wp_cache_debug( "Writing dynamic buffer to supercache file." ); + 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 ) { @@ -1927,45 +1993,55 @@ function wp_cache_get_ob(&$buffer) { } if ( $cache_compression && $wp_cache_gzip_encoding ) { - wp_cache_debug( "Gzipping dynamic buffer for display.", 5 ); + wp_cache_debug( 'Gzipping dynamic buffer for display.', 5 ); wp_cache_add_to_buffer( $buffer, "Compression = gzip" ); $gzdata = gzencode( $buffer, 6, FORCE_GZIP ); $gzsize = function_exists( 'mb_strlen' ) ? mb_strlen( $gzdata, '8bit' ) : strlen( $gzdata ); } } else { + if ( defined( 'WPSC_VARY_HEADER' ) ) { + if ( WPSC_VARY_HEADER != '' ) { + $vary_header = WPSC_VARY_HEADER; + } else { + $vary_header = ''; + } + } else { + $vary_header = 'Accept-Encoding, Cookie'; + } + if ( $vary_header ) { + $wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: ' . $vary_header; + } if ( $gz || $wp_cache_gzip_encoding ) { - wp_cache_debug( "Gzipping buffer.", 5 ); + wp_cache_debug( 'Gzipping buffer.', 5 ); wp_cache_add_to_buffer( $buffer, "Compression = gzip" ); $gzdata = gzencode( $buffer, 6, FORCE_GZIP ); $gzsize = function_exists( 'mb_strlen' ) ? mb_strlen( $gzdata, '8bit' ) : strlen( $gzdata ); $wp_cache_meta[ 'headers' ][ 'Content-Encoding' ] = 'Content-Encoding: ' . $wp_cache_gzip_encoding; - $wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: Accept-Encoding, Cookie'; // Return uncompressed data & store compressed for later use if ( $fr ) { - wp_cache_debug( "Writing gzipped buffer to wp-cache cache file.", 5 ); + 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 - $wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: Cookie'; if ( $cache_enabled && $wp_cache_object_cache ) { wp_cache_set( $oc_key, $buffer, 'supercache', $cache_max_time ); $added_cache = 1; } elseif ( $fr ) { - wp_cache_debug( "Writing non-gzipped buffer to wp-cache cache file." ); + wp_cache_debug( 'Writing non-gzipped buffer to wp-cache cache file.' ); fputs($fr, '<?php die(); ?>' . $buffer); } } if ( $fr2 ) { - wp_cache_debug( "Writing non-gzipped buffer to supercache file." ); + wp_cache_debug( 'Writing non-gzipped buffer to supercache file.' ); wp_cache_add_to_buffer( $buffer, "super cache" ); fputs($fr2, $buffer ); } if ( isset( $gzdata ) && $gz ) { - wp_cache_debug( "Writing gzipped buffer to supercache file." ); + wp_cache_debug( 'Writing gzipped buffer to supercache file.' ); fwrite($gz, $gzdata ); } } @@ -1976,16 +2052,20 @@ function wp_cache_get_ob(&$buffer) { $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 ); + 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 ( !@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 ); + @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 ); } - wp_cache_debug( "Renamed temp wp-cache file to {$dir}/$cache_filename", 5 ); $added_cache = 1; } } @@ -1993,7 +2073,7 @@ function wp_cache_get_ob(&$buffer) { 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 ); + 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 ); @@ -2032,13 +2112,24 @@ function wp_cache_get_ob(&$buffer) { } wp_cache_writers_exit(); if ( !headers_sent() && $wp_cache_gzip_encoding && $gzdata) { - wp_cache_debug( "Writing gzip content headers. Sending buffer to browser", 5 ); + wp_cache_debug( 'Writing gzip content headers. Sending buffer to browser', 5 ); header( 'Content-Encoding: ' . $wp_cache_gzip_encoding ); - header( 'Vary: Accept-Encoding, Cookie' ); + if ( defined( 'WPSC_VARY_HEADER' ) ) { + if ( WPSC_VARY_HEADER != '' ) { + $vary_header = WPSC_VARY_HEADER; + } else { + $vary_header = ''; + } + } else { + $vary_header = 'Accept-Encoding, Cookie'; + } + if ( $vary_header ) { + header( 'Vary: ' . $vary_header ); + } header( 'Content-Length: ' . $gzsize ); return $gzdata; } else { - wp_cache_debug( "Sending buffer to browser", 5 ); + wp_cache_debug( 'Sending buffer to browser', 5 ); return $buffer; } } @@ -2067,6 +2158,7 @@ function wp_cache_phase2_clean_cache($file_prefix) { } } closedir($handle); + do_action( 'wp_cache_cleared' ); } wp_cache_writers_exit(); } @@ -2075,7 +2167,7 @@ function prune_super_cache( $directory, $force = false, $rename = false ) { // Don't prune a NULL/empty directory. if ( null === $directory || '' === $directory ) { - wp_cache_debug( "prune_super_cache: directory is blank" ); + wp_cache_debug( 'prune_super_cache: directory is blank' ); return false; } @@ -2280,12 +2372,12 @@ function wp_cache_shutdown_callback() { * ref: https://wordpress.org/support/topic/fatal-error-while-updating-post-or-publishing-new-one/ */ $wpsc_feed_ttl = 1; - wp_cache_debug( "wp_cache_shutdown_callback: Plugin not loaded. Setting feed ttl to 60 seconds." ); + wp_cache_debug( 'wp_cache_shutdown_callback: Plugin not loaded. Setting feed ttl to 60 seconds.' ); } if ( false == $new_cache ) { - wp_cache_debug( "wp_cache_shutdown_callback: No cache file created. Returning." ); + wp_cache_debug( 'wp_cache_shutdown_callback: No cache file created. Returning.' ); return false; } @@ -2300,7 +2392,7 @@ function wp_cache_shutdown_callback() { $wp_cache_meta[ 'headers' ][ $key ] = "$key: $value"; } - wp_cache_debug( "wp_cache_shutdown_callback: collecting meta data.", 2 ); + wp_cache_debug( 'wp_cache_shutdown_callback: collecting meta data.', 2 ); if (!isset( $response['Last-Modified'] )) { $value = gmdate('D, d M Y H:i:s') . ' GMT'; @@ -2358,9 +2450,20 @@ function wp_cache_shutdown_callback() { if ( $cache_enabled && !$supercacheonly && $new_cache ) { if( !isset( $wp_cache_meta[ 'dynamic' ] ) && $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $wp_cache_meta[ 'headers' ] ) ) { - wp_cache_debug( "Sending gzip headers.", 2 ); + wp_cache_debug( 'Sending gzip headers.', 2 ); $wp_cache_meta[ 'headers' ][ 'Content-Encoding' ] = 'Content-Encoding: ' . $wp_cache_gzip_encoding; - $wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: Accept-Encoding, Cookie'; + if ( defined( 'WPSC_VARY_HEADER' ) ) { + if ( WPSC_VARY_HEADER != '' ) { + $vary_header = WPSC_VARY_HEADER; + } else { + $vary_header = ''; + } + } else { + $vary_header = 'Accept-Encoding, Cookie'; + } + if ( $vary_header ) { + $wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: ' . $vary_header; + } } $serial = '<?php die(); ?>' . json_encode( $wp_cache_meta ); @@ -2408,7 +2511,7 @@ function wp_cache_shutdown_callback() { } global $time_to_gc_cache; if( isset( $time_to_gc_cache ) && $time_to_gc_cache == 1 ) { - wp_cache_debug( "Executing wp_cache_gc action.", 3 ); + wp_cache_debug( 'Executing wp_cache_gc action.', 3 ); do_action( 'wp_cache_gc' ); } } @@ -2463,7 +2566,7 @@ function wp_cache_get_postid_from_comment( $comment_id, $status = 'NA' ) { $super_cache_enabled = 0; // don't remove the super cache static file until comment is approved define( 'DONOTDELETECACHE', 1 ); } else { - wp_cache_debug( "Moderated ping or trackback. Not deleting cache files..", 4 ); + wp_cache_debug( 'Moderated ping or trackback. Not deleting cache files..', 4 ); define( 'DONOTDELETECACHE', 1 ); return $postid; } @@ -2476,7 +2579,7 @@ function wp_cache_get_postid_from_comment( $comment_id, $status = 'NA' ) { wp_cache_debug( "Post $postid changed. Update cache.", 4 ); return wp_cache_post_change( $postid ); } else { - wp_cache_debug( "Unknown post changed. Update cache.", 4 ); + wp_cache_debug( 'Unknown post changed. Update cache.', 4 ); return wp_cache_post_change( wp_cache_post_id() ); } } @@ -2494,7 +2597,7 @@ function wp_cache_clear_cache( $blog_id = 0 ) { reset_oc_version(); } else { if ( $blog_id == 0 ) { - wp_cache_debug( "Clearing all cached files in wp_cache_clear_cache()", 4 ); + 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 { @@ -2503,6 +2606,7 @@ function wp_cache_clear_cache( $blog_id = 0 ) { prune_super_cache( $cache_path . 'blogs/', true ); } } + do_action( 'wp_cache_cleared' ); } function wpsc_delete_post_archives( $post ) { @@ -2531,7 +2635,7 @@ function wpsc_delete_post_archives( $post ) { } wpsc_delete_url_cache( $term_url ); - wp_cache_debug( "wpsc_delete_post_archives: deleting cache of taxonomies: " . $term_url ); + wp_cache_debug( 'wpsc_delete_post_archives: deleting cache of taxonomies: ' . $term_url ); } } @@ -2546,14 +2650,14 @@ function wpsc_delete_post_archives( $post ) { if ( $archive_url ) { wpsc_delete_url_cache( $archive_url ); - wp_cache_debug( "wpsc_delete_post_archives: deleting cache of post type archive: " . $archive_url ); + wp_cache_debug( 'wpsc_delete_post_archives: deleting cache of post type archive: ' . $archive_url ); } // Author archive page $author_url = get_author_posts_url( $post->post_author ); if ( $author_url ) { wpsc_delete_url_cache( $author_url ); - wp_cache_debug( "wpsc_delete_post_archives: deleting cache of author archive: " . $author_url ); + wp_cache_debug( 'wpsc_delete_post_archives: deleting cache of author archive: ' . $author_url ); } } @@ -2567,7 +2671,7 @@ function wpsc_delete_cats_tags( $post ) { $category_base = trailingslashit( $category_base ); // paranoid much? foreach ($categories as $cat) { prune_super_cache ( get_supercache_dir() . $category_base . $cat->slug . '/', true ); - wp_cache_debug( "wpsc_post_transition: deleting category: " . get_supercache_dir() . $category_base . $cat->slug . '/' ); + wp_cache_debug( 'wpsc_post_transition: deleting category: ' . get_supercache_dir() . $category_base . $cat->slug . '/' ); } } $posttags = get_the_tags($post->ID); @@ -2578,7 +2682,7 @@ function wpsc_delete_cats_tags( $post ) { $tag_base = trailingslashit( str_replace( '..', '', $tag_base ) ); // maybe! foreach ($posttags as $tag) { prune_super_cache( get_supercache_dir() . $tag_base . $tag->slug . '/', true ); - wp_cache_debug( "wpsc_post_transition: deleting tag: " . get_supercache_dir() . $tag_base . $tag->slug . '/' ); + wp_cache_debug( 'wpsc_post_transition: deleting tag: ' . get_supercache_dir() . $tag_base . $tag->slug . '/' ); } } } @@ -2587,13 +2691,13 @@ function wpsc_post_transition( $new_status, $old_status, $post ) { if ( ($old_status == 'publish' && $new_status != 'publish' ) // post unpublished || - ($old_status != 'publish' && $new_status == 'publish') // post published + ($new_status == 'publish') // post published or updated ) { //wpsc_delete_cats_tags( $post ); wpsc_delete_post_archives( $post ); $post_url = get_permalink( $post->ID ); wpsc_delete_url_cache( $post_url ); - wp_cache_debug( "wpsc_post_transition: deleting cache of post: " . $post_url ); + wp_cache_debug( 'wpsc_post_transition: deleting cache of post: ' . $post_url ); } } @@ -2614,7 +2718,7 @@ function wp_cache_post_edit($post_id) { // Some users are inexplicibly seeing this error on scheduled posts. // define this constant to disable the post status check. if ( false == defined( 'WPSCFORCEUPDATE' ) && !in_array($post->post_status, array( 'publish', 'private' ) ) ) { - wp_cache_debug( "wp_cache_post_edit: draft post, not deleting any cache files. status: " . $post->post_status, 4 ); + wp_cache_debug( 'wp_cache_post_edit: draft post, not deleting any cache files. status: ' . $post->post_status, 4 ); return $post_id; } @@ -2679,7 +2783,7 @@ function wp_cache_post_change( $post_id ) { // Some users are inexplicibly seeing this error on scheduled posts. // define this constant to disable the post status check. if ( false == defined( 'WPSCFORCEUPDATE' ) && is_object( $post ) && !in_array($post->post_status, array( 'publish', 'private' ) ) ) { - wp_cache_debug( "wp_cache_post_change: draft post, not deleting any cache files.", 4 ); + wp_cache_debug( 'wp_cache_post_change: draft post, not deleting any cache files.', 4 ); return $post_id; } $last_processed = $post_id; @@ -2687,12 +2791,20 @@ function wp_cache_post_change( $post_id ) { if( !wp_cache_writers_entry() ) return $post_id; - if ( isset( $wp_cache_refresh_single_only ) && $wp_cache_refresh_single_only && ( strpos( $_SERVER[ 'HTTP_REFERER' ], 'edit-comments.php' ) || strpos( $_SERVER[ 'REQUEST_URI' ], 'wp-comments-post.php' ) ) ) { + if ( + isset( $wp_cache_refresh_single_only ) && + $wp_cache_refresh_single_only && + ( + isset( $_SERVER['HTTP_REFERER'] ) && + strpos( $_SERVER['HTTP_REFERER'], 'edit-comments.php' ) || + strpos( $_SERVER['REQUEST_URI'], 'wp-comments-post.php' ) + ) + ) { if ( defined( 'DONOTDELETECACHE' ) ) { wp_cache_debug( "wp_cache_post_change: comment detected and it's moderated or spam. Not deleting cached files.", 4 ); return $post_id; } else { - wp_cache_debug( "wp_cache_post_change: comment detected. only deleting post page.", 4 ); + wp_cache_debug( 'wp_cache_post_change: comment detected. only deleting post page.', 4 ); $all = false; } } else { @@ -2711,24 +2823,24 @@ function wp_cache_post_change( $post_id ) { $dir = get_supercache_dir(); // make sure the front page has a rebuild file if ( false == wp_cache_post_id_gc( $post_id, $all ) ) { - wp_cache_debug( "wp_cache_post_change: not deleting any cache files as GC of post returned false" ); + wp_cache_debug( 'wp_cache_post_change: not deleting any cache files as GC of post returned false' ); wp_cache_writers_exit(); return false; } if ( $all == true ) { - wp_cache_debug( "Post change: supercache enabled: deleting cache files in " . $dir ); + wp_cache_debug( 'Post change: supercache enabled: deleting cache files in ' . $dir ); wpsc_rebuild_files( $dir ); do_action( 'gc_cache', 'prune', 'homepage' ); if ( get_option( 'show_on_front' ) == 'page' ) { - wp_cache_debug( "Post change: deleting page_on_front and page_for_posts pages.", 4 ); - wp_cache_debug( "Post change: page_on_front " . get_option( 'page_on_front' ), 4 ); + wp_cache_debug( 'Post change: deleting page_on_front and page_for_posts pages.', 4 ); + wp_cache_debug( 'Post change: page_on_front ' . get_option( 'page_on_front' ), 4 ); $permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( get_option( 'page_for_posts' ) ) ) ); - wp_cache_debug( "Post change: Deleting files in: " . str_replace( '//', '/', $dir . $permalink ) ); + wp_cache_debug( 'Post change: Deleting files in: ' . str_replace( '//', '/', $dir . $permalink ) ); wpsc_rebuild_files( $dir . $permalink ); do_action( 'gc_cache', 'prune', $permalink ); } } else { - wp_cache_debug( "wp_cache_post_change: not deleting all pages.", 4 ); + wp_cache_debug( 'wp_cache_post_change: not deleting all pages.', 4 ); } wp_cache_debug( "wp_cache_post_change: checking {$blog_cache_dir}meta/", 4 ); diff --git a/wp-content/plugins/wp-super-cache/wp-cache.php b/wp-content/plugins/wp-super-cache/wp-cache.php index bb985612b5e4988524abf5243314fcd5b2e3dc8d..9ca88af225baa8fdbec109dddb87022c5fe07d0c 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.5.9 +Version: 1.6.2 Author: Automattic Author URI: https://automattic.com/ License: GPL2+ @@ -29,7 +29,9 @@ Text Domain: wp-super-cache Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -require_once( dirname( __FILE__ ) . '/wp-cache-phase2.php'); +if ( ! function_exists( 'wp_cache_phase2' ) ) { + require_once( dirname( __FILE__ ) . '/wp-cache-phase2.php'); +} function wpsc_init() { global $wp_cache_config_file, $wp_cache_config_file_sample, $wp_cache_file, $wp_cache_check_wp_config, $wp_cache_link; @@ -59,6 +61,13 @@ function wpsc_init() { wpsc_init(); +/** + * WP-CLI requires explicit declaration of global variables. + * It's minimal list of global variables. + */ +global $super_cache_enabled, $cache_enabled, $wp_cache_home_path, $cache_path; +global $wp_cache_config_file, $wp_cache_config_file_sample; + if( !@include($wp_cache_config_file) ) { get_wpcachehome(); $wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php'; @@ -72,10 +81,12 @@ if ( class_exists( 'WP_REST_Controller' ) ) { include( dirname( __FILE__ ) . '/rest/load.php' ); } -function wp_super_cache_text_domain() { +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_text_domain' ); +add_action( 'init', 'wp_super_cache_init_action' ); function wp_cache_set_home() { global $wp_cache_is_home; @@ -112,7 +123,7 @@ function wpsupercache_uninstall() { wp_cache_remove_index(); - if ( null !== $cache_path && '' !== $cache_path ) { + if ( ! empty( $cache_path ) ) { @unlink( $cache_path . '.htaccess' ); @unlink( $cache_path . 'meta' ); @unlink( $cache_path . 'supercache' ); @@ -130,13 +141,19 @@ if ( is_admin() ) { function wpsupercache_deactivate() { global $wp_cache_config_file, $wp_cache_link, $cache_path; - if ( file_exists( $wp_cache_link ) ) + + if ( file_exists( $wp_cache_link ) ) { unlink( $wp_cache_link ); - prune_super_cache( $cache_path, true ); - wp_cache_remove_index(); - @unlink( $cache_path . '.htaccess' ); - @unlink( $cache_path . 'meta' ); - @unlink( $cache_path . 'supercache' ); + } + + if ( ! empty( $cache_path ) ) { + prune_super_cache( $cache_path, true ); + wp_cache_remove_index(); + @unlink( $cache_path . '.htaccess' ); + @unlink( $cache_path . 'meta' ); + @unlink( $cache_path . 'supercache' ); + } + wp_clear_scheduled_hook( 'wp_cache_check_site_hook' ); wp_clear_scheduled_hook( 'wp_cache_gc' ); wp_clear_scheduled_hook( 'wp_cache_gc_watcher' ); @@ -199,6 +216,7 @@ add_action( 'network_admin_menu', 'wp_cache_network_pages' ); function wp_cache_manager_error_checks() { global $wp_cache_debug, $wp_cache_cron_check, $cache_enabled, $super_cache_enabled, $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 $dismiss_htaccess_warning, $dismiss_readable_warning, $dismiss_gc_warning, $wp_cache_shutdown_gc, $is_nginx; + global $htaccess_path; if ( !wpsupercache_site_admin() ) return false; @@ -267,7 +285,7 @@ function wp_cache_manager_error_checks() { if ( false == function_exists( 'wpsc_deep_replace' ) ) { $msg = __( 'Warning! You must set WP_CACHE and WPCACHEHOME in your wp-config.php for this plugin to work correctly:' ) . '<br />'; $msg .= "<code>define( 'WP_CACHE', true );</code><br />"; - $msg .= "<code>define( 'WPCACHEHOME', '" . dirname( __FILE__ ) . "' );</code><br />"; + $msg .= "<code>define( 'WPCACHEHOME', '" . dirname( __FILE__ ) . "/' );</code><br />"; wp_die( $msg ); } @@ -360,7 +378,11 @@ function wp_cache_manager_error_checks() { } if ( ! $is_nginx && function_exists( "is_main_site" ) && true == is_main_site() ) { - $home_path = trailingslashit( get_home_path() ); + if ( ! isset( $htaccess_path ) ) { + $home_path = trailingslashit( get_home_path() ); + } else { + $home_path = $htaccess_path; + } $scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) ); if ( $cache_enabled && $wp_cache_mod_rewrite && !$wp_cache_mobile_enabled && strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) ) ) { echo '<div class="notice notice-warning"><h3>' . __( 'Mobile rewrite rules detected', 'wp-super-cache' ) . "</h3>"; @@ -720,7 +742,7 @@ function wp_cache_manager() { } elseif ( function_exists( 'lite_detection_ua_contains' ) ) { $wp_cache_mobile_browsers = explode( '|', lite_detection_ua_contains() ); } else { - $wp_cache_mobile_browsers = array( '2.0 MMP', '240x320', '400X240', 'AvantGo', 'BlackBerry', 'Blazer', 'Cellphone', 'Danger', 'DoCoMo', 'Elaine/3.0', 'EudoraWeb', 'Googlebot-Mobile', 'hiptop', 'IEMobile', 'KYOCERA/WX310K', 'LG/U990', 'MIDP-2.', 'MMEF20', 'MOT-V', 'NetFront', 'Newt', 'Nintendo Wii', 'Nitro', 'Nokia', 'Opera Mini', 'Palm', 'PlayStation Portable', 'portalmmm', 'Proxinet', 'ProxiNet', 'SHARP-TQ-GX10', 'SHG-i900', 'Small', 'SonyEricsson', 'Symbian OS', 'SymbianOS', 'TS21i-10', 'UP.Browser', 'UP.Link', 'webOS', 'Windows CE', 'WinWAP', 'YahooSeeker/M1A1-R2D2', 'iPhone', 'iPod', 'Android', 'BlackBerry9530', 'LG-TU915 Obigo', 'LGE VX', 'webOS', 'Nokia5800' ); + $wp_cache_mobile_browsers = array( '2.0 MMP', '240x320', '400X240', 'AvantGo', 'BlackBerry', 'Blazer', 'Cellphone', 'Danger', 'DoCoMo', 'Elaine/3.0', 'EudoraWeb', 'Googlebot-Mobile', 'hiptop', 'IEMobile', 'KYOCERA/WX310K', 'LG/U990', 'MIDP-2.', 'MMEF20', 'MOT-V', 'NetFront', 'Newt', 'Nintendo Wii', 'Nitro', 'Nokia', 'Opera Mini', 'Palm', 'PlayStation Portable', 'portalmmm', 'Proxinet', 'ProxiNet', 'SHARP-TQ-GX10', 'SHG-i900', 'Small', 'SonyEricsson', 'Symbian OS', 'SymbianOS', 'TS21i-10', 'UP.Browser', 'UP.Link', 'webOS', 'Windows CE', 'WinWAP', 'YahooSeeker/M1A1-R2D2', 'iPhone', 'iPod', 'iPad', 'Android', 'BlackBerry9530', 'LG-TU915 Obigo', 'LGE VX', 'webOS', 'Nokia5800' ); } if ( function_exists( "lite_detection_ua_prefixes" ) ) { $wp_cache_mobile_prefixes = lite_detection_ua_prefixes(); @@ -1251,10 +1273,10 @@ table.wpsc-settings-table { <p><?php _e( 'Caching is only one part of making a website faster. Here are some other plugins that will help:', 'wp-super-cache' ); ?></p> <ul style="list-style: square; margin-left: 2em;"> <li><?php printf( __( '<a href="%s">Jetpack</a> provides everything you need to build a successful WordPress website including an image/photo CDN (free) and a video hosting service (paid).', 'wp-super-cache' ), 'https://jetpack.com/redirect/?source=jitm-wpsc-recommended' ); ?></li> - <li><?php printf( __( '<a href="%s">Yahoo! Yslow</a> is an extension for the Firefox add-on Firebug. It analyzes web pages and suggests ways to improve their performance based on a set of rules for high performance web pages. Also try the performance tools online at <a href="%s">GTMetrix</a>.', 'wp-super-cache' ), 'http://yslow.org/', 'https://gtmetrix.com/' ); ?></li> + <li><?php printf( __( '<a href="%s">Yahoo! Yslow</a> analyzes web pages and suggests ways to improve their performance based on a set of rules for high performance web pages. Also try the performance tools online at <a href="%s">GTMetrix</a>.', 'wp-super-cache' ), 'http://yslow.org/', 'https://gtmetrix.com/' ); ?></li> <li><?php printf( __( '<a href="%s">Use Google Libraries</a> allows you to load some commonly used Javascript libraries from Google webservers. Ironically, it may reduce your Yslow score.', 'wp-super-cache' ), 'https://wordpress.org/plugins/use-google-libraries/' ); ?></li> <li><?php printf( __( '<strong>Advanced users only:</strong> Install an object cache. Choose from <a href="%s">Memcached</a>, <a href="%s">XCache</a>, <a href="%s">eAcccelerator</a> and others.', 'wp-super-cache' ), 'https://wordpress.org/plugins/memcached/', 'https://neosmart.net/WP/XCache/', 'https://neosmart.net/WP/eAccelerator/' ); ?></li> - <li><?php printf( __( '<a href="%s">Cron View</a> is a useful plugin to use when trying to debug garbage collection and preload problems.', 'wp-super-cache' ), 'https://wordpress.org/plugins/cron-view/' ); ?></li> + <li><?php printf( __( '<a href="%s">WP Crontrol</a> is a useful plugin to use when trying to debug garbage collection and preload problems.', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-crontrol/' ); ?></li> </ul> <?php @@ -1359,17 +1381,20 @@ function wpsc_admin_tabs( $current = 0 ) { } function wsc_mod_rewrite() { - global $valid_nonce, $cache_path, $wp_cache_mod_rewrite, $is_nginx; + global $valid_nonce, $cache_path; - if ( $is_nginx ) { + if ( $GLOBALS['is_nginx'] ) { return false; } - if ( defined( 'WPSC_DISABLE_HTACCESS_UPDATE' ) ) + if ( defined( 'WPSC_DISABLE_HTACCESS_UPDATE' ) ) { return false; + } - if ( !$wp_cache_mod_rewrite ) + if ( $GLOBALS['cache_enabled'] !== true || $GLOBALS['wp_cache_mod_rewrite'] !== 1 ) { return false; + } + ?> <a name="modrewrite"></a><fieldset class="options"> <h3><?php _e( 'Mod Rewrite Rules', 'wp-super-cache' ); ?></h3> @@ -1969,31 +1994,39 @@ function wpsc_update_debug_settings() { ); } - if ( isset( $_POST[ 'wpsc_delete_log' ] ) && $wp_cache_debug_log != '' ) { + if ( isset( $_POST[ 'wpsc_delete_log' ] ) && $_POST[ 'wpsc_delete_log' ] == 1 && $wp_cache_debug_log != '' ) { @unlink( $cache_path . $wp_cache_debug_log ); extract( wpsc_create_debug_log( $wp_cache_debug_log, $wp_cache_debug_username ) ); // $wp_cache_debug_log, $wp_cache_debug_username - } elseif ( isset( $_POST[ 'wp_super_cache_debug' ] ) ) { - if ( ! isset( $wp_cache_debug_log ) || $wp_cache_debug_log == '' ) { - extract( wpsc_create_debug_log() ); // $wp_cache_debug_log, $wp_cache_debug_username - } elseif ( ! file_exists( $cache_path . $wp_cache_debug_log ) ) { // make sure debug log exists before toggling debugging - extract( wpsc_create_debug_log( $wp_cache_debug_log, $wp_cache_debug_username ) ); // $wp_cache_debug_log, $wp_cache_debug_username - } - $wp_super_cache_debug = (int) $_POST[ 'wp_super_cache_debug' ]; - wp_cache_setting( 'wp_super_cache_debug', $wp_super_cache_debug ); } + if ( ! isset( $wp_cache_debug_log ) || $wp_cache_debug_log == '' ) { + extract( wpsc_create_debug_log() ); // $wp_cache_debug_log, $wp_cache_debug_username + } elseif ( ! file_exists( $cache_path . $wp_cache_debug_log ) ) { // make sure debug log exists before toggling debugging + extract( wpsc_create_debug_log( $wp_cache_debug_log, $wp_cache_debug_username ) ); // $wp_cache_debug_log, $wp_cache_debug_username + } + $wp_super_cache_debug = ( isset( $_POST[ 'wp_super_cache_debug' ] ) && $_POST[ 'wp_super_cache_debug' ] == 1 ) ? 1 : 0; + wp_cache_setting( 'wp_super_cache_debug', $wp_super_cache_debug ); + if ( isset( $_POST[ 'wp_cache_debug' ] ) ) { wp_cache_setting( 'wp_cache_debug_username', $wp_cache_debug_username ); wp_cache_setting( 'wp_cache_debug_log', $wp_cache_debug_log ); $wp_super_cache_comments = isset( $_POST[ 'wp_super_cache_comments' ] ) ? 1 : 0; wp_cache_setting( 'wp_super_cache_comments', $wp_super_cache_comments ); - $wp_cache_debug_ip = esc_html( $_POST[ 'wp_cache_debug_ip' ] ); + if ( isset( $_POST[ 'wp_cache_debug_ip' ] ) ) { + $wp_cache_debug_ip = esc_html( $_POST[ 'wp_cache_debug_ip' ] ); + } else { + $wp_cache_debug_ip = ''; + } wp_cache_setting( 'wp_cache_debug_ip', $wp_cache_debug_ip ); $wp_super_cache_front_page_check = isset( $_POST[ 'wp_super_cache_front_page_check' ] ) ? 1 : 0; wp_cache_setting( 'wp_super_cache_front_page_check', $wp_super_cache_front_page_check ); $wp_super_cache_front_page_clear = isset( $_POST[ 'wp_super_cache_front_page_clear' ] ) ? 1 : 0; wp_cache_setting( 'wp_super_cache_front_page_clear', $wp_super_cache_front_page_clear ); - $wp_super_cache_front_page_text = esc_html( $_POST[ 'wp_super_cache_front_page_text' ] ); + if ( isset( $_POST[ 'wp_super_cache_front_page_text' ] ) ) { + $wp_super_cache_front_page_text = esc_html( $_POST[ 'wp_super_cache_front_page_text' ] ); + } else { + $wp_super_cache_front_page_text = ''; + } wp_cache_setting( 'wp_super_cache_front_page_text', $wp_super_cache_front_page_text ); $wp_super_cache_front_page_notification = isset( $_POST[ 'wp_super_cache_front_page_notification' ] ) ? 1 : 0; wp_cache_setting( 'wp_super_cache_front_page_notification', $wp_super_cache_front_page_notification ); @@ -2041,7 +2074,8 @@ function wp_cache_debug_settings() { echo '<form name="wpsc_delete" action="" method="post">'; wp_nonce_field('wp-cache'); - submit_button( __( 'Delete', 'wp-super-cache' ), 'delete', 'wpsc_delete_log', false ); + echo "<input type='hidden' name='wpsc_delete_log' value='1' />"; + submit_button( __( 'Delete', 'wp-super-cache' ), 'delete', 'wpsc_delete_log_form', false ); echo "</form>"; echo '<form name="wpsc_delete" action="" method="post">'; if ( ! isset( $wp_super_cache_debug ) || $wp_super_cache_debug == 0 ) { @@ -2085,10 +2119,12 @@ function wp_cache_debug_settings() { function wp_cache_enable() { global $wp_cache_config_file, $cache_enabled; - if( wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = true;', $wp_cache_config_file) ) { - $cache_enabled = true; + if ( ! wp_cache_replace_line( '^\s*\$cache_enabled\s*=', '$cache_enabled = true;', $wp_cache_config_file ) ) { + return; } + $cache_enabled = true; + if ( wpsc_set_default_gc() ) { // gc might not be scheduled, check and schedule $timestamp = wp_next_scheduled( 'wp_cache_gc' ); @@ -2101,59 +2137,80 @@ 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; + } + + $cache_enabled = false; + wp_clear_scheduled_hook( 'wp_cache_check_site_hook' ); wp_clear_scheduled_hook( 'wp_cache_gc' ); wp_clear_scheduled_hook( 'wp_cache_gc_watcher' ); - if (wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file)) { - $cache_enabled = false; - } } + function wp_super_cache_enable() { global $supercachedir, $wp_cache_config_file, $super_cache_enabled; - if( is_dir( $supercachedir . ".disabled" ) ) - if( is_dir( $supercachedir ) ) { - prune_super_cache( $supercachedir . ".disabled", true ); - @unlink( $supercachedir . ".disabled" ); + if ( ! wp_cache_replace_line( '^\s*\$super_cache_enabled\s*=', '$super_cache_enabled = true;', $wp_cache_config_file ) ) { + return; + } + + $super_cache_enabled = true; + + if ( is_dir( $supercachedir . '.disabled' ) ) { + if ( is_dir( $supercachedir ) ) { + prune_super_cache( $supercachedir . '.disabled', true ); + @unlink( $supercachedir . '.disabled' ); } else { - @rename( $supercachedir . ".disabled", $supercachedir ); + @rename( $supercachedir . '.disabled', $supercachedir ); } - wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = true;', $wp_cache_config_file); - $super_cache_enabled = true; + } } function wp_super_cache_disable() { global $cache_path, $supercachedir, $wp_cache_config_file, $super_cache_enabled; - wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = false;', $wp_cache_config_file); - if( is_dir( $supercachedir ) ) - @rename( $supercachedir, $supercachedir . ".disabled" ); + if ( ! wp_cache_replace_line('^\s*\$super_cache_enabled\s*=', '$super_cache_enabled = false;', $wp_cache_config_file ) ) { + return; + } + $super_cache_enabled = false; + + if ( is_dir( $supercachedir ) ) { + @rename( $supercachedir, $supercachedir . '.disabled' ); + } sleep( 1 ); // allow existing processes to write to the supercachedir and then delete it - if (function_exists ('prune_super_cache') && is_dir( $supercachedir ) ) { + if ( function_exists( 'prune_super_cache' ) && is_dir( $supercachedir ) ) { prune_super_cache( $cache_path, true ); } + + if ( $GLOBALS['wp_cache_mod_rewrite'] === 1 ) { + remove_mod_rewrite_rules(); + } } function wp_cache_is_enabled() { global $wp_cache_config_file; - if(get_option('gzipcompression')) { - echo "<strong>" . __( 'Warning', 'wp-super-cache' ) . "</strong>: " . __( "GZIP compression is enabled in WordPress, wp-cache will be bypassed until you disable gzip compression.", 'wp-super-cache' ); + if ( get_option( 'gzipcompression' ) ) { + echo '<strong>' . __( 'Warning', 'wp-super-cache' ) . '</strong>: ' . __( 'GZIP compression is enabled in WordPress, wp-cache will be bypassed until you disable gzip compression.', 'wp-super-cache' ); return false; } - $lines = file($wp_cache_config_file); - foreach($lines as $line) { - if (preg_match('/^ *\$cache_enabled *= *true *;/', $line)) + + $lines = file( $wp_cache_config_file ); + foreach ( $lines as $line ) { + if ( preg_match( '/^\s*\$cache_enabled\s*=\s*true\s*;/', $line ) ) { return true; + } } + return false; } function wp_cache_remove_index() { global $cache_path; - if ( null === $cache_path || '' === $cache_path ) { + if ( empty( $cache_path ) ) { return; } @@ -2235,6 +2292,37 @@ function wp_cache_index_notice() { } add_action( 'admin_notices', 'wp_cache_index_notice' ); +function wpsc_config_file_notices() { + global $wp_cache_config_file; + if ( ! isset( $_GET['page'] ) || $_GET['page'] != 'wpsupercache' ) { + return false; + } + $notice = get_transient( 'wpsc_config_error' ); + if ( ! $notice ) { + return false; + } + switch( $notice ) { + case 'error_move_tmp_config_file': + $msg = sprintf( __( 'Error: Could not rename temporary file to configuration file. Please make sure %s is writeable by the webserver.' ), $wp_cache_config_file ); + break; + case 'config_file_ro': + $msg = sprintf( __( 'Error: Configuration file is read only. Please make sure %s is writeable by the webserver.' ), $wp_cache_config_file ); + break; + case 'tmp_file_ro': + $msg = sprintf( __( 'Error: The directory containing the configuration file %s is read only. Please make sure it is writeable by the webserver.' ), $wp_cache_config_file ); + break; + case 'config_file_not_loaded': + $msg = sprintf( __( 'Error: Configuration file %s could not be loaded. Please reload the page.' ), $wp_cache_config_file ); + break; + case 'config_file_missing': + $msg = sprintf( __( 'Error: Configuration file %s is missing. Please reload the page.' ), $wp_cache_config_file ); + break; + + } + echo '<div class="error"><p><strong>' . $msg . '</strong></p></div>'; +} +add_action( 'admin_notices', 'wpsc_config_file_notices' ); + function wpsc_dismiss_indexhtml_warning() { check_ajax_referer( "wpsc-index-dismiss" ); update_site_option( 'wp_super_cache_index_detected', 3 ); @@ -2267,6 +2355,9 @@ function wp_cache_add_index_protection() { add_site_option( 'wp_super_cache_index_detected', 1 ); // only show this once } } + if ( ! function_exists( 'insert_with_markers' ) ) { + include_once( ABSPATH . 'wp-admin/includes/misc.php' ); + } insert_with_markers( $cache_path . '.htaccess', "INDEX", array( 'Options -Indexes' ) ); } @@ -2829,6 +2920,8 @@ 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; + do_action( 'wp_cache_cleared' ); + if ( $wp_cache_object_cache && function_exists( "reset_oc_version" ) ) reset_oc_version(); @@ -3137,6 +3230,8 @@ function wpsc_get_logged_in_cookie() { function wpsc_get_htaccess_info() { global $wp_cache_mobile_enabled, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_disable_utf8; + global $htaccess_path; + if ( isset( $_SERVER[ "PHP_DOCUMENT_ROOT" ] ) ) { $document_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ]; $apache_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ]; @@ -3165,7 +3260,9 @@ function wpsc_get_htaccess_info() { $home_path = get_home_path(); $home_root = parse_url(get_bloginfo('url')); $home_root = isset( $home_root[ 'path' ] ) ? trailingslashit( $home_root[ 'path' ] ) : '/'; - if ( + if ( isset( $htaccess_path ) ) { + $home_path = $htaccess_path; + } elseif ( $home_root == '/' && $home_path != $_SERVER[ 'DOCUMENT_ROOT' ] ) { @@ -3191,7 +3288,7 @@ function wpsc_get_htaccess_info() { $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*//.*$"; } $condition_rules[] = "RewriteCond %{REQUEST_METHOD} !POST"; - $condition_rules[] = "RewriteCond %{QUERY_STRING} !.*=.*"; + $condition_rules[] = "RewriteCond %{QUERY_STRING} ^$"; $condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|" . wpsc_get_logged_in_cookie() . "|wp-postpass_).*$"; $condition_rules[] = "RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\\\"]+ [NC]"; $condition_rules[] = "RewriteCond %{HTTP:Profile} !^[a-z0-9\\\"]+ [NC]"; @@ -3240,7 +3337,30 @@ function wpsc_get_htaccess_info() { $gziprules = "<IfModule mod_mime.c>\n <FilesMatch \"\\.html\\.gz\$\">\n ForceType text/html\n FileETag None\n </FilesMatch>\n AddEncoding gzip .gz\n AddType text/html .gz\n</IfModule>\n"; $gziprules .= "<IfModule mod_deflate.c>\n SetEnvIfNoCase Request_URI \.gz$ no-gzip\n</IfModule>\n"; - $gziprules .= "<IfModule mod_headers.c>\n Header set Vary \"Accept-Encoding, Cookie\"\n Header set Cache-Control 'max-age=3, must-revalidate'\n</IfModule>\n"; + if ( defined( 'WPSC_VARY_HEADER' ) ) { + if ( WPSC_VARY_HEADER != '' ) { + $vary_header = WPSC_VARY_HEADER; + } + } else { + $vary_header = 'Accept-Encoding, Cookie'; + } + if ( defined( 'WPSC_CACHE_CONTROL_HEADER' ) ) { + if ( WPSC_CACHE_CONTROL_HEADER != '' ) { + $cache_control_header = WPSC_CACHE_CONTROL_HEADER; + } + } else { + $cache_control_header = 'max-age=3, must-revalidate'; + } + $headers_text = ""; + if ( $vary_header != '' ) { + $headers_text .= " Header set Vary '$vary_header'\n"; + } + if ( $cache_control_header != '' ) { + $headers_text .= " Header set Cache-Control '$cache_control_header'\n"; + } + if ( $headers_text != '' ) { + $gziprules .= "<IfModule mod_headers.c>\n$headers_text</IfModule>\n"; + } $gziprules .= "<IfModule mod_expires.c>\n ExpiresActive On\n ExpiresByType text/html A3\n</IfModule>\n"; $gziprules .= "Options -Indexes\n"; return array( "document_root" => $document_root, "apache_root" => $apache_root, "home_path" => $home_path, "home_root" => $home_root, "home_root_lc" => $home_root_lc, "inst_root" => $inst_root, "wprules" => $wprules, "scrules" => $scrules, "condition_rules" => $condition_rules, "rules" => $rules, "gziprules" => $gziprules ); @@ -3264,7 +3384,7 @@ function wp_cron_preload_cache() { if ( get_option( 'preload_cache_stop' ) ) { delete_option( 'preload_cache_stop' ); - wp_cache_debug( "wp_cron_preload_cache: preload cancelled", 1 ); + wp_cache_debug( 'wp_cron_preload_cache: preload cancelled', 1 ); return true; } @@ -3272,10 +3392,10 @@ function wp_cron_preload_cache() { sleep( 3 + mt_rand( 1, 5 ) ); if ( @file_exists( $mutex ) ) { if ( @filemtime( $mutex ) > ( time() - 600 ) ) { - wp_cache_debug( "wp_cron_preload_cache: preload mutex found and less than 600 seconds old. Aborting preload.", 1 ); + wp_cache_debug( 'wp_cron_preload_cache: preload mutex found and less than 600 seconds old. Aborting preload.', 1 ); return true; } else { - wp_cache_debug( "wp_cron_preload_cache: old preload mutex found and deleted. Preload continues.", 1 ); + wp_cache_debug( 'wp_cron_preload_cache: old preload mutex found and deleted. Preload continues.', 1 ); @unlink( $mutex ); } } @@ -3284,7 +3404,7 @@ function wp_cron_preload_cache() { $counter = get_option( 'preload_cache_counter' ); if ( is_array( $counter ) == false ) { - wp_cache_debug( "wp_cron_preload_cache: setting up preload for the first time!", 5 ); + wp_cache_debug( 'wp_cron_preload_cache: setting up preload for the first time!', 5 ); $counter = array( 'c' => 0, 't' => time() ); update_option( 'preload_cache_counter', $counter ); } @@ -3300,7 +3420,7 @@ function wp_cron_preload_cache() { wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Started', 'wp-super-cache' ), home_url(), '' ), ' ' ); if ( $wp_cache_preload_posts == 'all' || $c < $wp_cache_preload_posts ) { - wp_cache_debug( "wp_cron_preload_cache: doing taxonomy preload.", 5 ); + wp_cache_debug( 'wp_cron_preload_cache: doing taxonomy preload.', 5 ); $permalink_counter_msg = $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' ) ); @@ -3345,7 +3465,7 @@ function wp_cron_preload_cache() { wp_cache_debug( "wp_cron_preload_cache: fetched $url", 5 ); sleep( 1 ); if ( @file_exists( $cache_path . "stop_preload.txt" ) ) { - wp_cache_debug( "wp_cron_preload_cache: cancelling preload. stop_preload.txt found.", 5 ); + wp_cache_debug( 'wp_cron_preload_cache: cancelling preload. stop_preload.txt found.', 5 ); @unlink( $mutex ); @unlink( $cache_path . "stop_preload.txt" ); @unlink( $taxonomy_filename ); @@ -3405,7 +3525,7 @@ function wp_cron_preload_cache() { @fclose( $fp ); } if ( @file_exists( $cache_path . "stop_preload.txt" ) ) { - wp_cache_debug( "wp_cron_preload_cache: cancelling preload. stop_preload.txt found.", 5 ); + wp_cache_debug( 'wp_cron_preload_cache: cancelling preload. stop_preload.txt found.', 5 ); @unlink( $mutex ); @unlink( $cache_path . "stop_preload.txt" ); update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) ); @@ -3422,7 +3542,7 @@ function wp_cron_preload_cache() { if ( $wp_cache_preload_email_me && ( $wp_cache_preload_email_volume == 'medium' || $wp_cache_preload_email_volume == 'many' ) ) wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] %2$d posts refreshed', 'wp-super-cache' ), home_url(), ($c+100) ), __( "Refreshed the following posts:", 'wp-super-cache' ) . "\n$msg" ); if ( defined( 'DOING_CRON' ) ) { - wp_cache_debug( "wp_cron_preload_cache: scheduling the next preload in 30 seconds.", 5 ); + wp_cache_debug( 'wp_cron_preload_cache: scheduling the next preload in 30 seconds.', 5 ); wp_schedule_single_event( time() + 30, 'wp_cache_preload_hook' ); } } else { @@ -3535,16 +3655,16 @@ function wp_cache_disable_plugin( $delete_config_file = true ) { $file_not_deleted[] = 'wp-cache-config.php'; } if ( $file_not_deleted ) { - $msg = "<p>One or more files could not be deleted. These files and directories must be made writeable:</p>\n <ol><li>" . WP_CONTENT_DIR . "</li>\n"; - $code = "<ul>\n"; + $msg = __( "Dear User,\n\nWP Super Cache was removed from your blog or deactivated but some files could\nnot be deleted.\n\n", 'wp-super-cache' ); foreach( (array)$file_not_deleted as $filename ) { - $msg .= "<li>" . WP_CONTENT_DIR . "/{$filename}</li>"; - $code .= "<li><code>chmod 666 " . WP_CONTENT_DIR . "/{$filename}</code></li>\n"; + $msg .= WP_CONTENT_DIR . "/{$filename}\n"; } - $code .= "</ul>\n"; + $msg .= "\n"; + $msg .= sprintf( __( "You should delete these files manually.\nYou may need to change the permissions of the files or parent directory.\nYou can read more about this in the Codex at\n%s\n\nThank you.", 'wp-super-cache' ), 'https://codex.wordpress.org/Changing_File_Permissions#About_Chmod' ); - $msg .= "</ol>\n<p>First try fixing the directory permissions with this command and refresh this page:<br /><br /><code>chmod 777 " . WP_CONTENT_DIR . "</code><br /><br />If you still see this error, you have to fix the permissions on the files themselves and refresh this page again:</p> {$code}\n<p>Don't forget to fix things later:<br /><code>chmod 755 " . WP_CONTENT_DIR . "</code></p><p>If you don't know what <strong>chmod</strong> is read all about it <a href='https://codex.wordpress.org/Changing_File_Permissions#About_Chmod'>here</a> and note the warning about using 777 permission.</p><p>Please refresh this page when the permissions have been modified.</p>"; - wp_die( $msg ); + if ( apply_filters( 'wpsc_send_uninstall_errors', 1 ) ) { + wp_mail( get_option( 'admin_email' ), __( 'WP Super Cache: could not delete files', 'wp-super-cache' ), $msg ); + } } extract( wpsc_get_htaccess_info() ); // $document_root, $apache_root, $home_path, $home_root, $home_root_lc, $inst_root, $wprules, $scrules, $condition_rules, $rules, $gziprules if ( $scrules != '' && insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', array() ) ) { @@ -3814,14 +3934,9 @@ function update_mod_rewrite_rules( $add_rules = true ) { } $generated_rules = wpsc_get_htaccess_info(); + $existing_rules = implode( "\n", extract_from_markers( $home_path . '.htaccess', 'WPSuperCache' ) ); - if ( $add_rules ) { - $rules = $generated_rules[ 'rules' ]; - } else { - $rules = ''; - } - - $existing_rules = implode( "\n", extract_from_markers( $home_path . '.htaccess', 'WPSuperCache' ) ); + $rules = $add_rules ? $generated_rules[ 'rules' ] : ''; if ( $existing_rules == $rules ) { $update_mod_rewrite_rules_error = "rules have not changed"; @@ -3833,6 +3948,10 @@ function update_mod_rewrite_rules( $add_rules = true ) { return false; } + if ( empty( $rules ) ) { + return insert_with_markers( $home_path . '.htaccess', 'WPSuperCache', array() ); + } + $url = trailingslashit( get_bloginfo( 'url' ) ); $original_page = wp_remote_get( $url, array( 'timeout' => 60, 'blocking' => true ) ); if ( is_wp_error( $original_page ) ) {