From 6d14d80530ab1b3d2914a65f392bac7c31c27d83 Mon Sep 17 00:00:00 2001 From: lucha <lucha@paranoici.org> Date: Sat, 7 Oct 2017 11:37:38 +0200 Subject: [PATCH] [auto] plugin: wp-super-cache 1.5.7 --- .../plugins/awaitingmoderation.php | 11 ++ .../wp-super-cache/plugins/badbehaviour.php | 11 ++ .../wp-super-cache/plugins/domain-mapping.php | 12 ++ .../wp-super-cache/plugins/jetpack.php | 12 ++ .../wp-super-cache/plugins/searchengine.php | 78 ++++++-- .../wp-super-cache/plugins/wptouch.php | 12 ++ wp-content/plugins/wp-super-cache/readme.txt | 26 ++- .../class.wp-super-cache-rest-get-plugins.php | 16 ++ ...class.wp-super-cache-rest-get-settings.php | 6 +- ...ass.wp-super-cache-rest-update-plugins.php | 22 +++ .../plugins/wp-super-cache/rest/load.php | 19 ++ .../wp-super-cache/wp-cache-config-sample.php | 3 + .../wp-super-cache/wp-cache-phase1.php | 13 +- .../wp-super-cache/wp-cache-phase2.php | 123 +++++++++---- .../plugins/wp-super-cache/wp-cache.php | 167 ++++++++++++------ 15 files changed, 406 insertions(+), 125 deletions(-) create mode 100644 wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-rest-get-plugins.php create mode 100644 wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-rest-update-plugins.php diff --git a/wp-content/plugins/wp-super-cache/plugins/awaitingmoderation.php b/wp-content/plugins/wp-super-cache/plugins/awaitingmoderation.php index a6185be9f..0384226cd 100644 --- a/wp-content/plugins/wp-super-cache/plugins/awaitingmoderation.php +++ b/wp-content/plugins/wp-super-cache/plugins/awaitingmoderation.php @@ -51,4 +51,15 @@ function wp_supercache_awaitingmoderation_admin() { } add_cacheaction( 'cache_admin_page', 'wp_supercache_awaitingmoderation_admin' ); + +function wpsc_awaiting_moderation_list( $list ) { + $list[ 'awaitingmoderation' ] = array( + 'key' => 'awaitingmoderation', + 'url' => '', + 'title' => __( 'Awaiting Moderation', 'wp-super-cache' ), + 'desc' => __( 'Enables or disables plugin to Remove the text "Your comment is awaiting moderation." when someone leaves a moderated comment.', 'wp-super-cache' ), + ); + return $list; +} +add_cacheaction( 'wpsc_filter_list', 'wpsc_awaiting_moderation_list' ); ?> diff --git a/wp-content/plugins/wp-super-cache/plugins/badbehaviour.php b/wp-content/plugins/wp-super-cache/plugins/badbehaviour.php index 4f42d1a4d..fa305cd63 100644 --- a/wp-content/plugins/wp-super-cache/plugins/badbehaviour.php +++ b/wp-content/plugins/wp-super-cache/plugins/badbehaviour.php @@ -85,4 +85,15 @@ function wp_supercache_badbehaviour_admin() { } add_cacheaction( 'cache_admin_page', 'wp_supercache_badbehaviour_admin' ); +function wpsc_badbehaviour_list( $list ) { + $list[ 'badbehaviour' ] = array( + 'key' => 'badbehaviour', + 'url' => 'http://www.bad-behavior.ioerror.us/', + 'title' => __( 'Bad Behavior', 'wp-super-cache' ), + 'desc' => sprintf( __( 'Support for Bad Behavior. (Only WPCache caching supported, disabled compression and requires Bad Behavior in "%s/plugins/bad-behavior/") ', 'wp-super-cache' ), WP_CONTENT_DIR ), + ); + return $list; +} +add_cacheaction( 'wpsc_filter_list', 'wpsc_badbehaviour_list' ); + ?> diff --git a/wp-content/plugins/wp-super-cache/plugins/domain-mapping.php b/wp-content/plugins/wp-super-cache/plugins/domain-mapping.php index e5f381c0e..056263cc8 100644 --- a/wp-content/plugins/wp-super-cache/plugins/domain-mapping.php +++ b/wp-content/plugins/wp-super-cache/plugins/domain-mapping.php @@ -109,4 +109,16 @@ function wp_supercache_domain_mapping_exists() { if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wpsupercache' ) { add_cacheaction( 'add_cacheaction', 'wp_supercache_domain_mapping_exists' ); } + +function wpsc_domain_mapping_list( $list ) { + $list[ 'domain_mapping' ] = array( + 'key' => 'domain_mapping', + 'url' => 'http://wordpress.org/extend/plugins/wordpress-mu-domain-mapping/', + 'title' => __( 'Domain Mapping', 'wp-super-cache' ), + 'desc' => __( 'Provides support for Domain Mapping plugin to map multiple domains to a blog.', 'wp-super-cache' ), + ); + return $list; +} +add_cacheaction( 'wpsc_filter_list', 'wpsc_domain_mapping_list' ); + ?> diff --git a/wp-content/plugins/wp-super-cache/plugins/jetpack.php b/wp-content/plugins/wp-super-cache/plugins/jetpack.php index 1c398c6da..059062845 100644 --- a/wp-content/plugins/wp-super-cache/plugins/jetpack.php +++ b/wp-content/plugins/wp-super-cache/plugins/jetpack.php @@ -75,4 +75,16 @@ function wp_super_cache_jetpack_cookie_check( $cache_key ) { if ( isset( $cache_jetpack ) && $cache_jetpack == 1 ) { add_cacheaction( 'wp_cache_check_mobile', 'wp_super_cache_jetpack_cookie_check' ); } + +function wpsc_cache_jetpack_list( $list ) { + $list[ 'jetpack' ] = array( + 'key' => 'jetpack', + 'url' => 'http://wordpress.org/extend/plugins/jetpack/', + 'title' => __( 'Jetpack Mobile Theme', 'wp-super-cache' ), + 'desc' => __( 'Provides support for the Jetpack mobile theme and plugin. PHP caching mode and mobile support will be enabled too.', 'wp-super-cache' ), + ); + return $list; +} +add_cacheaction( 'wpsc_filter_list', 'wpsc_cache_jetpack_list' ); + ?> diff --git a/wp-content/plugins/wp-super-cache/plugins/searchengine.php b/wp-content/plugins/wp-super-cache/plugins/searchengine.php index bac62f5cd..9013a7913 100644 --- a/wp-content/plugins/wp-super-cache/plugins/searchengine.php +++ b/wp-content/plugins/wp-super-cache/plugins/searchengine.php @@ -2,7 +2,8 @@ function wp_supercache_searchengine( $string ) { global $passingthrough, $nevershowads, $cache_no_adverts_for_friends; - if( $cache_no_adverts_for_friends != 'yes' && $cache_no_adverts_for_friends != '1' ) + $cache_no_adverts_for_friends = wpsc_get_searchengine_setting(); + if ( ! $cache_no_adverts_for_friends ) return $string; if( $string != '' ) @@ -43,39 +44,67 @@ function searchenginesupercache( $user_info ) { } } +function wpsc_get_searchengine_setting() { + global $cache_no_adverts_for_friends; + + if ( ! isset( $cache_no_adverts_for_friends ) ) { + return 0; + } + + $changed = false; + if ( $cache_no_adverts_for_friends === 'yes' || $cache_no_adverts_for_friends === '1' ) { + $cache_no_adverts_for_friends = 1; + $changed = true; + } elseif ( $cache_no_adverts_for_friends === 'no' ) { + $cache_no_adverts_for_friends = 0; + $changed = true; + } + if ( $changed && function_exists( 'wp_cache_setting' ) ) { + wp_cache_setting( 'cache_no_adverts_for_friends', $cache_no_adverts_for_friends ); + } + + return $cache_no_adverts_for_friends; +} + function searchengine_phase2_actions() { global $cache_no_adverts_for_friends; - if( $cache_no_adverts_for_friends == 'yes' ) { + + $cache_no_adverts_for_friends = wpsc_get_searchengine_setting(); + if ( $cache_no_adverts_for_friends ) { add_filter( 'do_createsupercache', 'searchenginesupercache' ); } } add_cacheaction( 'add_cacheaction', 'searchengine_phase2_actions' ); function wp_supercache_searchengine_admin() { - global $cache_no_adverts_for_friends, $wp_cache_config_file, $valid_nonce; + global $cache_no_adverts_for_friends, $valid_nonce; - $cache_no_adverts_for_friends = $cache_no_adverts_for_friends == '' ? 'no' : $cache_no_adverts_for_friends; + $cache_no_adverts_for_friends = wpsc_get_searchengine_setting(); if(isset($_POST['cache_no_adverts_for_friends']) && $valid_nonce) { - $cache_no_adverts_for_friends = $_POST['cache_no_adverts_for_friends'] == __( 'Disable', 'wp-super-cache' ) ? 'no' : 'yes'; - wp_cache_replace_line('^ *\$cache_no_adverts_for_friends', "\$cache_no_adverts_for_friends = '$cache_no_adverts_for_friends';", $wp_cache_config_file); + if ( $cache_no_adverts_for_friends != (int)$_POST[ 'cache_no_adverts_for_friends' ] ) { + $changed = 1; + } else { + $changed = 0; + } + $cache_no_adverts_for_friends = (int)$_POST[ 'cache_no_adverts_for_friends' ]; + wp_cache_setting( 'cache_no_adverts_for_friends', $cache_no_adverts_for_friends ); } - $id = 'no_adverts_for_friends-section'; ?> - <fieldset id="<?php echo $id; ?>" class="options"> + <fieldset id="no_adverts_for_friends-section" class="options"> <h4><?php _e( 'No Adverts for Friends', 'wp-super-cache' ); ?></h4> <form name="wp_manager" action="" method="post"> - <label><input type="radio" name="cache_no_adverts_for_friends" value="1" <?php if( $cache_no_adverts_for_friends == 'yes' ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label> - <label><input type="radio" name="cache_no_adverts_for_friends" value="0" <?php if( $cache_no_adverts_for_friends == 'no' ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label> - <p><?php _e( '', 'wp-super-cache' ); ?></p><?php - echo '<p>' . __( 'Provides support for <a href="http://ocaoimh.ie/no-adverts-for-friends/">No Adverts for Friends</a>.', 'wp-super-cache' ) . '</p>'; - if ( isset( $changed ) && $changed ) { - if ( 'yes' == $cache_no_adverts_for_friends ) - $status = __( "enabled", 'wp-super-cache' ); - else - $status = __( "disabled", 'wp-super-cache' ); - echo "<p><strong>" . sprintf( __( "No Adverts for Friends support is now %s", 'wp-super-cache' ), $status ) . "</strong></p>"; - } + <label><input type="radio" name="cache_no_adverts_for_friends" value="1" <?php if ( $cache_no_adverts_for_friends ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label> + <label><input type="radio" name="cache_no_adverts_for_friends" value="0" <?php if ( ! $cache_no_adverts_for_friends ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label> + <?php + echo '<p>' . __( 'Provides support for <a href="https://odd.blog/no-adverts-for-friends/">No Adverts for Friends</a>.', 'wp-super-cache' ) . '</p>'; + if ( isset( $changed ) && $changed ) { + if ( $cache_no_adverts_for_friends ) + $status = __( "enabled", 'wp-super-cache' ); + else + $status = __( "disabled", 'wp-super-cache' ); + echo "<p><strong>" . sprintf( __( "No Adverts for Friends support is now %s", 'wp-super-cache' ), $status ) . "</strong></p>"; + } echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>'; wp_nonce_field('wp-cache'); ?> @@ -86,4 +115,15 @@ function wp_supercache_searchengine_admin() { } add_cacheaction( 'cache_admin_page', 'wp_supercache_searchengine_admin' ); +function wpsc_cache_no_adverts_for_friends_list( $list ) { + $list[ 'no_adverts_for_friends' ] = array( + 'key' => 'no_adverts_for_friends', + 'url' => 'https://odd.blog/no-adverts-for-friends/', + 'title' => __( 'No Adverts for Friends', 'wp-super-cache' ), + 'desc' => __( 'Provides support for No Adverts for Friends plugin.', 'wp-super-cache' ), + ); + return $list; +} +add_cacheaction( 'wpsc_filter_list', 'wpsc_cache_no_adverts_for_friends_list' ); + ?> diff --git a/wp-content/plugins/wp-super-cache/plugins/wptouch.php b/wp-content/plugins/wp-super-cache/plugins/wptouch.php index 744d7efbb..6e82634c0 100644 --- a/wp-content/plugins/wp-super-cache/plugins/wptouch.php +++ b/wp-content/plugins/wp-super-cache/plugins/wptouch.php @@ -119,4 +119,16 @@ if ( isset( $cache_wptouch ) && $cache_wptouch == 1 ) { add_cacheaction( 'wp_super_cache_mobile_prefixes', 'wp_super_cache_wptouch_prefixes' ); add_cacheaction( 'wp_cache_check_mobile', 'wp_super_cache_wptouch_cookie_check' ); } + +function wpsc_wptouch_list( $list ) { + $list[ 'wptouch' ] = array( + 'key' => 'wptouch', + 'url' => 'http://wordpress.org/extend/plugins/wptouch/', + 'title' => __( 'WPTouch', 'wp-super-cache' ), + 'desc' => __( 'Provides support for WPTouch mobile theme and plugin.', 'wp-super-cache' ), + ); + return $list; +} +add_cacheaction( 'wpsc_filter_list', 'wpsc_wptouch_list' ); + ?> diff --git a/wp-content/plugins/wp-super-cache/readme.txt b/wp-content/plugins/wp-super-cache/readme.txt index 9b67a1d39..a5d120ded 100644 --- a/wp-content/plugins/wp-super-cache/readme.txt +++ b/wp-content/plugins/wp-super-cache/readme.txt @@ -2,7 +2,7 @@ Contributors: donncha, automattic, kraftbj Tags: performance,caching,wp-cache,wp-super-cache,cache Tested up to: 4.8.1 -Stable tag: 1.5.4 +Stable tag: 1.5.7 Requires at least: 3.0 A very fast caching engine for WordPress that produces static html files. @@ -53,10 +53,30 @@ Interested in translating WP Super Cache to your language? See the [translation The cache directory, usually wp-content/cache/ is only for temporary files. Do not ever put important files or symlinks to important files or directories in that directory. They will be deleted if the plugin has write access to them. == Upgrade Notice == -Sitemap, feed, REST API and other maintenance fixes. - +Fixes fatal error for users who toggled the "no adverts for friends" plugin. == Changelog == += 1.5.7 = +* Fix fatal error in plugins/searchengine.php (#398) + += 1.5.6 = +* REST API: Added /plugins endpoint to handle the plugins settings page. (#382) +* Minor changes to indentaion and spaces to tabs conversion (#371) (#395) +* Don't set $wp_super_cache_comments here as it's not saved. (#379) +* realpath() only works on directories. The cache_file wasn't set correctly. (#377) +* Fix problem deleting cache from admin bar because of realpath() (#381) +* Use trigger_error() instead of echoing to the screen if a config file isn't writeable. (#394) +* Added the "wpsc_enable_wp_config_edit" filter to disable editing the wp-config.php (#392) +* Fix some PHP notices when comments are edited/published/maintained. (#386) +* Minor changes to description on plugins page. (#393) + += 1.5.5 = +* Catch fatal errors so they're not cached, improve code that catches unknown page types. (#367) +* Fix caching on older WP installs, and if the plugin is inactive on a blog, but still caching, give feeds a short TTL to ensure they're fresh. (#366) +* When preloading don't delete sub-directories, or child pages, when caching pages. (#363) +* Avoid PHP warnings from the REST API for settings that are not yet defined. (#361) +* Added missing settings to the config file. (#360) + = 1.5.4 = * Fix messages related to creating advanced-cache.php (#355, #354) * Deleting the plugin doesn't need to delete the cache directory as it's already done on deactivation. (#323) diff --git a/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-rest-get-plugins.php b/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-rest-get-plugins.php new file mode 100644 index 000000000..005d44e1a --- /dev/null +++ b/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-rest-get-plugins.php @@ -0,0 +1,16 @@ +<?php + +class WP_Super_Cache_Rest_Get_Plugins extends WP_REST_Controller { + + /** + * GET a list of plugins through the /plugins/ endpoint + * + * @param WP_REST_Request $request Full data about the request. + * @return WP_Error|WP_REST_Response + */ + public function callback( $request ) { + + $list = wpsc_get_plugin_list(); + return rest_ensure_response( $list ); + } +} 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 b6f5b805b..33a79d214 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 @@ -43,7 +43,11 @@ class WP_Super_Cache_Rest_Get_Settings extends WP_REST_Controller { } elseif ( isset( $map['global'] ) ) { $global_var = $map['global']; - $settings[ $name ] = $$global_var; + if ( false == isset( $$global_var ) ) { + $settings[ $name ] = false; + } else { + $settings[ $name ] = $$global_var; + } } } diff --git a/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-rest-update-plugins.php b/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-rest-update-plugins.php new file mode 100644 index 000000000..d11323370 --- /dev/null +++ b/wp-content/plugins/wp-super-cache/rest/class.wp-super-cache-rest-update-plugins.php @@ -0,0 +1,22 @@ +<?php + +class WP_Super_Cache_Rest_Update_Plugins extends WP_REST_Controller { + + /** + * Toggle plugins on/off through the /plugins/ endpoint + * + * @param WP_REST_Request $request Full data about the request. + * @return WP_Error|WP_REST_Response + */ + public function callback( $request ) { + $parameters = $request->get_json_params(); + + global $valid_nonce; + $valid_nonce = true; + + wpsc_update_plugin_list( $parameters ); + $list = wpsc_get_plugin_list(); + + return rest_ensure_response( $list ); + } +} diff --git a/wp-content/plugins/wp-super-cache/rest/load.php b/wp-content/plugins/wp-super-cache/rest/load.php index 75e081629..32007432b 100644 --- a/wp-content/plugins/wp-super-cache/rest/load.php +++ b/wp-content/plugins/wp-super-cache/rest/load.php @@ -8,6 +8,8 @@ require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-get-status.php' require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-test-cache.php' ); require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-delete-cache.php' ); require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-preload.php' ); +require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-get-plugins.php' ); +require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-update-plugins.php' ); class WP_Super_Cache_Router { @@ -32,6 +34,8 @@ class WP_Super_Cache_Router { $delete_cache = new WP_Super_Cache_Rest_Delete_Cache(); $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(); register_rest_route( $namespace, '/settings', array( array( @@ -87,6 +91,21 @@ class WP_Super_Cache_Router { 'permission_callback' => __CLASS__ . '::create_item_permissions_check', ) ); + register_rest_route( $namespace, '/plugins', array( + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $get_plugins, 'callback' ), + 'permission_callback' => __CLASS__ . '::get_item_permissions_check', + 'args' => array(), + ), + array( + 'methods' => WP_REST_Server::CREATABLE, + 'callback' => array( $update_plugins, 'callback' ), + 'permission_callback' => __CLASS__ . '::update_item_permissions_check', + 'args' => array(), + ), + ) ); + } /** 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 fccb848d4..c8722c608 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 @@ -98,4 +98,7 @@ $wp_cache_preload_email_volume = 'none'; $wp_cache_mobile_prefixes = ''; $cached_direct_pages = array(); $wpsc_served_header = false; +$cache_gc_email_me = 0; +$wpsc_save_headers = 0; +$cache_schedule_interval = 'daily'; ?> 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 fcd73cb45..c7406f40c 100644 --- a/wp-content/plugins/wp-super-cache/wp-cache-phase1.php +++ b/wp-content/plugins/wp-super-cache/wp-cache-phase1.php @@ -46,6 +46,8 @@ if( is_array( $plugins ) ) { } } +$wp_start_time = microtime(); + if ( $wp_cache_not_logged_in && wp_cache_get_cookies_values() ) { wp_cache_debug( 'Caching disabled for logged in users on settings page.' ); return true; @@ -109,8 +111,6 @@ function setup_blog_cache_dir() { @mkdir( $blog_cache_dir . 'meta' ); } -$wp_start_time = microtime(); - function get_wp_cache_key( $url = false ) { global $wp_cache_request_uri, $wp_cache_gzip_encoding, $WPSC_HTTP_HOST; if ( ! $url ) { @@ -129,8 +129,8 @@ function wp_super_cache_init() { $cache_filename = $file_prefix . $key . '.php'; $meta_file = $file_prefix . $key . '.php'; - $cache_file = wpsc_get_realpath( $blog_cache_dir . $cache_filename ); - $meta_pathname = wpsc_get_realpath( $blog_cache_dir . 'meta/' . $meta_file ); + $cache_file = wpsc_get_realpath( $blog_cache_dir ) . '/' . $cache_filename; + $meta_pathname = wpsc_get_realpath( $blog_cache_dir . 'meta/' ) . '/' . $meta_file; return compact( 'key', 'cache_filename', 'meta_file', 'cache_file', 'meta_pathname' ); } @@ -200,7 +200,8 @@ function wp_cache_serve_cache_file() { foreach( $rss_types as $rss_type ) { if ( strpos( $meta[ 'headers' ][ 'Content-Type' ], $rss_type ) ) { global $wpsc_last_post_update; - if ( isset( $wpsc_last_post_update ) && filemtime( $meta_pathname ) < $wpsc_last_post_update ) { + if ( isset( $wpsc_last_post_update ) && filemtime( $meta_pathname ) < $wpsc_last_post_update || + ( isset( $meta[ 'ttl' ] ) && ( time() - filemtime( $meta_pathname ) ) > $meta[ 'ttl' ] ) ) { wp_cache_debug( "wp_cache_serve_cache_file: feed out of date. deleting cache files: $meta_pathname, $cache_file" ); @unlink( $meta_pathname ); @unlink( $cache_file ); @@ -583,7 +584,7 @@ function wp_cache_debug( $message, $level = 1 ) { return false; // Log message: Date URI Message - $log_message = date('H:i:s') . " " . getmypid() . " {$_SERVER['REQUEST_URI']} {$message}\n\r"; + $log_message = date('H:i:s') . " " . getmypid() . " {$_SERVER['REQUEST_URI']} {$message}" . PHP_EOL; // path to the log file in the cache folder $log_file = $cache_path . str_replace('/', '', str_replace('..', '', $wp_cache_debug_log)); 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 e3fc54e4a..53b2324f9 100644 --- a/wp-content/plugins/wp-super-cache/wp-cache-phase2.php +++ b/wp-content/plugins/wp-super-cache/wp-cache-phase2.php @@ -32,8 +32,8 @@ function wp_cache_phase2() { 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('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' ); @@ -58,7 +58,7 @@ function wp_cache_phase2() { header('Vary: Accept-Encoding, Cookie'); else header('Vary: Cookie'); - ob_start( 'wp_cache_ob_callback' ); + ob_start( 'wp_cache_ob_callback' ); wp_cache_debug( 'Created output buffer', 4 ); // restore old supercache file temporarily @@ -289,7 +289,7 @@ function wp_cache_mutex_init() { return true; if( !is_bool( $use_flock ) ) { - if(function_exists('sem_get')) + if(function_exists('sem_get')) $use_flock = false; else $use_flock = true; @@ -370,12 +370,29 @@ function wp_super_cache_query_vars() { $wp_super_cache_query[ 'is_home' ] = 1; if ( is_author() ) $wp_super_cache_query[ 'is_author' ] = 1; - if ( is_feed() || get_query_var( 'sitemap' ) || get_query_var( 'xsl' ) || get_query_var( 'xml_sitemap' ) ) + if ( is_feed() || ( method_exists( $GLOBALS['wp_query'], 'get') && ( get_query_var( 'sitemap' ) || get_query_var( 'xsl' ) || get_query_var( 'xml_sitemap' ) ) ) ) $wp_super_cache_query[ 'is_feed' ] = 1; + if ( is_404() ) + $wp_super_cache_query = array( 'is_404' => 1 ); return $wp_super_cache_query; } +function wpsc_is_fatal_error() { + global $wp_super_cache_query; + + if ( null === ( $error = error_get_last() ) ) { + return false; + } + + if ( $error['type'] & ( E_ERROR | E_CORE_ERROR | E_PARSE | E_COMPILE_ERROR | E_USER_ERROR ) ) { + $wp_super_cache_query[ 'is_fatal_error' ] = 1; + return true; + } + + return false; +} + 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; $buffer = apply_filters( 'wp_cache_ob_callback_filter', $buffer ); @@ -385,13 +402,16 @@ function wp_cache_ob_callback( $buffer ) { // All the things that can stop a page being cached $cache_this_page = true; - if ( empty( $wp_super_cache_query ) ) { + if ( wpsc_is_fatal_error() ) { + $cache_this_page = false; + wp_cache_debug( 'wp_cache_ob_callback: PHP Fatal error occurred. Not caching incomplete page.' ); + } elseif ( empty( $wp_super_cache_query ) && !empty( $buffer ) && is_object( $wp_query ) ) { $wp_super_cache_query = wp_super_cache_query_vars(); } - if ( empty( $wp_super_cache_query ) ) { + if ( empty( $wp_super_cache_query ) && function_exists( 'apply_filter' ) && apply_filter( 'wpsc_only_cache_known_pages', 1 ) ) { $cache_this_page = false; - wp_cache_debug( 'wp_cache_ob_callback: wp_super_cache_query is empty. Not caching unknown page type.' ); + wp_cache_debug( 'wp_cache_ob_callback: wp_super_cache_query is empty. Not caching unknown page type. Return 0 to the wpsc_only_cache_known_pages filter to cache this page.' ); } elseif ( defined( 'DONOTCACHEPAGE' ) ) { wp_cache_debug( 'DONOTCACHEPAGE defined. Caching disabled.', 2 ); $cache_this_page = false; @@ -454,9 +474,6 @@ function wp_cache_ob_callback( $buffer ) { if ( isset( $wpsc_save_headers ) && $wpsc_save_headers ) $super_cache_enabled = false; // use standard caching to record headers - if ( !isset( $wp_query ) ) - wp_cache_debug( 'wp_cache_ob_callback: WARNING! $query not defined but the plugin has worked around that problem.', 4 ); - if ( $cache_this_page ) { wp_cache_debug( 'Output buffer callback', 4 ); @@ -500,9 +517,9 @@ function wp_cache_append_tag( &$buffer ) { $timestamp = gmdate('Y-m-d H:i:s', (time() + ( $wp_cache_gmt_offset * 3600))); if ( $cache_enabled || $super_cache_enabled ) { - $msg = "\n<!-- Cached page generated by WP-Super-Cache on $timestamp -->\n"; + $msg = "Cached page generated by WP-Super-Cache on $timestamp"; } else { - $msg = "\n<!-- Live page served on $timestamp -->\n"; + $msg = "Live page served on $timestamp"; } if ( strpos( $buffer, '<html' ) === false ) { @@ -510,7 +527,7 @@ function wp_cache_append_tag( &$buffer ) { return false; } - $buffer .= $msg; + $buffer .= "\n<!-- $msg -->\n"; } function wp_cache_add_to_buffer( &$buffer, $text ) { @@ -530,7 +547,7 @@ function wp_cache_add_to_buffer( &$buffer, $text ) { $buffer .= "\n<!-- $text -->"; } -/* +/* * If dynamic caching is enabled then run buffer through wpsc_cachedata filter before returning it. * or we'll return template tags to visitors. */ @@ -560,7 +577,7 @@ function wp_cache_get_ob(&$buffer) { $new_cache = true; $wp_cache_meta = array(); - /* Mode paranoic, check for closing tags + /* Mode paranoic, check for closing tags * we avoid caching incomplete files */ if ( $buffer == '' ) { $new_cache = false; @@ -589,7 +606,7 @@ function wp_cache_get_ob(&$buffer) { wp_cache_debug( "robots.txt detected. Not caching.", 2 ); } } - + if( !$new_cache ) return wp_cache_maybe_dynamic( $buffer ); @@ -771,13 +788,13 @@ function wp_cache_get_ob(&$buffer) { 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 ); + 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 ); + 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." ); @@ -788,7 +805,7 @@ function wp_cache_get_ob(&$buffer) { 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." ); fwrite($gz, $gzdata ); @@ -874,7 +891,7 @@ function wp_cache_phase2_clean_cache($file_prefix) { if( !wp_cache_writers_entry() ) return false; wp_cache_debug( "wp_cache_phase2_clean_cache: Cleaning cache in $blog_cache_dir" ); - if ( $handle = @opendir( $blog_cache_dir ) ) { + if ( $handle = @opendir( $blog_cache_dir ) ) { while ( false !== ($file = @readdir($handle))) { if ( strpos( $file, $file_prefix ) !== false ) { if ( strpos( $file, '.html' ) ) { @@ -940,7 +957,7 @@ function prune_super_cache( $directory, $force = false, $rename = false ) { continue; $entry = $directory . $entry; prune_super_cache( $entry, $force, $rename ); - // If entry is a directory, AND it's not a protected one, AND we're either forcing the delete, OR the file is out of date, + // If entry is a directory, AND it's not a protected one, AND we're either forcing the delete, OR the file is out of date, if( is_dir( $entry ) && !in_array( $entry, $protected_directories ) && ( $force || @filemtime( $entry ) + $cache_max_time <= $now ) ) { // if the directory isn't empty can't delete it if( $handle = @opendir( $entry ) ) { @@ -1064,9 +1081,9 @@ function wp_cache_phase2_clean_expired( $file_prefix, $force = false ) { $now = time(); wp_cache_debug( "Cleaning expired cache files in $blog_cache_dir", 2 ); $deleted = 0; - if ( ( $handle = @opendir( $blog_cache_dir ) ) ) { + if ( ( $handle = @opendir( $blog_cache_dir ) ) ) { while ( false !== ($file = readdir($handle))) { - if ( preg_match("/^$file_prefix/", $file) && + if ( preg_match("/^$file_prefix/", $file) && (@filemtime( $blog_cache_dir . $file) + $cache_max_time) <= $now ) { @unlink( $blog_cache_dir . $file ); @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) ); @@ -1098,6 +1115,17 @@ function wp_cache_shutdown_callback() { global $wp_cache_request_uri, $wp_cache_key, $wp_cache_object_cache, $cache_enabled, $wp_cache_blog_charset, $wp_cache_not_logged_in; global $WPSC_HTTP_HOST, $wp_super_cache_query; + if ( ! function_exists( 'wpsc_init' ) ) { + /* + * If a server has multiple networks the plugin may not have been activated + * on all of them. Give feeds on those blogs a short TTL. + * 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." ); + } + + if ( false == $new_cache ) { wp_cache_debug( "wp_cache_shutdown_callback: No cache file created. Returning." ); return false; @@ -1150,10 +1178,18 @@ function wp_cache_shutdown_callback() { $value = "application/rss+xml"; } } + if ( isset( $wpsc_feed_ttl ) && $wpsc_feed_ttl == 1 ) { + $wp_cache_meta[ 'ttl' ] = 60; + } + wp_cache_debug( "wp_cache_shutdown_callback: feed is type: $type - $value" ); } elseif ( get_query_var( 'sitemap' ) || get_query_var( 'xsl' ) || get_query_var( 'xml_sitemap' ) ) { wp_cache_debug( "wp_cache_shutdown_callback: sitemap detected: text/xml" ); $value = "text/xml"; + if ( isset( $wpsc_feed_ttl ) && $wpsc_feed_ttl == 1 ) { + $wp_cache_meta[ 'ttl' ] = 60; + } + } else { // not a feed $value = get_option( 'html_type' ); if( $value == '' ) @@ -1219,6 +1255,20 @@ function wp_cache_no_postid($id) { function wp_cache_get_postid_from_comment( $comment_id, $status = 'NA' ) { global $super_cache_enabled, $wp_cache_request_uri; + + if ( defined( 'DONOTDELETECACHE' ) ) { + return; + } + + // Check is it "Empty Spam" or "Empty Trash" + if ( isset( $GLOBALS[ 'pagenow' ] ) && $GLOBALS[ 'pagenow' ] === 'edit-comments.php' && + ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) + ) { + wp_cache_debug( "Delete all SPAM or Trash comments. Don't delete any cache files.", 4 ); + define( 'DONOTDELETECACHE', 1 ); + return; + } + $comment = get_comment($comment_id, ARRAY_A); if ( $status != 'NA' ) { $comment[ 'old_comment_approved' ] = $comment[ 'comment_approved' ]; @@ -1231,7 +1281,7 @@ function wp_cache_get_postid_from_comment( $comment_id, $status = 'NA' ) { define( 'DONOTDELETECACHE', 1 ); return wp_cache_post_id(); } - $postid = $comment['comment_post_ID']; + $postid = isset( $comment[ 'comment_post_ID' ] ) ? (int) $comment[ 'comment_post_ID' ] : 0; // Do nothing if comment is not moderated // http://ocaoimh.ie/2006/12/05/caching-wordpress-with-wp-cache-in-a-spam-filled-world if ( !preg_match('/wp-admin\//', $wp_cache_request_uri) ) { @@ -1256,12 +1306,12 @@ function wp_cache_get_postid_from_comment( $comment_id, $status = 'NA' ) { } } // We must check it up again due to WP bugs calling two different actions - // for delete, for example both wp_set_comment_status and delete_comment + // for delete, for example both wp_set_comment_status and delete_comment // are called when deleting a comment if ($postid > 0) { wp_cache_debug( "Post $postid changed. Update cache.", 4 ); return wp_cache_post_change( $postid ); - } elseif ( $_GET[ 'delete_all' ] != 'Empty Trash' && $_GET[ 'delete_all2' ] != 'Empty Spam' ) { + } else { wp_cache_debug( "Unknown post changed. Update cache.", 4 ); return wp_cache_post_change( wp_cache_post_id() ); } @@ -1343,7 +1393,7 @@ function wp_cache_post_edit($post_id) { if ( is_object( $post ) == false ) return $post_id; - // Some users are inexplicibly seeing this error on scheduled posts. + // 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 ); @@ -1368,7 +1418,7 @@ 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(); @@ -1389,7 +1439,7 @@ function wp_cache_post_id_gc( $post_id, $all = 'all' ) { do_action( 'gc_cache', 'prune', 'page/' ); } else { wp_cache_debug( "wp_cache_post_id_gc clearing cached index files in $dir.", 4 ); - prune_super_cache( $dir, true, true ); + prune_super_cache( $dir, true, true ); do_action( 'gc_cache', 'prune', $permalink ); } } @@ -1403,7 +1453,7 @@ function wp_cache_post_change( $post_id ) { return $post_id; } $post = get_post( $post_id ); - // Some users are inexplicibly seeing this error on scheduled posts. + // 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 ); @@ -1458,7 +1508,7 @@ function wp_cache_post_change( $post_id ) { wp_cache_debug( "wp_cache_post_change: checking {$blog_cache_dir}meta/", 4 ); $supercache_files_deleted = false; - if ( $handle = @opendir( $blog_cache_dir ) ) { + if ( $handle = @opendir( $blog_cache_dir ) ) { while ( false !== ($file = readdir($handle))) { if ( strpos( $file, $file_prefix ) !== false ) { if ( strpos( $file, '.html' ) ) { @@ -1518,7 +1568,7 @@ function wp_cache_post_id() { // We try hard all options. More frequent first. if ($post_ID > 0 ) return $post_ID; if ($comment_post_ID > 0 ) return $comment_post_ID; - if (is_single() || is_page()) return $posts[0]->ID; + if (is_singular() && !empty($posts)) return $posts[0]->ID; if (isset( $_GET[ 'p' ] ) && $_GET['p'] > 0) return $_GET['p']; if (isset( $_POST[ 'p' ] ) && $_POST['p'] > 0) return $_POST['p']; return 0; @@ -1560,7 +1610,7 @@ function wp_cache_gc_cron() { return false; } - update_option( 'wpsupercache_gc_time', time() ); + update_option( 'wpsupercache_gc_time', time() ); wp_cache_debug( "wp_cache_gc_cron: Set GC Flag. ($gc_flag)", 5 ); $fp = @fopen( $gc_flag, 'w' ); @fclose( $fp ); @@ -1642,9 +1692,4 @@ function wp_cache_gc_watcher() { } } -function wpsc_timestamp_cache_update( $type, $permalink ) { - wp_cache_setting( 'wpsc_last_post_update', time() ); -} -add_action( 'gc_cache', 'wpsc_timestamp_cache_update', 10, 2 ); - ?> diff --git a/wp-content/plugins/wp-super-cache/wp-cache.php b/wp-content/plugins/wp-super-cache/wp-cache.php index 9f7ac154e..048e55124 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.4 +Version: 1.5.7 Author: Automattic Author URI: https://automattic.com/ License: GPL2+ @@ -455,17 +455,20 @@ function admin_bar_delete_page() { return false; if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'delcachepage' && ( isset( $_GET[ '_wpnonce' ] ) ? wp_verify_nonce( $_REQUEST[ '_wpnonce' ], 'delete-cache' ) : false ) ) { $path = realpath( trailingslashit( get_supercache_dir() . str_replace( '..', '', preg_replace( '/:.*$/', '', $_GET[ 'path' ] ) ) ) ) . '/'; - if ( $path == '/' ) + if ( $path == '/' ) { return false; // Directory not found. Probably not cached. - if ( false == wp_cache_confirm_delete( $path ) || substr( $path, 0, strlen( get_supercache_dir() ) ) != get_supercache_dir() ) + } + $supercachepath = realpath(get_supercache_dir()); + if ( false == wp_cache_confirm_delete( $path ) || substr( $path, 0, strlen( $supercachepath ) ) != $supercachepath ) { die( "Could not delete directory" ); + } wpsc_delete_files( $path ); wp_redirect( preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_GET[ 'path' ] ) ); die(); } } if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'delcachepage' ) - add_action( 'admin_init', 'admin_bar_delete_page' ); + add_action( 'admin_init', 'admin_bar_delete_page' ); function wp_cache_manager_updates() { global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_hello_world, $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; @@ -768,18 +771,18 @@ function wp_cache_manager() { <script type='text/javascript'> <!-- function toggleLayer( whichLayer ) { - var elem, vis; - if( document.getElementById ) // this is the way the standards work - elem = document.getElementById( whichLayer ); - else if( document.all ) // this is the way old msie versions work - elem = document.all[whichLayer]; - else if( document.layers ) // this is the way nn4 works - elem = document.layers[whichLayer]; - vis = elem.style; - // if the style.display value is blank we try to figure it out here - if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined) - vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none'; - vis.display = (vis.display==''||vis.display=='block')?'none':'block'; + var elem, vis; + if( document.getElementById ) // this is the way the standards work + elem = document.getElementById( whichLayer ); + else if( document.all ) // this is the way old msie versions work + elem = document.all[whichLayer]; + else if( document.layers ) // this is the way nn4 works + elem = document.layers[whichLayer]; + vis = elem.style; + // if the style.display value is blank we try to figure it out here + if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined) + vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none'; + vis.display = (vis.display==''||vis.display=='block')?'none':'block'; } // --> //Clicking header opens fieldset options @@ -1229,12 +1232,14 @@ table.wpsc-settings-table { echo '<input type="hidden" name="action" value="test" />'; if ( isset( $_SERVER['HTTPS' ] ) && 'on' == strtolower( $_SERVER['HTTPS' ] ) ) echo "<input type='checkbox' name='httponly' checked='checked' value='1' /> " . __( 'Send non-secure (non https) request for homepage', 'wp-super-cache' ); - if ( isset( $wp_super_cache_comments ) && $wp_super_cache_comments == 0 ) { - echo "<p>" . __( '<strong>Warning!</strong> Cache comments are currently disabled. Please go to the Debug page and enable Cache Status Messages there. You should clear the cache before testing.', 'wp-super-cache' ) . "</p>"; - echo '<div class="submit"><input disabled style="color: #aaa" class="button-secondary" type="submit" name="test" value="' . __( 'Test Cache', 'wp-super-cache' ) . '" /></div>'; - } else { - echo '<div class="submit"><input class="button-secondary" type="submit" name="test" value="' . __( 'Test Cache', 'wp-super-cache' ) . '" /></div>'; - } + + if ( isset( $wp_super_cache_comments ) && $wp_super_cache_comments == 0 ) { + echo "<p>" . __( '<strong>Warning!</strong> Cache comments are currently disabled. Please go to the Debug page and enable Cache Status Messages there. You should clear the cache before testing.', 'wp-super-cache' ) . "</p>"; + echo '<div class="submit"><input disabled style="color: #aaa" class="button-secondary" type="submit" name="test" value="' . __( 'Test Cache', 'wp-super-cache' ) . '" /></div>'; + } else { + echo '<div class="submit"><input class="button-secondary" type="submit" name="test" value="' . __( 'Test Cache', 'wp-super-cache' ) . '" /></div>'; + } + wp_nonce_field('wp-cache'); echo '</form>'; } @@ -1318,9 +1323,9 @@ table.wpsc-settings-table { } function wpsc_plugins_tab() { - echo '<p>' . __( 'Cache plugins are PHP scripts that live in a plugins folder inside the wp-super-cache folder. They are loaded when Supercache loads, much sooner than regular WordPress plugins.', 'wp-super-cache' ) . '</p>'; - echo '<p>' . __( 'This is strictly an advanced feature only and knowledge of both PHP and WordPress actions is required to create them.', 'wp-super-cache' ) . '</p>'; - echo '<p>' . __( '<strong>Warning</strong>! Due to the way WordPress upgrades plugins, the plugins you upload to wp-super-cache/plugins/ will be deleted when you upgrade WP Super Cache. You can avoid this by loading the plugins from elsewhere. Set <strong>$wp_cache_plugins_dir</strong> to the new location in wp-config.php and WP Super Cache will look there instead.<br />More info available in the <a href="http://ocaoimh.ie/wp-super-cache-developers/">developer documentation</a>.', 'wp-super-cache' ) . '</p>'; + echo '<p>' . __( 'Cache plugins are PHP scripts you\'ll find in a dedicated folder inside the WP Super Cache folder (wp-super-cache/plugins/). They load at the same time as WP Super Cache, and before regular WordPress plugins.', 'wp-super-cache' ) . '</p>'; + echo '<p>' . __( 'Keep in mind that cache plugins are for advanced users only. To create and manage them, you\'ll need extensive knowledge of both PHP and WordPress actions.', 'wp-super-cache' ) . '</p>'; + echo '<p>' . sprintf( __( '<strong>Warning</strong>! Due to the way WordPress upgrades plugins, the ones you upload to the WP Super Cache folder (wp-super-cache/plugins/) will be deleted when you upgrade WP Super Cache. To avoid this loss, load your cache plugins from a different location. When you set <strong>$wp_cache_plugins_dir</strong> to the new location in wp-config.php, WP Super Cache will look there instead. <br />You can find additional details in the <a href="%s">developer documentation</a>.', 'wp-super-cache' ), 'https://odd.blog/wp-super-cache-developers/' ) . '</p>'; ob_start(); if( defined( 'WP_CACHE' ) ) { if( function_exists( 'do_cacheaction' ) ) { @@ -2006,7 +2011,7 @@ function wpsc_update_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 } 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 + 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 ); @@ -2173,7 +2178,7 @@ function wp_cache_is_enabled() { } $lines = file($wp_cache_config_file); foreach($lines as $line) { - if (preg_match('/^ *\$cache_enabled *= *true *;/', $line)) + if (preg_match('/^ *\$cache_enabled *= *true *;/', $line)) return true; } return false; @@ -2199,14 +2204,14 @@ function wp_cache_replace_line($old, $new, $my_file) { return false; } if (!is_writeable_ACLSafe($my_file)) { - echo "Error: file $my_file is not writable.\n"; + trigger_error( "Error: file $my_file is not writable." ); return false; } $found = false; $lines = file($my_file); foreach( (array)$lines as $line ) { - if ( preg_match("/$old/", $line)) { + if ( preg_match("/$old/", $line)) { $found = true; break; } @@ -2341,7 +2346,7 @@ function wp_cache_logout_all() { } } if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'wpsclogout' ) - add_action( 'admin_init', 'wp_cache_logout_all' ); + add_action( 'admin_init', 'wp_cache_logout_all' ); function wp_cache_add_index_protection() { global $cache_path, $blog_cache_dir; @@ -2488,6 +2493,12 @@ function wp_cache_create_advanced_cache() { } $line = 'define( \'WPCACHEHOME\', \'' . dirname( __FILE__ ) . '/\' );'; + + if ( ! apply_filters( 'wpsc_enable_wp_config_edit', true ) ) { + echo '<div class="notice notice-error"><h3>' . __( 'Warning', 'wp-super-cache' ) . "! " . sprintf( __( 'Not allowed to edit %s per configuration.', 'wp-super-cache' ), $global_config_file ) . "</h3></div>"; + 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"><h3>' . __( 'Warning', 'wp-super-cache' ) . "! <em>" . sprintf( __( 'Could not update %s!</em> WPCACHEHOME must be set in config file.', 'wp-super-cache' ), $global_config_file ) . "</h3></div>"; return false; @@ -2508,7 +2519,7 @@ function wp_cache_create_advanced_cache() { function wp_cache_check_link() { global $wp_cache_link, $wp_cache_file; - $ret = true; + $ret = true; if( file_exists($wp_cache_link) ) { $file = file_get_contents( $wp_cache_link ); if( strpos( $file, "WP SUPER CACHE 0.8.9.1" ) || strpos( $file, "WP SUPER CACHE 1.2" ) ) { @@ -3094,13 +3105,13 @@ add_filter( 'favorite_actions', 'wp_cache_favorite_action' ); function wp_cache_plugin_notice( $plugin ) { global $cache_enabled; - if( $plugin == 'wp-super-cache/wp-cache.php' && !$cache_enabled && function_exists( "admin_url" ) ) + if( $plugin == 'wp-super-cache/wp-cache.php' && !$cache_enabled && function_exists( 'admin_url' ) ) echo '<td colspan="5" class="plugin-update">' . sprintf( __( 'WP Super Cache must be configured. Go to <a href="%s">the admin page</a> to enable and configure the plugin.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '</td>'; } add_action( 'after_plugin_row', 'wp_cache_plugin_notice' ); function wp_cache_plugin_actions( $links, $file ) { - if( $file == 'wp-super-cache/wp-cache.php' && function_exists( "admin_url" ) ) { + if( $file == 'wp-super-cache/wp-cache.php' && function_exists( 'admin_url' ) ) { $settings_link = '<a href="' . admin_url( 'options-general.php?page=wpsupercache' ) . '">' . __( 'Settings', 'wp-super-cache' ) . '</a>'; array_unshift( $links, $settings_link ); // before other links } @@ -3110,7 +3121,7 @@ add_filter( 'plugin_action_links', 'wp_cache_plugin_actions', 10, 2 ); function wp_cache_admin_notice() { global $cache_enabled, $wp_cache_phase1_loaded; - if( substr( $_SERVER["PHP_SELF"], -11 ) == 'plugins.php' && !$cache_enabled && function_exists( "admin_url" ) ) + if( substr( $_SERVER['PHP_SELF'], -11 ) == 'plugins.php' && !$cache_enabled && function_exists( 'admin_url' ) ) echo '<div class="notice notice-info"><p><strong>' . sprintf( __('WP Super Cache is disabled. Please go to the <a href="%s">plugin admin page</a> to enable caching.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '</strong></p></div>'; if ( defined( 'WP_CACHE' ) && WP_CACHE == true && ( defined( 'ADVANCEDCACHEPROBLEM' ) || ( $cache_enabled && false == isset( $wp_cache_phase1_loaded ) ) ) ) { @@ -3133,22 +3144,22 @@ function wp_cache_check_site() { $front_page = wp_remote_get( site_url(), array('timeout' => 60, 'blocking' => true ) ); if( is_array( $front_page ) ) { // Check for gzipped front page - if ( $front_page[ 'headers' ][ 'content-type' ] == 'application/x-gzip' ) { - if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) { - wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Please clear cache!', 'wp-super-cache' ), home_url() ), sprintf( __( "Please visit %s to clear the cache as the front page of your site is now downloading!", 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) ); - } else { - wp_cache_clear_cache( $wpdb->blogid ); - wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Cache Cleared!', 'wp-super-cache' ), home_url() ), sprintf( __( "The cache on your blog has been cleared because the front page of your site is now downloading. Please visit %s to verify the cache has been cleared.", 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) ); - } - } + if ( $front_page[ 'headers' ][ 'content-type' ] == 'application/x-gzip' ) { + if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) { + wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Please clear cache!', 'wp-super-cache' ), home_url() ), sprintf( __( "Please visit %s to clear the cache as the front page of your site is now downloading!", 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) ); + } else { + wp_cache_clear_cache( $wpdb->blogid ); + wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Cache Cleared!', 'wp-super-cache' ), home_url() ), sprintf( __( "The cache on your blog has been cleared because the front page of your site is now downloading. Please visit %s to verify the cache has been cleared.", 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) ); + } + } // Check for broken front page if ( isset( $wp_super_cache_front_page_text ) && $wp_super_cache_front_page_text != '' && false === strpos( $front_page[ 'body' ], $wp_super_cache_front_page_text ) ) { if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) { - wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Please clear cache!', 'wp-super-cache' ), home_url() ), sprintf( __( 'Please visit %1$s to clear the cache as the front page of your site is not correct and missing the text, "%2$s"!', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ), $wp_super_cache_front_page_text ) ); - } else { - wp_cache_clear_cache( $wpdb->blogid ); - wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Cache Cleared!', 'wp-super-cache' ), home_url() ), sprintf( __( 'The cache on your blog has been cleared because the front page of your site is missing the text "%2$s". Please visit %1$s to verify the cache has been cleared.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ), $wp_super_cache_front_page_text ) ); + wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Please clear cache!', 'wp-super-cache' ), home_url() ), sprintf( __( 'Please visit %1$s to clear the cache as the front page of your site is not correct and missing the text, "%2$s"!', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ), $wp_super_cache_front_page_text ) ); + } else { + wp_cache_clear_cache( $wpdb->blogid ); + wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Cache Cleared!', 'wp-super-cache' ), home_url() ), sprintf( __( 'The cache on your blog has been cleared because the front page of your site is missing the text "%2$s". Please visit %1$s to verify the cache has been cleared.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ), $wp_super_cache_front_page_text ) ); } } } @@ -3346,7 +3357,11 @@ function clear_post_supercache( $post_id ) { include_once( 'wp-cache-phase2.php' ); wp_cache_debug( "clear_post_supercache: deleting files in $dir", 2 ); - prune_super_cache( $dir, true ); + if ( get_post_type( $post_id ) != 'page' ) { // don't delete child pages if they exist + prune_super_cache( $dir, true ); + } else { + wpsc_delete_files( $dir ); + } } function wp_cron_preload_cache() { @@ -3586,13 +3601,18 @@ function wp_cache_disable_plugin( $delete_config_file = true ) { } else { $global_config_file = dirname(ABSPATH) . '/wp-config.php'; } - $line = 'define(\'WP_CACHE\', true);'; - if ( strpos( file_get_contents( $global_config_file ), $line ) && ( !is_writeable_ACLSafe( $global_config_file ) || !wp_cache_replace_line( 'define *\( *\'WP_CACHE\'', '', $global_config_file ) ) ) { - wp_die( "Could not remove WP_CACHE define from $global_config_file. Please edit that file and remove the line containing the text 'WP_CACHE'. Then refresh this page." ); - } - $line = 'define( \'WPCACHEHOME\','; - if ( strpos( file_get_contents( $global_config_file ), $line ) && ( !is_writeable_ACLSafe( $global_config_file ) || !wp_cache_replace_line( 'define *\( *\'WPCACHEHOME\'', '', $global_config_file ) ) ) { - wp_die( "Could not remove WPCACHEHOME define from $global_config_file. Please edit that file and remove the line containing the text 'WPCACHEHOME'. Then refresh this page." ); + + if ( apply_filters( 'wpsc_enable_wp_config_edit', true ) ) { + $line = 'define(\'WP_CACHE\', true);'; + if ( strpos( file_get_contents( $global_config_file ), $line ) && ( !is_writeable_ACLSafe( $global_config_file ) || !wp_cache_replace_line( 'define *\( *\'WP_CACHE\'', '', $global_config_file ) ) ) { + wp_die( "Could not remove WP_CACHE define from $global_config_file. Please edit that file and remove the line containing the text 'WP_CACHE'. Then refresh this page." ); + } + $line = 'define( \'WPCACHEHOME\','; + if ( strpos( file_get_contents( $global_config_file ), $line ) && ( !is_writeable_ACLSafe( $global_config_file ) || !wp_cache_replace_line( 'define *\( *\'WPCACHEHOME\'', '', $global_config_file ) ) ) { + wp_die( "Could not remove WPCACHEHOME define from $global_config_file. Please edit that file and remove the line containing the text 'WPCACHEHOME'. Then refresh this page." ); + } + } elseif ( function_exists( 'wp_cache_debug' ) ) { + wp_cache_debug( 'wp_cache_disable_plugin: not allowed to edit wp-config.php per configuration.' ); } uninstall_supercache( WP_CONTENT_DIR . '/cache' ); @@ -3730,8 +3750,8 @@ function wpsc_preload_settings( $min_refresh_interval = 'NA' ) { } elseif ( isset( $_POST[ 'preload_now' ] ) ) { wpsc_enable_preload(); return $return; - } - + } + if ( $min_refresh_interval == 'NA' ) { $count = wpsc_post_count(); if ( $count > 1000 ) { @@ -3798,7 +3818,7 @@ function wpsc_preload_settings( $min_refresh_interval = 'NA' ) { } function wpsc_is_preloading() { - if ( wp_next_scheduled( 'wp_cache_preload_hook' ) || wp_next_scheduled( 'wp_cache_full_preload_hook' ) ) { + if ( wp_next_scheduled( 'wp_cache_preload_hook' ) || wp_next_scheduled( 'wp_cache_full_preload_hook' ) ) { return true; } else { return false; @@ -3958,3 +3978,36 @@ function update_mod_rewrite_rules( $add_rules = true ) { return true; } + +function wpsc_timestamp_cache_update( $type, $permalink ) { + wp_cache_setting( 'wpsc_last_post_update', time() ); +} +add_action( 'gc_cache', 'wpsc_timestamp_cache_update', 10, 2 ); + +function wpsc_get_plugin_list() { + $list = do_cacheaction( 'wpsc_filter_list' ); + foreach( $list as $t => $details ) { + $key = "cache_" . $details[ 'key' ]; + global $$key; + if ( isset( $$key ) && $$key == 1 ) { + $list[ $t ][ 'enabled' ] = true; + } else { + $list[ $t ][ 'enabled' ] = false; + } + + $list[ $t ][ 'desc' ] = strip_tags( $list[ $t ][ 'desc' ] ); + $list[ $t ][ 'title' ] = strip_tags( $list[ $t ][ 'title' ] ); + } + return $list; +} + +function wpsc_update_plugin_list( $update ) { + $list = do_cacheaction( 'wpsc_filter_list' ); + foreach( $update as $key => $enabled ) { + $plugin_toggle = "cache_{$key}"; + global $$plugin_toggle; + if ( isset( $$plugin_toggle ) || isset( $list[ $key ] ) ) { + wp_cache_setting( $plugin_toggle, (int)$enabled ); + } + } +} -- GitLab