WP Super Cache - Version 1.5.0

Version Description

Added REST API settings endpoints, simplified settings, reorganised cache files. Lots of bug fixes.

=

Download this release

Release Info

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

Code changes from version 1.4.9 to 1.5.0

advanced-cache.php CHANGED
@@ -8,8 +8,9 @@ function wpcache_broken_message() {
8
  $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
9
  $xmlrpc_request = defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST;
10
  $rest_request = defined( 'REST_REQUEST' ) && REST_REQUEST;
 
11
 
12
- $skip_output = ( $doing_ajax || $xmlrpc_request || $rest_request );
13
  if ( false == strpos( $_SERVER[ 'REQUEST_URI' ], 'wp-admin' ) && !$skip_output ) {
14
  echo "<!-- WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory. -->";
15
  }
8
  $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
9
  $xmlrpc_request = defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST;
10
  $rest_request = defined( 'REST_REQUEST' ) && REST_REQUEST;
11
+ $robots_request = strpos( $_SERVER[ 'REQUEST_URI' ], 'robots.txt' ) != false;
12
 
13
+ $skip_output = ( $doing_ajax || $xmlrpc_request || $rest_request || $robots_request);
14
  if ( false == strpos( $_SERVER[ 'REQUEST_URI' ], 'wp-admin' ) && !$skip_output ) {
15
  echo "<!-- WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory. -->";
16
  }
ossdl-cdn.php CHANGED
@@ -4,8 +4,8 @@
4
 
5
  /* Set up some defaults */
6
  if ( get_option( 'ossdl_off_cdn_url' ) == false )
7
- add_option('ossdl_off_cdn_url', get_option('siteurl'));
8
- $ossdl_off_blog_url = get_option('siteurl');
9
  $ossdl_off_cdn_url = trim( get_option('ossdl_off_cdn_url') );
10
  if ( get_option( 'ossdl_off_include_dirs' ) == false )
11
  add_option('ossdl_off_include_dirs', 'wp-content,wp-includes');
@@ -20,7 +20,7 @@ if ( !is_array( $arr_of_excludes ) )
20
  if ( get_option( 'ossdl_cname' ) == false )
21
  add_option('ossdl_cname', '');
22
  $ossdl_cname = trim(get_option('ossdl_cname'));
23
- $ossdl_https = trim(get_option('ossdl_https'));
24
  $arr_of_cnames = array_map('trim', explode(',', $ossdl_cname));
25
  if ($arr_of_cnames[0] == '') $arr_of_cnames = array();
26
 
@@ -123,10 +123,14 @@ if ( false == isset( $ossdlcdn ) )
123
  if ( $ossdlcdn == 1 )
124
  add_action('init', 'do_scossdl_off_ob_start');
125
 
126
- function scossdl_off_options() {
127
- global $ossdlcdn, $wp_cache_config_file;
128
-
129
  $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
 
 
 
 
 
 
130
  if ( $valid_nonce && isset($_POST['action']) && ( $_POST['action'] == 'update_ossdl_off' )){
131
  update_option('ossdl_off_cdn_url', $_POST['ossdl_off_cdn_url']);
132
  update_option('ossdl_off_include_dirs', $_POST['ossdl_off_include_dirs'] == '' ? 'wp-content,wp-includes' : $_POST['ossdl_off_include_dirs']);
@@ -142,20 +146,27 @@ function scossdl_off_options() {
142
  }
143
  wp_cache_replace_line('^ *\$ossdlcdn', "\$ossdlcdn = $ossdlcdn;", $wp_cache_config_file);
144
  }
 
 
 
 
 
 
 
145
  $example_cdn_uri = str_replace( 'http://', 'http://cdn.', str_replace( 'www.', '', get_option( 'siteurl' ) ) );
146
  $example_cnames = str_replace( 'http://cdn.', 'http://cdn1.', $example_cdn_uri );
147
  $example_cnames .= ',' . str_replace( 'http://cdn.', 'http://cdn2.', $example_cdn_uri );
148
  $example_cnames .= ',' . str_replace( 'http://cdn.', 'http://cdn3.', $example_cdn_uri );
149
 
150
- $example_cdn_uri = get_option('ossdl_off_cdn_url') == get_option('siteurl') ? $example_cdn_uri : get_option('ossdl_off_cdn_url');
151
- $example_cdn_uri .= '/wp-includes/js/prototype.js';
152
  ?>
153
- <p><?php _e( 'Your website probably uses lots of static files. Image, Javascript and CSS files are usually static files that could just as easily be served from another site or CDN. Therefore, this plugin replaces any links in the <code>wp-content</code> and <code>wp-includes</code> directories (except for PHP files) on your site with the URL you provide below. That way you can either copy all the static content to a dedicated host or mirror the files to a CDN by <a href="http://knowledgelayer.softlayer.com/questions/365/How+does+Origin+Pull+work%3F" target="_blank">origin pull</a>.', 'wp-super-cache' ); ?></p>
154
  <p><?php printf( __( '<strong style="color: red">WARNING:</strong> Test some static urls e.g., %s to ensure your CDN service is fully working before saving changes.', 'wp-super-cache' ), '<code>' . $example_cdn_uri . '</code>' ); ?></p>
155
  <p><?php _e( 'You can define different CDN URLs for each site on a multsite network.', 'wp-super-cache' ); ?></p>
156
  <p><form method="post" action="">
157
  <?php wp_nonce_field('wp-cache'); ?>
158
- <table class="form-table"><tbod>
159
  <tr valign="top">
160
  <td style='text-align: right'>
161
  <input id='ossdlcdn' type="checkbox" name="ossdlcdn" value="1" <?php if ( $ossdlcdn ) echo "checked=1"; ?> />
@@ -195,7 +206,7 @@ function scossdl_off_options() {
195
  </tr>
196
  </tbody></table>
197
  <input type="hidden" name="action" value="update_ossdl_off" />
198
- <p class="submit"><input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /></p>
199
  </form></p>
200
  <p><?php _e( 'CDN functionality provided by <a href="http://wordpress.org/plugins/ossdl-cdn-off-linker/">OSSDL CDN Off Linker</a> by <a href="http://mark.ossdl.de/">Mark Kubacki</a>', 'wp-super-cache' ); ?></p>
201
  <?php
4
 
5
  /* Set up some defaults */
6
  if ( get_option( 'ossdl_off_cdn_url' ) == false )
7
+ add_option('ossdl_off_cdn_url', get_home_url() );
8
+ $ossdl_off_blog_url = apply_filters( 'ossdl_off_blog_url', get_home_url() );
9
  $ossdl_off_cdn_url = trim( get_option('ossdl_off_cdn_url') );
10
  if ( get_option( 'ossdl_off_include_dirs' ) == false )
11
  add_option('ossdl_off_include_dirs', 'wp-content,wp-includes');
20
  if ( get_option( 'ossdl_cname' ) == false )
21
  add_option('ossdl_cname', '');
22
  $ossdl_cname = trim(get_option('ossdl_cname'));
23
+ $ossdl_https = intval(get_option('ossdl_https'));
24
  $arr_of_cnames = array_map('trim', explode(',', $ossdl_cname));
25
  if ($arr_of_cnames[0] == '') $arr_of_cnames = array();
26
 
123
  if ( $ossdlcdn == 1 )
124
  add_action('init', 'do_scossdl_off_ob_start');
125
 
126
+ if ( function_exists( 'wp_verify_nonce' ) )
 
 
127
  $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
128
+ else
129
+ $valid_nonce = false;
130
+
131
+ function scossdl_off_update() {
132
+ global $ossdlcdn, $wp_cache_config_file, $valid_nonce;
133
+
134
  if ( $valid_nonce && isset($_POST['action']) && ( $_POST['action'] == 'update_ossdl_off' )){
135
  update_option('ossdl_off_cdn_url', $_POST['ossdl_off_cdn_url']);
136
  update_option('ossdl_off_include_dirs', $_POST['ossdl_off_include_dirs'] == '' ? 'wp-content,wp-includes' : $_POST['ossdl_off_include_dirs']);
146
  }
147
  wp_cache_replace_line('^ *\$ossdlcdn', "\$ossdlcdn = $ossdlcdn;", $wp_cache_config_file);
148
  }
149
+ }
150
+
151
+ function scossdl_off_options() {
152
+ global $ossdlcdn, $wp_cache_config_file, $valid_nonce;
153
+
154
+ scossdl_off_update();
155
+
156
  $example_cdn_uri = str_replace( 'http://', 'http://cdn.', str_replace( 'www.', '', get_option( 'siteurl' ) ) );
157
  $example_cnames = str_replace( 'http://cdn.', 'http://cdn1.', $example_cdn_uri );
158
  $example_cnames .= ',' . str_replace( 'http://cdn.', 'http://cdn2.', $example_cdn_uri );
159
  $example_cnames .= ',' . str_replace( 'http://cdn.', 'http://cdn3.', $example_cdn_uri );
160
 
161
+ $example_cdn_uri = get_option('ossdl_off_cdn_url') == get_home_url() ? $example_cdn_uri : get_option('ossdl_off_cdn_url');
162
+ $example_cdn_uri .= '/wp-includes/js/jquery/jquery-migrate.js';
163
  ?>
164
+ <p><?php _e( 'Your website probably uses lots of static files. Image, Javascript and CSS files are usually static files that could just as easily be served from another site or CDN. Therefore, this plugin replaces any links in the <code>wp-content</code> and <code>wp-includes</code> directories (except for PHP files) on your site with the URL you provide below. That way you can either copy all the static content to a dedicated host or mirror the files to a CDN by <a href="https://knowledgelayer.softlayer.com/faq/how-does-origin-pull-work" target="_blank">origin pull</a>.', 'wp-super-cache' ); ?></p>
165
  <p><?php printf( __( '<strong style="color: red">WARNING:</strong> Test some static urls e.g., %s to ensure your CDN service is fully working before saving changes.', 'wp-super-cache' ), '<code>' . $example_cdn_uri . '</code>' ); ?></p>
166
  <p><?php _e( 'You can define different CDN URLs for each site on a multsite network.', 'wp-super-cache' ); ?></p>
167
  <p><form method="post" action="">
168
  <?php wp_nonce_field('wp-cache'); ?>
169
+ <table class="form-table"><tbody>
170
  <tr valign="top">
171
  <td style='text-align: right'>
172
  <input id='ossdlcdn' type="checkbox" name="ossdlcdn" value="1" <?php if ( $ossdlcdn ) echo "checked=1"; ?> />
206
  </tr>
207
  </tbody></table>
208
  <input type="hidden" name="action" value="update_ossdl_off" />
209
+ <p class="submit"><input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'wp-super-cache' ) ?>" /></p>
210
  </form></p>
211
  <p><?php _e( 'CDN functionality provided by <a href="http://wordpress.org/plugins/ossdl-cdn-off-linker/">OSSDL CDN Off Linker</a> by <a href="http://mark.ossdl.de/">Mark Kubacki</a>', 'wp-super-cache' ); ?></p>
212
  <?php
plugins/awaitingmoderation.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  function awaitingmoderation_action( $buffer ) {
4
- $buffer = str_replace( __( 'Your comment is awaiting moderation.' ), '', $buffer );
5
  return $buffer;
6
  }
7
 
@@ -37,9 +37,9 @@ function wp_supercache_awaitingmoderation_admin() {
37
  <?php
38
  if ($changed) {
39
  if ( $cache_awaitingmoderation )
40
- $status = __( "enabled" );
41
  else
42
- $status = __( "disabled" );
43
  echo "<p><strong>" . sprintf( __( "Awaiting Moderation is now %s", 'wp-super-cache' ), $status ) . "</strong></p>";
44
  }
45
  echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
1
  <?php
2
 
3
  function awaitingmoderation_action( $buffer ) {
4
+ $buffer = str_replace( __( 'Your comment is awaiting moderation.', 'wp-super-cache' ), '', $buffer );
5
  return $buffer;
6
  }
7
 
37
  <?php
38
  if ($changed) {
39
  if ( $cache_awaitingmoderation )
40
+ $status = __( "enabled", 'wp-super-cache' );
41
  else
42
+ $status = __( "disabled", 'wp-super-cache' );
43
  echo "<p><strong>" . sprintf( __( "Awaiting Moderation is now %s", 'wp-super-cache' ), $status ) . "</strong></p>";
44
  }
45
  echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
plugins/badbehaviour.php CHANGED
@@ -65,12 +65,12 @@ function wp_supercache_badbehaviour_admin() {
65
  <label><input type="radio" name="cache_badbehaviour" value="1" <?php if( $cache_badbehaviour ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
66
  <label><input type="radio" name="cache_badbehaviour" value="0" <?php if( !$cache_badbehaviour ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
67
  <p><?php _e( '', 'wp-super-cache' ); ?></p><?php
68
- echo '<p>' . sprintf( __( '(Only legacy caching supported, disabled compression and requires <a href="http://www.bad-behavior.ioerror.us/">Bad Behavior</a> in "%s/plugins/bad-behavior/") ', 'wp-super-cache' ), WP_CONTENT_DIR ) . '</p>';
69
  if ( isset( $changed ) && $changed ) {
70
  if ( $cache_badbehaviour )
71
- $status = __( "enabled" );
72
  else
73
- $status = __( "disabled" );
74
  echo "<p><strong>" . sprintf( __( "Bad Behavior support is now %s", 'wp-super-cache' ), $status ) . "</strong></p>";
75
  }
76
  echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
65
  <label><input type="radio" name="cache_badbehaviour" value="1" <?php if( $cache_badbehaviour ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
66
  <label><input type="radio" name="cache_badbehaviour" value="0" <?php if( !$cache_badbehaviour ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
67
  <p><?php _e( '', 'wp-super-cache' ); ?></p><?php
68
+ echo '<p>' . sprintf( __( '(Only WPCache caching supported, disabled compression and requires <a href="http://www.bad-behavior.ioerror.us/">Bad Behavior</a> in "%s/plugins/bad-behavior/") ', 'wp-super-cache' ), WP_CONTENT_DIR ) . '</p>';
69
  if ( isset( $changed ) && $changed ) {
70
  if ( $cache_badbehaviour )
71
+ $status = __( "enabled", 'wp-super-cache' );
72
  else
73
+ $status = __( "disabled", 'wp-super-cache' );
74
  echo "<p><strong>" . sprintf( __( "Bad Behavior support is now %s", 'wp-super-cache' ), $status ) . "</strong></p>";
75
  }
76
  echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
plugins/domain-mapping.php CHANGED
@@ -78,9 +78,9 @@ function wp_supercache_domain_mapping_admin() {
78
  echo '<p>' . __( 'Provides support for <a href="http://wordpress.org/extend/plugins/wordpress-mu-domain-mapping/">Domain Mapping</a> plugin to map multiple domains to a blog.', 'wp-super-cache' ) . '</p>';
79
  if ( isset( $changed ) && $changed ) {
80
  if ( $cache_domain_mapping )
81
- $status = __( "enabled" );
82
  else
83
- $status = __( "disabled" );
84
  echo "<p><strong>" . sprintf( __( "Domain Mapping support is now %s", 'wp-super-cache' ), $status ) . "</strong></p>";
85
  }
86
  echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
@@ -93,7 +93,7 @@ function wp_supercache_domain_mapping_admin() {
93
  add_cacheaction( 'cache_admin_page', 'wp_supercache_domain_mapping_admin' );
94
 
95
  function wp_supercache_domain_mapping_notice() {
96
- global $cache_enabled, $cache_domain_mapping;
97
  if( $cache_enabled )
98
  echo '<div class="error"><p><strong>' . __('Domain Mapping plugin detected! Please go to the Supercache plugins page and enable the domain mapping helper plugin.', 'wp-super-cache' ) . '</strong></p></div>';
99
  }
78
  echo '<p>' . __( 'Provides support for <a href="http://wordpress.org/extend/plugins/wordpress-mu-domain-mapping/">Domain Mapping</a> plugin to map multiple domains to a blog.', 'wp-super-cache' ) . '</p>';
79
  if ( isset( $changed ) && $changed ) {
80
  if ( $cache_domain_mapping )
81
+ $status = __( "enabled", 'wp-super-cache' );
82
  else
83
+ $status = __( "disabled", 'wp-super-cache' );
84
  echo "<p><strong>" . sprintf( __( "Domain Mapping support is now %s", 'wp-super-cache' ), $status ) . "</strong></p>";
85
  }
86
  echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
93
  add_cacheaction( 'cache_admin_page', 'wp_supercache_domain_mapping_admin' );
94
 
95
  function wp_supercache_domain_mapping_notice() {
96
+ global $cache_enabled;
97
  if( $cache_enabled )
98
  echo '<div class="error"><p><strong>' . __('Domain Mapping plugin detected! Please go to the Supercache plugins page and enable the domain mapping helper plugin.', 'wp-super-cache' ) . '</strong></p></div>';
99
  }
plugins/jetpack.php CHANGED
@@ -25,7 +25,7 @@ function wp_super_cache_jetpack_admin() {
25
  <h4><?php _e( 'Jetpack Mobile Theme', 'wp-super-cache' ); ?></h4>
26
  <?php
27
  if ( false == file_exists( dirname( WPCACHEHOME ) . '/jetpack/class.jetpack-user-agent.php' ) ) {
28
- echo "<strong>" . sprintf( __( "Jetpack not found in %s. Install it and enable the mobile theme and this helper plugin to cache visits by mobile visitors." ), dirname( WPCACHEHOME ) ) . "</strong>";
29
  } else { ?>
30
  <form name="wp_manager" action="" method="post">
31
  <label><input type="radio" name="cache_jetpack" value="1" <?php if( $cache_jetpack ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
@@ -34,9 +34,9 @@ function wp_super_cache_jetpack_admin() {
34
  echo '<p>' . __( 'Provides support for the <a href="http://wordpress.org/extend/plugins/jetpack/">Jetpack</a> mobile theme and plugin. PHP caching mode and mobile support will be enabled too.', 'wp-super-cache' ) . '</p>';
35
  if ( isset( $changed ) && $changed ) {
36
  if ( $cache_jetpack )
37
- $status = __( "enabled" );
38
  else
39
- $status = __( "disabled" );
40
  echo "<p><strong>" . sprintf( __( "Jetpack Mobile Theme support is now %s", 'wp-super-cache' ), $status ) . "</strong></p>";
41
  }
42
  echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
25
  <h4><?php _e( 'Jetpack Mobile Theme', 'wp-super-cache' ); ?></h4>
26
  <?php
27
  if ( false == file_exists( dirname( WPCACHEHOME ) . '/jetpack/class.jetpack-user-agent.php' ) ) {
28
+ echo "<strong>" . sprintf( __( "Jetpack not found in %s. Install it and enable the mobile theme and this helper plugin to cache visits by mobile visitors.", 'wp-super-cache' ), dirname( WPCACHEHOME ) ) . "</strong>";
29
  } else { ?>
30
  <form name="wp_manager" action="" method="post">
31
  <label><input type="radio" name="cache_jetpack" value="1" <?php if( $cache_jetpack ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
34
  echo '<p>' . __( 'Provides support for the <a href="http://wordpress.org/extend/plugins/jetpack/">Jetpack</a> mobile theme and plugin. PHP caching mode and mobile support will be enabled too.', 'wp-super-cache' ) . '</p>';
35
  if ( isset( $changed ) && $changed ) {
36
  if ( $cache_jetpack )
37
+ $status = __( "enabled", 'wp-super-cache' );
38
  else
39
+ $status = __( "disabled", 'wp-super-cache' );
40
  echo "<p><strong>" . sprintf( __( "Jetpack Mobile Theme support is now %s", 'wp-super-cache' ), $status ) . "</strong></p>";
41
  }
42
  echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
plugins/searchengine.php CHANGED
@@ -41,7 +41,6 @@ function searchenginesupercache( $user_info ) {
41
  } else {
42
  return false;
43
  }
44
- return $user_info;
45
  }
46
 
47
  function searchengine_phase2_actions() {
@@ -72,9 +71,9 @@ function wp_supercache_searchengine_admin() {
72
  echo '<p>' . __( 'Provides support for <a href="http://ocaoimh.ie/no-adverts-for-friends/">No Adverts for Friends</a>.', 'wp-super-cache' ) . '</p>';
73
  if ( isset( $changed ) && $changed ) {
74
  if ( 'yes' == $cache_no_adverts_for_friends )
75
- $status = __( "enabled" );
76
  else
77
- $status = __( "disabled" );
78
  echo "<p><strong>" . sprintf( __( "No Adverts for Friends support is now %s", 'wp-super-cache' ), $status ) . "</strong></p>";
79
  }
80
  echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
41
  } else {
42
  return false;
43
  }
 
44
  }
45
 
46
  function searchengine_phase2_actions() {
71
  echo '<p>' . __( 'Provides support for <a href="http://ocaoimh.ie/no-adverts-for-friends/">No Adverts for Friends</a>.', 'wp-super-cache' ) . '</p>';
72
  if ( isset( $changed ) && $changed ) {
73
  if ( 'yes' == $cache_no_adverts_for_friends )
74
+ $status = __( "enabled", 'wp-super-cache' );
75
  else
76
+ $status = __( "disabled", 'wp-super-cache' );
77
  echo "<p><strong>" . sprintf( __( "No Adverts for Friends support is now %s", 'wp-super-cache' ), $status ) . "</strong></p>";
78
  }
79
  echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
plugins/wptouch.php CHANGED
@@ -25,9 +25,9 @@ function wp_super_cache_wptouch_admin() {
25
  echo '<p>' . __( 'Provides support for <a href="http://wordpress.org/extend/plugins/wptouch/">WPTouch</a> mobile theme and plugin.', 'wp-super-cache' ) . '</p>';
26
  if ( isset( $changed ) && $changed ) {
27
  if ( $cache_wptouch )
28
- $status = __( "enabled" );
29
  else
30
- $status = __( "disabled" );
31
  echo "<p><strong>" . sprintf( __( "WPTouch support is now %s", 'wp-super-cache' ), $status ) . "</strong></p>";
32
  }
33
  echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
@@ -40,7 +40,7 @@ function wp_super_cache_wptouch_admin() {
40
  add_cacheaction( 'cache_admin_page', 'wp_super_cache_wptouch_admin' );
41
 
42
  function wp_super_cache_wptouch_notice() {
43
- global $cache_enabled, $cache_wptouch;
44
  if( $cache_enabled )
45
  echo '<div class="error"><p><strong>' . __('WPTouch plugin detected! Please go to the Supercache plugins page and enable the WPTouch helper plugin.', 'wp-super-cache' ) . '</strong></p></div>';
46
  }
@@ -80,7 +80,7 @@ function wp_super_cache_maybe_disable_wptouch( $t ) {
80
  add_cacheaction( 'disable_mobile_check', 'wp_super_cache_maybe_disable_wptouch' );
81
 
82
  function wp_super_cache_wptouch_browsers( $browsers ) {
83
- global $cache_wptouch, $wptouch_exclude_ua, $wp_cache_config_file;
84
 
85
  if ( false == function_exists( 'bnc_wptouch_get_exclude_user_agents' ) || false == function_exists( 'bnc_wptouch_get_user_agents' ) )
86
  return $browsers;
25
  echo '<p>' . __( 'Provides support for <a href="http://wordpress.org/extend/plugins/wptouch/">WPTouch</a> mobile theme and plugin.', 'wp-super-cache' ) . '</p>';
26
  if ( isset( $changed ) && $changed ) {
27
  if ( $cache_wptouch )
28
+ $status = __( "enabled", 'wp-super-cache' );
29
  else
30
+ $status = __( "disabled", 'wp-super-cache' );
31
  echo "<p><strong>" . sprintf( __( "WPTouch support is now %s", 'wp-super-cache' ), $status ) . "</strong></p>";
32
  }
33
  echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
40
  add_cacheaction( 'cache_admin_page', 'wp_super_cache_wptouch_admin' );
41
 
42
  function wp_super_cache_wptouch_notice() {
43
+ global $cache_enabled;
44
  if( $cache_enabled )
45
  echo '<div class="error"><p><strong>' . __('WPTouch plugin detected! Please go to the Supercache plugins page and enable the WPTouch helper plugin.', 'wp-super-cache' ) . '</strong></p></div>';
46
  }
80
  add_cacheaction( 'disable_mobile_check', 'wp_super_cache_maybe_disable_wptouch' );
81
 
82
  function wp_super_cache_wptouch_browsers( $browsers ) {
83
+ global $wptouch_exclude_ua, $wp_cache_config_file;
84
 
85
  if ( false == function_exists( 'bnc_wptouch_get_exclude_user_agents' ) || false == function_exists( 'bnc_wptouch_get_user_agents' ) )
86
  return $browsers;
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: donncha, automattic, kraftbj
3
  Tags: performance,caching,wp-cache,wp-super-cache,cache
4
  Tested up to: 4.8
5
- Stable tag: 1.4.9
6
  Requires at least: 3.0
7
 
8
  A very fast caching engine for WordPress that produces static html files.
@@ -10,59 +10,62 @@ A very fast caching engine for WordPress that produces static html files.
10
  == Description ==
11
  This plugin generates static html files from your dynamic WordPress blog. After a html file is generated your webserver will serve that file instead of processing the comparatively heavier and more expensive WordPress PHP scripts.
12
 
13
- The static html files will be served to the vast majority of your users, but because a user's details are displayed in the comment form after they leave a comment those requests are handled by the legacy caching engine. Static files are served to:
14
 
15
  1. Users who are not logged in.
16
  2. Users who have not left a comment on your blog.
17
  3. Or users who have not viewed a password protected post.
18
 
19
- 99% of your visitors will be served static html files. Those users who don't see the static files will still benefit because they will see different cached files that aren't quite as efficient but still better than uncached. This plugin will help your server cope with a front page appearance on digg.com or other social networking site.
20
-
21
- If for some reason "supercaching" doesn't work on your server then don't worry. Caching will still be performed, but every request will require loading the PHP engine. In normal circumstances this isn't bad at all. Visitors to your site will notice no slowdown or difference. Supercache really comes into it's own if your server is underpowered, or you're experiencing heavy traffic.
22
- Super Cached html files will be served more quickly than PHP generated cached files but in every day use, the difference isn't noticeable.
23
 
24
  The plugin serves cached files in 3 ways (ranked by speed):
25
 
26
- 1. Mod_Rewrite. The fastest method is by using Apache mod_rewrite (or whatever similar module your web server supports) to serve "supercached" static html files. This completely bypasses PHP and is extremely quick. If your server is hit by a deluge of traffic it is more likely to cope as the requests are "lighter". This does require the Apache mod_rewrite module (which is probably installed if you have custom permalinks) and a modification of your .htaccess file. Visits by anonymous or unknown users will be served this way.
27
- 2. PHP. Supercached static files can now be served by PHP. The plugin will serve a "supercached" file if it exists and it's almost as fast as the mod_rewrite method. It's easier to configure as the .htaccess file doesn't need to be changed. You still need a custom permalink. You can keep portions of your page dynamic in this caching mode. Your server may not cope as well with a really large amount of traffic. (You're gaming Digg aren't you? You'll need mod_rewrite, the rest of us are ok with PHP!)
28
- 3. Legacy caching. This is mainly used to cache pages for known users. These are logged in users, visitors who leave comments or those who should be shown custom per-user data. It's the most flexible caching method but also the slowest. As each page is different it's often better not to cache pages for these users at all and avoid legacy caching. Legacy caching will also cache visits by unknown users if this caching mode is selected. You can have dynamic parts to your page in this mode too.
29
 
30
- If you're new to caching use PHP caching. It's easy to set up and very fast. Avoid legacy caching if you can.
31
 
32
  = Recommended Settings =
33
- Advanced users will probably want to use mod_rewrite caching, but PHP caching is almost as good and recommended for everyone else. Enable the following:
34
 
35
- 1. PHP caching.
36
  2. Compress pages.
37
  3. Don't cache pages for known users.
38
  4. Cache rebuild.
39
  5. CDN support.
40
  6. Extra homepage checks.
41
 
42
- Garbage collection is the act of cleaning up cache files that are out of date and stale. There's no correct value for the expiry time but a good starting point is 1800 seconds if you're not using legacy mode. If you are using that mode start with an expiry time of 600 seconds.
43
 
44
- If you are not using legacy mode caching consider deleting the contents of the "Rejected User Agents" text box and allow search engines to create supercache static files.
45
 
46
  Likewise, preload as many posts as you can and enable "Preload Mode". Garbage collection will still occur but it won't affect the preloaded files. If you don't care about sidebar widgets updating often set the preload interval to 2880 minutes (2 days) so all your posts aren't recached very often. When the preload occurs the cache files for the post being refreshed is deleted and then regenerated. Afterwards a garbage collection of all old files is performed to clean out stale cache files.
47
- With preloading on cached files will still be deleted when posts are made or edited or comments made.
48
 
49
- See the [WP Super Cache homepage](https://wordpress.org/plugins/wp-super-cache/) for further information. [Developer documentation](http://z9.io/wp-super-cache-developers/) is also available for those who need to interact with the cache or write plugins.
50
 
51
  There's a [GIT repository](https://github.com/Automattic/wp-super-cache) too if you want to contribute a patch.
52
 
53
  The [changelog](http://svn.wp-plugins.org/wp-super-cache/trunk/Changelog.txt) is a good place to start if you want to know what has changed since you last downloaded the plugin.
54
 
55
- Interested in translating WP Super Cache to your language? Grab the [development version](http://downloads.wordpress.org/plugin/wp-super-cache.zip) where you will find an up to date wp-super-cache.pot. Send any translation files to donncha @ ocaoimh.ie and thank you!
56
 
57
  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.
58
 
59
  == Upgrade Notice ==
60
 
61
- = 1.4.9 =
62
- Fixed XSS on the settings page, settings page updates, file locking fixes and PHP 7.1 fix, caching fixes on static homepage blogs and more.
63
 
64
  == Changelog ==
65
 
 
 
 
 
 
 
 
66
  = 1.4.9 =
67
  * Fixed bug when not running sem_remove after sem_release. See https://github.com/Automattic/wp-super-cache/issues/85
68
  * Fixed a PHP error impacting PHP 7.1.
@@ -363,13 +366,16 @@ To manually uninstall:
363
  Go to Settings->WP Super Cache and look for the "Cache Tester" form on the easy settings page. Click "Test Cache" and the plugin will request the front page of the site twice, comparing a timestamp on each to make sure they match.
364
 
365
  If you want to do it manually, enable debugging in the plugin settings page and load the log file in a new browser tab. Then view your blog while logged in and logged out. You should see activity in the log. View the source of any page on your site. When a page is first created, you'll see the text "Dynamic page generated in XXXX seconds." and "Cached page generated by WP-Super-Cache on YYYY-MM-DD HH:MM:SS" at the end of the source code. On reload, a cached page will show the same timestamp so wait a few seconds before checking.
366
- In legacy caching mode, if you have compression enabled, the text "Compression = gzip" will be added. If compression is disabled and the page is served as a static html file, the text "super cache" will be added. The only other way to check if your cached file was served by PHP script or from the static cache is by looking at the HTTP headers. PHP cached pages will have the header "WP-Super-Cache: Served supercache file from PHP". Legacy cached files will have the header, "WP-Super-Cache: Served legacy cache file". I used the <a href="https://addons.mozilla.org/en-US/firefox/addon/3829">Live HTTP Headers</a> extension for Firefox to examine the headers. You should also check your cache directory in wp-content/cache/supercache/hostname/ for static cache files.
367
  If the plugin rules are missing from your .htaccess file, the plugin will attempt to serve the super cached page if it's found. The header "WP-Super-Cache: Served supercache file from PHP" if this happens.
368
 
369
- = Legacy (WP-Cache) vs Supercache files =
370
 
371
- WP-Cache files are stored in wp-content/cache/ (or on MU sites in a blogs sub directory) and are named wp-cache-XXXXXXXXXXXXXXXXX.html. Associated meta files are stored in a meta sub directory. Those files contain information about the cached file. These files are generated by the "legacy caching" code in the plugin.
372
- Supercache files are stored in wp-content/cache/supercache/HOSTNAME/ where HOSTNAME is your domain name. The files are stored in directories matching your site's permalink structure.
 
 
 
373
 
374
  = Will comments and other dynamic parts of my blog update immediately? =
375
 
@@ -383,11 +389,11 @@ No, it will do the opposite. Super Cache files are compressed and stored that wa
383
 
384
  Note: this functionality is disabled by default. You will have to enable it on the Advanced Settings page.
385
 
386
- There are 2 ways of doing this. You can use Javascript to draw the part of the page you want to keep dynamic. That's what Google Adsense and many widgets from external sites do and is the recommended way. Or you can use a WP Super Cache filter to do the job but you can't use mod_rewrite mode caching. You have to switch to PHP or legacy caching.
387
 
388
  WP Super Cache 1.4 introduced a cacheaction filter called wpsc_cachedata. The cached page to be displayed goes through this filter and allows modification of the page. If the page contains a placeholder tag the filter can be used to replace that tag with your dynamically generated html.
389
  The function that hooks on to the wpsc_cachedata filter should be put in a file in the WP Super Cache plugins folder unless you use the late_init feature. An example plugin is included. Edit [dynamic-cache-test.php](http://svn.wp-plugins.org/wp-super-cache/trunk/plugins/dynamic-cache-test.php) to see the example code.
390
- There are two example functions there. There's a simple function that replaces a string (or tag) you define when the cached page is served. The other example function uses an output buffer to generate the dynamic content. Due to a limitation in how PHP works the output buffer code MUST run before the wpsc_cachedata filter is hit, at least for when a page is cached. It doesn't matter when serving cached pages. See [this post](http://z9.io/y/6j) for a more technical and longer explanation.
391
  To execute WordPress functions you must enable the 'Late init' feature on the advanced settings page.
392
 
393
  = How do I use WordPress functions in cached dynamic pages? =
@@ -399,17 +405,17 @@ Cached files are served before almost all of WordPress is loaded. While that's g
399
 
400
  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.
401
 
402
- = Why do my WP Super Cache plugin disappear when I upgrade the plugin? =
403
 
404
  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.
405
 
406
  = What does the Cache Rebuild feature do? =
407
 
408
- 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](http://z9.io/2009/01/23/wp-super-cache-089/) for more.
409
 
410
  = Why doesn't the plugin cache requests by search engine bots by default? =
411
 
412
- Those bots usually only visit each page once and if the page is not popular there's no point creating a cache file that will sit idle on your server. However if you're not using legacy caching you can allow these visits to be cached by removing the list of bots from "Rejected User Agents" on the Advanced settings page.
413
 
414
  = A category page is showing instead of my homepage =
415
 
@@ -418,19 +424,19 @@ A tiny proportion of websites will have problems with the following configuratio
418
  1. Uses a static page for the front page.
419
  2. Uses /%category%/%postname%/ permalink structure.
420
 
421
- Sometimes a category page is cached as the homepage of the site instead of the static page. I can't [replicate the problem](http://wordpress.org/support/topic/237415/page/2?replies=38) but a simple solution is to switch the plugin to PHP mode. For normal traffic you will see no difference in the speed of your site. You can also enable "Extra homepage checks" on the Advanced Settings page.
422
 
423
  = Why do I get warnings about caching from http://ismyblogworking.com/ =
424
 
425
  "Your blog doesn't support client caching (no 304 response to If-modified-since)."
426
  "Your feed doesn't support caching (no 304 response to If-modified-since)"
427
 
428
- Supercache doesn't support 304 header checks in mod_rewrite mode but does support it in PHP mode. This is caching done by your browser, not the server. It is a check your browser does to ask the server if an updated version of the current page is available. If not, it doesn't download the old version again. The page is still cached by your server, just not by your visitors' browsers.
429
  Try the Cacheability Engine at http://www.ircache.net/cgi-bin/cacheability.py or http://redbot.org/ for further analysis.
430
 
431
  = How should I best use the utm_source tracking tools in Google Analytics with this plugin? =
432
 
433
- That tracking adds a query string to each url linked from various sources like Twitter and feedreaders. Unfortunately it stops pages being supercached. See [Joost's comment here](http://z9.io/remove-unused-utmsource-urls/#comment-672813) for how to turn it into an anchor tag which can be supercached.
434
 
435
  = The plugin complains that wp-content is writable! htdocs is writable! =
436
 
@@ -459,7 +465,7 @@ The only real limit are limits defined by your server. For example, EXT2 and EXT
459
 
460
  = How do I serve cached mobile pages to clients on small screens like phones and tablets? =
461
 
462
- You'll have to use a separate mobile plugin to render a page formatted for those visitors. The following plugins have been tested but YMMV depending on mobile client.
463
 
464
  * [Jetpack's Mobile Theme Module](http://wordpress.org/plugins/jetpack)
465
  * [WPTouch](http://wordpress.org/plugins/wptouch/)
@@ -492,7 +498,7 @@ If things don't work when you installed the plugin here are a few things to chec
492
  `127.0.0.1 myhostname.com`
493
  17. If old pages are being served to your visitors via the supercache, you may be missing Apache modules (or their equivalents if you don't use Apache). 3 modules are required: mod_mime, mod_headers and mod_expires. The last two are especially important for making sure browsers load new versions of existing pages on your site.
494
  18. The error message, "WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed!" appears at the end of every page. Open the file wp-content/advanced-cache.php in your favourite editor. Is the path to wp-cache-phase1.php correct? This file will normally be in wp-content/plugins/wp-super-cache/. If it is not correct the caching engine will not load.
495
- 19. Caching doesn't work. The timestamp on my blog keeps changing when I reload. Check that the path in your .htaccess rules matches where the supercache directory is. You may have to hardcode it. Or use the plugin in PHP or legacy caching mode.
496
  20. If supercache cache files are generated but not served, check the permissions on all your wp-content/cache/supercache folders (and each of wp-content cache and supercache folders) and wp-content/cache/.htaccess. If your PHP runs as a different user to Apache and permissions are strict Apache may not be able to read the PHP generated cache files. To fix you must add the following line to your wp-config.php (Add it above the WP_CACHE define.) Then clear your cache.
497
 
498
  `umask( 0022 );`
@@ -513,6 +519,20 @@ If that doesn't work, add this line to your wp-config.php:
513
  18. The error message, "WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory." appears at the end of every page. You can delete wp-content/advanced-cache.php and reload the plugin settings page or edit wp-config.php and look for WPCACHEHOME and make sure it points at the wp-super-cache folder. This will normally be wp-content/plugins/wp-super-cache/ but you'll likely need the full path to that file (so it's easier to let the settings page fix it). If it is not correct the caching engine will not load.
514
  19. If your server is running into trouble because of the number of semaphores used by the plugin it's because your users are using file locking which is not recommended (but is needed by a small number of users). You can globally disable file locking by defining the constant WPSC_DISABLE_LOCKING, or defining the constant WPSC_REMOVE_SEMAPHORE so that sem_remove() is called after every page is cached but that seems to cause problems for other processes requesting the same semaphore. Best to disable it.
515
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
516
 
517
  == CDN ==
518
 
@@ -522,6 +542,10 @@ A Content Delivery Network (CDN) is usually a network of computers situated arou
522
 
523
  Configure this on the "CDN" tab of the plugin settings page. This is an advanced technique and requires a basic understanding of how your webserver or CDNs work. Please be sure to clear the file cache after you configure the CDN.
524
 
 
 
 
 
525
  == Custom Caching ==
526
  It is now possible to hook into the caching process using the add_cacheaction() function.
527
 
@@ -535,34 +559,7 @@ There is one regular WordPress filter too. Use the "do_createsupercache" filter
535
  to customize the checks made before caching. The filter accepts one parameter.
536
  The output of WP-Cache's wp_cache_get_cookies_values() function.
537
 
538
- See plugins/searchengine.php as an example I use for my [No Adverts for Friends](http://z9.io/no-adverts-for-friends/) plugin.
539
-
540
- == Links ==
541
- [WP Widget Cache](http://wordpress.org/plugins/wp-widget-cache/) is another caching plugin for WordPress. This plugin caches the output of widgets and may significantly speed up dynamic page generation times.
542
 
543
  == Updates ==
544
- Updates to the plugin will be posted here, to [Holy Shmoly!](http://z9.io/) and the [WP Super Cache homepage](https://wordpress.org/plugins/wp-super-cache/) will always link to the newest version.
545
-
546
- == Thanks ==
547
- I would sincerely like to thank [John Pozadzides](http://onemansblog.com/) for giving me the idea for this, for writing the "How it works" section and for testing the plugin through 2 front page appearances on digg.com
548
-
549
- Thanks to James Farmer and Andrew Billits of [Edu Blogs](http://edublogs.org/) fame who helped me make this more WordPress MU friendly.
550
-
551
- Translators who did a great job converting the text of the plugin to their native language. Thank you!
552
-
553
- * [Gianni Diurno](http://gidibao.net/) (Italian)
554
- * [Omi](http://equipajedemano.info/) (Spanish)
555
- * [tomchen1989](http://emule-fans.com/) and [Christopher Meng](http://cicku.me) (Simplified Chinese)
556
- * Tai (Japanese)
557
- * [Vitaly](http://pressword.com.ua/wordpress/) (Ukranian)
558
- * [Pseric](http://pseric.com/) and [Priv](http://priv.tw/blog) (Traditional Chinese)
559
- * [Ma�tre M�](http://maitremo.fr/) (French)
560
- * [Mathias Roth](http://trade-service.eu/) (German)
561
- * Bar�� �nver (Turkish)
562
- * [Elvis Fweb](http://wp.turkenichev.ru/) (Russian)
563
- * Fredrik Fors�ll (Swedish)
564
- * [Alyona Lompar](http://wwww.webhostinggeeks.com/) (Ukranian)
565
- * [Nata Strazda](http://www.webhostingrating.com/) (Lithuanian)
566
- * [Alexander Alexandrov](http://www.designcontest.com/) (Belarusian)
567
- * [Michail Bogdanov](http://www.webhostinghub.com/) (Romanian)
568
- * [Anja Skrba](http://science.webhostinggeeks.com/wordpress-super-cache) (Serbo-Croatian)
2
  Contributors: donncha, automattic, kraftbj
3
  Tags: performance,caching,wp-cache,wp-super-cache,cache
4
  Tested up to: 4.8
5
+ Stable tag: 1.5.0
6
  Requires at least: 3.0
7
 
8
  A very fast caching engine for WordPress that produces static html files.
10
  == Description ==
11
  This plugin generates static html files from your dynamic WordPress blog. After a html file is generated your webserver will serve that file instead of processing the comparatively heavier and more expensive WordPress PHP scripts.
12
 
13
+ The static html files will be served to the vast majority of your users:
14
 
15
  1. Users who are not logged in.
16
  2. Users who have not left a comment on your blog.
17
  3. Or users who have not viewed a password protected post.
18
 
19
+ 99% of your visitors will be served static html files. One cached file can be served thousands of times. Other visitors will be served custom cached files tailored to their visit. If they are logged in, or have left comments those details will be displayed and cached for them.
 
 
 
20
 
21
  The plugin serves cached files in 3 ways (ranked by speed):
22
 
23
+ 1. Expert. The fastest method is by using Apache mod_rewrite (or whatever similar module your web server supports) to serve "supercached" static html files. This completely bypasses PHP and is extremely quick. If your server is hit by a deluge of traffic it is more likely to cope as the requests are "lighter". This does require the Apache mod_rewrite module (which is probably installed if you have custom permalinks) and a modification of your .htaccess file which is risky and may take down your site if modified incorrectly.
24
+ 2. Simple. Supercached static files can be served by PHP and this is the recommended way of using the plugin. The plugin will serve a "supercached" file if it exists and it's almost as fast as the mod_rewrite method. It's easier to configure as the .htaccess file doesn't need to be changed. You still need a custom permalink. You can keep portions of your page dynamic in this caching mode.
25
+ 3. WP-Cache caching. This is mainly used to cache pages for known users, URLs with parameters and feeds. Known users are logged in users, visitors who leave comments or those who should be shown custom per-user data. It's the most flexible caching method and slightly slower. WP-Cache caching will also cache visits by unknown users if supercaching is disabled. You can have dynamic parts to your page in this mode too. This mode is always enabled but you can disable caching for known users, URLs with parameters, or feeds separately. Set the constant "DISABLE_SUPERCACHE" to 1 in your wp-config.php if you want to only use WP-Cache caching.
26
 
27
+ If you're not comfortable with editing PHP files then use simple mode. It's easy to set up and very fast.
28
 
29
  = Recommended Settings =
 
30
 
31
+ 1. Simple caching.
32
  2. Compress pages.
33
  3. Don't cache pages for known users.
34
  4. Cache rebuild.
35
  5. CDN support.
36
  6. Extra homepage checks.
37
 
38
+ Garbage collection is the act of cleaning up cache files that are out of date and stale. There's no correct value for the expiry time but a good starting point is 1800 seconds.
39
 
40
+ Consider deleting the contents of the "Rejected User Agents" text box and allow search engines to cache files for you.
41
 
42
  Likewise, preload as many posts as you can and enable "Preload Mode". Garbage collection will still occur but it won't affect the preloaded files. If you don't care about sidebar widgets updating often set the preload interval to 2880 minutes (2 days) so all your posts aren't recached very often. When the preload occurs the cache files for the post being refreshed is deleted and then regenerated. Afterwards a garbage collection of all old files is performed to clean out stale cache files.
43
+ Cached files will still be deleted when posts are made or edited or comments made when preloading is enabled.
44
 
45
+ See the [WP Super Cache homepage](https://wordpress.org/plugins/wp-super-cache/) for further information. [Developer documentation](https://odd.blog/wp-super-cache-developers/) is also available for those who need to interact with the cache or write plugins.
46
 
47
  There's a [GIT repository](https://github.com/Automattic/wp-super-cache) too if you want to contribute a patch.
48
 
49
  The [changelog](http://svn.wp-plugins.org/wp-super-cache/trunk/Changelog.txt) is a good place to start if you want to know what has changed since you last downloaded the plugin.
50
 
51
+ Interested in translating WP Super Cache to your language? See the [translation page](https://translate.wordpress.org/projects/wp-plugins/wp-super-cache) for the plugin.
52
 
53
  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.
54
 
55
  == Upgrade Notice ==
56
 
57
+ = 1.5.0 =
58
+ Added REST API settings endpoints, simplified settings, reorganised cache files. Lots of bug fixes.
59
 
60
  == Changelog ==
61
 
62
+ = 1.5.0 =
63
+ * REST API settings endpoints.
64
+ * Simplified settings page.
65
+ * WP-Cache files reorganised.
66
+ * Caching of more http headers.
67
+ * Lots of bug fixes.
68
+
69
  = 1.4.9 =
70
  * Fixed bug when not running sem_remove after sem_release. See https://github.com/Automattic/wp-super-cache/issues/85
71
  * Fixed a PHP error impacting PHP 7.1.
366
  Go to Settings->WP Super Cache and look for the "Cache Tester" form on the easy settings page. Click "Test Cache" and the plugin will request the front page of the site twice, comparing a timestamp on each to make sure they match.
367
 
368
  If you want to do it manually, enable debugging in the plugin settings page and load the log file in a new browser tab. Then view your blog while logged in and logged out. You should see activity in the log. View the source of any page on your site. When a page is first created, you'll see the text "Dynamic page generated in XXXX seconds." and "Cached page generated by WP-Super-Cache on YYYY-MM-DD HH:MM:SS" at the end of the source code. On reload, a cached page will show the same timestamp so wait a few seconds before checking.
369
+ If Supercaching is disabled and you have compression enabled, the text "Compression = gzip" will be added. If compression is disabled and the page is served as a static html file, the text "super cache" will be added. The only other way to check if your cached file was served by PHP script or from the static cache is by looking at the HTTP headers. PHP cached pages will have the header "WP-Super-Cache: Served supercache file from PHP". WPCache cached files will have the header, "WP-Super-Cache: Served WPCache cache file". You should also check your cache directory in wp-content/cache/supercache/hostname/ for static cache files.
370
  If the plugin rules are missing from your .htaccess file, the plugin will attempt to serve the super cached page if it's found. The header "WP-Super-Cache: Served supercache file from PHP" if this happens.
371
 
372
+ = How do I disable Supercaching? =
373
 
374
+ If you only want to use the WP-Cache engine then edit your wp-config.php or create an mu-plugin that sets the constant 'DISABLE_SUPERCACHE' to 1.
375
+
376
+ = WP-Cache vs Supercache files =
377
+
378
+ All cache files are stored in wp-content/cache/supercache/HOSTNAME/ where HOSTNANE is your domain name. The files are stored in directories matching your site's permalink structure. Supercache files are index.html or some variant of that, depending on what type of visitor hit the blog. Other files are named wp-cache-XXXXXXXXXXXXXXXXX.php. Associated meta filesnames start with "meta". Those files contain information about the cached file. These files are generated by the "WPCache caching" engine in the plugin.
379
 
380
  = Will comments and other dynamic parts of my blog update immediately? =
381
 
389
 
390
  Note: this functionality is disabled by default. You will have to enable it on the Advanced Settings page.
391
 
392
+ There are 2 ways of doing this. You can use Javascript to draw the part of the page you want to keep dynamic. That's what Google Adsense and many widgets from external sites do and is the recommended way. Or you can use a WP Super Cache filter to do the job but you can't use mod_rewrite mode caching. You have to use the "simple" delivery method or disable supercaching.
393
 
394
  WP Super Cache 1.4 introduced a cacheaction filter called wpsc_cachedata. The cached page to be displayed goes through this filter and allows modification of the page. If the page contains a placeholder tag the filter can be used to replace that tag with your dynamically generated html.
395
  The function that hooks on to the wpsc_cachedata filter should be put in a file in the WP Super Cache plugins folder unless you use the late_init feature. An example plugin is included. Edit [dynamic-cache-test.php](http://svn.wp-plugins.org/wp-super-cache/trunk/plugins/dynamic-cache-test.php) to see the example code.
396
+ There are two example functions there. There's a simple function that replaces a string (or tag) you define when the cached page is served. The other example function uses an output buffer to generate the dynamic content. Due to a limitation in how PHP works the output buffer code MUST run before the wpsc_cachedata filter is hit, at least for when a page is cached. It doesn't matter when serving cached pages. See [this post](https://odd.blog/y/6j) for a more technical and longer explanation.
397
  To execute WordPress functions you must enable the 'Late init' feature on the advanced settings page.
398
 
399
  = How do I use WordPress functions in cached dynamic pages? =
405
 
406
  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.
407
 
408
+ = Why do my WP Super Cache plugins disappear when I upgrade the plugin? =
409
 
410
  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.
411
 
412
  = What does the Cache Rebuild feature do? =
413
 
414
+ 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.
415
 
416
  = Why doesn't the plugin cache requests by search engine bots by default? =
417
 
418
+ Those bots usually only visit each page once and if the page is not popular there's no point creating a cache file that will sit idle on your server. However you can allow these visits to be cached by removing the list of bots from "Rejected User Agents" on the Advanced settings page.
419
 
420
  = A category page is showing instead of my homepage =
421
 
424
  1. Uses a static page for the front page.
425
  2. Uses /%category%/%postname%/ permalink structure.
426
 
427
+ Sometimes a category page is cached as the homepage of the site instead of the static page. I can't [replicate the problem](http://wordpress.org/support/topic/237415/page/2?replies=38) but a simple solution is to use the "Simple" mode. You can also enable "Extra homepage checks" on the Advanced Settings page.
428
 
429
  = Why do I get warnings about caching from http://ismyblogworking.com/ =
430
 
431
  "Your blog doesn't support client caching (no 304 response to If-modified-since)."
432
  "Your feed doesn't support caching (no 304 response to If-modified-since)"
433
 
434
+ Supercache doesn't support 304 header checks in Expert mode but does support it in Simple mode. This is caching done by your browser, not the server. It is a check your browser does to ask the server if an updated version of the current page is available. If not, it doesn't download the old version again. The page is still cached by your server, just not by your visitors' browsers.
435
  Try the Cacheability Engine at http://www.ircache.net/cgi-bin/cacheability.py or http://redbot.org/ for further analysis.
436
 
437
  = How should I best use the utm_source tracking tools in Google Analytics with this plugin? =
438
 
439
+ That tracking adds a query string to each url linked from various sources like Twitter and feedreaders. Unfortunately it stops pages being supercached. See [Joost's comment here](https://odd.blog/remove-unused-utmsource-urls/#comment-672813) for how to turn it into an anchor tag which can be supercached.
440
 
441
  = The plugin complains that wp-content is writable! htdocs is writable! =
442
 
465
 
466
  = How do I serve cached mobile pages to clients on small screens like phones and tablets? =
467
 
468
+ Your theme is probably responsive which means it resizes the page to suit whatever device is displaying the page. If it's not responsive, you'll have to use a separate mobile plugin to render a page formatted for those visitors. The following plugins have been tested but YMMV depending on mobile client. You'll have to enable mobile browser support as well on the Advanced settings page.
469
 
470
  * [Jetpack's Mobile Theme Module](http://wordpress.org/plugins/jetpack)
471
  * [WPTouch](http://wordpress.org/plugins/wptouch/)
498
  `127.0.0.1 myhostname.com`
499
  17. If old pages are being served to your visitors via the supercache, you may be missing Apache modules (or their equivalents if you don't use Apache). 3 modules are required: mod_mime, mod_headers and mod_expires. The last two are especially important for making sure browsers load new versions of existing pages on your site.
500
  18. The error message, "WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed!" appears at the end of every page. Open the file wp-content/advanced-cache.php in your favourite editor. Is the path to wp-cache-phase1.php correct? This file will normally be in wp-content/plugins/wp-super-cache/. If it is not correct the caching engine will not load.
501
+ 19. Caching doesn't work. The timestamp on my blog keeps changing when I reload. Check that the path in your .htaccess rules matches where the supercache directory is. You may have to hardcode it. Try disabling supercache mode.
502
  20. If supercache cache files are generated but not served, check the permissions on all your wp-content/cache/supercache folders (and each of wp-content cache and supercache folders) and wp-content/cache/.htaccess. If your PHP runs as a different user to Apache and permissions are strict Apache may not be able to read the PHP generated cache files. To fix you must add the following line to your wp-config.php (Add it above the WP_CACHE define.) Then clear your cache.
503
 
504
  `umask( 0022 );`
519
  18. The error message, "WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory." appears at the end of every page. You can delete wp-content/advanced-cache.php and reload the plugin settings page or edit wp-config.php and look for WPCACHEHOME and make sure it points at the wp-super-cache folder. This will normally be wp-content/plugins/wp-super-cache/ but you'll likely need the full path to that file (so it's easier to let the settings page fix it). If it is not correct the caching engine will not load.
520
  19. If your server is running into trouble because of the number of semaphores used by the plugin it's because your users are using file locking which is not recommended (but is needed by a small number of users). You can globally disable file locking by defining the constant WPSC_DISABLE_LOCKING, or defining the constant WPSC_REMOVE_SEMAPHORE so that sem_remove() is called after every page is cached but that seems to cause problems for other processes requesting the same semaphore. Best to disable it.
521
 
522
+ == Preloading ==
523
+
524
+ You can generate cached files for the posts, categories and tags of your site by preloading. Preloading will visit each page of your site generating a cached page as it goes along, just like any other visitor to the site. Due to the sequential nature of this function, it can take some time to preload a complete site if there are many posts.
525
+ To make preloading more effective it can be useful to disable garbage collection so that older cache files are not deleted. This is done by enabling "Preload Mode" in the settings. Be aware however, that pages will go out of date eventually but that updates by submitting comments or editing posts will clear portions of the cache.
526
+
527
+ == Garbage Collection ==
528
+
529
+ Your cache directory fills up over time, which takes up space on your server. If space is limited or billed by capacity, or if you worry that the cached pages of your site will go stale then garbage collection has to be done. Garbage collection happens on a regular basis and deletes old files in the cache directory. On the advanced settings page you can specify:
530
+ 1. Cache timeout. How long cache files are considered fresh for. After this time they are stale and can be deleted.
531
+ 2. Scheduler. Setup how often garbage collection should be done.
532
+ 3. Notification emails. You can be informed on garbage collection job progress.
533
+ There's no right or wrong settings for garbage collection. It depends on your own site.
534
+ If your site gets regular updates, or comments then set the timeout to 1800 seconds, and set the timer to 600 seconds.
535
+ If your site is mostly static you can disable garbage collection by entering 0 as the timeout, or use a really large timeout value.
536
 
537
  == CDN ==
538
 
542
 
543
  Configure this on the "CDN" tab of the plugin settings page. This is an advanced technique and requires a basic understanding of how your webserver or CDNs work. Please be sure to clear the file cache after you configure the CDN.
544
 
545
+ == REST API ==
546
+
547
+ There are now REST API endpoints for accessing the settings of this plugin. You'll need to be authenticated as an admin user with permission to view the settings page to use it. This has not been documented yet but you can find all the code that deals with this in the "rest" directory.
548
+
549
  == Custom Caching ==
550
  It is now possible to hook into the caching process using the add_cacheaction() function.
551
 
559
  to customize the checks made before caching. The filter accepts one parameter.
560
  The output of WP-Cache's wp_cache_get_cookies_values() function.
561
 
562
+ See plugins/searchengine.php as an example I use for my [No Adverts for Friends](https://odd.blog/no-adverts-for-friends/) plugin.
 
 
 
563
 
564
  == Updates ==
565
+ Updates to the plugin will be posted here, to [Holy Shmoly!](https://odd.blog/) and the [WP Super Cache homepage](https://wordpress.org/plugins/wp-super-cache/) will always link to the newest version.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
rest/class.wp-super-cache-rest-delete-cache.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class WP_Super_Cache_Rest_Delete_Cache extends WP_REST_Controller {
4
+
5
+ /**
6
+ * Get a collection of items
7
+ *
8
+ * @param WP_REST_Request $request Full data about the request.
9
+ * @return WP_Error|WP_REST_Response
10
+ */
11
+ public function callback( $request ) {
12
+ $params = $request->get_json_params();
13
+
14
+ if ( isset( $params['id'] ) && is_numeric( $params['id'] ) ) {
15
+ wpsc_delete_post_cache( $params['id'] );
16
+
17
+ } elseif ( !empty( $params['expired'] ) ) {
18
+ global $file_prefix;
19
+ wp_cache_clean_expired( $file_prefix );
20
+
21
+ } elseif ( isset( $params['url'] ) ) {
22
+ global $cache_path;
23
+
24
+ $directory = $cache_path . 'supercache/' . $params[ 'url' ];
25
+ wpsc_delete_files( $directory );
26
+ prune_super_cache( $directory . '/page', true );
27
+
28
+ } else {
29
+ global $file_prefix;
30
+ wp_cache_clean_cache( $file_prefix, !empty( $params['all'] ) );
31
+ }
32
+
33
+ return rest_ensure_response( array( 'Cache Cleared' => true ) );
34
+ }
35
+ }
rest/class.wp-super-cache-rest-get-cache.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class WP_Super_Cache_Rest_Get_Cache extends WP_REST_Controller {
4
+
5
+ /**
6
+ * Get a collection of items
7
+ *
8
+ * @param WP_REST_Request $request Full data about the request.
9
+ * @return WP_Error|WP_REST_Response
10
+ */
11
+ public function callback( $request ) {
12
+ global $valid_nonce;
13
+
14
+ $valid_nonce = true;
15
+ $_GET[ 'listfiles' ] = 1;
16
+ $sizes = wpsc_generate_sizes_array();
17
+ $supercachedir = get_supercache_dir();
18
+ $list = wpsc_dirsize( $supercachedir, $sizes );
19
+ $return_list = array();
20
+
21
+ foreach( $list as $type => $file_list ) {
22
+ foreach ( $file_list as $state => $value ) {
23
+ if ( is_array( $value ) ) {
24
+ foreach( $value as $filenames ) {
25
+ foreach( $filenames as $filename => $t ) {
26
+ if ( $type == 'wpcache' ) {
27
+ $filename = dirname( $filename );
28
+ }
29
+ if ( false == isset( $return_list[ $type ][ $state ] ) || false == in_array( $filename, $return_list[ $type ][ $state ] ) )
30
+ $return_list[ $type ][ $state ][] = $filename;
31
+ }
32
+ }
33
+ }
34
+ }
35
+
36
+ if ( isset ( $return_list[ $type ] ) ) {
37
+ $list[ $type ] = $return_list[ $type ];
38
+ }
39
+
40
+ unset( $return_list[ $type ] );
41
+ }
42
+
43
+ return rest_ensure_response( $list );
44
+ }
45
+ }
rest/class.wp-super-cache-rest-get-settings.php ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once __DIR__ . '/class.wp-super-cache-settings-map.php';
4
+
5
+ class WP_Super_Cache_Rest_Get_Settings extends WP_REST_Controller {
6
+
7
+ /**
8
+ * Get the settings.
9
+ *
10
+ * @param WP_REST_Request $request Full data about the request.
11
+ * @return WP_Error|WP_REST_Response
12
+ */
13
+ public function callback( $request ) {
14
+ $settings = array();
15
+
16
+ global $wp_cache_config_file;
17
+
18
+ if ( defined( 'WPLOCKDOWN' ) ) {
19
+ $config_file = file_get_contents( $wp_cache_config_file );
20
+ if ( false === strpos( $config_file, "defined( 'WPLOCKDOWN' )" ) ) {
21
+ wp_cache_replace_line( '^.*WPLOCKDOWN', "if ( ! defined( 'WPLOCKDOWN' ) ) define( 'WPLOCKDOWN', " . $this->get_is_lock_down_enabled() . " );", $wp_cache_config_file );
22
+ }
23
+ }
24
+
25
+ if ( function_exists( "opcache_invalidate" ) ) {
26
+ opcache_invalidate( $wp_cache_config_file );
27
+ }
28
+ include( $wp_cache_config_file );
29
+
30
+ foreach ( WP_Super_Cache_Settings_Map::$map as $name => $map ) {
31
+ if ( isset ( $map['get'] ) ) {
32
+ $get_method = $map['get'];
33
+
34
+ if ( method_exists( $this, $get_method ) ) {
35
+ $settings[ $name ] = $this->$get_method();
36
+
37
+ } elseif ( function_exists( $get_method ) ) {
38
+ $settings[ $name ] = $get_method();
39
+ }
40
+
41
+ } else if ( isset ( $map['option'] ) ) {
42
+ $settings[ $name ] = get_option( $map['option'] );
43
+
44
+ } elseif ( isset( $map['global'] ) ) {
45
+ $global_var = $map['global'];
46
+ $settings[ $name ] = $$global_var;
47
+ }
48
+ }
49
+
50
+ return $this->prepare_item_for_response( $settings, $request );
51
+ }
52
+
53
+ /**
54
+ * @return string
55
+ */
56
+ public function get_cache_path_url() {
57
+ global $cache_path;
58
+
59
+ return site_url( str_replace( ABSPATH, '', "{$cache_path}" ) );
60
+ }
61
+
62
+ /**
63
+ * @return string
64
+ */
65
+ public function get_cache_type() {
66
+ global $wp_cache_config_file;
67
+ if ( function_exists( "opcache_invalidate" ) ) {
68
+ opcache_invalidate( $wp_cache_config_file );
69
+ }
70
+ include( $wp_cache_config_file );
71
+
72
+ if ( $super_cache_enabled ) {
73
+ if ( $wp_cache_mod_rewrite == 1 ) {
74
+ return 'mod_rewrite';
75
+ } else {
76
+ return 'PHP';
77
+ }
78
+ } else {
79
+ return 'wpcache';
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Prepare the item for the REST response
85
+ *
86
+ * @param mixed $item WordPress representation of the item.
87
+ * @param WP_REST_Request $request Request object.
88
+ * @return mixed
89
+ */
90
+ public function prepare_item_for_response( $item, $request ) {
91
+ $settings = array();
92
+
93
+ $integers = array( 'cache_max_time', 'preload_interval' );
94
+ $string_arrays = array( 'cache_stats', 'cache_acceptable_files', 'cache_rejected_uri', 'cache_rejected_user_agent',
95
+ 'cache_direct_pages' );
96
+ foreach( $item as $key => $value ) {
97
+ if ( is_array( $value ) && false == in_array( $key, $string_arrays ) ) {
98
+ array_walk( $value, array( $this, 'make_array_bool' ) );
99
+
100
+ } elseif ( ( $value === 0 || $value === 1 ) && false == in_array( $key, $integers ) ) {
101
+ $value = (bool)$value;
102
+ }
103
+
104
+ $settings[ $key ] = $value;
105
+ }
106
+
107
+ $strings_to_bool = array( 'ossdl_https', 'refresh_current_only_on_comments' );
108
+ foreach( $strings_to_bool as $key ) {
109
+ if ( isset( $settings[ $key ] ) ) {
110
+ $settings[ $key ] = (bool)$settings[ $key ];
111
+ }
112
+ }
113
+
114
+ return rest_ensure_response( $settings );
115
+ }
116
+
117
+ /**
118
+ * @param mixed $value
119
+ * @param string $key
120
+ */
121
+ public function make_array_bool( &$value, $key ) {
122
+ if ( $value == 0 || $value == 1 ) {
123
+ $value = (bool) $value;
124
+ }
125
+ }
126
+
127
+ /**
128
+ * @return bool
129
+ */
130
+ protected function get_is_submit_enabled() {
131
+ global $wp_cache_config_file;
132
+ return is_writeable_ACLSafe( $wp_cache_config_file );
133
+ }
134
+
135
+ /**
136
+ * @return bool
137
+ */
138
+ protected function get_is_preload_enabled() {
139
+ return false === defined( 'DISABLESUPERCACHEPRELOADING' );
140
+ }
141
+
142
+ /**
143
+ * @return false|int
144
+ */
145
+ protected function get_next_gc() {
146
+ return wp_next_scheduled( 'wp_cache_gc' );
147
+ }
148
+
149
+ /**
150
+ * @return int
151
+ */
152
+ protected function get_is_preload_active() {
153
+ if ( wp_next_scheduled( 'wp_cache_preload_hook' ) || wp_next_scheduled( 'wp_cache_full_preload_hook' ) ) {
154
+ return true;
155
+ } else {
156
+ return false;
157
+ }
158
+ }
159
+
160
+ /**
161
+ * @return int
162
+ */
163
+ protected function get_minimum_preload_interval() {
164
+ global $wpdb;
165
+ $posts_count = wp_count_posts();
166
+ $count = $posts_count->publish;
167
+ if ( $count > 1000 ) {
168
+ $min_refresh_interval = 720;
169
+ } else {
170
+ $min_refresh_interval = 30;
171
+ }
172
+
173
+ return $min_refresh_interval;
174
+ }
175
+
176
+ /**
177
+ * @return int
178
+ */
179
+ protected function get_is_lock_down_enabled() {
180
+ if ( defined( 'WPLOCKDOWN' ) ) {
181
+ return constant( 'WPLOCKDOWN' ) ? 1 : 0;
182
+ }
183
+
184
+ return 0;
185
+ }
186
+
187
+ /**
188
+ * @return int
189
+ */
190
+ protected function get_post_count() {
191
+ $posts_count = wp_count_posts();
192
+ return $posts_count->publish;
193
+ }
194
+
195
+ /**
196
+ * @return string
197
+ */
198
+ protected function get_default_cache_path() {
199
+ return WP_CONTENT_DIR . '/wp-cache/';
200
+ }
201
+ }
rest/class.wp-super-cache-rest-get-stats.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class WP_Super_Cache_Rest_Get_Stats extends WP_REST_Controller {
4
+
5
+ /**
6
+ * Get the cache stats for the site.
7
+ *
8
+ * @param WP_REST_Request $request Full data about the request.
9
+ * @return WP_Error|WP_REST_Response
10
+ */
11
+ public function callback( $request ) {
12
+ global $valid_nonce;
13
+ $_GET[ 'listfiles' ] = 1;
14
+ $valid_nonce = true;
15
+
16
+ return rest_ensure_response( wp_cache_regenerate_cache_file_stats() );
17
+ }
18
+ }
rest/class.wp-super-cache-rest-get-status.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class WP_Super_Cache_Rest_Get_Status extends WP_REST_Controller {
4
+
5
+ /**
6
+ * Get any status that might be visible.
7
+ *
8
+ * @param WP_REST_Request $request Full data about the request.
9
+ * @return WP_Error|WP_REST_Response
10
+ */
11
+ public function callback( $request ) {
12
+ $status = array();
13
+
14
+ include_once( ABSPATH . 'wp-admin/includes/file.php' ); // get_home_path()
15
+ include_once( ABSPATH . 'wp-admin/includes/misc.php' ); // extract_from_markers()
16
+ $this->add_rewrite_status( $status );
17
+ $this->add_cache_disabled_status( $status );
18
+ $this->add_compression_status( $status );
19
+ $this->add_php_mod_rewrite_status( $status );
20
+ $this->add_preload_status( $status );
21
+
22
+ if ( empty( $status ) ) {
23
+ return rest_ensure_response( new stdclass() );
24
+ } else {
25
+ return rest_ensure_response( $status );
26
+ }
27
+ }
28
+
29
+ /**
30
+ * @param array $status
31
+ */
32
+ protected function add_preload_status( & $status ) {
33
+ global $wp_cache_config_file;
34
+
35
+ include( $wp_cache_config_file );
36
+
37
+ if ( false == $cache_enabled ) {
38
+ $status[ 'preload_disabled_cache_off' ] = true;
39
+ }
40
+ if ( false == $super_cache_enabled ) {
41
+ $status[ 'preload_disabled_supercache_off' ] = true;
42
+ }
43
+ if ( true === defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
44
+ $status[ 'preload_disabled_by_admin' ] = true;
45
+ }
46
+ }
47
+
48
+ /**
49
+ * @param array $status
50
+ */
51
+ protected function add_php_mod_rewrite_status( & $status ) {
52
+ global $wp_cache_config_file;
53
+
54
+ include( $wp_cache_config_file );
55
+
56
+ if ( $cache_enabled && !$wp_cache_mod_rewrite ) {
57
+ $scrules = trim( implode( "\n", extract_from_markers( trailingslashit( get_home_path() ) . '.htaccess', 'WPSuperCache' ) ) );
58
+ if ( $scrules != '' ) {
59
+ $status[ 'php_mod_rewrite' ] = true;
60
+ }
61
+ }
62
+ }
63
+
64
+ /**
65
+ * @param array $status
66
+ */
67
+ protected function add_cache_disabled_status( & $status ) {
68
+ global $wp_cache_config_file;
69
+
70
+ if ( ! is_writeable_ACLSafe( $wp_cache_config_file ) ) {
71
+ $status['cache_disabled'] = true;
72
+ }
73
+ }
74
+
75
+ /**
76
+ * @param array $status
77
+ */
78
+ protected function add_compression_status( & $status ) {
79
+ if ( defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
80
+ $status['compression_disabled_by_admin'] = true;
81
+ } elseif ( false == function_exists( 'gzencode' ) ) {
82
+ $status['compression_disabled_no_gzencode'] = true;
83
+ }
84
+ }
85
+
86
+ /**
87
+ * @param array $status
88
+ */
89
+ protected function add_rewrite_status( & $status ) {
90
+ global $home_path, $wp_cache_config_file;
91
+
92
+ include( $wp_cache_config_file );
93
+
94
+ // Return if the rewrite caching is disabled.
95
+ if ( ! $cache_enabled || ! $super_cache_enabled || ! $wp_cache_mod_rewrite ) {
96
+ return;
97
+ }
98
+
99
+ $scrules = implode( "\n", extract_from_markers( $home_path . '.htaccess', 'WPSuperCache' ) );
100
+ extract( wpsc_get_htaccess_info() );
101
+
102
+ if ( $scrules != $rules ) {
103
+ $status[ 'mod_rewrite_rules' ] = true;
104
+ }
105
+ $got_rewrite = apache_mod_loaded( 'mod_rewrite', true );
106
+ if ( $wp_cache_mod_rewrite && false == apply_filters( 'got_rewrite', $got_rewrite ) ) {
107
+ $status[ 'mod_rewrite_missing' ] = true;
108
+ }
109
+
110
+ if ( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) {
111
+ $status[ 'htaccess_ro' ] = true;
112
+ }
113
+ }
114
+ }
rest/class.wp-super-cache-rest-preload.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class WP_Super_Cache_Rest_Preload extends WP_REST_Controller {
4
+
5
+ /**
6
+ * Update the cache settings.
7
+ *
8
+ * @param WP_REST_Request $request Full data about the request.
9
+ * @return WP_Error|WP_REST_Response
10
+ */
11
+ public function callback( $request ) {
12
+ $parameters = $request->get_json_params();
13
+
14
+ if ( defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
15
+ wp_cache_debug( 'WP_Super_Cache_Rest_Preload: preload disabled by admin' );
16
+ return rest_ensure_response( array( 'error' => 'preload disabled by admin' ) );
17
+ }
18
+
19
+ if ( isset( $parameters[ 'enable' ] ) ) {
20
+ if ( $parameters[ 'enable' ] == true ) {
21
+ wp_cache_debug( 'WP_Super_Cache_Rest_Preload: enable' );
22
+ wpsc_enable_preload();
23
+ return( rest_ensure_response( array( 'enabled' => true ) ) );
24
+ } else {
25
+ wp_cache_debug( 'WP_Super_Cache_Rest_Preload: cancel' );
26
+ wpsc_cancel_preload();
27
+ return( rest_ensure_response( array( 'enabled' => false ) ) );
28
+ }
29
+ }
30
+ }
31
+ }
rest/class.wp-super-cache-rest-test-cache.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class WP_Super_Cache_Rest_Test_Cache extends WP_REST_Controller {
4
+
5
+ /**
6
+ * Get a collection of items
7
+ *
8
+ * @param WP_REST_Request $request Full data about the request.
9
+ * @return WP_Error|WP_REST_Response
10
+ */
11
+ public function callback( $request ) {
12
+ global $cache_path;
13
+
14
+ $url = trailingslashit( get_bloginfo( 'url' ) );
15
+
16
+ $response = array( 'status' => 'UNKNOWN' );
17
+ $has_errors = false;
18
+
19
+ $attempts = array( 'prime', 'first', 'second' );
20
+
21
+ $c = 0;
22
+ foreach ( $attempts as $attempt_name ) {
23
+ $attempt = array();
24
+ $page[ $c ] = wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
25
+
26
+ if ( ! is_wp_error( $page[ $c ] ) ) {
27
+ $fp = fopen( $cache_path . $c . ".html", "w" );
28
+ fwrite( $fp, $page[ $c ][ 'body' ] );
29
+ fclose( $fp );
30
+ }
31
+
32
+ if ( is_wp_error( $page[ $c ] ) ) {
33
+ $has_errors = true;
34
+ $attempt['status'] = false;
35
+ $attempt['errors'] = $this->format_error( $page[ $c ] );
36
+
37
+ } elseif ( $page[ $c ]['response']['code'] != 200 ) {
38
+ $has_errors = true;
39
+ $attempt['status'] = false;
40
+ $attempt['errors'] = array( $page[ $c ]['response']['message'] );
41
+
42
+ // Don't run this step on prime cache.
43
+ } elseif ( 0 !== $c && 0 === preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[ $c ]['body'], $matches2 ) ) {
44
+ $has_errors = true;
45
+ $attempt['status'] = false;
46
+ $attempt['errors'] = array( __( 'Timestamps not found', 'wp-super-cache' ) );
47
+
48
+ } else {
49
+ $attempt['status'] = true;
50
+ }
51
+
52
+
53
+ $response[ 'attempts' ][ $attempt_name ] = $attempt;
54
+ $c++;
55
+ }
56
+
57
+ if (
58
+ false == $has_errors &&
59
+ preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[ 1 ][ 'body' ], $matches1 ) &&
60
+ preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[ 2 ][ 'body' ], $matches2 ) &&
61
+ $matches1[2] == $matches2[2]
62
+ ) {
63
+ $response[ 'status' ] = true;
64
+ } else {
65
+ $response[ 'status' ] = false;
66
+ $response[ 'error' ] = array( __( 'Timestamps do not match', 'wp-super-cache' ) );
67
+ }
68
+
69
+ $error = '';
70
+ if ( $response[ 'status' ] == false ) {
71
+ if ( isset( $response[ 'error' ] ) ) {
72
+ $error = $response[ 'error' ];
73
+ } else {
74
+ foreach( $response[ 'attempts' ] as $attempt ) {
75
+ $error .= $attempt[ 'errors' ] . "\n";
76
+ }
77
+ }
78
+ return new WP_Error( 'test_error', $error, array( 'status' => 500 ) );
79
+ }
80
+ return rest_ensure_response( $response );
81
+ }
82
+
83
+ /**
84
+ * @param WP_Error $error
85
+ * @return array
86
+ */
87
+ protected function format_error( WP_Error $error ) {
88
+ $messages = array();
89
+ foreach ( $error->get_error_codes() as $code ) {
90
+ foreach ( $error->get_error_messages( $code ) as $err ) {
91
+ $messages[] = $err;
92
+ }
93
+ }
94
+
95
+ return $messages;
96
+ }
97
+ }
rest/class.wp-super-cache-rest-update-settings.php ADDED
@@ -0,0 +1,654 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3