Commit 6d14d805 authored by lucha's avatar lucha

[auto] plugin: wp-super-cache 1.5.7

parent 4008fa2a
......@@ -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' );
?>
......@@ -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' );
?>
......@@ -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' );
?>
......@@ -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' );
?>
......@@ -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' );
?>
......@@ -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' );
?>
......@@ -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)
......
<?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 );
}
}
......@@ -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;
}
}
}
......
<?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 );
}
}
......@@ -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(),
),
) );
}
/**
......
......@@ -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';
?>
......@@ -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));
......
......@@ -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." );
}