Commit 14af1a2d authored by lucha's avatar lucha
Browse files

[auto] plugin: wp-super-cache 1.6.4

parent aec578c9
# WP Super Cache #
* Contributors: donncha, automattic, kraftbj
* Tags: performance, caching, wp-cache, wp-super-cache, cache
* Tested up to: 4.9.6
* Stable tag: 1.6.2
* Requires at least: 3.0
* Tested up to: 4.9.8
* Stable tag: 1.6.4
* Requires at least: 3.1
* Requires PHP: 5.2.4
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
......@@ -89,6 +89,11 @@ 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.
WP Super Cache has it's own plugin system. This code is loaded when WP Super Cache loads and can be used to change how caching is done. This is before most of WordPress loads so some functionality will not be available. Plugins can be located anywhere that PHP can load them. Add your own plugin by calling wpsc_add_plugin( $name ) where $name is the full filename and path to the plugin. You only need to call that function once to add it. Use wpsc_delete_plugin( $name ) to remove it from the list of loaded plugins.
The cookies WP Super Cache uses to identify "known users" can be modified now by adding the names of those cookies to a list in the plugin configuration. Use wpsc_add_cookie( $name ) to add a new cookie, and wpsc_delete_cookie( $name ) to remove it. The cookie names also modify the mod_rewrite rules used by the plugin but I recommend using Simple mode caching to avoid complications with updating the .htaccess file.
The cookie name and value are used to differenciate users so you can have one cookie, but different values for each type of user on your site for example. They'll be served different cache files.
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 ###
......@@ -200,7 +205,7 @@ Cached files are served before almost all of WordPress is loaded. While that's g
This plugin caches entire pages but some plugins think they can run PHP code every time a page loads. To fix this, the plugin needs to use Javascript/AJAX methods or the wpsc_cachedata filter described in the previous answer to update or display dynamic information.
### Why do my WP Super Cache plugins disappear when I upgrade the plugin? ###
WordPress deletes the plugin folder when it updates a plugin. This is the same with WP Super Cache so any modified files in wp-super-cache/plugins/ will be deleted. You can define the variable $wp_cache_plugins_dir in wp-config.php or wp-content/wp-cache-config.php and point it at a directory outside of the wp-super-cache folder. The plugin will look there for it's plugins.
WordPress deletes the plugin folder when it updates a plugin. This is the same with WP Super Cache so any modified files in wp-super-cache/plugins/ will be deleted. You can put your custom plugins in a different directory in a number of ways. You can define the variable $wp_cache_plugins_dir in wp-config.php or wp-content/wp-cache-config.php and point it at a directory outside of the wp-super-cache folder. The plugin will look there for it's plugins. Or if you distribute a plugin that needs to load early you can use the function `wpsc_add_plugin( $filename )` to add a new plugin wherever it may be. Use `wpsc_delete_plugin( $filename )` to remove the plugin file. See [#574](https://github.com/Automattic/wp-super-cache/pull/574/) or [this post](https://odd.blog/2017/10/25/writing-wp-super-cache-plugins/) on writing WP Super Cache plugins.
### What does the Cache Rebuild feature do? ###
When a visitor leaves a comment the cached file for that page is deleted and the next visitor recreates the cached page. A page takes time to load so what happens if it receives 100 visitors during this time? There won't be a cached page so WordPress will serve a fresh page for each user and the plugin will try to create a cached page for each of those 100 visitors causing a huge load on your server. This feature stops this happening. The cached page is not cleared when a comment is left. It is marked for rebuilding instead. The next visitor within the next 10 seconds will regenerate the cached page while the old page is served to the other 99 visitors. The page is eventually loaded by the first visitor and the cached page updated. See [this post](https://odd.blog/2009/01/23/wp-super-cache-089/) for more.
......@@ -261,6 +266,29 @@ Your theme is probably responsive which means it resizes the page to suit whatev
## Changelog ##
### 1.6.4 ###
* Changes between [1.6.3 and 1.6.4](https://github.com/Automattic/wp-super-cache/compare/1.6.3...1.6.4)
* Fixes for WP-CLI (#587) (#592)
* Bumped the minimum WordPress version to 3.1 to use functions introduced then. (#591)
* Fixes to wpsc_post_transition to avoid a fatal error using get_sample_permalink. (#595)
* Fixed the admin bar "Delete Cache" link. (#589)
* Fixed the headings used in the settings page. (#597)
### 1.6.3 ###
* Changes between [1.6.2 and 1.6.3](https://github.com/Automattic/wp-super-cache/compare/1.6.2...1.6.3)
* Added cookie helper functions (#580)
* Added plugin helper functions (#574)
* Added actions to modify cookie and plugin lists. (#582)
* Really disable garbage collection when timeout = 0 (#571)
* Added warnings about DISABLE_WP_CRON (#575)
* Don't clean expired cache files after preload if garbage collection is disabled (#572)
* On preload, if deleting a post don't delete the sub directories if it's the homepage. (#573)
* Fix generation of semaphores when using WP CLI (#576)
* Fix deleting from the admin bar (#578)
* Avoid a strpos() warning. (#579)
* Improve deleting of cache in edit/delete/publish actions (#577)
* Fixes to headers code (#496)
### 1.6.2 ###
* Fixed serving expired supercache files (#562)
* Write directly to the config file to avoid permission problems with wp-content. (#563)
......@@ -663,4 +691,4 @@ Your theme is probably responsive which means it resizes the page to suit whatev
## Upgrade Notice ##
Fix problems writing to the config file for some users.
Bug fixes
<?php
if ( false == isset( $_SERVER['HTTP_HOST'] ) ) {
global $WPSC_HTTP_HOST, $blogcacheid;
if ( ! empty( $_SERVER['HTTP_HOST'] ) ) {
$WPSC_HTTP_HOST = htmlentities( $_SERVER['HTTP_HOST'] );
} elseif ( PHP_SAPI === 'cli' && function_exists( 'get_option' ) ) {
$WPSC_HTTP_HOST = (string) parse_url( get_option( 'home' ), PHP_URL_HOST );
} else {
$cache_enabled = false;
$WPSC_HTTP_HOST = '';
} else {
$WPSC_HTTP_HOST = htmlentities( $_SERVER['HTTP_HOST'] );
}
// We want to be able to identify each blog in a WordPress MU install
......@@ -17,7 +21,7 @@ if ( ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == tr
$base = '';
}
$request_uri = str_replace( '..', '', preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI'] ) );
if ( strpos( $request_uri, '/', 1 ) ) {
if ( strlen( $request_uri ) > 0 && strpos( $request_uri, '/', 1 ) ) {
if ( $base == '/' ) {
$blogcacheid = substr( $request_uri, 1, strpos( $request_uri, '/', 1 ) - 1 );
} else {
......
......@@ -49,6 +49,28 @@ if ( is_array( $plugins ) ) {
}
}
if ( isset( $wpsc_plugins ) && is_array( $wpsc_plugins ) ) {
foreach( $wpsc_plugins as $plugin_file ) {
if ( file_exists( ABSPATH . $plugin_file ) ) {
include_once( ABSPATH . $plugin_file );
}
}
}
if (
file_exists( WPCACHEHOME . '../wp-super-cache-plugins/' ) &&
is_dir( WPCACHEHOME . '../wp-super-cache-plugins/' )
) {
$plugins = glob( WPCACHEHOME . '../wp-super-cache-plugins/*.php' );
if ( is_array( $plugins ) ) {
foreach ( $plugins as $plugin ) {
if ( is_file( $plugin ) ) {
require_once $plugin;
}
}
}
}
$wp_start_time = microtime();
if ( $wp_cache_not_logged_in && wp_cache_get_cookies_values() ) {
......
......@@ -120,7 +120,7 @@ function wp_cache_serve_cache_file() {
} elseif ( isset( $wpsc_save_headers ) && $wpsc_save_headers ) {
wp_cache_debug( 'Saving headers. Cannot serve a supercache file.' );
return false;
} elseif ( ( filemtime( $file ) + $cache_max_time ) < time() ) {
} elseif ( $cache_max_time > 0 && ( filemtime( $file ) + $cache_max_time ) < time() ) {
wp_cache_debug( sprintf( "Cache has expired and is older than %d seconds old.", $cache_max_time ) );
return false;
}
......@@ -196,17 +196,15 @@ function wp_cache_serve_cache_file() {
// don't try to match modified dates if using dynamic code.
if ( $wp_cache_mfunc_enabled == 0 && $wp_supercache_304 ) {
if ( function_exists( 'apache_request_headers' ) ) {
$request = apache_request_headers();
$remote_mod_time = ( isset ( $request[ 'If-Modified-Since' ] ) ) ? $request[ 'If-Modified-Since' ] : null;
} else {
if ( isset( $_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ] ) )
$remote_mod_time = $_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ];
else
$remote_mod_time = null;
$headers = apache_request_headers();
$remote_mod_time = isset ( $headers['If-Modified-Since'] ) ? $headers['If-Modified-Since'] : null;
if ( is_null( $remote_mod_time ) && isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
$remote_mod_time = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
}
$local_mod_time = gmdate("D, d M Y H:i:s",filemtime( $file )).' GMT';
if ( !is_null($remote_mod_time) && $remote_mod_time == $local_mod_time ) {
if ( ! is_null( $remote_mod_time ) && $remote_mod_time == $local_mod_time ) {
header( $_SERVER[ 'SERVER_PROTOCOL' ] . " 304 Not Modified" );
exit();
}
......@@ -322,6 +320,7 @@ function wp_cache_late_loader() {
}
function wp_cache_get_cookies_values() {
global $wpsc_cookies;
static $string = '';
if ( $string != '' ) {
......@@ -350,6 +349,20 @@ function wp_cache_get_cookies_values() {
// If you use this hook, make sure you update your .htaccess rules with the same conditions
$string = do_cacheaction( 'wp_cache_get_cookies_values', $string );
if (
isset( $wpsc_cookies ) &&
is_array( $wpsc_cookies ) &&
! empty( $wpsc_cookies )
) {
foreach( $wpsc_cookies as $name ) {
if ( isset( $_COOKIE[ $name ] ) ) {
wp_cache_debug( "wp_cache_get_cookies_values - found extra cookie: $name" );
$string .= $name . "=" . $_COOKIE[ $name ] . ",";
}
}
}
if ( $string != '' )
$string = md5( $string );
......@@ -698,9 +711,10 @@ function wpsc_delete_files( $dir, $delete = true ) {
}
}
$orig_dir = $dir;
$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: ' . $orig_dir );
return false;
}
......@@ -1340,15 +1354,21 @@ function wpcache_logged_in_message() {
function wp_cache_user_agent_is_rejected() {
global $cache_rejected_user_agent;
if (!function_exists('apache_request_headers')) return false;
if ( empty( $cache_rejected_user_agent ) || ! is_array( $cache_rejected_user_agent ) ) {
return false;
}
$headers = apache_request_headers();
if (!isset($headers["User-Agent"])) return false;
if ( false == is_array( $cache_rejected_user_agent ) )
if ( empty( $headers['User-Agent'] ) ) {
return false;
foreach ($cache_rejected_user_agent as $expr) {
if (strlen($expr) > 0 && stristr($headers["User-Agent"], $expr))
}
foreach ( $cache_rejected_user_agent as $user_agent ) {
if ( ! empty( $user_agent ) && stristr( $headers['User-Agent'], $user_agent ) ) {
return true;
}
}
return false;
}
......@@ -2325,6 +2345,11 @@ function wp_cache_rebuild_or_delete( $file ) {
function wp_cache_phase2_clean_expired( $file_prefix, $force = false ) {
global $cache_path, $cache_max_time, $blog_cache_dir, $wp_cache_preload_on;
if ( $cache_max_time == 0 ) {
wp_cache_debug( "wp_cache_phase2_clean_expired: disabled because GC disabled.", 2 );
return false;
}
clearstatcache();
if( !wp_cache_writers_entry() )
return false;
......@@ -2662,6 +2687,10 @@ function wpsc_delete_post_archives( $post ) {
}
function wpsc_delete_cats_tags( $post ) {
if ( function_exists( '_deprecated_function' ) ) {
_deprecated_function( __FUNCTION__, 'WP Super Cache 1.6.3', 'wpsc_delete_post_archives' );
}
$post = get_post($post);
$categories = get_the_category($post->ID);
if ( $categories ) {
......@@ -2688,32 +2717,46 @@ function wpsc_delete_cats_tags( $post ) {
}
function wpsc_post_transition( $new_status, $old_status, $post ) {
if (
($old_status == 'publish' && $new_status != 'publish' ) // post unpublished
||
($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 );
$ptype = is_object( $post ) ? get_post_type_object( $post->post_type ) : null;
if ( empty( $ptype ) || ! $ptype->public ) {
return;
}
if ( $old_status === 'publish' && $new_status !== 'publish' ) { // post unpublished
if ( ! function_exists( 'get_sample_permalink' ) ) {
require_once( ABSPATH . 'wp-admin/includes/post.php' );
}
list( $permalink, $post_name ) = get_sample_permalink( $post );
$post_url = str_replace( array( "%postname%", "%pagename%" ), $post->post_name, $permalink );
}
elseif ( $old_status !== 'publish' && $new_status === 'publish' ) { // post published
wp_cache_post_edit( $post->ID );
return;
}
if ( ! empty( $post_url ) ) {
wp_cache_debug( 'wpsc_post_transition: deleting cache of post: ' . $post_url );
wpsc_delete_url_cache( $post_url );
wpsc_delete_post_archives( $post );
}
}
/* check if we want to clear out all cached files on post updates, otherwise call standard wp_cache_post_change() */
function wp_cache_post_edit($post_id) {
function wp_cache_post_edit( $post_id ) {
global $wp_cache_clear_on_post_edit, $cache_path, $blog_cache_dir, $wp_cache_object_cache;
static $last_post_edited = -1;
if ( $post_id == $last_post_edited ) {
wp_cache_debug( "wp_cache_post_edit: Already processed post $post_id.", 4 );
$action = current_filter();
wp_cache_debug( "wp_cache_post_edit(${action}): Already processed post $post_id.", 4 );
return $post_id;
}
$post = get_post( $post_id );
if ( is_object( $post ) == false )
if ( ! is_object( $post ) || 'auto-draft' === $post->post_status ) {
return $post_id;
}
// Some users are inexplicibly seeing this error on scheduled posts.
// define this constant to disable the post status check.
......@@ -2733,8 +2776,10 @@ function wp_cache_post_edit($post_id) {
prune_super_cache( get_supercache_dir(), true );
}
} else {
wp_cache_debug( "wp_cache_post_edit: Clearing cache for post $post_id on post edit.", 2 );
$action = current_filter();
wp_cache_debug( "wp_cache_post_edit: Clearing cache for post $post_id on ${action}", 2 );
wp_cache_post_change( $post_id );
wpsc_delete_post_archives( $post_id ); // delete related archive pages.
}
}
......@@ -2776,7 +2821,8 @@ function wp_cache_post_change( $post_id ) {
static $last_processed = -1;
if ( $post_id == $last_processed ) {
wp_cache_debug( "wp_cache_post_change: Already processed post $post_id.", 4 );
$action = current_filter();
wp_cache_debug( "wp_cache_post_change(${action}): Already processed post $post_id.", 4 );
return $post_id;
}
$post = get_post( $post_id );
......@@ -2834,10 +2880,17 @@ function wp_cache_post_change( $post_id ) {
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 );
$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 ) );
wpsc_rebuild_files( $dir . $permalink );
do_action( 'gc_cache', 'prune', $permalink );
/**
* It's possible that page_for_posts is zero.
* Quick fix to reduce issues in debugging.
*/
wp_cache_debug( 'Post change: page_for_posts ' . get_option( 'page_for_posts' ), 4 );
if ( get_option( 'page_for_posts' ) ) {
$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 ) );
wpsc_rebuild_files( $dir . $permalink );
do_action( 'gc_cache', 'prune', $permalink );
}
}
} else {
wp_cache_debug( 'wp_cache_post_change: not deleting all pages.', 4 );
......@@ -3029,4 +3082,23 @@ function wp_cache_gc_watcher() {
}
}
?>
if ( ! function_exists( 'apache_request_headers' ) ) {
/**
* A fallback for get request headers.
* Based on comments from http://php.net/manual/en/function.apache-request-headers.php
*
* @return array List of request headers
*/
function apache_request_headers() {
$headers = array();
foreach ( array_keys( $_SERVER ) as $skey ) {
if ( 0 === strpos( $skey, 'HTTP_' ) ) {
$header = implode( '-', array_map( 'ucfirst', array_slice( explode( '_', strtolower( $skey ) ) , 1 ) ) );
$headers[ $header ] = $_SERVER[ $skey ];
}
}
return $headers;
}
}
......@@ -3,7 +3,7 @@
Plugin Name: WP Super Cache
Plugin URI: https://wordpress.org/plugins/wp-super-cache/
Description: Very fast caching plugin for WordPress.
Version: 1.6.2
Version: 1.6.4
Author: Automattic
Author URI: https://automattic.com/
License: GPL2+
......@@ -65,9 +65,22 @@ 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 $super_cache_enabled, $cache_enabled, $wp_cache_mod_rewrite, $wp_cache_home_path, $cache_path, $file_prefix;
global $wp_cache_mutex_disabled, $mutex_filename, $sem_id, $wp_super_cache_late_init;
global $cache_compression, $cache_max_time, $wp_cache_shutdown_gc, $cache_rebuild_files;
global $wp_super_cache_debug, $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file;
global $wp_cache_debug_log, $wp_cache_debug_ip, $wp_cache_debug_username, $wp_cache_debug_email;
global $cache_time_interval, $cache_scheduled_time, $cache_schedule_interval, $cache_schedule_type, $cache_gc_email_me;
global $wp_cache_preload_on, $wp_cache_preload_interval, $wp_cache_preload_posts, $wp_cache_preload_taxonomies;
global $wp_cache_preload_email_me, $wp_cache_preload_email_volume;
global $wp_cache_mobile, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes;
global $wp_cache_config_file, $wp_cache_config_file_sample;
// WP-CLI: Hotfix for $blog_cache_dir for single site. It'll be removed after merging #590
if ( empty( $GLOBALS['blog_cache_dir'] ) && ! is_multisite() ) {
$GLOBALS['blog_cache_dir'] = $cache_path;
}
if( !@include($wp_cache_config_file) ) {
get_wpcachehome();
$wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
......@@ -82,9 +95,11 @@ if ( class_exists( 'WP_REST_Controller' ) ) {
}
function wp_super_cache_init_action() {
load_plugin_textdomain( 'wp-super-cache', false, basename( dirname( __FILE__ ) ) . '/languages' );
wpsc_register_post_hooks();
}
add_action( 'init', 'wp_super_cache_init_action' );
......@@ -222,7 +237,7 @@ function wp_cache_manager_error_checks() {
return false;
if ( version_compare( PHP_VERSION, '5.3.0', '<' ) && ( 1 == ini_get( 'safe_mode' ) || "on" == strtolower( ini_get( 'safe_mode' ) ) ) ) {
echo '<div class="notice notice-error"><h3>' . __( 'Warning! PHP Safe Mode Enabled!', 'wp-super-cache' ) . '</h3><p>' .
echo '<div class="notice notice-error"><h4>' . __( 'Warning! PHP Safe Mode Enabled!', 'wp-super-cache' ) . '</h4><p>' .
__( 'You may experience problems running this plugin because SAFE MODE is enabled.', 'wp-super-cache' ) . '<br />';
......@@ -236,20 +251,26 @@ function wp_cache_manager_error_checks() {
}
if ( '' == get_option( 'permalink_structure' ) ) {
echo '<div class="notice notice-error"><h3>' . __( 'Permlink Structure Error', 'wp-super-cache' ) . '</h3>';
echo '<div class="notice notice-error"><h4>' . __( 'Permlink Structure Error', 'wp-super-cache' ) . '</h4>';
echo "<p>" . __( 'A custom url or permalink structure is required for this plugin to work correctly. Please go to the <a href="options-permalink.php">Permalinks Options Page</a> to configure your permalinks.', 'wp-super-cache' ) . "</p>";
echo '</div>';
return false;
}
if( $wp_cache_debug || !$wp_cache_cron_check ) {
if( function_exists( "wp_remote_get" ) == false ) {
if ( $wp_cache_debug || ! $wp_cache_cron_check ) {
if ( defined( 'DISABLE_WP_CRON' ) && constant( 'DISABLE_WP_CRON' ) ) {
?>
<div class="notice notice-error"><h4><?php _e( 'CRON System Disabled', 'wp-super-cache' ); ?></h4>
<p><?php _e( 'The WordPress CRON jobs system is disabled. This means the garbage collection system will not work unless you run the CRON system manually.', 'wp-super-cache' ); ?></p>
</div>
<?php
} elseif ( function_exists( "wp_remote_get" ) == false ) {
$hostname = str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'siteurl' ) ) );
if( strpos( $hostname, '/' ) )
$hostname = substr( $hostname, 0, strpos( $hostname, '/' ) );
$ip = gethostbyname( $hostname );
if( substr( $ip, 0, 3 ) == '127' || substr( $ip, 0, 7 ) == '192.168' ) {
?><div class="notice notice-warning"><h3><?php printf( __( 'Warning! Your hostname "%s" resolves to %s', 'wp-super-cache' ), $hostname, $ip ); ?></h3>
?><div class="notice notice-warning"><h4><?php printf( __( 'Warning! Your hostname "%s" resolves to %s', 'wp-super-cache' ), $hostname, $ip ); ?></h4>
<p><?php printf( __( 'Your server thinks your hostname resolves to %s. Some services such as garbage collection by this plugin, and WordPress scheduled posts may not operate correctly.', 'wp-super-cache' ), $ip ); ?></p>
<p><?php printf( __( 'Please see entry 16 in the <a href="%s">Troubleshooting section</a> of the readme.txt', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-super-cache/faq/' ); ?></p>
</div>
......@@ -263,7 +284,7 @@ function wp_cache_manager_error_checks() {
$cron = wp_remote_get($cron_url, array('timeout' => 0.01, 'blocking' => true));
if( is_array( $cron ) ) {
if( $cron[ 'response' ][ 'code' ] == '404' ) {
?><div class="notice notice-error"><h3>Warning! wp-cron.php not found!</h3>
?><div class="notice notice-error"><h4>Warning! wp-cron.php not found!</h4>
<p><?php _e( 'Unfortunately, WordPress cannot find the file wp-cron.php. This script is required for the correct operation of garbage collection by this plugin, WordPress scheduled posts as well as other critical activities.', 'wp-super-cache' ); ?></p>
<p><?php printf( __( 'Please see entry 16 in the <a href="%s">Troubleshooting section</a> of the readme.txt', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-super-cache/faq/' ); ?></p>
</div>
......@@ -294,7 +315,7 @@ function wp_cache_manager_error_checks() {
}
if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) {
?><div class="notice notice-warning"><h3><?php _e( 'Zlib Output Compression Enabled!', 'wp-super-cache' ); ?></h3>
?><div class="notice notice-warning"><h4><?php _e( 'Zlib Output Compression Enabled!', 'wp-super-cache' ); ?></h4>
<p><?php _e( 'PHP is compressing the data sent to the visitors of your site. Disabling this is recommended as the plugin caches the compressed output once instead of compressing the same page over and over again. Also see #21 in the Troubleshooting section. See <a href="http://php.net/manual/en/zlib.configuration.php">this page</a> for instructions on modifying your php.ini.', 'wp-super-cache' ); ?></p></div><?php
}
......@@ -305,14 +326,14 @@ function wp_cache_manager_error_checks() {
! got_mod_rewrite() &&
! $is_nginx
) {
?><div class="notice notice-warning"><h3><?php _e( 'Mod rewrite may not be installed!', 'wp-super-cache' ); ?></h3>
?><div class="notice notice-warning"><h4><?php _e( 'Mod rewrite may not be installed!', 'wp-super-cache' ); ?></h4>
<p><?php _e( 'It appears that mod_rewrite is not installed. Sometimes this check isn&#8217;t 100% reliable, especially if you are not using Apache. Please verify that the mod_rewrite module is loaded. It is required for serving Super Cache static files in expert mode. You will still be able to simple mode.', 'wp-super-cache' ); ?></p></div><?php
}
if( !is_writeable_ACLSafe( $wp_cache_config_file ) ) {
if ( !defined( 'SUBMITDISABLED' ) )
define( "SUBMITDISABLED", 'disabled style="color: #aaa" ' );
?><div class="notice notice-error"><h3><?php _e( 'Read Only Mode. Configuration cannot be changed.', 'wp-super-cache' ); ?></h3>
?><div class="notice notice-error"><h4><?php _e( 'Read Only Mode. Configuration cannot be changed.', 'wp-super-cache' ); ?></h4>
<p><?php printf( __( 'The WP Super Cache configuration file is <code>%s/wp-cache-config.php</code> and cannot be modified. That file must be writeable by the web server to make any changes.', 'wp-super-cache' ), WP_CONTENT_DIR ); ?>
<?php _e( 'A simple way of doing that is by changing the permissions temporarily using the CHMOD command or through your ftp client. Make sure it&#8217;s globally writeable and it should be fine.', 'wp-super-cache' ); ?></p>
<p><?php _e( '<a href="https://codex.wordpress.org/Changing_File_Permissions">This page</a> explains how to change file permissions.', 'wp-super-cache' ); ?></p>
......@@ -335,7 +356,7 @@ function wp_cache_manager_error_checks() {
$gc_flag = get_gc_flag();
if ( $dismiss_gc_warning == 0 ) {
if ( false == maybe_stop_gc( $gc_flag ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) {
?><div class="notice notice-warning"><h3><?php _e( 'Warning! Garbage collection is not scheduled!', 'wp-super-cache' ); ?></h3>
?><div class="notice notice-warning"><h4><?php _e( 'Warning! Garbage collection is not scheduled!', 'wp-super-cache' ); ?></h4>
<p><?php _e( 'Garbage collection by this plugin clears out expired and old cached pages on a regular basis. Use <a href="#expirytime">this form</a> to enable it.', 'wp-super-cache' ); ?> </p>
<form action="" method="POST">
<input type="hidden" name="action" value="dismiss_gc_warning" />
......@@ -362,7 +383,7 @@ function wp_cache_manager_error_checks() {
$wp_content_stat = stat(WP_CONTENT_DIR . '/');
$wp_content_mode = decoct( $wp_content_stat[ 'mode' ] & 0777 );
if( substr( $wp_content_mode, -2 ) == '77' ) {
?><div class="notice notice-warning"><h3><?php printf( __( 'Warning! %s is writeable!', 'wp-super-cache' ), WP_CONTENT_DIR ); ?></h3>
?><div class="notice notice-warning"><h4><?php printf( __( 'Warning! %s is writeable!', 'wp-super-cache' ), WP_CONTENT_DIR ); ?></h4>
<p><?php printf( __( 'You should change the permissions on %s and make it more restrictive. Use your ftp client, or the following command to fix things:', 'wp-super-cache' ), WP_CONTENT_DIR ); ?> <code>chmod 755 <?php echo WP_CONTENT_DIR; ?>/</code></p>
<p><?php _e( '<a href="https://codex.wordpress.org/Changing_File_Permissions">This page</a> explains how to change file permissions.', 'wp-super-cache' ); ?></p>
<form action="" method="POST">
......@@ -385,14 +406,14 @@ function wp_cache_manager_error_checks() {
}
$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>";
echo '<div class="notice notice-warning"><h4>' . __( 'Mobile rewrite rules detected', 'wp-super-cache' ) . "</h4>";
echo "<p>" . __( 'For best performance you should enable "Mobile device support" or delete the mobile rewrite rules in your .htaccess. Look for the 2 lines with the text "2.0\ MMP|240x320" and delete those.', 'wp-super-cache' ) . "</p><p>" . __( 'This will have no affect on ordinary users but mobile users will see uncached pages.', 'wp-super-cache' ) . "</p></div>";
} elseif ( $wp_cache_mod_rewrite && $cache_enabled && $wp_cache_mobile_enabled && $scrules != '' && (
( '' != $wp_cache_mobile_prefixes && false === strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_prefixes ), ' ' ) ) ) ||
( '' != $wp_cache_mobile_browsers && false === strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) ) ) )
) {
?>
<div class="notice notice-warning"><h3><?php _e( 'Rewrite rules must be updated', 'wp-super-cache' ); ?></h3>
<div class="notice notice-warning"><h4><?php _e( 'Rewrite rules must be updated', 'wp-super-cache' ); ?></h4>
<p><?php _e( 'The rewrite rules required by this plugin have changed or are missing. ', 'wp-super-cache' ); ?>
<?php _e( 'Mobile support requires extra rules in your .htaccess file, or you can set the plugin to simple mode. Here are your options (in order of difficulty):', 'wp-super-cache' ); ?>
<ol><li> <?php _e( 'Set the plugin to simple mode and enable mobile support.', 'wp-super-cache' ); ?></li>
......@@ -403,7 +424,7 @@ function wp_cache_manager_error_checks() {
}
if ( $cache_enabled && $super_cache_enabled && $wp_cache_mod_rewrite && $scrules == '' ) {
?><div class='notice notice-warning'><h3><?php _e( 'Rewrite rules must be updated', 'wp-super-cache' ); ?></h3>
?><div class='notice notice-warning'><h4><?php _e( 'Rewrite rules must be updated', 'wp-super-cache' ); ?></h4>
<p><?php _e( 'The rewrite rules required by this plugin have changed or are missing. ', 'wp-super-cache' ); ?>
<?php _e( 'Scroll down the Advanced Settings page and click the <strong>Update Mod_Rewrite Rules</strong> button.', 'wp-super-cache' ); ?></p></div><?php
}
......@@ -418,8 +439,8 @@ function wp_cache_manager_error_checks() {
}
}
if( isset( $missing_mods) && is_array( $missing_mods ) ) {
?><div class='notice notice-warning'><h3><?php _e( 'Missing Apache Modules', 'wp-super-cache' ); ?></h3>
<p><?php __( 'The following Apache modules are missing. The plugin will work in simple mode without them but in export mode, your visitors may see corrupted pages or out of date content however.', 'wp-super-cache' ); ?></p><?php
?><div class='notice notice-warning'><h4><?php _e( 'Missing Apache Modules', 'wp-super-cache' ); ?></h4>
<p><?php __( 'The following Apache modules are missing. The plugin will work in simple mode without them but in expert mode, your visitors may see corrupted pages or out of date content however.', 'wp-super-cache' ); ?></p><?php
echo "<ul>";
foreach( $missing_mods as $req => $desc ) {
echo "<li> $req - $desc</li>";
......@@ -438,7 +459,7 @@ function wp_cache_manager_error_checks() {
if ( isset( $disable_supercache_htaccess_warning ) == false )
$disable_supercache_htaccess_warning = false;
if ( ! $is_nginx && $dismiss_htaccess_warning == 0 && $wp_cache_mod_rewrite && $super_cache_enabled && $disable_supercache_htaccess_warning == false && get_option( 'siteurl' ) != get_option( 'home' ) ) {
?><div class="notice notice-info"><h3><?php _e( '.htaccess file may need to be moved', 'wp-super-cache' ); ?></h3>
?><div class="notice notice-info"><h4><?php _e( '.htaccess file may need to be moved', 'wp-super-cache' ); ?></h4>
<p><?php _e( 'It appears you have WordPress installed in a sub directory as described <a href="https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory">here</a>. Unfortunately, WordPress writes to the .htaccess in the install directory, not where your site is served from.<br />When you update the rewrite rules in this plugin you will have to copy the file to where your site is hosted. This will be fixed in the future.', 'wp-super-cache' ); ?></p>
<form action="" method="POST">
<input type="hidden" name="action" value="dismiss_htaccess_warning" />
......@@ -455,26 +476,40 @@ function wp_cache_manager_error_checks() {
}
add_filter( 'wp_super_cache_error_checking', 'wp_cache_manager_error_checks' );
/**
* Delete cache for a specific page.
*/
function admin_bar_delete_page() {
// Delete cache for a specific page
if ( function_exists('current_user_can') && false == current_user_can('delete_others_posts') )
if ( function_exists( 'current_user_can' ) && false == current_user_can( 'delete_others_posts' ) ) {
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 == '/' ) {
return false; // Directory not found. Probably not cached.
}
$supercachepath = realpath(get_supercache_dir());
}
$req_path = filter_input( INPUT_GET, 'path' );
$referer = wp_get_referer();
$valid_nonce = ( $req_path && isset( $_GET['_wpnonce'] ) ) ? wp_verify_nonce( $_GET['_wpnonce'], 'delete-cache' ) : false;
$path = $valid_nonce ? realpath( trailingslashit( get_supercache_dir() . str_replace( '..', '', preg_replace( '/:.*$/', '', $req_path ) ) ) ) : false;
if ( $path ) {
$path = trailingslashit( $path );
$supercachepath = realpath( get_supercache_dir() );
if ( false == wp_cache_confirm_delete( $path ) || substr( $path, 0, strlen( $supercachepath ) ) != $supercachepath ) {
die( "Could not delete directory" );
wp_die( 'Could not delete directory' );
}
wpsc_delete_files( $path );