WP Super Cache - Version 1.5.8

Version Description

  • PHP 7 fixes. (#429)
  • Fix debug comments checkbox. (#433)
  • Only register uninstall function in admin pages to save queries. (#430)
  • Check that wp-cache-phase1.php is loaded before saving settings page. (#428)
  • If a url has a "?" in it then don't delete the associated cache. It'll delete the whole cache after stripping out ?... part. (#427 & #420)
  • Allow static functions in classes to be used in cacheactions. (#425)
  • Don't make AJAX requests anonymous. (#423)
  • Fixed link to chmod explanation. (#421)
  • Add more escaping to the CDN settings page. (#416)
  • Use SERVER_PROTOCOL to determine http protocol. (#412 & #413)
  • If preload stalls only send one email per day, but do display an admin notice. (#432)
  • Fixed more PHP warnings in #438 and #437
  • Hide mod_rewrite warnings for Nginx users. #434
Download this release

Release Info

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

Code changes from version 1.5.7.1 to 1.5.8

ossdl-cdn.php CHANGED
@@ -34,8 +34,8 @@ if ($arr_of_cnames[0] == '') $arr_of_cnames = array();
34
  * @return Boolean true if to exclude given match from rewriting
35
  */
36
  function scossdl_off_exclude_match($match, $excludes) {
37
- foreach ($excludes as $badword) {
38
- if (stristr($match, $badword) != false) {
39
  return true;
40
  }
41
  }
@@ -160,13 +160,14 @@ function scossdl_off_options() {
160
 
161
  $example_cdn_uri = get_option('ossdl_off_cdn_url') == get_option( 'siteurl' ) ? $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
 
167
  <?php if ( $ossdl_off_blog_url != get_home_url() ) { ?>
168
- <p><?php printf( __( '<strong style="color: red">WARNING:</strong> Your siteurl and homeurl are different. The plugin is using %s as the homepage URL of your site but if that is wrong please use the filter "ossdl_off_blog_url" to fix it.', 'wp-super-cache' ), '<code>' . $ossdl_off_blog_url . '</code>' ); ?></p>
169
- <?php } ?>
170
 
171
  <p><?php _e( 'You can define different CDN URLs for each site on a multsite network.', 'wp-super-cache' ); ?></p>
172
  <p><form method="post" action="">
@@ -189,7 +190,7 @@ function scossdl_off_options() {
189
  <th scope="row"><label for="ossdl_off_cdn_url"><?php _e( 'Off-site URL', 'wp-super-cache' ); ?></label></th>
190
  <td>
191
  <input type="text" name="ossdl_off_cdn_url" value="<?php echo esc_url( get_option( 'ossdl_off_cdn_url' ) ); ?>" size="64" class="regular-text code" /><br />
192
- <span class="description"><?php printf( __( 'The new URL to be used in place of %1$s for rewriting. No trailing <code>/</code> please.<br />Example: <code>%2$s</code>.', 'wp-super-cache' ), get_option( 'siteurl' ), $example_cdn_uri ); ?></span>
193
  </td>
194
  </tr>
195
  <tr valign="top">
@@ -210,7 +211,7 @@ function scossdl_off_options() {
210
  <th scope="row"><label for="ossdl_cname"><?php _e( 'Additional CNAMES', 'wp-super-cache' ); ?></label></th>
211
  <td>
212
  <input type="text" name="ossdl_cname" value="<?php echo esc_attr( get_option( 'ossdl_cname' ) ); ?>" size="64" class="regular-text code" /><br />
213
- <span class="description"><?php printf( __( 'These <a href="http://en.wikipedia.org/wiki/CNAME_record">CNAMES</a> will be used in place of %1$s for rewriting (in addition to the off-site URL above). Use a comma as the delimiter. For pages with a large number of static files, this can improve browser performance. CNAMEs may also need to be configured on your CDN.<br />Example: %2$s', 'wp-super-cache' ), get_option( 'siteurl' ), $example_cnames ); ?></span>
214
  </td>
215
  </tr>
216
  <tr valign="top">
34
  * @return Boolean true if to exclude given match from rewriting
35
  */
36
  function scossdl_off_exclude_match($match, $excludes) {
37
+ foreach( $excludes as $badword ) {
38
+ if ( ! empty( $badword ) && stripos( $match, $badword ) !== false ) {
39
  return true;
40
  }
41
  }
160
 
161
  $example_cdn_uri = get_option('ossdl_off_cdn_url') == get_option( 'siteurl' ) ? $example_cdn_uri : get_option('ossdl_off_cdn_url');
162
  $example_cdn_uri .= '/wp-includes/js/jquery/jquery-migrate.js';
163
+ $example_cdn_uri = esc_url( $example_cdn_uri );
164
  ?>
165
  <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>
166
+ <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>' . esc_html( $example_cdn_uri ) . '</code>' ); ?></p>
167
 
168
  <?php if ( $ossdl_off_blog_url != get_home_url() ) { ?>
169
+ <p><?php printf( __( '<strong style="color: red">WARNING:</strong> Your siteurl and homeurl are different. The plugin is using %s as the homepage URL of your site but if that is wrong please use the filter "ossdl_off_blog_url" to fix it.', 'wp-super-cache' ), '<code>' . esc_html( $ossdl_off_blog_url ) . '</code>' ); ?></p>
170
+ <?php } ?>
171
 
172
  <p><?php _e( 'You can define different CDN URLs for each site on a multsite network.', 'wp-super-cache' ); ?></p>
173
  <p><form method="post" action="">
190
  <th scope="row"><label for="ossdl_off_cdn_url"><?php _e( 'Off-site URL', 'wp-super-cache' ); ?></label></th>
191
  <td>
192
  <input type="text" name="ossdl_off_cdn_url" value="<?php echo esc_url( get_option( 'ossdl_off_cdn_url' ) ); ?>" size="64" class="regular-text code" /><br />
193
+ <span class="description"><?php printf( __( 'The new URL to be used in place of %1$s for rewriting. No trailing <code>/</code> please.<br />Example: <code>%2$s</code>.', 'wp-super-cache' ), esc_html( get_option( 'siteurl' ) ), esc_html( $example_cdn_uri ) ); ?></span>
194
  </td>
195
  </tr>
196
  <tr valign="top">
211
  <th scope="row"><label for="ossdl_cname"><?php _e( 'Additional CNAMES', 'wp-super-cache' ); ?></label></th>
212
  <td>
213
  <input type="text" name="ossdl_cname" value="<?php echo esc_attr( get_option( 'ossdl_cname' ) ); ?>" size="64" class="regular-text code" /><br />
214
+ <span class="description"><?php printf( __( 'These <a href="http://en.wikipedia.org/wiki/CNAME_record">CNAMES</a> will be used in place of %1$s for rewriting (in addition to the off-site URL above). Use a comma as the delimiter. For pages with a large number of static files, this can improve browser performance. CNAMEs may also need to be configured on your CDN.<br />Example: %2$s', 'wp-super-cache' ), esc_html( get_option( 'siteurl' ) ), esc_html( $example_cnames ) ); ?></span>
215
  </td>
216
  </tr>
217
  <tr valign="top">
readme.txt CHANGED
@@ -1,8 +1,8 @@
1
  === WP Super Cache ===
2
  Contributors: donncha, automattic, kraftbj
3
  Tags: performance,caching,wp-cache,wp-super-cache,cache
4
- Tested up to: 4.8.2
5
- Stable tag: 1.5.7.1
6
  Requires at least: 3.0
7
 
8
  A very fast caching engine for WordPress that produces static html files.
@@ -53,9 +53,24 @@ Interested in translating WP Super Cache to your language? See the [translation
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
- Fixes fatal error for older versions of WP and corrupted config file issues.
57
 
58
  == Changelog ==
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  = 1.5.7.1 =
60
  * If the HTTP HOST is empty then don't use it in strpos to avoid a PHP warning. (#408)
61
  * Don't preload posts with permalinks that contain rejected strings. (#407)
1
  === WP Super Cache ===
2
  Contributors: donncha, automattic, kraftbj
3
  Tags: performance,caching,wp-cache,wp-super-cache,cache
4
+ Tested up to: 4.8.3
5
+ Stable tag: 1.5.8
6
  Requires at least: 3.0
7
 
8
  A very fast caching engine for WordPress that produces static html files.
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
+ Many bug fixes
57
 
58
  == Changelog ==
59
+ = 1.5.8 =
60
+ * PHP 7 fixes. (#429)
61
+ * Fix debug comments checkbox. (#433)
62
+ * Only register uninstall function in admin pages to save queries. (#430)
63
+ * Check that wp-cache-phase1.php is loaded before saving settings page. (#428)
64
+ * If a url has a "?" in it then don't delete the associated cache. It'll delete the whole cache after stripping out ?... part. (#427 & #420)
65
+ * Allow static functions in classes to be used in cacheactions. (#425)
66
+ * Don't make AJAX requests anonymous. (#423)
67
+ * Fixed link to chmod explanation. (#421)
68
+ * Add more escaping to the CDN settings page. (#416)
69
+ * Use SERVER_PROTOCOL to determine http protocol. (#412 & #413)
70
+ * If preload stalls only send one email per day, but do display an admin notice. (#432)
71
+ * Fixed more PHP warnings in #438 and #437
72
+ * Hide mod_rewrite warnings for Nginx users. #434
73
+
74
  = 1.5.7.1 =
75
  * If the HTTP HOST is empty then don't use it in strpos to avoid a PHP warning. (#408)
76
  * Don't preload posts with permalinks that contain rejected strings. (#407)
rest/class.wp-super-cache-rest-get-settings.php CHANGED
@@ -42,11 +42,10 @@ class WP_Super_Cache_Rest_Get_Settings extends WP_REST_Controller {
42
  $settings[ $name ] = get_option( $map['option'] );
43
 
44
  } elseif ( isset( $map['global'] ) ) {
45
- $global_var = $map['global'];
46
- if ( false == isset( $$global_var ) ) {
47
  $settings[ $name ] = false;
48
  } else {
49
- $settings[ $name ] = $$global_var;
50
  }
51
  }
52
  }
42
  $settings[ $name ] = get_option( $map['option'] );
43
 
44
  } elseif ( isset( $map['global'] ) ) {
45
+ if ( false == isset( $GLOBALS[ $map[ 'global' ] ] ) ) {
 
46
  $settings[ $name ] = false;
47
  } else {
48
+ $settings[ $name ] = $GLOBALS[ $map[ 'global' ] ];
49
  }
50
  }
51
  }
rest/class.wp-super-cache-rest-update-settings.php CHANGED
@@ -502,9 +502,7 @@ class WP_Super_Cache_Rest_Update_Settings extends WP_REST_Controller {
502
  );
503
 
504
  foreach ( $advanced_settings as $setting ) {
505
- global ${$setting};
506
-
507
- $value = ( isset( $$setting ) && $$setting == 1 ) ? 1 : 0;
508
  $this->set_value_by_key( $value, $setting );
509
  }
510
  }
@@ -529,9 +527,8 @@ class WP_Super_Cache_Rest_Update_Settings extends WP_REST_Controller {
529
  );
530
 
531
  foreach ( $all_time_settings as $time_setting ) {
532
- global ${$time_setting};
533
- if ( false == isset( $_POST[ $time_setting ] ) || $$time_setting == $_POST[ $time_setting ] ) {
534
- $_POST[ $time_setting ] = $$time_setting; // fill in the potentially missing fields before updating GC settings.
535
  }
536
  }
537
 
@@ -590,8 +587,7 @@ class WP_Super_Cache_Rest_Update_Settings extends WP_REST_Controller {
590
 
591
  foreach ( $all_preload_settings as $key => $original ) {
592
  if ( ! isset( $_POST[ $key ] ) ) {
593
- global ${$original};
594
- $_POST[ $original ] = $$original;
595
  } else {
596
  $_POST[ $original ] = $_POST[ $key ];
597
  if ( $key !== 'preload_interval' && ( $_POST[ $key ] === 0 || $_POST[ $key ] === false ) ) {
@@ -649,8 +645,7 @@ class WP_Super_Cache_Rest_Update_Settings extends WP_REST_Controller {
649
  }
650
  $_POST[ 'wp_cache_debug' ] = 1;
651
  } else {
652
- global $$setting;
653
- $_POST[ $setting ] = $$setting;
654
  }
655
  }
656
  global $valid_nonce;
502
  );
503
 
504
  foreach ( $advanced_settings as $setting ) {
505
+ $value = ( isset( $GLOBALS[ $setting ] ) && $GLOBALS[ $setting ] == 1 ) ? 1 : 0;
 
 
506
  $this->set_value_by_key( $value, $setting );
507
  }
508
  }
527
  );
528
 
529
  foreach ( $all_time_settings as $time_setting ) {
530
+ if ( false == isset( $_POST[ $time_setting ] ) || $GLOBALS[ $time_setting ] == $_POST[ $time_setting ] ) {
531
+ $_POST[ $time_setting ] = $GLOBALS[ $time_setting ]; // fill in the potentially missing fields before updating GC settings.
 
532
  }
533
  }
534
 
587
 
588
  foreach ( $all_preload_settings as $key => $original ) {
589
  if ( ! isset( $_POST[ $key ] ) ) {
590
+ $_POST[ $original ] = $GLOBALS[ $original ];
 
591
  } else {
592
  $_POST[ $original ] = $_POST[ $key ];
593
  if ( $key !== 'preload_interval' && ( $_POST[ $key ] === 0 || $_POST[ $key ] === false ) ) {
645
  }
646
  $_POST[ 'wp_cache_debug' ] = 1;
647
  } else {
648
+ $_POST[ $setting ] = $GLOBALS[ $setting ];
 
649
  }
650
  }
651
  global $valid_nonce;
wp-cache-config-sample.php CHANGED
@@ -101,4 +101,5 @@ $wpsc_served_header = false;
101
  $cache_gc_email_me = 0;
102
  $wpsc_save_headers = 0;
103
  $cache_schedule_interval = 'daily';
 
104
  ?>
101
  $cache_gc_email_me = 0;
102
  $wpsc_save_headers = 0;
103
  $cache_schedule_interval = 'daily';
104
+ $wp_super_cache_comments = 1;
105
  ?>
wp-cache-phase1.php CHANGED
@@ -283,7 +283,7 @@ function wp_cache_serve_cache_file() {
283
  }
284
  $local_mod_time = gmdate("D, d M Y H:i:s",filemtime( $file )).' GMT';
285
  if ( !is_null($remote_mod_time) && $remote_mod_time == $local_mod_time ) {
286
- header("HTTP/1.0 304 Not Modified");
287
  exit();
288
  }
289
  header( 'Last-Modified: ' . $local_mod_time );
@@ -454,11 +454,7 @@ function do_cacheaction( $action, $value = '' ) {
454
  if( array_key_exists($action, $wp_supercache_actions) && is_array( $wp_supercache_actions[ $action ] ) ) {
455
  $actions = $wp_supercache_actions[ $action ];
456
  foreach( $actions as $func ) {
457
- if ( is_array( $func ) ) {
458
- $value = $func[0]->{$func[1]}( $value );
459
- } else {
460
- $value = $func( $value );
461
- }
462
  }
463
  }
464
 
@@ -572,6 +568,15 @@ function wp_cache_debug( $message, $level = 1 ) {
572
  // path to the log file in the cache folder
573
  $log_file = $cache_path . str_replace('/', '', str_replace('..', '', $wp_cache_debug_log));
574
 
 
 
 
 
 
 
 
 
 
575
  error_log( $log_message, 3, $log_file );
576
  }
577
 
@@ -868,7 +873,7 @@ function get_oc_key( $url = false ) {
868
  }
869
 
870
  function wp_supercache_cache_for_admins() {
871
- if ( isset( $_GET[ 'preview' ] ) || function_exists( "is_admin" ) && is_admin() )
872
  return true;
873
 
874
  if ( false == do_cacheaction( 'wp_supercache_remove_cookies', true ) )
@@ -953,4 +958,113 @@ function wpsc_get_protected_directories() {
953
  );
954
  }
955
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
956
  ?>
283
  }
284
  $local_mod_time = gmdate("D, d M Y H:i:s",filemtime( $file )).' GMT';
285
  if ( !is_null($remote_mod_time) && $remote_mod_time == $local_mod_time ) {
286
+ header( $_SERVER[ 'SERVER_PROTOCOL' ] . " 304 Not Modified" );
287
  exit();
288
  }
289
  header( 'Last-Modified: ' . $local_mod_time );
454
  if( array_key_exists($action, $wp_supercache_actions) && is_array( $wp_supercache_actions[ $action ] ) ) {
455
  $actions = $wp_supercache_actions[ $action ];
456
  foreach( $actions as $func ) {
457
+ $value = call_user_func_array( $func, array( $value ) );
 
 
 
 
458
  }
459
  }
460
 
568
  // path to the log file in the cache folder
569
  $log_file = $cache_path . str_replace('/', '', str_replace('..', '', $wp_cache_debug_log));
570
 
571
+ if ( ! file_exists( $log_file ) && function_exists( 'wpsc_create_debug_log' ) ) {
572
+ global $wp_cache_debug_username;
573
+ if ( ! isset( $wp_cache_debug_username ) ) {
574
+ $wp_cache_debug_username = '';
575
+ }
576
+
577
+ wpsc_create_debug_log( $wp_cache_debug_log, $wp_cache_debug_username );
578
+ }
579
+
580
  error_log( $log_message, 3, $log_file );
581
  }
582
 
873
  }
874
 
875
  function wp_supercache_cache_for_admins() {
876
+ if ( isset( $_GET[ 'preview' ] ) || function_exists( "is_admin" ) && is_admin() || defined( 'DOING_AJAX' ) )
877
  return true;
878
 
879
  if ( false == do_cacheaction( 'wp_supercache_remove_cookies', true ) )
958
  );
959
  }
960
 
961
+ function wpsc_create_debug_log( $filename = '', $username = '' ) {
962
+ global $cache_path, $wp_cache_debug_username, $wp_cache_debug_log;
963
+ if ( $filename != '' ) {
964
+ $wp_cache_debug_log = $filename;
965
+ } else {
966
+ $wp_cache_debug_log = md5( time() + mt_rand() ) . ".php";
967
+ }
968
+ if ( $username != '' ) {
969
+ $wp_cache_debug_username = $username;
970
+ } else {
971
+ $wp_cache_debug_username = md5( time() + mt_rand() );
972
+ }
973
+
974
+ $msg = '
975
+ if ( !isset( $_SERVER[ "PHP_AUTH_USER" ] ) || ( $_SERVER[ "PHP_AUTH_USER" ] != "' . $wp_cache_debug_username . '" && $_SERVER[ "PHP_AUTH_PW" ] != "' . $wp_cache_debug_username . '" ) ) {
976
+ header( "WWW-Authenticate: Basic realm=\"WP-Super-Cache Debug Log\"" );
977
+ header("HTTP/1.0 401 Unauthorized");
978
+ echo "You must login to view the debug log";
979
+ exit;
980
+ }' . PHP_EOL;
981
+ $fp = fopen( $cache_path . $wp_cache_debug_log, 'w' );
982
+ if ( $fp ) {
983
+ fwrite( $fp, '<' . "?php\n" );
984
+ fwrite( $fp, $msg );
985
+ fwrite( $fp, '?' . "><pre>" . PHP_EOL );
986
+ fwrite( $fp, '<' . '?php // END HEADER ?' . '>' . PHP_EOL );
987
+ fclose( $fp );
988
+ wp_cache_setting( 'wp_cache_debug_log', $wp_cache_debug_log );
989
+ wp_cache_setting( 'wp_cache_debug_username', $wp_cache_debug_username );
990
+ }
991
+ $fp = fopen( $cache_path . 'view_' . $wp_cache_debug_log, 'w' );
992
+ if ( $fp ) {
993
+ fwrite( $fp, '<' . "?php" . PHP_EOL );
994
+ $msg .= '$debug_log = file( "./' . $wp_cache_debug_log . '" );
995
+ $start_log = 1 + array_search( "<" . "?php // END HEADER ?" . ">" . PHP_EOL, $debug_log );
996
+ if ( $start_log > 1 ) {
997
+ $debug_log = array_slice( $debug_log, $start_log );
998
+ }
999
+ ?' . '><form action="" method="GET"><' . '?php
1000
+
1001
+ $checks = array( "wp-admin", "exclude_filter", "wp-content", "wp-json" );
1002
+ foreach( $checks as $check ) {
1003
+ if ( isset( $_GET[ $check ] ) ) {
1004
+ $$check = 1;
1005
+ } else {
1006
+ $$check = 0;
1007
+ }
1008
+ }
1009
+
1010
+ if ( isset( $_GET[ "filter" ] ) ) {
1011
+ $filter = htmlspecialchars( $_GET[ "filter" ] );
1012
+ } else {
1013
+ $filter = "";
1014
+ }
1015
+
1016
+ unset( $checks[1] ); // exclude_filter
1017
+ ?' . '>
1018
+ Exclude requests: <br />
1019
+ <' . '?php foreach ( $checks as $check ) { ?>
1020
+ <label><input type="checkbox" name="<' . '?php echo $check; ?' . '>" value="1" <' . '?php if ( $$check ) { echo "checked"; } ?' . '> /> <' . '?php echo $check; ?' . '></label><br />
1021
+ <' . '?php } ?' . '>
1022
+ <br />
1023
+ Text to filter by:
1024
+
1025
+ <input type="text" name="filter" value="<' . '?php echo $filter; ?' . '>" /><br />
1026
+ <input type="checkbox" name="exclude_filter" value="1" <' . '?php if ( $exclude_filter ) { echo "checked"; } ?' . '> /> Exclude by filter instead of include.<br />
1027
+ <input type="submit" value="Submit" />
1028
+ </form>
1029
+ <' . '?php
1030
+ foreach ( $debug_log as $t => $line ) {
1031
+ foreach( $checks as $check ) {
1032
+ if ( $$check && false !== strpos( $line, " /$check/" ) ) {
1033
+ unset( $debug_log[ $t ] );
1034
+ }
1035
+ }
1036
+ if ( $filter ) {
1037
+ if ( false !== strpos( $line, $filter ) && $exclude_filter ) {
1038
+ unset( $debug_log[ $t ] );
1039
+ } elseif ( false === strpos( $line, $filter ) && ! $exclude_filter ) {
1040
+ unset( $debug_log[ $t ] );
1041
+ }
1042
+ }
1043
+ }
1044
+ foreach( $debug_log as $line ) {
1045
+ echo $line . "<br />";
1046
+ }';
1047
+ fwrite( $fp, $msg );
1048
+ fclose( $fp );
1049
+ }
1050
+
1051
+ return array( 'wp_cache_debug_log' => $wp_cache_debug_log, 'wp_cache_debug_username' => $wp_cache_debug_username );
1052
+ }
1053
+
1054
+ function wpsc_delete_url_cache( $url ) {
1055
+ if ( false !== strpos( $url, '?' ) ) {
1056
+ wp_cache_debug( 'wpsc_delete_url_cache: URL contains the character "?". Not deleting URL: ' . $url );
1057
+ return false;
1058
+ }
1059
+ $dir = str_replace( get_option( 'home' ), '', $url );
1060
+ if ( $dir != '' ) {
1061
+ $supercachedir = get_supercache_dir();
1062
+ wpsc_delete_files( $supercachedir . $dir );
1063
+ prune_super_cache( $supercachedir . $dir . '/page', true );
1064
+ return true;
1065
+ } else {
1066
+ return false;
1067
+ }
1068
+ }
1069
+
1070
  ?>
wp-cache-phase2.php CHANGED
@@ -18,6 +18,8 @@ function wp_cache_phase2() {
18
  wp_cache_debug( 'Setting up WordPress actions', 5 );
19
 
20
  add_action( 'template_redirect', 'wp_super_cache_query_vars' );
 
 
21
 
22
  // Post ID is received
23
  add_action('wp_trash_post', 'wp_cache_post_edit', 0);
@@ -352,6 +354,7 @@ function wp_cache_writers_exit() {
352
 
353
  function wp_super_cache_query_vars() {
354
  global $wp_super_cache_query;
 
355
  if ( is_search() )
356
  $wp_super_cache_query[ 'is_search' ] = 1;
357
  if ( is_page() )
@@ -370,14 +373,57 @@ function wp_super_cache_query_vars() {
370
  $wp_super_cache_query[ 'is_home' ] = 1;
371
  if ( is_author() )
372
  $wp_super_cache_query[ 'is_author' ] = 1;
373
- if ( is_feed() || ( method_exists( $GLOBALS['wp_query'], 'get') && ( get_query_var( 'sitemap' ) || get_query_var( 'xsl' ) || get_query_var( 'xml_sitemap' ) ) ) )
 
 
 
 
 
 
 
 
 
 
374
  $wp_super_cache_query[ 'is_feed' ] = 1;
 
 
 
 
 
 
 
 
 
 
 
375
  if ( is_404() )
376
  $wp_super_cache_query = array( 'is_404' => 1 );
377
 
378
  return $wp_super_cache_query;
379
  }
380
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381
  function wpsc_is_fatal_error() {
382
  global $wp_super_cache_query;
383
 
@@ -395,27 +441,26 @@ function wpsc_is_fatal_error() {
395
 
396
  function wp_cache_ob_callback( $buffer ) {
397
  global $wp_cache_pages, $wp_query, $wp_super_cache_query, $cache_acceptable_files, $wp_cache_no_cache_for_get, $wp_cache_object_cache, $wp_cache_request_uri, $do_rebuild_list, $wpsc_file_mtimes, $wpsc_save_headers, $super_cache_enabled;
398
- $buffer = apply_filters( 'wp_cache_ob_callback_filter', $buffer );
399
-
400
- $script = basename($_SERVER['PHP_SELF']);
401
 
402
  // All the things that can stop a page being cached
403
  $cache_this_page = true;
404
 
405
  if ( wpsc_is_fatal_error() ) {
406
- $cache_this_page = false;
407
  wp_cache_debug( 'wp_cache_ob_callback: PHP Fatal error occurred. Not caching incomplete page.' );
408
- } elseif ( empty( $wp_super_cache_query ) && !empty( $buffer ) && is_object( $wp_query ) ) {
 
409
  $wp_super_cache_query = wp_super_cache_query_vars();
 
 
410
  }
411
 
412
- if ( empty( $wp_super_cache_query ) && function_exists( 'apply_filter' ) && apply_filter( 'wpsc_only_cache_known_pages', 1 ) ) {
413
- $cache_this_page = false;
414
- wp_cache_debug( 'wp_cache_ob_callback: wp_super_cache_query is empty. Not caching unknown page type. Return 0 to the wpsc_only_cache_known_pages filter to cache this page.' );
415
- } elseif ( defined( 'DONOTCACHEPAGE' ) ) {
416
  wp_cache_debug( 'DONOTCACHEPAGE defined. Caching disabled.', 2 );
417
  $cache_this_page = false;
418
- } elseif ( $wp_cache_no_cache_for_get && false == empty( $_GET ) && false == defined( 'DOING_CRON' ) ) {
419
  wp_cache_debug( "Non empty GET request. Caching disabled on settings page. " . json_encode( $_GET ), 1 );
420
  $cache_this_page = false;
421
  } elseif ( $_SERVER["REQUEST_METHOD"] == 'POST' || !empty( $_POST ) || get_option( 'gzipcompression' ) ) {
@@ -469,6 +514,21 @@ function wp_cache_ob_callback( $buffer ) {
469
  } elseif ( isset( $wp_cache_pages[ 'feed' ] ) && $wp_cache_pages[ 'feed' ] == 1 && isset( $wp_super_cache_query[ 'is_feed' ] ) ) {
470
  wp_cache_debug( 'Not caching feed.', 2 );
471
  $cache_this_page = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
472
  }
473
 
474
  if ( isset( $wpsc_save_headers ) && $wpsc_save_headers )
@@ -481,7 +541,7 @@ function wp_cache_ob_callback( $buffer ) {
481
  $buffer = wp_cache_get_ob( $buffer );
482
  wp_cache_shutdown_callback();
483
 
484
- if ( isset( $wpsc_file_mtimes ) && is_array( $wpsc_file_mtimes ) && !empty( $wpsc_file_mtimes ) ) {
485
  foreach( $wpsc_file_mtimes as $cache_file => $old_mtime ) {
486
  if ( $old_mtime == @filemtime( $cache_file ) ) {
487
  wp_cache_debug( "wp_cache_ob_callback deleting unmodified rebuilt cache file: $cache_file" );
@@ -493,7 +553,7 @@ function wp_cache_ob_callback( $buffer ) {
493
  }
494
  return $buffer;
495
  } else {
496
- if ( is_array( $do_rebuild_list ) && false == empty( $do_rebuild_list ) ) {
497
  foreach( $do_rebuild_list as $dir => $n ) {
498
  if ( wp_cache_confirm_delete( $dir ) ) {
499
  wp_cache_debug( 'wp_cache_ob_callback clearing rebuilt files in ' . $dir );
@@ -566,7 +626,7 @@ function wp_cache_get_ob(&$buffer) {
566
  global $cache_enabled, $cache_path, $cache_filename, $wp_start_time, $supercachedir;
567
  global $new_cache, $wp_cache_meta, $cache_compression, $wp_super_cache_query;
568
  global $wp_cache_gzip_encoding, $super_cache_enabled;
569
- global $wp_cache_404, $gzsize, $supercacheonly;
570
  global $blog_cache_dir, $wp_supercache_cache_list;
571
  global $wp_cache_not_logged_in, $wp_cache_object_cache, $cache_max_time;
572
  global $wp_cache_is_home, $wp_cache_front_page_checks, $wp_cache_mfunc_enabled;
@@ -587,7 +647,7 @@ function wp_cache_get_ob(&$buffer) {
587
  }
588
  }
589
 
590
- if ( $wp_cache_404 && false == apply_filters( 'wpsupercache_404', false ) ) {
591
  $new_cache = false;
592
  if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) {
593
  wp_cache_debug( "404 file not found not cached", 2 );
@@ -597,13 +657,9 @@ function wp_cache_get_ob(&$buffer) {
597
 
598
  if ( !preg_match( apply_filters( 'wp_cache_eof_tags', '/(<\/html>|<\/rss>|<\/feed>|<\/urlset|<\?xml)/i' ), $buffer ) ) {
599
  $new_cache = false;
600
- if( false === strpos( $_SERVER[ 'REQUEST_URI' ], 'robots.txt' ) ) {
601
- if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) {
602
- wp_cache_debug( "No closing html tag. Not caching.", 2 );
603
- wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. No closing HTML tag. Check your theme." );
604
- }
605
- } else {
606
- wp_cache_debug( "robots.txt detected. Not caching.", 2 );
607
  }
608
  }
609
 
@@ -1157,42 +1213,35 @@ function wp_cache_shutdown_callback() {
1157
  // correct Content-Type header for feeds, if we didn't see
1158
  // it in the response headers already. -- dougal
1159
  if ( isset( $wp_super_cache_query[ 'is_feed' ] ) ) {
1160
- $type = get_query_var('feed');
1161
- $type = str_replace('/','',$type);
1162
- switch ($type) {
1163
- case 'atom':
1164
- $value = "application/atom+xml";
1165
- break;
1166
- case 'rdf':
1167
- $value = "application/rdf+xml";
1168
- break;
1169
- case 'sitemap':
1170
- $value = "text/xml";
1171
- break;
1172
- case 'rss':
1173
- case 'rss2':
1174
- default:
1175
- if ( get_query_var( 'sitemap' ) || get_query_var( 'xsl' ) || get_query_var( 'xml_sitemap' ) ) {
1176
- wp_cache_debug( "wp_cache_shutdown_callback: feed sitemap detected: text/xml" );
1177
- $value = "text/xml";
1178
- } else {
1179
- $value = "application/rss+xml";
1180
- }
1181
- }
1182
- if ( isset( $wpsc_feed_ttl ) && $wpsc_feed_ttl == 1 ) {
1183
- $wp_cache_meta[ 'ttl' ] = 60;
1184
  }
1185
  $is_feed = true;
1186
 
1187
- wp_cache_debug( "wp_cache_shutdown_callback: feed is type: $type - $value" );
1188
- } elseif ( get_query_var( 'sitemap' ) || get_query_var( 'xsl' ) || get_query_var( 'xml_sitemap' ) ) {
1189
- wp_cache_debug( "wp_cache_shutdown_callback: sitemap detected: text/xml" );
1190
- $value = "text/xml";
1191
  if ( isset( $wpsc_feed_ttl ) && $wpsc_feed_ttl == 1 ) {
1192
  $wp_cache_meta[ 'ttl' ] = 60;
1193
  }
1194
  $is_feed = true;
1195
 
 
 
 
1196
  } else { // not a feed
1197
  $value = get_option( 'html_type' );
1198
  if( $value == '' )
@@ -1354,6 +1403,58 @@ function wp_cache_clear_cache( $blog_id = 0 ) {
1354
  }
1355
  }
1356
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1357
  function wpsc_delete_cats_tags( $post ) {
1358
  $post = get_post($post);
1359
  $categories = get_the_category($post->ID);
@@ -1386,9 +1487,11 @@ function wpsc_post_transition( $new_status, $old_status, $post ) {
1386
  ||
1387
  ($old_status != 'publish' && $new_status == 'publish') // post published
1388
  ) {
1389
- wpsc_delete_cats_tags( $post );
1390
- prune_super_cache( get_supercache_dir() . '/' . $post->post_name . '/', true );
1391
- wp_cache_debug( "wpsc_post_transition: deleting post: " . get_supercache_dir() . '/' . $post->post_name . '/' );
 
 
1392
  }
1393
  }
1394
 
@@ -1437,9 +1540,13 @@ function wp_cache_post_id_gc( $post_id, $all = 'all' ) {
1437
 
1438
  $post_id = intval( $post_id );
1439
  if( $post_id == 0 )
1440
- return;
1441
 
1442
  $permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( $post_id ) ) );
 
 
 
 
1443
  $dir = get_current_url_supercache_dir( $post_id );
1444
  wp_cache_debug( "wp_cache_post_id_gc post_id: $post_id " . get_permalink( $post_id ) . " clearing cache in $dir.", 4 );
1445
  if ( $all ) {
@@ -1455,6 +1562,7 @@ function wp_cache_post_id_gc( $post_id, $all = 'all' ) {
1455
  prune_super_cache( $dir, true, true );
1456
  do_action( 'gc_cache', 'prune', $permalink );
1457
  }
 
1458
  }
1459
 
1460
  function wp_cache_post_change( $post_id ) {
@@ -1500,7 +1608,11 @@ function wp_cache_post_change( $post_id ) {
1500
  // Delete supercache files whenever a post change event occurs, even if supercache is currently disabled.
1501
  $dir = get_supercache_dir();
1502
  // make sure the front page has a rebuild file
1503
- wp_cache_post_id_gc( $post_id, $all );
 
 
 
 
1504
  if ( $all == true ) {
1505
  wp_cache_debug( "Post change: supercache enabled: deleting cache files in " . $dir );
1506
  wpsc_rebuild_files( $dir );
18
  wp_cache_debug( 'Setting up WordPress actions', 5 );
19
 
20
  add_action( 'template_redirect', 'wp_super_cache_query_vars' );
21
+ add_filter( 'wp_redirect_status', 'wpsc_catch_http_status_code' );
22
+ add_filter( 'status_header', 'wpsc_catch_status_header', 10, 2 );
23
 
24
  // Post ID is received
25
  add_action('wp_trash_post', 'wp_cache_post_edit', 0);
354
 
355
  function wp_super_cache_query_vars() {
356
  global $wp_super_cache_query;
357
+
358
  if ( is_search() )
359
  $wp_super_cache_query[ 'is_search' ] = 1;
360
  if ( is_page() )
373
  $wp_super_cache_query[ 'is_home' ] = 1;
374
  if ( is_author() )
375
  $wp_super_cache_query[ 'is_author' ] = 1;
376
+
377
+ // REST API
378
+ if ( ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ||
379
+ ( defined( 'JSON_REQUEST' ) && JSON_REQUEST ) ||
380
+ ( defined( 'WC_API_REQUEST' ) && WC_API_REQUEST )
381
+ ) {
382
+ $wp_super_cache_query[ 'is_rest' ] = 1;
383
+ }
384
+
385
+ // Feeds, sitemaps and robots.txt
386
+ if ( is_feed() ) {
387
  $wp_super_cache_query[ 'is_feed' ] = 1;
388
+ if ( get_query_var( 'feed' ) == 'sitemap' ) {
389
+ $wp_super_cache_query[ 'is_sitemap' ] = 1;
390
+ }
391
+ } elseif ( get_query_var( 'sitemap' ) || get_query_var( 'xsl' ) || get_query_var( 'xml_sitemap' ) ) {
392
+ $wp_super_cache_query[ 'is_feed' ] = 1;
393
+ $wp_super_cache_query[ 'is_sitemap' ] = 1;
394
+ } elseif ( is_robots() ) {
395
+ $wp_super_cache_query[ 'is_robots' ] = 1;
396
+ }
397
+
398
+ // Reset everything if it's 404
399
  if ( is_404() )
400
  $wp_super_cache_query = array( 'is_404' => 1 );
401
 
402
  return $wp_super_cache_query;
403
  }
404
 
405
+ function wpsc_catch_status_header( $status_header, $code ) {
406
+
407
+ if ( $code != 200 )
408
+ wpsc_catch_http_status_code( $code );
409
+
410
+ return $status_header;
411
+ }
412
+
413
+ function wpsc_catch_http_status_code( $status ) {
414
+ global $wp_super_cache_query;
415
+
416
+ if ( in_array( intval( $status ), array( 301, 302, 303, 307 ) ) ) {
417
+ $wp_super_cache_query[ 'is_redirect' ] = 1;
418
+ } elseif ( $status == 304 ) {
419
+ $wp_super_cache_query[ 'is_304' ] = 1;
420
+ } elseif ( $status == 404 ) {
421
+ $wp_super_cache_query[ 'is_404' ] = 1;
422
+ }
423
+
424
+ return $status;
425
+ }
426
+
427
  function wpsc_is_fatal_error() {
428
  global $wp_super_cache_query;
429
 
441
 
442
  function wp_cache_ob_callback( $buffer ) {
443
  global $wp_cache_pages, $wp_query, $wp_super_cache_query, $cache_acceptable_files, $wp_cache_no_cache_for_get, $wp_cache_object_cache, $wp_cache_request_uri, $do_rebuild_list, $wpsc_file_mtimes, $wpsc_save_headers, $super_cache_enabled;
444
+ $script = basename( $_SERVER[ 'PHP_SELF' ] );
 
 
445
 
446
  // All the things that can stop a page being cached
447
  $cache_this_page = true;
448
 
449
  if ( wpsc_is_fatal_error() ) {
 
450
  wp_cache_debug( 'wp_cache_ob_callback: PHP Fatal error occurred. Not caching incomplete page.' );
451
+ $cache_this_page = false;
452
+ } elseif ( empty( $wp_super_cache_query ) && !empty( $buffer ) && is_object( $wp_query ) && method_exists( $wp_query, 'get' ) ) {
453
  $wp_super_cache_query = wp_super_cache_query_vars();
454
+ } elseif ( empty( $wp_super_cache_query ) && function_exists( 'http_response_code' ) ) {
455
+ wpsc_catch_http_status_code( http_response_code() );
456
  }
457
 
458
+ $buffer = apply_filters( 'wp_cache_ob_callback_filter', $buffer );
459
+
460
+ if ( defined( 'DONOTCACHEPAGE' ) ) {
 
461
  wp_cache_debug( 'DONOTCACHEPAGE defined. Caching disabled.', 2 );
462
  $cache_this_page = false;
463
+ } elseif ( $wp_cache_no_cache_for_get && !empty( $_GET ) && false == defined( 'DOING_CRON' ) ) {
464
  wp_cache_debug( "Non empty GET request. Caching disabled on settings page. " . json_encode( $_GET ), 1 );
465
  $cache_this_page = false;
466
  } elseif ( $_SERVER["REQUEST_METHOD"] == 'POST' || !empty( $_POST ) || get_option( 'gzipcompression' ) ) {
514
  } elseif ( isset( $wp_cache_pages[ 'feed' ] ) && $wp_cache_pages[ 'feed' ] == 1 && isset( $wp_super_cache_query[ 'is_feed' ] ) ) {
515
  wp_cache_debug( 'Not caching feed.', 2 );
516
  $cache_this_page = false;
517
+ } elseif ( isset( $wp_super_cache_query[ 'is_rest' ] ) ) {
518
+ wp_cache_debug( 'REST API detected. Caching disabled.' );
519
+ $cache_this_page = false;
520
+ } elseif ( isset( $wp_super_cache_query[ 'is_robots' ] ) ) {
521
+ wp_cache_debug( 'robots.txt detected. Caching disabled.' );
522
+ $cache_this_page = false;
523
+ } elseif ( isset( $wp_super_cache_query[ 'is_redirect' ] ) ) {
524
+ wp_cache_debug( 'Redirect detected. Caching disabled.' );
525
+ $cache_this_page = false;
526
+ } elseif ( isset( $wp_super_cache_query[ 'is_304' ] ) ) {
527
+ wp_cache_debug( 'HTTP 304 (Not Modified) sent. Caching disabled.' );
528
+ $cache_this_page = false;
529
+ } elseif ( empty( $wp_super_cache_query ) && !empty( $buffer ) && apply_filters( 'wpsc_only_cache_known_pages', 1 ) ) {
530
+ wp_cache_debug( 'wp_cache_ob_callback: wp_super_cache_query is empty. Not caching unknown page type. Return 0 to the wpsc_only_cache_known_pages filter to cache this page.' );
531
+ $cache_this_page = false;
532
  }
533
 
534
  if ( isset( $wpsc_save_headers ) && $wpsc_save_headers )
541
  $buffer = wp_cache_get_ob( $buffer );
542
  wp_cache_shutdown_callback();
543
 
544
+ if ( !empty( $wpsc_file_mtimes ) && is_array( $wpsc_file_mtimes ) ) {
545
  foreach( $wpsc_file_mtimes as $cache_file => $old_mtime ) {
546
  if ( $old_mtime == @filemtime( $cache_file ) ) {
547
  wp_cache_debug( "wp_cache_ob_callback deleting unmodified rebuilt cache file: $cache_file" );
553
  }
554
  return $buffer;
555
  } else {
556
+ if ( !empty( $do_rebuild_list ) && is_array( $do_rebuild_list ) ) {
557
  foreach( $do_rebuild_list as $dir => $n ) {
558
  if ( wp_cache_confirm_delete( $dir ) ) {
559
  wp_cache_debug( 'wp_cache_ob_callback clearing rebuilt files in ' . $dir );
626
  global $cache_enabled, $cache_path, $cache_filename, $wp_start_time, $supercachedir;
627
  global $new_cache, $wp_cache_meta, $cache_compression, $wp_super_cache_query;
628
  global $wp_cache_gzip_encoding, $super_cache_enabled;
629
+ global $gzsize, $supercacheonly;
630
  global $blog_cache_dir, $wp_supercache_cache_list;
631
  global $wp_cache_not_logged_in, $wp_cache_object_cache, $cache_max_time;
632
  global $wp_cache_is_home, $wp_cache_front_page_checks, $wp_cache_mfunc_enabled;
647
  }
648
  }
649
 
650
+ if ( isset( $wp_super_cache_query[ 'is_404' ] ) && false == apply_filters( 'wpsupercache_404', false ) ) {
651
  $new_cache = false;
652
  if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) {
653
  wp_cache_debug( "404 file not found not cached", 2 );
657
 
658
  if ( !preg_match( apply_filters( 'wp_cache_eof_tags', '/(<\/html>|<\/rss>|<\/feed>|<\/urlset|<\?xml)/i' ), $buffer ) ) {
659
  $new_cache = false;
660
+ if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) {
661
+ wp_cache_debug( "No closing html tag. Not caching.", 2 );
662
+ wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. No closing HTML tag. Check your theme." );
 
 
 
 
663
  }
664
  }
665
 
1213
  // correct Content-Type header for feeds, if we didn't see
1214
  // it in the response headers already. -- dougal
1215
  if ( isset( $wp_super_cache_query[ 'is_feed' ] ) ) {
1216
+ if ( isset( $wp_super_cache_query[ 'is_sitemap' ] ) ) {
1217
+ $type = 'sitemap';
1218
+ $value = 'text/xml';
1219
+ } else {
1220
+ $type = get_query_var( 'feed' );
1221
+ $type = str_replace('/','',$type);
1222
+ switch ($type) {
1223
+ case 'atom':
1224
+ $value = 'application/atom+xml';
1225
+ break;
1226
+ case 'rdf':
1227
+ $value = 'application/rdf+xml';
1228
+ break;
1229
+ case 'rss':
1230
+ case 'rss2':
1231
+ default:
1232
+ $value = 'application/rss+xml';
1233
+ }
 
 
 
 
 
 
1234
  }
1235
  $is_feed = true;
1236
 
 
 
 
 
1237
  if ( isset( $wpsc_feed_ttl ) && $wpsc_feed_ttl == 1 ) {
1238
  $wp_cache_meta[ 'ttl' ] = 60;
1239
  }
1240
  $is_feed = true;
1241
 
1242
+ wp_cache_debug( "wp_cache_shutdown_callback: feed is type: $type - $value" );
1243
+ } elseif ( isset( $wp_super_cache_query[ 'is_rest' ] ) ) { // json
1244
+ $value = 'application/json';
1245
  } else { // not a feed
1246
  $value = get_option( 'html_type' );
1247
  if( $value == '' )
1403
  }
1404
  }
1405
 
1406
+ function wpsc_delete_post_archives( $post ) {
1407
+ $post = get_post( $post );
1408
+ if ( ! is_object( $post ) ) {
1409
+ return;
1410
+ }
1411
+
1412
+ // Taxonomies - categories, tags, custom taxonomies
1413
+ foreach( get_object_taxonomies( $post, 'objects' ) as $taxonomy ) {
1414
+
1415
+ if ( ! $taxonomy->public || ! $taxonomy->rewrite ) {
1416
+ continue;
1417
+ }
1418
+
1419
+ $terms = get_the_terms( $post->ID, $taxonomy->name );
1420
+ if ( empty( $terms ) ) {
1421
+ continue;
1422
+ }
1423
+
1424
+ foreach( $terms as $term ) {
1425
+
1426
+ $term_url = get_term_link( $term, $taxonomy->name );
1427
+ if ( is_wp_error( $term_url ) ) {
1428
+ continue;
1429
+ }
1430
+
1431
+ wpsc_delete_url_cache( $term_url );
1432
+ wp_cache_debug( "wpsc_delete_post_archives: deleting cache of taxonomies: " . $term_url );
1433
+ }
1434
+ }
1435
+
1436
+ // Post type archive page
1437
+ if ( $post->post_type === 'page' ) {
1438
+ $archive_url = false;
1439
+ } elseif ( $post->post_type === 'post' && get_option( 'show_on_front' ) !== 'posts' && ! get_option( 'page_for_posts' ) ) {
1440
+ $archive_url = false;
1441
+ } else {
1442
+ $archive_url = get_post_type_archive_link( $post->post_type );
1443
+ }
1444
+
1445
+ if ( $archive_url ) {
1446
+ wpsc_delete_url_cache( $archive_url );
1447
+ wp_cache_debug( "wpsc_delete_post_archives: deleting cache of post type archive: " . $archive_url );
1448
+ }
1449
+
1450
+ // Author archive page
1451
+ $author_url = get_author_posts_url( $post->post_author );
1452
+ if ( $author_url ) {
1453
+ wpsc_delete_url_cache( $author_url );
1454
+ wp_cache_debug( "wpsc_delete_post_archives: deleting cache of author archive: " . $author_url );
1455
+ }
1456
+ }
1457
+
1458
  function wpsc_delete_cats_tags( $post ) {
1459
  $post = get_post($post);
1460
  $categories = get_the_category($post->ID);
1487
  ||
1488
  ($old_status != 'publish' && $new_status == 'publish') // post published
1489
  ) {
1490
+ //wpsc_delete_cats_tags( $post );
1491
+ wpsc_delete_post_archives( $post );
1492
+ $post_url = get_permalink( $post->ID );
1493
+ wpsc_delete_url_cache( $post_url );
1494
+ wp_cache_debug( "wpsc_post_transition: deleting cache of post: " . $post_url );
1495
  }
1496
  }
1497
 
1540
 
1541
  $post_id = intval( $post_id );
1542
  if( $post_id == 0 )
1543
+ return true;
1544
 
1545
  $permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( $post_id ) ) );
1546
+ if ( false !== strpos( $permalink, '?' ) ) {
1547
+ wp_cache_debug( 'wp_cache_post_id_gc: NOT CLEARING CACHE. Permalink has a "?". ' . $permalink );
1548
+ return false;
1549
+ }
1550
  $dir = get_current_url_supercache_dir( $post_id );
1551
  wp_cache_debug( "wp_cache_post_id_gc post_id: $post_id " . get_permalink( $post_id ) . " clearing cache in $dir.", 4 );
1552
  if ( $all ) {
1562
  prune_super_cache( $dir, true, true );
1563
  do_action( 'gc_cache', 'prune', $permalink );
1564
  }
1565
+ return true;
1566
  }
1567
 
1568
  function wp_cache_post_change( $post_id ) {
1608
  // Delete supercache files whenever a post change event occurs, even if supercache is currently disabled.
1609
  $dir = get_supercache_dir();
1610
  // make sure the front page has a rebuild file
1611
+ if ( false == wp_cache_post_id_gc( $post_id, $all ) ) {
1612
+ wp_cache_debug( "wp_cache_post_change: not deleting any cache files as GC of post returned false" );
1613
+ wp_cache_writers_exit();
1614
+ return false;
1615
+ }
1616
  if ( $all == true ) {
1617
  wp_cache_debug( "Post change: supercache enabled: deleting cache files in " . $dir );
1618
  wpsc_rebuild_files( $dir );
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.5.7.1
7
  Author: Automattic
8
  Author URI: https://automattic.com/
9
  License: GPL2+
@@ -151,7 +151,9 @@ function wpsupercache_uninstall() {
151
  wp_cache_disable_plugin();
152
  delete_site_option( 'wp_super_cache_index_detected' );
153
  }
154
- register_uninstall_hook( __FILE__, 'wpsupercache_uninstall' );
 
 
155
 
156
  function wpsupercache_deactivate() {
157
  global $wp_cache_config_file, $wp_cache_link, $cache_path;
@@ -227,7 +229,7 @@ add_action( 'network_admin_menu', 'wp_cache_network_pages' );
227
 
228
  function wp_cache_manager_error_checks() {
229
  global $wp_cache_debug, $wp_cache_cron_check, $cache_enabled, $super_cache_enabled, $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_mobile_enabled, $wp_cache_mod_rewrite;
230
- global $dismiss_htaccess_warning, $dismiss_readable_warning, $dismiss_gc_warning, $wp_cache_shutdown_gc;
231
 
232
  if ( !wpsupercache_site_admin() )
233
  return false;
@@ -302,7 +304,13 @@ function wp_cache_manager_error_checks() {
302
  <p><?php _e( 'PHP is compressing the data sent to the visitors of your site. Disabling this is recommended as the plugin caches the compressed output once instead of compressing the same page over and over again. Also see #21 in the Troubleshooting section. See <a href="http://php.net/manual/en/zlib.configuration.php">this page</a> for instructions on modifying your php.ini.', 'wp-super-cache' ); ?></p></div><?php
303
  }
304
 
305
- if( $cache_enabled == true && $super_cache_enabled == true && $wp_cache_mod_rewrite && !got_mod_rewrite() ) {
 
 
 
 
 
 
306
  ?><div class="notice notice-warning"><h3><?php _e( 'Mod rewrite may not be installed!', 'wp-super-cache' ); ?></h3>
307
  <p><?php _e( 'It appears that mod_rewrite is not installed. Sometimes this check isn&#8217;t 100% reliable, especially if you are not using Apache. Please verify that the mod_rewrite module is loaded. It is required for serving Super Cache static files in expert mode. You will still be able to simple mode.', 'wp-super-cache' ); ?></p></div><?php
308
  }
@@ -375,7 +383,7 @@ function wp_cache_manager_error_checks() {
375
  }
376
  }
377
 
378
- if ( function_exists( "is_main_site" ) && true == is_main_site() ) {
379
  $home_path = trailingslashit( get_home_path() );
380
  $scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
381
  if ( $cache_enabled && $wp_cache_mod_rewrite && !$wp_cache_mobile_enabled && strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) ) ) {
@@ -403,7 +411,7 @@ function wp_cache_manager_error_checks() {
403
  }
404
  }
405
 
406
- if ( $wp_cache_mod_rewrite && $super_cache_enabled && function_exists( 'apache_get_modules' ) ) {
407
  $mods = apache_get_modules();
408
  $required_modules = array( 'mod_mime' => __( 'Required to serve compressed supercache files properly.', 'wp-super-cache' ), 'mod_headers' => __( 'Required to set caching information on supercache pages. IE7 users will see old pages without this module.', 'wp-super-cache' ), 'mod_expires' => __( 'Set the expiry date on supercached pages. Visitors may not see new pages when they refresh or leave comments without this module.', 'wp-super-cache' ) );
409
  foreach( $required_modules as $req => $desc ) {
@@ -431,7 +439,7 @@ function wp_cache_manager_error_checks() {
431
  }
432
  if ( isset( $disable_supercache_htaccess_warning ) == false )
433
  $disable_supercache_htaccess_warning = false;
434
- if ( $dismiss_htaccess_warning == 0 && $wp_cache_mod_rewrite && $super_cache_enabled && $disable_supercache_htaccess_warning == false && get_option( 'siteurl' ) != get_option( 'home' ) ) {
435
  ?><div class="notice notice-info"><h3><?php _e( '.htaccess file may need to be moved', 'wp-super-cache' ); ?></h3>
436
  <p><?php _e( 'It appears you have WordPress installed in a sub directory as described <a href="http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory">here</a>. Unfortunately, WordPress writes to the .htaccess in the install directory, not where your site is served from.<br />When you update the rewrite rules in this plugin you will have to copy the file to where your site is hosted. This will be fixed in the future.', 'wp-super-cache' ); ?></p>
437
  <form action="" method="POST">
@@ -486,6 +494,13 @@ function wp_cache_manager_updates() {
486
  if ( $valid_nonce == false )
487
  return false;
488
 
 
 
 
 
 
 
 
489
  if ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'easysetup' ) {
490
  $_POST[ 'action' ] = 'scupdates';
491
  if( isset( $_POST[ 'wp_cache_easy_on' ] ) && $_POST[ 'wp_cache_easy_on' ] == 1 ) {
@@ -518,7 +533,7 @@ function wp_cache_manager_updates() {
518
  }
519
  $advanced_settings = array( 'wp_super_cache_late_init', 'wp_cache_disable_utf8', 'wp_cache_no_cache_for_get', 'wp_supercache_304', 'wp_cache_mfunc_enabled', 'wp_cache_mobile_enabled', 'wp_cache_front_page_checks', 'wp_supercache_cache_list', 'wp_cache_hello_world', 'wp_cache_clear_on_post_edit', 'wp_cache_not_logged_in', 'wp_cache_make_known_anon','wp_cache_object_cache', 'wp_cache_refresh_single_only', 'cache_compression' );
520
  foreach( $advanced_settings as $setting ) {
521
- if ( isset( $$setting ) && $$setting == 1 ) {
522
  $_POST[ $setting ] = 1;
523
  }
524
  }
@@ -724,7 +739,7 @@ function wp_cache_manager() {
724
  global $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_supercache_cache_list, $cache_page_secret;
725
  global $wp_super_cache_front_page_check, $wp_cache_object_cache, $_wp_using_ext_object_cache, $wp_cache_refresh_single_only, $wp_cache_mobile_prefixes;
726
  global $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $wp_cache_disable_utf8, $wp_cache_mfunc_enabled;
727
- global $wp_super_cache_comments, $wp_cache_home_path, $wpsc_save_headers;
728
 
729
  if ( !wpsupercache_site_admin() )
730
  return false;
@@ -1016,9 +1031,13 @@ table.wpsc-settings-table {
1016
  <tr valign="top">
1017
  <th scope="row"><label for="super_cache_enabled"><?php _e( 'Cache Delivery Method', 'wp-super-cache' ); ?></label></th>
1018
  <td>
 
1019
  <label><input type='radio' name='wp_cache_mod_rewrite' <?php if ( $wp_cache_mod_rewrite == 0 ) echo "checked"; ?> value='0'> <?php _e( '<acronym title="Use PHP to serve cached files">Simple</acronym>', 'wp-super-cache' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br />
1020
  <label><input type='radio' name='wp_cache_mod_rewrite' <?php if ( $wp_cache_mod_rewrite == 1 ) echo "checked"; ?> value='1'> <?php _e( '<acronym title="Use mod_rewrite to serve cached files">Expert</acronym>', 'wp-super-cache' ); ?></label><br />
1021
  <em><small class='description'><?php _e( 'Expert caching requires changes to important server files and may require manual intervention if enabled.', 'wp-super-cache' ); ?></small></em>
 
 
 
1022
  </fieldset>
1023
  </td>
1024
  </tr>
@@ -1099,7 +1118,7 @@ table.wpsc-settings-table {
1099
  <li><?php _e( 'Submit a blank entry to set it to the default directory, WP_CONTENT_DIR . /cache/.', 'wp-super-cache' ); ?></li>
1100
  <?php if ( get_site_option( 'wp_super_cache_index_detected' ) && strlen( $cache_path ) > strlen( ABSPATH ) && ABSPATH == substr( $cache_path, 0, strlen( ABSPATH ) ) ) {
1101
  $msg = __( 'The plugin detected a bare directory index in your cache directory, which would let visitors see your cache files directly and might expose private posts.', 'wp-super-cache' );
1102
- if ( $super_cache_enabled && $wp_cache_mod_rewrite == 1 ) {
1103
  $msg .= ' ' . __( 'You are using expert mode to serve cache files so the plugin has added <q>Options -Indexes</q> to the .htaccess file in the cache directory to disable indexes. However, if that does not work, you should contact your system administrator or support and ask for them to be disabled, or use simple mode and move the cache outside of the web root.', 'wp-super-cache' );
1104
  } else {
1105
  $msg .= ' <strong>' . sprintf( __( 'index.html files have been added in key directories, but unless directory indexes are disabled, it is probably better to store the cache files outside of the web root of %s', 'wp-super-cache' ), ABSPATH ) . '</strong>';
@@ -1164,7 +1183,7 @@ table.wpsc-settings-table {
1164
  </tr>
1165
  </table>
1166
  <?php
1167
- if ( $cache_enabled && !$wp_cache_mod_rewrite ) {
1168
  $scrules = trim( implode( "\n", extract_from_markers( trailingslashit( get_home_path() ) . '.htaccess', 'WPSuperCache' ) ) );
1169
  if ( $scrules != '' ) {
1170
  echo "<p><strong>" . __( 'Notice: Simple caching enabled but Supercache mod_rewrite rules from expert mode detected. Cached files will be served using those rules. If your site is working ok, please ignore this message. Otherwise, you can edit the .htaccess file in the root of your install and remove the SuperCache rules.', 'wp-super-cache' ) . '</strong></p>';
@@ -1371,7 +1390,11 @@ function wpsc_admin_tabs( $current = 0 ) {
1371
  }
1372
 
1373
  function wsc_mod_rewrite() {
1374
- global $valid_nonce, $cache_path, $wp_cache_mod_rewrite;
 
 
 
 
1375
 
1376
  if ( defined( 'WPSC_DISABLE_HTACCESS_UPDATE' ) )
1377
  return false;
@@ -1952,43 +1975,16 @@ function wp_cache_edit_accepted() {
1952
  echo "</form>\n";
1953
  }
1954
 
1955
- function wpsc_create_debug_log( $filename = '', $username = '' ) {
1956
- global $cache_path, $wp_cache_debug_username, $wp_cache_debug_log;
1957
- if ( $filename != '' ) {
1958
- $wp_cache_debug_log = $filename;
1959
- } else {
1960
- $wp_cache_debug_log = md5( time() + mt_rand() ) . ".php";
1961
- }
1962
- if ( $username != '' ) {
1963
- $wp_cache_debug_username = $username;
1964
- } else {
1965
- $wp_cache_debug_username = md5( time() + mt_rand() );
1966
- }
1967
-
1968
- $fp = fopen( $cache_path . $wp_cache_debug_log, 'w' );
1969
- if ( $fp ) {
1970
- fwrite( $fp, '<' . "?php\n" );
1971
- $msg = '
1972
- if ( !isset( $_SERVER[ "PHP_AUTH_USER" ] ) || ( $_SERVER[ "PHP_AUTH_USER" ] != "' . $wp_cache_debug_username . '" && $_SERVER[ "PHP_AUTH_PW" ] != "' . $wp_cache_debug_username . '" ) ) {
1973
- header( "WWW-Authenticate: Basic realm=\"WP-Super-Cache Debug Log\"" );
1974
- header("HTTP/1.0 401 Unauthorized");
1975
- echo "You must login to view the debug log";
1976
- exit;
1977
- }';
1978
- fwrite( $fp, $msg );
1979
- fwrite( $fp, '?' . "><pre>" );
1980
- fclose( $fp );
1981
- wp_cache_setting( 'wp_cache_debug_log', $wp_cache_debug_log );
1982
- wp_cache_setting( 'wp_cache_debug_username', $wp_cache_debug_username );
1983
- }
1984
- return array( 'wp_cache_debug_log' => $wp_cache_debug_log, 'wp_cache_debug_username' => $wp_cache_debug_username );
1985
- }
1986
-
1987
  function wpsc_update_debug_settings() {
1988
  global $wp_super_cache_debug, $wp_cache_debug_log, $wp_cache_debug_ip, $cache_path, $valid_nonce, $wp_cache_config_file, $wp_super_cache_comments;
1989
  global $wp_super_cache_front_page_check, $wp_super_cache_front_page_clear, $wp_super_cache_front_page_text, $wp_super_cache_front_page_notification, $wp_super_cache_advanced_debug;
1990
  global $wp_cache_debug_username;
1991
 
 
 
 
 
 
1992
  if ( false == $valid_nonce ) {
1993
  return array (
1994
  'wp_super_cache_debug' => $wp_super_cache_debug,
@@ -2065,11 +2061,12 @@ function wp_cache_debug_settings() {
2065
  if ( ! isset( $wp_cache_debug_log ) || $wp_cache_debug_log == '' ) {
2066
  extract( wpsc_create_debug_log() ); // $wp_cache_debug_log, $wp_cache_debug_username
2067
  }
2068
- $log_file_link = "<a href='" . site_url( str_replace( ABSPATH, '', "{$cache_path}{$wp_cache_debug_log}" ) ) . "'>$wp_cache_debug_log</a>";
 
2069
  if ( $wp_super_cache_debug == 1 ) {
2070
- echo "<p>" . sprintf( __( 'Currently logging to: %s', 'wp-super-cache' ), $log_file_link ) . "</p>";
2071
  } else {
2072
- echo "<p>" . sprintf( __( 'Last Logged to: %s', 'wp-super-cache' ), $log_file_link ) . "</p>";
2073
  }
2074
  echo "<p>" . sprintf( __( 'Username/Password: %s', 'wp-super-cache' ), $wp_cache_debug_username ) . "</p>";
2075
 
@@ -2186,8 +2183,8 @@ function wp_cache_is_enabled() {
2186
 
2187
  function wp_cache_setting( $field, $value ) {
2188
  global $wp_cache_config_file;
2189
- global ${$field};
2190
- $$field = $value;
2191
  if ( is_numeric( $value ) ) {
2192
  wp_cache_replace_line( '^ *\$' . $field, "\$$field = $value;", $wp_cache_config_file );
2193
  } elseif ( is_object( $value ) || is_array( $value ) ) {
@@ -2209,37 +2206,56 @@ function wp_cache_replace_line($old, $new, $my_file) {
2209
  }
2210
 
2211
  $found = false;
2212
- $lines = file($my_file);
2213
- foreach( (array)$lines as $line ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2214
  if ( preg_match("/$old/", $line)) {
2215
  $found = true;
2216
  break;
2217
  }
2218
  }
2219
- if ($found) {
2220
- $fd = fopen($my_file, 'w');
2221
- foreach( (array)$lines as $line ) {
2222
- if ( !preg_match( "/$old/", $line ) ) {
2223
- fputs($fd, $line);
 
 
 
 
 
 
2224
  } elseif ( $new != '' ) {
2225
- fputs($fd, "$new //Added by WP-Cache Manager\n");
2226
  }
2227
  }
2228
- fclose($fd);
2229
- return true;
2230
- }
2231
- $fd = fopen($my_file, 'w');
2232
- $done = false;
2233
- foreach( (array)$lines as $line ) {
2234
- if ( $done || !preg_match('/^(if\ \(\ \!\ )?define|\$|\?>/', $line) ) {
2235
- fputs($fd, $line);
2236
- } else {
2237
- fputs($fd, "$new //Added by WP-Cache Manager\n");
2238
- fputs($fd, $line);
2239
- $done = true;
2240
  }
2241
  }
2242
- fclose($fd);
 
2243
  return true;
2244
  }
2245
 
@@ -2680,8 +2696,8 @@ function wp_cache_files() {
2680
  $count = 0;
2681
  $expired = 0;
2682
  $now = time();
 
2683
  if ( ( $handle = @opendir( $blog_cache_dir ) ) ) {
2684
- $wp_cache_fsize = 0;
2685
  if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletewpcache' ) {
2686
  $deleteuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', base64_decode( $_GET[ 'uri' ] ) ) );
2687
  } else {
@@ -2779,7 +2795,7 @@ function wp_cache_files() {
2779
  else
2780
  $age = 0;
2781
  echo "<li>" . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), $cache_stats[ 'supercache' ][ 'expired' ] ) . "</li></ul>";
2782
- if ( $valid_nonce && array_key_exists('listfiles', $_GET) && $_GET[ 'listfiles' ] ) {
2783
  echo "<div style='padding: 10px; border: 1px solid #333; height: 400px; width: 90%; overflow: auto'>";
2784
  $cache_description = array( 'supercache' => __( 'Super Cached Files', 'wp-super-cache' ), 'wpcache' => __( 'Full Cache Files', 'wp-super-cache' ) );
2785
  foreach( $cache_stats as $type => $details ) {
@@ -2948,18 +2964,6 @@ function wp_cache_clean_cache( $file_prefix, $all = false ) {
2948
 
2949
  }
2950
 
2951
- function wpsc_delete_url_cache( $url ) {
2952
- $dir = str_replace( get_option( 'home' ), '', $url );
2953
- if ( $dir != '' ) {
2954
- $supercachedir = get_supercache_dir();
2955
- wpsc_delete_files( $supercachedir . $dir );
2956
- prune_super_cache( $supercachedir . $dir . '/page', true );
2957
- return true;
2958
- } else {
2959
- return false;
2960
- }
2961
- }
2962
-
2963
  function wpsc_delete_post_cache( $id ) {
2964
  $post = get_post( $id );
2965
  wpsc_delete_url_cache( get_author_posts_url( $post->post_author ) );
@@ -3084,11 +3088,14 @@ if( get_option( 'gzipcompression' ) )
3084
  // Catch 404 requests. Themes that use query_posts() destroy $wp_query->is_404
3085
  function wp_cache_catch_404() {
3086
  global $wp_cache_404;
 
 
3087
  $wp_cache_404 = false;
3088
  if( is_404() )
3089
  $wp_cache_404 = true;
3090
  }
3091
- add_action( 'template_redirect', 'wp_cache_catch_404' );
 
3092
 
3093
  function wp_cache_favorite_action( $actions ) {
3094
  if ( false == wpsupercache_site_admin() )
@@ -3592,13 +3599,27 @@ add_filter( 'option_preload_cache_counter', 'option_preload_cache_counter' );
3592
  function check_up_on_preloading() {
3593
  $value = get_option( 'preload_cache_counter' );
3594
  if ( $value[ 'c' ] > 0 && ( time() - $value[ 't' ] ) > 3600 && false == wp_next_scheduled( 'wp_cache_preload_hook' ) ) {
3595
- if ( is_admin() )
3596
- wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Preload may have stalled.', 'wp-super-cache' ), get_bloginfo( 'url' ) ), sprintf( __( "Preload has been restarted.\n%s", 'wp-super-cache' ), admin_url( "options-general.php?page=wpsupercache" ) ) );
 
 
 
 
 
3597
  wp_schedule_single_event( time() + 30, 'wp_cache_preload_hook' );
3598
  }
3599
  }
3600
  add_action( 'init', 'check_up_on_preloading' ); // sometimes preloading stops working. Kickstart it.
3601
 
 
 
 
 
 
 
 
 
 
3602
  function wp_cache_disable_plugin( $delete_config_file = true ) {
3603
  global $wp_rewrite;
3604
  if ( file_exists( ABSPATH . 'wp-config.php') ) {
@@ -3639,7 +3660,7 @@ function wp_cache_disable_plugin( $delete_config_file = true ) {
3639
  }
3640
  $code .= "</ul>\n";
3641
 
3642
- $msg .= "</ol>\n<p>First try fixing the directory permissions with this command and refresh this page:<br /><br /><code>chmod 777 " . WP_CONTENT_DIR . "</code><br /><br />If you still see this error, you have to fix the permissions on the files themselves and refresh this page again:</p> {$code}\n<p>Don't forgot to fix things later:<br /><code>chmod 755 " . WP_CONTENT_DIR . "</code></p><p>If you don't know what <strong>chmod</strong> is use <a href='http://www.google.ie/search?hl=en&q=ftp+chmod+777'>this Google search</a> to find out all about it.</p><p>Please refresh this page when the permissions have been modified.</p>";
3643
  wp_die( $msg );
3644
  }
3645
  extract( wpsc_get_htaccess_info() ); // $document_root, $apache_root, $home_path, $home_root, $home_root_lc, $inst_root, $wprules, $scrules, $condition_rules, $rules, $gziprules
@@ -4005,8 +4026,7 @@ function wpsc_get_plugin_list() {
4005
  $list = do_cacheaction( 'wpsc_filter_list' );
4006
  foreach( $list as $t => $details ) {
4007
  $key = "cache_" . $details[ 'key' ];
4008
- global $$key;
4009
- if ( isset( $$key ) && $$key == 1 ) {
4010
  $list[ $t ][ 'enabled' ] = true;
4011
  } else {
4012
  $list[ $t ][ 'enabled' ] = false;
@@ -4022,8 +4042,7 @@ function wpsc_update_plugin_list( $update ) {
4022
  $list = do_cacheaction( 'wpsc_filter_list' );
4023
  foreach( $update as $key => $enabled ) {
4024
  $plugin_toggle = "cache_{$key}";
4025
- global $$plugin_toggle;
4026
- if ( isset( $$plugin_toggle ) || isset( $list[ $key ] ) ) {
4027
  wp_cache_setting( $plugin_toggle, (int)$enabled );
4028
  }
4029
  }
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.5.8
7
  Author: Automattic
8
  Author URI: https://automattic.com/
9
  License: GPL2+
151
  wp_cache_disable_plugin();
152
  delete_site_option( 'wp_super_cache_index_detected' );
153
  }
154
+ if ( is_admin() ) {
155
+ register_uninstall_hook( __FILE__, 'wpsupercache_uninstall' );
156
+ }
157
 
158
  function wpsupercache_deactivate() {
159
  global $wp_cache_config_file, $wp_cache_link, $cache_path;
229
 
230
  function wp_cache_manager_error_checks() {
231
  global $wp_cache_debug, $wp_cache_cron_check, $cache_enabled, $super_cache_enabled, $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_mobile_enabled, $wp_cache_mod_rewrite;
232
+ global $dismiss_htaccess_warning, $dismiss_readable_warning, $dismiss_gc_warning, $wp_cache_shutdown_gc, $is_nginx;
233
 
234
  if ( !wpsupercache_site_admin() )
235
  return false;
304
  <p><?php _e( 'PHP is compressing the data sent to the visitors of your site. Disabling this is recommended as the plugin caches the compressed output once instead of compressing the same page over and over again. Also see #21 in the Troubleshooting section. See <a href="http://php.net/manual/en/zlib.configuration.php">this page</a> for instructions on modifying your php.ini.', 'wp-super-cache' ); ?></p></div><?php
305
  }
306
 
307
+ if (
308
+ $cache_enabled == true &&
309
+ $super_cache_enabled == true &&
310
+ $wp_cache_mod_rewrite &&
311
+ ! got_mod_rewrite() &&
312
+ ! $is_nginx
313
+ ) {
314
  ?><div class="notice notice-warning"><h3><?php _e( 'Mod rewrite may not be installed!', 'wp-super-cache' ); ?></h3>
315
  <p><?php _e( 'It appears that mod_rewrite is not installed. Sometimes this check isn&#8217;t 100% reliable, especially if you are not using Apache. Please verify that the mod_rewrite module is loaded. It is required for serving Super Cache static files in expert mode. You will still be able to simple mode.', 'wp-super-cache' ); ?></p></div><?php
316
  }
383
  }
384
  }
385
 
386
+ if ( ! $is_nginx && function_exists( "is_main_site" ) && true == is_main_site() ) {
387
  $home_path = trailingslashit( get_home_path() );
388
  $scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
389
  if ( $cache_enabled && $wp_cache_mod_rewrite && !$wp_cache_mobile_enabled && strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) ) ) {
411
  }
412
  }
413
 
414
+ if ( ! $is_nginx && $wp_cache_mod_rewrite && $super_cache_enabled && function_exists( 'apache_get_modules' ) ) {
415
  $mods = apache_get_modules();
416
  $required_modules = array( 'mod_mime' => __( 'Required to serve compressed supercache files properly.', 'wp-super-cache' ), 'mod_headers' => __( 'Required to set caching information on supercache pages. IE7 users will see old pages without this module.', 'wp-super-cache' ), 'mod_expires' => __( 'Set the expiry date on supercached pages. Visitors may not see new pages when they refresh or leave comments without this module.', 'wp-super-cache' ) );
417
  foreach( $required_modules as $req => $desc ) {
439
  }
440
  if ( isset( $disable_supercache_htaccess_warning ) == false )
441
  $disable_supercache_htaccess_warning = false;
442
+ if ( ! $is_nginx && $dismiss_htaccess_warning == 0 && $wp_cache_mod_rewrite && $super_cache_enabled && $disable_supercache_htaccess_warning == false && get_option( 'siteurl' ) != get_option( 'home' ) ) {
443
  ?><div class="notice notice-info"><h3><?php _e( '.htaccess file may need to be moved', 'wp-super-cache' ); ?></h3>
444
  <p><?php _e( 'It appears you have WordPress installed in a sub directory as described <a href="http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory">here</a>. Unfortunately, WordPress writes to the .htaccess in the install directory, not where your site is served from.<br />When you update the rewrite rules in this plugin you will have to copy the file to where your site is hosted. This will be fixed in the future.', 'wp-super-cache' ); ?></p>
445
  <form action="" method="POST">
494
  if ( $valid_nonce == false )
495
  return false;
496
 
497
+ if ( false == function_exists( 'wpsc_deep_replace' ) ) {
498
+ $msg = __( 'Warning! You must set WP_CACHE and WPCACHEHOME in your wp-config.php for this plugin to work correctly:' ) . '<br />';
499
+ $msg .= "<code>define( 'WP_CACHE', true );</code><br />";
500
+ $msg .= "<code>define( 'WPCACHEHOME', '" . dirname( __FILE__ ) . "' );</code><br />";
501
+ wp_die( $msg );
502
+ }
503
+
504
  if ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'easysetup' ) {
505
  $_POST[ 'action' ] = 'scupdates';
506
  if( isset( $_POST[ 'wp_cache_easy_on' ] ) && $_POST[ 'wp_cache_easy_on' ] == 1 ) {
533
  }
534
  $advanced_settings = array( 'wp_super_cache_late_init', 'wp_cache_disable_utf8', 'wp_cache_no_cache_for_get', 'wp_supercache_304', 'wp_cache_mfunc_enabled', 'wp_cache_mobile_enabled', 'wp_cache_front_page_checks', 'wp_supercache_cache_list', 'wp_cache_hello_world', 'wp_cache_clear_on_post_edit', 'wp_cache_not_logged_in', 'wp_cache_make_known_anon','wp_cache_object_cache', 'wp_cache_refresh_single_only', 'cache_compression' );
535
  foreach( $advanced_settings as $setting ) {
536
+ if ( isset( $GLOBALS[ $setting ] ) && $GLOBALS[ $setting ] == 1 ) {
537
  $_POST[ $setting ] = 1;
538
  }
539
  }
739
  global $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_supercache_cache_list, $cache_page_secret;
740
  global $wp_super_cache_front_page_check, $wp_cache_object_cache, $_wp_using_ext_object_cache, $wp_cache_refresh_single_only, $wp_cache_mobile_prefixes;
741
  global $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $wp_cache_disable_utf8, $wp_cache_mfunc_enabled;
742
+ global $wp_super_cache_comments, $wp_cache_home_path, $wpsc_save_headers, $is_nginx;
743
 
744
  if ( !wpsupercache_site_admin() )
745
  return false;
1031
  <tr valign="top">
1032
  <th scope="row"><label for="super_cache_enabled"><?php _e( 'Cache Delivery Method', 'wp-super-cache' ); ?></label></th>
1033
  <td>
1034
+ <fieldset>
1035
  <label><input type='radio' name='wp_cache_mod_rewrite' <?php if ( $wp_cache_mod_rewrite == 0 ) echo "checked"; ?> value='0'> <?php _e( '<acronym title="Use PHP to serve cached files">Simple</acronym>', 'wp-super-cache' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br />
1036
  <label><input type='radio' name='wp_cache_mod_rewrite' <?php if ( $wp_cache_mod_rewrite == 1 ) echo "checked"; ?> value='1'> <?php _e( '<acronym title="Use mod_rewrite to serve cached files">Expert</acronym>', 'wp-super-cache' ); ?></label><br />
1037
  <em><small class='description'><?php _e( 'Expert caching requires changes to important server files and may require manual intervention if enabled.', 'wp-super-cache' ); ?></small></em>
1038
+ <?php if ( $is_nginx ) { ?>
1039
+ <em><small class='description'><?php printf( __( 'Nginx rules can be found <a href="%s">here</a> but are not officially supported.', 'wp-super-cache' ), 'https://codex.wordpress.org/Nginx#WP_Super_Cache_Rules' ); ?></small></em>
1040
+ <?php } ?>
1041
  </fieldset>
1042
  </td>
1043
  </tr>
1118
  <li><?php _e( 'Submit a blank entry to set it to the default directory, WP_CONTENT_DIR . /cache/.', 'wp-super-cache' ); ?></li>
1119
  <?php if ( get_site_option( 'wp_super_cache_index_detected' ) && strlen( $cache_path ) > strlen( ABSPATH ) && ABSPATH == substr( $cache_path, 0, strlen( ABSPATH ) ) ) {
1120
  $msg = __( 'The plugin detected a bare directory index in your cache directory, which would let visitors see your cache files directly and might expose private posts.', 'wp-super-cache' );
1121
+ if ( ! $is_nginx && $super_cache_enabled && $wp_cache_mod_rewrite == 1 ) {
1122
  $msg .= ' ' . __( 'You are using expert mode to serve cache files so the plugin has added <q>Options -Indexes</q> to the .htaccess file in the cache directory to disable indexes. However, if that does not work, you should contact your system administrator or support and ask for them to be disabled, or use simple mode and move the cache outside of the web root.', 'wp-super-cache' );
1123
  } else {
1124
  $msg .= ' <strong>' . sprintf( __( 'index.html files have been added in key directories, but unless directory indexes are disabled, it is probably better to store the cache files outside of the web root of %s', 'wp-super-cache' ), ABSPATH ) . '</strong>';
1183
  </tr>
1184
  </table>
1185
  <?php
1186
+ if ( ! $is_nginx && $cache_enabled && !$wp_cache_mod_rewrite ) {
1187
  $scrules = trim( implode( "\n", extract_from_markers( trailingslashit( get_home_path() ) . '.htaccess', 'WPSuperCache' ) ) );
1188
  if ( $scrules != '' ) {
1189
  echo "<p><strong>" . __( 'Notice: Simple caching enabled but Supercache mod_rewrite rules from expert mode detected. Cached files will be served using those rules. If your site is working ok, please ignore this message. Otherwise, you can edit the .htaccess file in the root of your install and remove the SuperCache rules.', 'wp-super-cache' ) . '</strong></p>';
1390
  }
1391
 
1392
  function wsc_mod_rewrite() {
1393
+ global $valid_nonce, $cache_path, $wp_cache_mod_rewrite, $is_nginx;
1394
+
1395
+ if ( $is_nginx ) {
1396
+ return false;
1397
+ }
1398
 
1399
  if ( defined( 'WPSC_DISABLE_HTACCESS_UPDATE' ) )
1400
  return false;
1975
  echo "</form>\n";
1976
  }
1977
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1978
  function wpsc_update_debug_settings() {
1979
  global $wp_super_cache_debug, $wp_cache_debug_log, $wp_cache_debug_ip, $cache_path, $valid_nonce, $wp_cache_config_file, $wp_super_cache_comments;
1980
  global $wp_super_cache_front_page_check, $wp_super_cache_front_page_clear, $wp_super_cache_front_page_text, $wp_super_cache_front_page_notification, $wp_super_cache_advanced_debug;
1981
  global $wp_cache_debug_username;
1982
 
1983
+ if ( ! isset( $wp_super_cache_comments ) ) {
1984
+ $wp_super_cache_comments = 1; // defaults to "enabled".
1985
+ wp_cache_setting( 'wp_super_cache_comments', $wp_super_cache_comments );
1986
+ }
1987
+
1988
  if ( false == $valid_nonce ) {
1989
  return array (
1990
  'wp_super_cache_debug' => $wp_super_cache_debug,
2061
  if ( ! isset( $wp_cache_debug_log ) || $wp_cache_debug_log == '' ) {
2062
  extract( wpsc_create_debug_log() ); // $wp_cache_debug_log, $wp_cache_debug_username
2063
  }
2064
+ $log_file_link = "<a href='" . site_url( str_replace( ABSPATH, '', "{$cache_path}view_{$wp_cache_debug_log}" ) ) . "'>$wp_cache_debug_log</a>";
2065
+ $raw_log_file_link = "<a href='" . site_url( str_replace( ABSPATH, '', "{$cache_path}{$wp_cache_debug_log}" ) ) . "'>" . __( 'RAW', 'wp-super-cache' ) . "</a>";
2066
  if ( $wp_super_cache_debug == 1 ) {
2067
+ echo "<p>" . sprintf( __( 'Currently logging to: %s (%s)', 'wp-super-cache' ), $log_file_link, $raw_log_file_link ) . "</p>";
2068
  } else {
2069
+ echo "<p>" . sprintf( __( 'Last Logged to: %s (%s)', 'wp-super-cache' ), $log_file_link, $raw_log_file_link ) . "</p>";
2070
  }
2071
  echo "<p>" . sprintf( __( 'Username/Password: %s', 'wp-super-cache' ), $wp_cache_debug_username ) . "</p>";
2072
 
2183
 
2184
  function wp_cache_setting( $field, $value ) {
2185
  global $wp_cache_config_file;
2186
+
2187
+ $GLOBALS[ $field ] = $value;
2188
  if ( is_numeric( $value ) ) {
2189
  wp_cache_replace_line( '^ *\$' . $field, "\$$field = $value;", $wp_cache_config_file );
2190
  } elseif ( is_object( $value ) || is_array( $value ) ) {
2206
  }
2207
 
2208
  $found = false;
2209
+ $loaded = false;
2210
+ $c = 0;
2211
+ $lines = array();
2212
+ while( ! $loaded ) {
2213
+ $lines = file( $my_file );
2214
+ if ( ! empty( $lines ) && is_array( $lines ) ) {
2215
+ $loaded = true;
2216
+ } else {
2217
+ $c++;
2218
+ if ( $c > 100 ) {
2219
+ trigger_error( "wp_cache_replace_line: Error - file $my_file could not be loaded." );
2220
+ return false;
2221
+ }
2222
+ }
2223
+ }
2224
+ foreach( (array) $lines as $line ) {
2225
  if ( preg_match("/$old/", $line)) {
2226
  $found = true;
2227
  break;
2228
  }
2229
  }
2230
+
2231
+ $tmp_file = dirname( $my_file ) . '/' . mt_rand() . '.php';
2232
+ $fd = fopen( $tmp_file, 'w' );
2233
+ if ( ! $fd ) {
2234
+ trigger_error( "wp_cache_replace_line: Error - could not write to $tmp_file" );
2235
+ return false;
2236
+ }
2237
+ if ( $found ) {
2238
+ foreach( (array) $lines as $line ) {
2239
+ if ( ! preg_match( "/$old/", $line ) ) {
2240
+ fputs( $fd, $line );
2241
  } elseif ( $new != '' ) {
2242
+ fputs( $fd, "$new\n" );
2243
  }
2244
  }
2245
+ } else {
2246
+ $done = false;
2247
+ foreach( (array) $lines as $line ) {
2248
+ if ( $done || ! preg_match( '/^(if\ \(\ \!\ )?define|\$|\?>/', $line ) ) {
2249
+ fputs($fd, $line);
2250
+ } else {
2251
+ fputs($fd, "$new\n");
2252
+ fputs($fd, $line);
2253
+ $done = true;
2254
+ }
 
 
2255
  }
2256
  }
2257
+ fclose( $fd );
2258
+ @rename( $tmp_file, $my_file );
2259
  return true;
2260
  }
2261
 
2696
  $count = 0;
2697
  $expired = 0;
2698
  $now = time();
2699
+ $wp_cache_fsize = 0;
2700
  if ( ( $handle = @opendir( $blog_cache_dir ) ) ) {
 
2701
  if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletewpcache' ) {
2702
  $deleteuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', base64_decode( $_GET[ 'uri' ] ) ) );
2703
  } else {
2795
  else
2796
  $age = 0;
2797
  echo "<li>" . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), $cache_stats[ 'supercache' ][ 'expired' ] ) . "</li></ul>";
2798
+ if ( $valid_nonce && array_key_exists('listfiles', $_GET) && isset( $_GET[ 'listfiles' ] ) ) {
2799
  echo "<div style='padding: 10px; border: 1px solid #333; height: 400px; width: 90%; overflow: auto'>";
2800
  $cache_description = array( 'supercache' => __( 'Super Cached Files', 'wp-super-cache' ), 'wpcache' => __( 'Full Cache Files', 'wp-super-cache' ) );
2801
  foreach( $cache_stats as $type => $details ) {
2964
 
2965
  }
2966
 
 
 
 
 
 
 
 
 
 
 
 
 
2967
  function wpsc_delete_post_cache( $id ) {
2968
  $post = get_post( $id );
2969
  wpsc_delete_url_cache( get_author_posts_url( $post->post_author ) );
3088
  // Catch 404 requests. Themes that use query_posts() destroy $wp_query->is_404
3089
  function wp_cache_catch_404() {
3090
  global $wp_cache_404;
3091
+ if ( function_exists( '_deprecated_function' ) )
3092
+ _deprecated_function( __FUNCTION__, 'WP Super Cache 1.5.6' );
3093
  $wp_cache_404 = false;
3094
  if( is_404() )
3095
  $wp_cache_404 = true;
3096
  }
3097
+ //More info - https://github.com/Automattic/wp-super-cache/pull/373
3098
+ //add_action( 'template_redirect', 'wp_cache_catch_404' );
3099
 
3100
  function wp_cache_favorite_action( $actions ) {
3101
  if ( false == wpsupercache_site_admin() )
3599
  function check_up_on_preloading() {
3600
  $value = get_option( 'preload_cache_counter' );
3601
  if ( $value[ 'c' ] > 0 && ( time() - $value[ 't' ] ) > 3600 && false == wp_next_scheduled( 'wp_cache_preload_hook' ) ) {
3602
+ if ( is_admin() ) {
3603
+ if ( get_option( 'wpsc_preload_restart_email' ) < ( time() - 86400 ) ) {
3604
+ wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Preload may have stalled.', 'wp-super-cache' ), get_bloginfo( 'url' ) ), sprintf( __( "Preload has been restarted.\n%s", 'wp-super-cache' ), admin_url( "options-general.php?page=wpsupercache" ) ) );
3605
+ update_option( 'wpsc_preload_restart_email', time() );
3606
+ }
3607
+ add_action( 'admin_notices', 'wpsc_preload_restart_notice' );
3608
+ }
3609
  wp_schedule_single_event( time() + 30, 'wp_cache_preload_hook' );
3610
  }
3611
  }
3612
  add_action( 'init', 'check_up_on_preloading' ); // sometimes preloading stops working. Kickstart it.
3613
 
3614
+ function wpsc_preload_restart_notice() {
3615
+
3616
+ if ( false == wpsupercache_site_admin() )
3617
+ return false;
3618
+ if ( ! isset( $_GET[ 'page' ] ) || $_GET[ 'page' ] != 'wpsupercache' )
3619
+ return false;
3620
+ echo '<div class="notice notice-error"><p>' . __( 'Warning! WP Super Cache preload was interrupted but has been restarted.', 'wp-super-cache' ) . '</p></div>';
3621
+ }
3622
+
3623
  function wp_cache_disable_plugin( $delete_config_file = true ) {
3624
  global $wp_rewrite;
3625
  if ( file_exists( ABSPATH . 'wp-config.php') ) {
3660
  }
3661
  $code .= "</ul>\n";
3662
 
3663
+ $msg .= "</ol>\n<p>First try fixing the directory permissions with this command and refresh this page:<br /><br /><code>chmod 777 " . WP_CONTENT_DIR . "</code><br /><br />If you still see this error, you have to fix the permissions on the files themselves and refresh this page again:</p> {$code}\n<p>Don't forget to fix things later:<br /><code>chmod 755 " . WP_CONTENT_DIR . "</code></p><p>If you don't know what <strong>chmod</strong> is read all about it <a href='https://codex.wordpress.org/Changing_File_Permissions#About_Chmod'>here</a> and note the warning about using 777 permission.</p><p>Please refresh this page when the permissions have been modified.</p>";
3664
  wp_die( $msg );
3665
  }
3666
  extract( wpsc_get_htaccess_info() ); // $document_root, $apache_root, $home_path, $home_root, $home_root_lc, $inst_root, $wprules, $scrules, $condition_rules, $rules, $gziprules
4026
  $list = do_cacheaction( 'wpsc_filter_list' );
4027
  foreach( $list as $t => $details ) {
4028
  $key = "cache_" . $details[ 'key' ];
4029
+ if ( isset( $GLOBALS[ $key ] ) && $GLOBALS[ $key ] == 1 ) {
 
4030
  $list[ $t ][ 'enabled' ] = true;
4031
  } else {
4032
  $list[ $t ][ 'enabled' ] = false;
4042
  $list = do_cacheaction( 'wpsc_filter_list' );
4043
  foreach( $update as $key => $enabled ) {
4044
  $plugin_toggle = "cache_{$key}";
4045
+ if ( isset( $GLOBALS[ $plugin_toggle ] ) || isset( $list[ $key ] ) ) {
 
4046
  wp_cache_setting( $plugin_toggle, (int)$enabled );
4047
  }
4048
  }