WP Super Cache - Version 1.7.9

Version Description

Download this release

Release Info

Developer donncha
Plugin Icon 128x128 WP Super Cache
Version 1.7.9
Comparing to
See all releases

Code changes from version 1.7.8 to 1.7.9

inc/delete-cache-button.php CHANGED
@@ -1,4 +1,7 @@
1
  <?php
 
 
 
2
 
3
  /**
4
  * Adds "Delete Cache" button in WP Toolbar.
@@ -21,7 +24,7 @@ function wpsc_admin_bar_render( $wp_admin_bar ) {
21
  'id' => 'delete-cache',
22
  'title' => __( 'Delete Cache', 'wp-super-cache' ),
23
  'meta' => array( 'title' => __( 'Delete cache of the current page', 'wp-super-cache' ) ),
24
- 'href' => wp_nonce_url( admin_url( 'index.php?action=delcachepage&path=' . rawurlencode( $path ) ), 'delete-cache' )
25
  ) );
26
  }
27
 
@@ -31,7 +34,7 @@ function wpsc_admin_bar_render( $wp_admin_bar ) {
31
  'id' => 'delete-cache',
32
  'title' => __( 'Delete Cache', 'wp-super-cache' ),
33
  'meta' => array( 'title' => __( 'Delete Super Cache cached files', 'wp-super-cache' ) ),
34
- 'href' => wp_nonce_url( admin_url( 'index.php?admin=1&action=delcachepage&path=' . rawurlencode( trailingslashit( $path_to_home ) ) ), 'delete-cache' )
35
  ) );
36
  }
37
  }
@@ -41,6 +44,15 @@ function wpsc_delete_cache_scripts() {
41
  if ( ! is_user_logged_in() ) {
42
  return;
43
  }
 
 
 
 
 
 
 
 
 
44
  $path_to_home = rtrim( (string) parse_url( get_option( 'home' ), PHP_URL_PATH ), '/' );
45
 
46
  wp_enqueue_script( 'delete-cache-button', plugins_url( '/delete-cache-button.js', __FILE__ ), array('jquery'), '1.0', 1 );
@@ -58,26 +70,72 @@ function wpsc_delete_cache_scripts() {
58
  $path_to_home = '/';
59
  }
60
 
61
- $nonce = wp_create_nonce( 'delete-cache-' . rawurlencode( $path_to_home ) . '_' . $admin );
62
  wp_localize_script( 'delete-cache-button', 'wpsc_ajax', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'path' => $path_to_home, 'admin' => $admin, 'nonce' => $nonce ) );
63
  }
64
- add_action( 'wp_ajax_ajax-delete-cache', 'wpsc_admin_bar_delete_cache' );
65
- add_action( 'wp_enqueue_scripts', 'wpsc_delete_cache_scripts' );
66
  add_action( 'admin_enqueue_scripts', 'wpsc_delete_cache_scripts' );
67
 
68
  /**
69
  * Delete cache for a specific page.
70
  */
71
- function wpsc_admin_bar_delete_cache() {
72
  // response output
73
  header( "Content-Type: application/json" );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
 
75
  if ( ! current_user_can( 'delete_others_posts' ) ) {
76
- return json_encode( false );
77
  }
78
 
79
  $req_path = isset( $_POST['path'] ) ? sanitize_text_field( stripslashes( $_POST['path'] ) ) : '';
80
- $valid_nonce = ( $req_path && isset( $_POST['nonce'] ) ) ? wp_verify_nonce( $_POST['nonce'], 'delete-cache-' . rawurlencode( $_POST['path'] ) . '_' . $_POST['admin'] ) : false;
 
 
 
 
 
81
 
82
  $path = $valid_nonce ? realpath( trailingslashit( get_supercache_dir() . str_replace( '..', '', preg_replace( '/:.*$/', '', $req_path ) ) ) ) : false;
83
 
@@ -91,17 +149,16 @@ function wpsc_admin_bar_delete_cache() {
91
  $path = trailingslashit( $path );
92
  $supercachepath = realpath( get_supercache_dir() );
93
 
94
- if ( false === wp_cache_confirm_delete( $path ) ||
95
- 0 !== strpos( $path, $supercachepath )
96
- ) {
97
  wp_cache_debug( 'Could not delete directory: ' . $path );
98
- wp_die( json_encode( 'Could not delete directory' ) );
 
99
  }
100
 
101
  wp_cache_debug( 'Deleting cache files in directory: ' . $path );
102
  wpsc_delete_files( $path );
103
  return;
104
  } else {
105
- wp_cache_debug( 'Could not delete directory. It does not exist: ' . esc_attr( $_POST['path'] ) );
106
  }
107
  }
1
  <?php
2
+ if ( defined( 'WPSCDISABLEDELETEBUTTON' ) ) {
3
+ return;
4
+ }
5
 
6
  /**
7
  * Adds "Delete Cache" button in WP Toolbar.
24
  'id' => 'delete-cache',
25
  'title' => __( 'Delete Cache', 'wp-super-cache' ),
26
  'meta' => array( 'title' => __( 'Delete cache of the current page', 'wp-super-cache' ) ),
27
+ 'href' => wp_nonce_url( admin_url( 'index.php?action=delcachepage&path=' . rawurlencode( $path ) ), 'delete-cache-' . $path . '_0', 'nonce' )
28
  ) );
29
  }
30
 
34
  'id' => 'delete-cache',
35
  'title' => __( 'Delete Cache', 'wp-super-cache' ),
36
  'meta' => array( 'title' => __( 'Delete Super Cache cached files', 'wp-super-cache' ) ),
37
+ 'href' => wp_nonce_url( admin_url( 'index.php?admin=1&action=delcachepage&path=' . rawurlencode( trailingslashit( $path_to_home ) ) ), 'delete-cache-' . trailingslashit( $path_to_home ) . '_1', 'nonce' )
38
  ) );
39
  }
40
  }
44
  if ( ! is_user_logged_in() ) {
45
  return;
46
  }
47
+
48
+ if (
49
+ is_plugin_active( 'amp/amp.php' ) ||
50
+ ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() )
51
+ ) {
52
+ wp_cache_debug( 'AMP detected. Not loading Delete Cache button JavaScript.' );
53
+ return;
54
+ }
55
+
56
  $path_to_home = rtrim( (string) parse_url( get_option( 'home' ), PHP_URL_PATH ), '/' );
57
 
58
  wp_enqueue_script( 'delete-cache-button', plugins_url( '/delete-cache-button.js', __FILE__ ), array('jquery'), '1.0', 1 );
70
  $path_to_home = '/';
71
  }
72
 
73
+ $nonce = wp_create_nonce( 'delete-cache-' . $path_to_home . '_' . $admin );
74
  wp_localize_script( 'delete-cache-button', 'wpsc_ajax', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'path' => $path_to_home, 'admin' => $admin, 'nonce' => $nonce ) );
75
  }
76
+ add_action( 'wp_ajax_ajax-delete-cache', 'wpsc_admin_bar_delete_cache_ajax' );
 
77
  add_action( 'admin_enqueue_scripts', 'wpsc_delete_cache_scripts' );
78
 
79
  /**
80
  * Delete cache for a specific page.
81
  */
82
+ function wpsc_admin_bar_delete_cache_ajax() {
83
  // response output
84
  header( "Content-Type: application/json" );
85
+ if ( ! wpsc_delete_cache_directory() ) {
86
+ if ( defined( 'WPSCDELETEERROR' ) ) {
87
+ return json_decode( constant( 'WPSCDELETEERROR' ) );
88
+ } else {
89
+ return json_decode( false );
90
+ }
91
+ }
92
+ }
93
+
94
+ function wpsc_admin_bar_delete_cache() {
95
+ $referer = wp_get_referer();
96
+
97
+ if ( ! isset( $_GET['admin'] ) ) {
98
+ $_GET['admin'] = 0;
99
+ }
100
+
101
+ foreach( array( 'path', 'nonce', 'admin' ) as $part ) {
102
+ if ( isset( $_GET[ $part ] ) ) {
103
+ $_POST[ $part ] = $_GET[ $part ];
104
+ }
105
+ }
106
+ wpsc_delete_cache_directory();
107
+
108
+ $req_path = isset( $_POST['path'] ) ? sanitize_text_field( stripslashes( $_POST['path'] ) ) : '';
109
+ $valid_nonce = ( $req_path && isset( $_POST['nonce'] ) ) ? wp_verify_nonce( $_POST['nonce'], 'delete-cache-' . $_POST['path'] . '_' . $_POST['admin'] ) : false;
110
+
111
+ if ( $valid_nonce && $referer && $req_path && ( false !== stripos( $referer, $req_path ) || 0 === stripos( $referer, wp_login_url() ) ) ) {
112
+ if ( $_POST['admin'] ) {
113
+ wp_safe_redirect( $referer );
114
+ } else {
115
+ wp_safe_redirect( esc_url_raw( home_url( $req_path ) ) );
116
+ }
117
+ exit;
118
+ } else {
119
+ die( "Oops. Problem with nonce. Please delete cached page from settings page." );
120
+ }
121
+ }
122
+
123
+ if ( 'delcachepage' === filter_input( INPUT_GET, 'action' ) ) {
124
+ add_action( 'admin_init', 'wpsc_admin_bar_delete_cache' );
125
+ }
126
 
127
+ function wpsc_delete_cache_directory() {
128
  if ( ! current_user_can( 'delete_others_posts' ) ) {
129
+ return false;
130
  }
131
 
132
  $req_path = isset( $_POST['path'] ) ? sanitize_text_field( stripslashes( $_POST['path'] ) ) : '';
133
+ $valid_nonce = ( $req_path && isset( $_POST['nonce'] ) ) ? wp_verify_nonce( $_POST['nonce'], 'delete-cache-' . $_POST['path'] . '_' . $_POST['admin'] ) : false;
134
+
135
+ if ( ! $valid_nonce ) {
136
+ wp_cache_debug( 'wpsc_delete_cache_directory: nonce was not valid' );
137
+ return false;
138
+ }
139
 
140
  $path = $valid_nonce ? realpath( trailingslashit( get_supercache_dir() . str_replace( '..', '', preg_replace( '/:.*$/', '', $req_path ) ) ) ) : false;
141
 
149
  $path = trailingslashit( $path );
150
  $supercachepath = realpath( get_supercache_dir() );
151
 
152
+ if ( false === wp_cache_confirm_delete( $path ) || 0 !== strpos( $path, $supercachepath ) ) {
 
 
153
  wp_cache_debug( 'Could not delete directory: ' . $path );
154
+ define( 'WPSCDELETEERROR', 'Could not delete directory' );
155
+ return false;
156
  }
157
 
158
  wp_cache_debug( 'Deleting cache files in directory: ' . $path );
159
  wpsc_delete_files( $path );
160
  return;
161
  } else {
162
+ wp_cache_debug( 'wpsc_delete_cache_directory: Could not delete directory. It does not exist: ' . esc_attr( $_POST['path'] ) );
163
  }
164
  }
inc/preload-notification.js CHANGED
@@ -12,7 +12,7 @@ function load_preload_status() {
12
  jQuery.get({
13
  url: wpsc_preload_ajax.preload_permalink_url + '?' + Math.random(),
14
  success: function( response ) {
15
- jQuery( '#preload_status' ).html( response );
16
  }
17
  })
18
  }
12
  jQuery.get({
13
  url: wpsc_preload_ajax.preload_permalink_url + '?' + Math.random(),
14
  success: function( response ) {
15
+ jQuery( '#preload_status' ).text( response );
16
  }
17
  })
18
  }
partials/debug.php CHANGED
@@ -9,7 +9,7 @@ if ( ! isset( $wp_cache_debug_log ) || $wp_cache_debug_log == '' ) {
9
  extract( wpsc_create_debug_log() ); // $wp_cache_debug_log, $wp_cache_debug_username
10
  }
11
 
12
- $log_file_link = "<a href='" . site_url( str_replace( ABSPATH, '', "{$cache_path}view_{$wp_cache_debug_log}?wp-admin=1&wp-json=1&filter=" ) ) . "'>$wp_cache_debug_log</a>";
13
 
14
  if ( $wp_super_cache_debug == 1 ) {
15
  echo "<p>" . sprintf( __( 'Currently logging to: %s', 'wp-super-cache' ), $log_file_link ) . "</p>";
9
  extract( wpsc_create_debug_log() ); // $wp_cache_debug_log, $wp_cache_debug_username
10
  }
11
 
12
+ $log_file_link = "<a href='" . home_url( str_replace( $_SERVER['DOCUMENT_ROOT'], '', "{$cache_path}view_{$wp_cache_debug_log}?wp-admin=1&wp-json=1&filter=" ) ) . "'>$wp_cache_debug_log</a>";
13
 
14
  if ( $wp_super_cache_debug == 1 ) {
15
  echo "<p>" . sprintf( __( 'Currently logging to: %s', 'wp-super-cache' ), $log_file_link ) . "</p>";
partials/easy.php CHANGED
@@ -128,7 +128,9 @@ if ( is_multisite() && wpsupercache_site_admin() ) {
128
  <li><?php printf( __( '<a href="%s">Jetpack</a> provides everything you need to build a successful WordPress website including an image/photo CDN (free) and a video hosting service (paid).', 'wp-super-cache' ), 'https://jetpack.com/redirect/?source=jitm-wpsc-recommended' ); ?></li>
129
  <li><?php printf( __( '<a href="%s">Yahoo! Yslow</a> analyzes web pages and suggests ways to improve their performance based on a set of rules for high performance web pages. Also try the performance tools online at <a href="%s">GTMetrix</a>.', 'wp-super-cache' ), 'http://yslow.org/', 'https://gtmetrix.com/' ); ?></li>
130
  <li><?php printf( __( '<a href="%s">Use Google Libraries</a> allows you to load some commonly used Javascript libraries from Google webservers. Ironically, it may reduce your Yslow score.', 'wp-super-cache' ), 'https://wordpress.org/plugins/use-google-libraries/' ); ?></li>
 
131
  <li><?php printf( __( '<strong>Advanced users only:</strong> Install an object cache. Choose from <a href="%s">Memcached</a>, <a href="%s">XCache</a>, <a href="%s">eAcccelerator</a> and others.', 'wp-super-cache' ), 'https://wordpress.org/plugins/memcached/', 'https://neosmart.net/WP/XCache/', 'https://neosmart.net/WP/eAccelerator/' ); ?></li>
132
  <li><?php printf( __( '<a href="%s">WP Crontrol</a> is a useful plugin to use when trying to debug garbage collection and preload problems.', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-crontrol/' ); ?></li>
133
  </ul>
 
134
 
128
  <li><?php printf( __( '<a href="%s">Jetpack</a> provides everything you need to build a successful WordPress website including an image/photo CDN (free) and a video hosting service (paid).', 'wp-super-cache' ), 'https://jetpack.com/redirect/?source=jitm-wpsc-recommended' ); ?></li>
129
  <li><?php printf( __( '<a href="%s">Yahoo! Yslow</a> analyzes web pages and suggests ways to improve their performance based on a set of rules for high performance web pages. Also try the performance tools online at <a href="%s">GTMetrix</a>.', 'wp-super-cache' ), 'http://yslow.org/', 'https://gtmetrix.com/' ); ?></li>
130
  <li><?php printf( __( '<a href="%s">Use Google Libraries</a> allows you to load some commonly used Javascript libraries from Google webservers. Ironically, it may reduce your Yslow score.', 'wp-super-cache' ), 'https://wordpress.org/plugins/use-google-libraries/' ); ?></li>
131
+ <li><?php printf( __( '<a href="%s">commonWP</a> does the same job as "Use Google Libraries" and offloads some commonly used static files to an external CDN.', 'wp-super-cache' ), 'https://wordpress.org/plugins/commonwp/' ); ?></li>
132
  <li><?php printf( __( '<strong>Advanced users only:</strong> Install an object cache. Choose from <a href="%s">Memcached</a>, <a href="%s">XCache</a>, <a href="%s">eAcccelerator</a> and others.', 'wp-super-cache' ), 'https://wordpress.org/plugins/memcached/', 'https://neosmart.net/WP/XCache/', 'https://neosmart.net/WP/eAccelerator/' ); ?></li>
133
  <li><?php printf( __( '<a href="%s">WP Crontrol</a> is a useful plugin to use when trying to debug garbage collection and preload problems.', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-crontrol/' ); ?></li>
134
  </ul>
135
+ <p><?php _e( "* The links above (apart from Jetpack) go to websites outside the author's control. Caution is advised when testing any new software.", 'wp-super-cache' ); ?></p>
136
 
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  * Contributors: donncha, automattic
3
  * Tags: performance, caching, wp-cache, wp-super-cache, cache
4
  * Tested up to: 6.0
5
- * Stable tag: 1.7.8
6
  * Requires at least: 3.1
7
  * Requires PHP: 5.2.4
8
  * License: GPLv2 or later
@@ -269,6 +269,10 @@ Your theme is probably responsive which means it resizes the page to suit whatev
269
 
270
  ## Changelog ##
271
 
 
 
 
 
272
  ### 1.7.8 ###
273
  * Change the admin bar "Delete Cache" button into an AJAX link #808 #810
274
  * Fix link to log file in custom WordPress structure #807
@@ -792,4 +796,4 @@ Your theme is probably responsive which means it resizes the page to suit whatev
792
 
793
 
794
  ## Upgrade Notice ##
795
- Misc fixes and new features
2
  * Contributors: donncha, automattic
3
  * Tags: performance, caching, wp-cache, wp-super-cache, cache
4
  * Tested up to: 6.0
5
+ * Stable tag: 1.7.9
6
  * Requires at least: 3.1
7
  * Requires PHP: 5.2.4
8
  * License: GPLv2 or later
269
 
270
  ## Changelog ##
271
 
272
+ ### 1.7.9 ###
273
+ * Fix nonces used by "Delete Cache" button and remove JS from it on the frontend admin bar.
274
+ * Define the constant WPSCDISABLEDELETEBUTTON to disable the "Delete Cache" button in the admin bar.
275
+
276
  ### 1.7.8 ###
277
  * Change the admin bar "Delete Cache" button into an AJAX link #808 #810
278
  * Fix link to log file in custom WordPress structure #807
796
 
797
 
798
  ## Upgrade Notice ##
799
+ Misc fixes
wp-cache.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP Super Cache
4
  Plugin URI: https://wordpress.org/plugins/wp-super-cache/
5
  Description: Very fast caching plugin for WordPress.
6
- Version: 1.7.8
7
  Author: Automattic
8
  Author URI: https://automattic.com/
9
  License: GPL2+
3
  Plugin Name: WP Super Cache
4
  Plugin URI: https://wordpress.org/plugins/wp-super-cache/
5
  Description: Very fast caching plugin for WordPress.
6
+ Version: 1.7.9
7
  Author: Automattic
8
  Author URI: https://automattic.com/
9
  License: GPL2+