WP Super Cache - Version 1.5.9

Version Description

Download this release

Release Info

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

Code changes from version 1.5.8 to 1.5.9

advanced-cache.php CHANGED
@@ -1,28 +1,30 @@
1
  <?php
2
- # WP SUPER CACHE 1.2
3
  function wpcache_broken_message() {
4
  global $wp_cache_config_file;
5
- if ( isset( $wp_cache_config_file ) == false )
6
  return '';
 
7
 
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
  }
17
  }
18
 
19
  if ( false == defined( 'WPCACHEHOME' ) ) {
20
  define( 'ADVANCEDCACHEPROBLEM', 1 );
21
- } elseif ( !include_once( WPCACHEHOME . 'wp-cache-phase1.php' ) ) {
22
- if ( !@is_file( WPCACHEHOME . 'wp-cache-phase1.php' ) ) {
23
  define( 'ADVANCEDCACHEPROBLEM', 1 );
24
  }
25
  }
26
- if ( defined( 'ADVANCEDCACHEPROBLEM' ) )
27
  register_shutdown_function( 'wpcache_broken_message' );
28
- ?>
 
1
  <?php
2
+ // WP SUPER CACHE 1.2
3
  function wpcache_broken_message() {
4
  global $wp_cache_config_file;
5
+ if ( isset( $wp_cache_config_file ) == false ) {
6
  return '';
7
+ }
8
 
9
+ $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
10
  $xmlrpc_request = defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST;
11
+ $rest_request = defined( 'REST_REQUEST' ) && REST_REQUEST;
12
+ $robots_request = strpos( $_SERVER['REQUEST_URI'], 'robots.txt' ) != false;
13
 
14
+ $skip_output = ( $doing_ajax || $xmlrpc_request || $rest_request || $robots_request );
15
+ if ( false == strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) && ! $skip_output ) {
16
+ 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. -->';
17
  }
18
  }
19
 
20
  if ( false == defined( 'WPCACHEHOME' ) ) {
21
  define( 'ADVANCEDCACHEPROBLEM', 1 );
22
+ } elseif ( ! include_once WPCACHEHOME . 'wp-cache-phase1.php' ) {
23
+ if ( ! @is_file( WPCACHEHOME . 'wp-cache-phase1.php' ) ) {
24
  define( 'ADVANCEDCACHEPROBLEM', 1 );
25
  }
26
  }
27
+ if ( defined( 'ADVANCEDCACHEPROBLEM' ) ) {
28
  register_shutdown_function( 'wpcache_broken_message' );
29
+ }
30
+
languages/wp-super-cache-sr_RS.po CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013
2
  # This file is distributed under the same license as the package.
3
  msgid ""
4
  msgstr ""
1
+ # Copyright (C) 2013
2
  # This file is distributed under the same license as the package.
3
  msgid ""
4
  msgstr ""
languages/wp-super-cache-zh_CN.po CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2012
2
  # This file is distributed under the same license as the package.
3
  msgid ""
4
  msgstr ""
1
+ # Copyright (C) 2012
2
  # This file is distributed under the same license as the package.
3
  msgid ""
4
  msgstr ""
ossdl-cdn.php CHANGED
@@ -3,38 +3,47 @@
3
  /* Taken from OSSDL CDN off-linker, a plugin by W-Mark Kubacki (http://mark.ossdl.de/) and used with permission */
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
- if ( get_option( 'ossdl_off_blog_url' ) == false )
 
9
  add_option( 'ossdl_off_blog_url', apply_filters( 'ossdl_off_blog_url', untrailingslashit( get_option( 'siteurl' ) ) ) );
 
10
  $ossdl_off_blog_url = get_option( 'ossdl_off_blog_url' );
11
- $ossdl_off_cdn_url = trim( get_option('ossdl_off_cdn_url') );
12
- if ( get_option( 'ossdl_off_include_dirs' ) == false )
13
- add_option('ossdl_off_include_dirs', 'wp-content,wp-includes');
14
- $ossdl_off_include_dirs = trim(get_option('ossdl_off_include_dirs'));
15
- if ( get_option( 'ossdl_off_exclude' ) == false )
16
- add_option('ossdl_off_exclude', '.php');
17
- $ossdl_off_exclude = trim(get_option('ossdl_off_exclude'));
18
- $arr_of_excludes = array_map('trim', explode(',', $ossdl_off_exclude));
19
- if ( !is_array( $arr_of_excludes ) )
 
 
20
  $arr_of_excludes = array();
 
21
 
22
- if ( get_option( 'ossdl_cname' ) == false )
23
- add_option('ossdl_cname', '');
24
- $ossdl_cname = trim(get_option('ossdl_cname'));
25
- $ossdl_https = intval(get_option('ossdl_https'));
26
- $arr_of_cnames = array_map('trim', explode(',', $ossdl_cname));
27
- if ($arr_of_cnames[0] == '') $arr_of_cnames = array();
 
 
 
28
 
29
  /**
30
  * Determines whether to exclude a match.
31
  *
32
- * @param String $match URI to examine
33
- * @param Array $excludes array of "badwords"
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
  }
@@ -42,14 +51,19 @@ function scossdl_off_exclude_match($match, $excludes) {
42
  return false;
43
  }
44
 
45
- /**
46
  * Compute string modulo, based on SHA1 hash
 
 
 
 
 
47
  */
48
- function scossdl_string_mod($s, $mod) {
49
  /* The full SHA1 is too large for PHP integer types. This should be
50
  * enough for our purpose */
51
- $n = hexdec(substr(sha1($s), 0, 5));
52
- return $n % $mod;
53
  }
54
 
55
  /**
@@ -57,29 +71,32 @@ function scossdl_string_mod($s, $mod) {
57
  *
58
  * Called by #scossdl_off_filter.
59
  */
60
- function scossdl_off_rewriter($match) {
61
  global $ossdl_off_blog_url, $ossdl_off_cdn_url, $arr_of_excludes, $arr_of_cnames, $ossdl_https;
62
 
63
- if ( $ossdl_off_cdn_url == '' )
64
  return $match[0];
 
65
 
66
- if ( $ossdl_https && substr( $match[0], 0, 5 ) == 'https' )
67
  return $match[0];
 
68
 
69
- if ( false == in_array( $ossdl_off_cdn_url, $arr_of_cnames ) )
70
  $arr_of_cnames[] = $ossdl_off_cdn_url;
 
71
 
72
  if ( scossdl_off_exclude_match( $match[0], $arr_of_excludes ) ) {
73
  return $match[0];
74
- } else {
75
- $include_dirs = scossdl_off_additional_directories();
76
- if ( preg_match( '/' . $include_dirs . '/', $match[0] ) ) {
77
- $offset = scossdl_string_mod($match[1], count($arr_of_cnames));
78
- return str_replace($ossdl_off_blog_url, $arr_of_cnames[$offset], $match[0]);
79
- } else {
80
- return $match[0];
81
- }
82
  }
 
 
 
 
 
 
 
 
83
  }
84
 
85
  /**
@@ -88,27 +105,29 @@ function scossdl_off_rewriter($match) {
88
  * @return String with the pattern with {@literal |} as prefix, or empty
89
  */
90
  function scossdl_off_additional_directories() {
91
- global $ossdl_off_include_dirs;
92
- $input = explode(',', $ossdl_off_include_dirs);
93
- if ($ossdl_off_include_dirs == '' || count($input) < 1) {
94
- return 'wp\-content|wp\-includes';
95
- } else {
96
- return implode('|', array_map('quotemeta', array_map('trim', $input)));
97
- }
 
98
  }
99
 
100
  /**
101
  * Output filter which runs the actual plugin logic.
102
  */
103
- function scossdl_off_filter($content) {
104
  global $ossdl_off_blog_url, $ossdl_off_cdn_url;
105
- if ($ossdl_off_blog_url == $ossdl_off_cdn_url) { // no rewrite needed
 
106
  return $content;
107
- } else {
108
- $dirs = scossdl_off_additional_directories();
109
- $regex = '#(?<=[(\"\'])'.quotemeta($ossdl_off_blog_url).'/(?:((?:'.$dirs.')[^\"\')]+)|([^/\"\']+\.[^/\"\')]+))(?=[\"\')])#';
110
- return preg_replace_callback($regex, 'scossdl_off_rewriter', $content);
111
  }
 
 
 
 
112
  }
113
 
114
  /**
@@ -116,40 +135,39 @@ function scossdl_off_filter($content) {
116
  */
117
  function do_scossdl_off_ob_start() {
118
  global $ossdl_off_blog_url, $ossdl_off_cdn_url;
119
- if ($ossdl_off_blog_url != $ossdl_off_cdn_url) {
120
  add_filter( 'wp_cache_ob_callback_filter', 'scossdl_off_filter' );
121
  }
122
  }
123
- if ( false == isset( $ossdlcdn ) )
124
  $ossdlcdn = 1; // have to default to on for existing users.
125
- if ( $ossdlcdn == 1 )
126
- add_action('init', 'do_scossdl_off_ob_start');
 
 
127
 
128
  function scossdl_off_update() {
129
- global $ossdlcdn, $wp_cache_config_file;
130
-
131
- $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
132
-
133
- if ( $valid_nonce && isset($_POST['action']) && ( $_POST['action'] == 'update_ossdl_off' )){
134
- update_option( 'ossdl_off_cdn_url', untrailingslashit( $_POST[ 'ossdl_off_cdn_url' ] ) );
135
- update_option( 'ossdl_off_blog_url', untrailingslashit( $_POST[ 'ossdl_off_blog_url' ] ) );
136
- update_option('ossdl_off_include_dirs', $_POST['ossdl_off_include_dirs'] == '' ? 'wp-content,wp-includes' : $_POST['ossdl_off_include_dirs']);
137
- update_option('ossdl_off_exclude', $_POST['ossdl_off_exclude']);
138
- update_option('ossdl_cname', $_POST['ossdl_cname']);
139
- if ( !isset( $_POST[ 'ossdl_https' ] ) )
140
- $_POST[ 'ossdl_https' ] = 0;
141
- update_option('ossdl_https', (int)$_POST['ossdl_https']);
142
- if ( isset( $_POST[ 'ossdlcdn' ] ) ) {
143
- $ossdlcdn = 1;
144
- } else {
145
- $ossdlcdn = 0;
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, $ossdl_off_blog_url;
153
 
154
  scossdl_off_update();
155
 
@@ -158,9 +176,9 @@ function scossdl_off_options() {
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_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>
@@ -171,11 +189,11 @@ function scossdl_off_options() {
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="">
174
- <?php wp_nonce_field('wp-cache'); ?>
175
  <table class="form-table"><tbody>
176
  <tr valign="top">
177
  <td style='text-align: right'>
178
- <input id='ossdlcdn' type="checkbox" name="ossdlcdn" value="1" <?php if ( $ossdlcdn ) echo "checked=1"; ?> />
179
  </td>
180
  <th scope="row"><label for="ossdlcdn"><?php _e( 'Enable CDN Support', 'wp-super-cache' ); ?></label></th>
181
  </tr>
@@ -219,9 +237,8 @@ function scossdl_off_options() {
219
  </tr>
220
  </tbody></table>
221
  <input type="hidden" name="action" value="update_ossdl_off" />
222
- <p class="submit"><input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'wp-super-cache' ) ?>" /></p>
223
  </form></p>
224
- <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>
225
  <?php
226
  }
227
- ?>
3
  /* Taken from OSSDL CDN off-linker, a plugin by W-Mark Kubacki (http://mark.ossdl.de/) and used with permission */
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
+ }
9
+ if ( get_option( 'ossdl_off_blog_url' ) === false ) {
10
  add_option( 'ossdl_off_blog_url', apply_filters( 'ossdl_off_blog_url', untrailingslashit( get_option( 'siteurl' ) ) ) );
11
+ }
12
  $ossdl_off_blog_url = get_option( 'ossdl_off_blog_url' );
13
+ $ossdl_off_cdn_url = trim( get_option( 'ossdl_off_cdn_url' ) );
14
+ if ( get_option( 'ossdl_off_include_dirs' ) === false ) {
15
+ add_option( 'ossdl_off_include_dirs', 'wp-content,wp-includes' );
16
+ }
17
+ $ossdl_off_include_dirs = trim( get_option( 'ossdl_off_include_dirs' ) );
18
+ if ( get_option( 'ossdl_off_exclude' ) === false ) {
19
+ add_option( 'ossdl_off_exclude', '.php' );
20
+ }
21
+ $ossdl_off_exclude = trim( get_option( 'ossdl_off_exclude' ) );
22
+ $arr_of_excludes = array_map( 'trim', explode( ',', $ossdl_off_exclude ) );
23
+ if ( ! is_array( $arr_of_excludes ) ) {
24
  $arr_of_excludes = array();
25
+ }
26
 
27
+ if ( get_option( 'ossdl_cname' ) == false ) {
28
+ add_option( 'ossdl_cname', '' );
29
+ }
30
+ $ossdl_cname = trim( get_option( 'ossdl_cname' ) );
31
+ $ossdl_https = intval( get_option( 'ossdl_https' ) );
32
+ $arr_of_cnames = array_map( 'trim', explode( ',', $ossdl_cname ) );
33
+ if ( $arr_of_cnames[0] == '' ) {
34
+ $arr_of_cnames = array();
35
+ }
36
 
37
  /**
38
  * Determines whether to exclude a match.
39
  *
40
+ * @param string $match URI to examine.
41
+ * @param array $excludes Array of "badwords".
42
+ *
43
+ * @return boolean true if to exclude given match from rewriting.
44
  */
45
+ function scossdl_off_exclude_match( $match, $excludes ) {
46
+ foreach ( $excludes as $badword ) {
47
  if ( ! empty( $badword ) && stripos( $match, $badword ) !== false ) {
48
  return true;
49
  }
51
  return false;
52
  }
53
 
54
+ /**
55
  * Compute string modulo, based on SHA1 hash
56
+ *
57
+ * @param string $str
58
+ * @param int $mod
59
+ *
60
+ * @return int
61
  */
62
+ function scossdl_string_mod( $str, $mod ) {
63
  /* The full SHA1 is too large for PHP integer types. This should be
64
  * enough for our purpose */
65
+ $num = hexdec( substr( sha1( $str ), 0, 5 ) );
66
+ return $num % $mod;
67
  }
68
 
69
  /**
71
  *
72
  * Called by #scossdl_off_filter.
73
  */
74
+ function scossdl_off_rewriter( $match ) {
75
  global $ossdl_off_blog_url, $ossdl_off_cdn_url, $arr_of_excludes, $arr_of_cnames, $ossdl_https;
76
 
77
+ if ( $ossdl_off_cdn_url == '' ) {
78
  return $match[0];
79
+ }
80
 
81
+ if ( $ossdl_https && 0 === strncmp( $match[0], 'https', 5 ) ) {
82
  return $match[0];
83
+ }
84
 
85
+ if ( false === in_array( $ossdl_off_cdn_url, $arr_of_cnames ) ) {
86
  $arr_of_cnames[] = $ossdl_off_cdn_url;
87
+ }
88
 
89
  if ( scossdl_off_exclude_match( $match[0], $arr_of_excludes ) ) {
90
  return $match[0];
 
 
 
 
 
 
 
 
91
  }
92
+
93
+ $include_dirs = scossdl_off_additional_directories();
94
+ if ( preg_match( '/' . $include_dirs . '/', $match[0] ) ) {
95
+ $offset = scossdl_string_mod( $match[1], count( $arr_of_cnames ) );
96
+ return str_replace( $ossdl_off_blog_url, $arr_of_cnames[ $offset ], $match[0] );
97
+ }
98
+
99
+ return $match[0];
100
  }
101
 
102
  /**
105
  * @return String with the pattern with {@literal |} as prefix, or empty
106
  */
107
  function scossdl_off_additional_directories() {
108
+ global $ossdl_off_include_dirs;
109
+
110
+ $arr_dirs = explode( ',', $ossdl_off_include_dirs );
111
+ if ( $ossdl_off_include_dirs == '' || count( $arr_dirs ) < 1 ) {
112
+ return 'wp\-content|wp\-includes';
113
+ }
114
+
115
+ return implode( '|', array_map( 'preg_quote', array_map( 'trim', $arr_dirs ) ) );
116
  }
117
 
118
  /**
119
  * Output filter which runs the actual plugin logic.
120
  */
121
+ function scossdl_off_filter( $content ) {
122
  global $ossdl_off_blog_url, $ossdl_off_cdn_url;
123
+
124
+ if ( $ossdl_off_blog_url == $ossdl_off_cdn_url ) { // no rewrite needed
125
  return $content;
 
 
 
 
126
  }
127
+
128
+ $dirs = scossdl_off_additional_directories();
129
+ $regex = '#(?<=[(\"\'])' . preg_quote( $ossdl_off_blog_url ) . '/(?:((?:' . $dirs . ')[^\"\')]+)|([^/\"\']+\.[^/\"\')]+))(?=[\"\')])#';
130
+ return preg_replace_callback( $regex, 'scossdl_off_rewriter', $content );
131
  }
132
 
133
  /**
135
  */
136
  function do_scossdl_off_ob_start() {
137
  global $ossdl_off_blog_url, $ossdl_off_cdn_url;
138
+ if ( $ossdl_off_blog_url != $ossdl_off_cdn_url ) {
139
  add_filter( 'wp_cache_ob_callback_filter', 'scossdl_off_filter' );
140
  }
141
  }
142
+ if ( false == isset( $ossdlcdn ) ) {
143
  $ossdlcdn = 1; // have to default to on for existing users.
144
+ }
145
+ if ( $ossdlcdn == 1 ) {
146
+ add_action( 'init', 'do_scossdl_off_ob_start' );
147
+ }
148
 
149
  function scossdl_off_update() {
150
+
151
+ if ( isset( $_POST['action'], $_POST['_wpnonce'] )
152
+ && 'update_ossdl_off' === $_POST['action']
153
+ && wp_verify_nonce( $_POST['_wpnonce'], 'wp-cache' )
154
+ ) {
155
+ update_option( 'ossdl_off_cdn_url', untrailingslashit( $_POST['ossdl_off_cdn_url'] ) );
156
+ update_option( 'ossdl_off_blog_url', untrailingslashit( $_POST['ossdl_off_blog_url'] ) );
157
+ update_option( 'ossdl_off_include_dirs', $_POST['ossdl_off_include_dirs'] == '' ? 'wp-content,wp-includes' : $_POST['ossdl_off_include_dirs'] );
158
+ update_option( 'ossdl_off_exclude', $_POST['ossdl_off_exclude'] );
159
+ update_option( 'ossdl_cname', $_POST['ossdl_cname'] );
160
+
161
+ $ossdl_https = empty( $_POST['ossdl_https'] ) ? 0 : 1;
162
+ $ossdlcdn = empty( $_POST['ossdlcdn'] ) ? 0 : 1;
163
+
164
+ update_option( 'ossdl_https', $ossdl_https );
165
+ wp_cache_setting( 'ossdlcdn', $ossdlcdn );
 
 
 
166
  }
167
  }
168
 
169
  function scossdl_off_options() {
170
+ global $ossdlcdn, $ossdl_off_blog_url;
171
 
172
  scossdl_off_update();
173
 
176
  $example_cnames .= ',' . str_replace( 'http://cdn.', 'http://cdn2.', $example_cdn_uri );
177
  $example_cnames .= ',' . str_replace( 'http://cdn.', 'http://cdn3.', $example_cdn_uri );
178
 
179
+ $example_cdn_uri = get_option( 'ossdl_off_cdn_url' ) == get_option( 'siteurl' ) ? $example_cdn_uri : get_option( 'ossdl_off_cdn_url' );
180
  $example_cdn_uri .= '/wp-includes/js/jquery/jquery-migrate.js';
181
+ $example_cdn_uri = esc_url( $example_cdn_uri );
182
  ?>
183
  <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>
184
  <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>
189
 
190
  <p><?php _e( 'You can define different CDN URLs for each site on a multsite network.', 'wp-super-cache' ); ?></p>
191
  <p><form method="post" action="">
192
+ <?php wp_nonce_field( 'wp-cache' ); ?>
193
  <table class="form-table"><tbody>
194
  <tr valign="top">
195
  <td style='text-align: right'>
196
+ <input id='ossdlcdn' type="checkbox" name="ossdlcdn" value="1" <?php if ( $ossdlcdn ) { echo "checked=1"; } ?> />
197
  </td>
198
  <th scope="row"><label for="ossdlcdn"><?php _e( 'Enable CDN Support', 'wp-super-cache' ); ?></label></th>
199
  </tr>
237
  </tr>
238
  </tbody></table>
239
  <input type="hidden" name="action" value="update_ossdl_off" />
240
+ <p class="submit"><input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'wp-super-cache' ); ?>" /></p>
241
  </form></p>
242
+ <p><?php _e( 'CDN functionality provided by <a href="https://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>
243
  <?php
244
  }
 
plugins/awaitingmoderation.php CHANGED
@@ -7,21 +7,21 @@ function awaitingmoderation_action( $buffer ) {
7
 
8
  function awaitingmoderation_actions() {
9
  global $cache_awaitingmoderation;
10
- if( $cache_awaitingmoderation == '1' ) {
11
  add_filter( 'wpsupercache_buffer', 'awaitingmoderation_action' );
12
  }
13
  }
14
  add_cacheaction( 'add_cacheaction', 'awaitingmoderation_actions' );
15
 
16
- //Your comment is awaiting moderation.
17
  function wp_supercache_awaitingmoderation_admin() {
18
  global $cache_awaitingmoderation, $wp_cache_config_file, $valid_nonce;
19
 
20
- $cache_awaitingmoderation = $cache_awaitingmoderation == '' ? '0' : $cache_awaitingmoderation;
21
 
22
- if(isset($_POST['cache_awaitingmoderation']) && $valid_nonce) {
23
- $cache_awaitingmoderation = (int)$_POST['cache_awaitingmoderation'];
24
- wp_cache_replace_line('^ *\$cache_awaitingmoderation', "\$cache_awaitingmoderation = '$cache_awaitingmoderation';", $wp_cache_config_file);
25
  $changed = true;
26
  } else {
27
  $changed = false;
@@ -31,19 +31,20 @@ function wp_supercache_awaitingmoderation_admin() {
31
  <fieldset id="<?php echo $id; ?>" class="options">
32
  <h4><?php _e( 'Awaiting Moderation', 'wp-super-cache' ); ?></h4>
33
  <form name="wp_manager" action="" method="post">
34
- <label><input type="radio" name="cache_awaitingmoderation" value="1" <?php if( $cache_awaitingmoderation ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
35
- <label><input type="radio" name="cache_awaitingmoderation" value="0" <?php if( !$cache_awaitingmoderation ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
36
  <p><?php _e( 'Enables or disables plugin to Remove the text "Your comment is awaiting moderation." when someone leaves a moderated comment.', 'wp-super-cache' ); ?></p>
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>';
46
- wp_nonce_field('wp-cache');
47
  ?>
48
  </form>
49
  </fieldset>
@@ -53,13 +54,12 @@ function wp_supercache_awaitingmoderation_admin() {
53
  add_cacheaction( 'cache_admin_page', 'wp_supercache_awaitingmoderation_admin' );
54
 
55
  function wpsc_awaiting_moderation_list( $list ) {
56
- $list[ 'awaitingmoderation' ] = array(
57
- 'key' => 'awaitingmoderation',
58
- 'url' => '',
59
  'title' => __( 'Awaiting Moderation', 'wp-super-cache' ),
60
- 'desc' => __( 'Enables or disables plugin to Remove the text "Your comment is awaiting moderation." when someone leaves a moderated comment.', 'wp-super-cache' ),
61
  );
62
  return $list;
63
  }
64
  add_cacheaction( 'wpsc_filter_list', 'wpsc_awaiting_moderation_list' );
65
- ?>
7
 
8
  function awaitingmoderation_actions() {
9
  global $cache_awaitingmoderation;
10
+ if ( '1' === $cache_awaitingmoderation ) {
11
  add_filter( 'wpsupercache_buffer', 'awaitingmoderation_action' );
12
  }
13
  }
14
  add_cacheaction( 'add_cacheaction', 'awaitingmoderation_actions' );
15
 
16
+ // Your comment is awaiting moderation.
17
  function wp_supercache_awaitingmoderation_admin() {
18
  global $cache_awaitingmoderation, $wp_cache_config_file, $valid_nonce;
19
 
20
+ $cache_awaitingmoderation = '' === $cache_awaitingmoderation ? '0' : $cache_awaitingmoderation;
21
 
22
+ if ( isset( $_POST['cache_awaitingmoderation'] ) && $valid_nonce ) {
23
+ $cache_awaitingmoderation = (int) $_POST['cache_awaitingmoderation'];
24
+ wp_cache_replace_line( '^ *\$cache_awaitingmoderation', "\$cache_awaitingmoderation = '$cache_awaitingmoderation';", $wp_cache_config_file );
25
  $changed = true;
26
  } else {
27
  $changed = false;
31
  <fieldset id="<?php echo $id; ?>" class="options">
32
  <h4><?php _e( 'Awaiting Moderation', 'wp-super-cache' ); ?></h4>
33
  <form name="wp_manager" action="" method="post">
34
+ <label><input type="radio" name="cache_awaitingmoderation" value="1" <?php if ( $cache_awaitingmoderation ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
35
+ <label><input type="radio" name="cache_awaitingmoderation" value="0" <?php if ( ! $cache_awaitingmoderation ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
36
  <p><?php _e( 'Enables or disables plugin to Remove the text "Your comment is awaiting moderation." when someone leaves a moderated comment.', 'wp-super-cache' ); ?></p>
37
  <?php
38
+ if ( $changed ) {
39
+ if ( $cache_awaitingmoderation ) {
40
+ $status = __( 'enabled', 'wp-super-cache' );
41
+ } else {
42
+ $status = __( 'disabled', 'wp-super-cache' );
43
+ }
44
+ echo '<p><strong>' . sprintf( __( 'Awaiting Moderation is now %s', 'wp-super-cache' ), $status ) . '</strong></p>';
45
  }
46
+ echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
47
+ wp_nonce_field( 'wp-cache' );
48
  ?>
49
  </form>
50
  </fieldset>
54
  add_cacheaction( 'cache_admin_page', 'wp_supercache_awaitingmoderation_admin' );
55
 
56
  function wpsc_awaiting_moderation_list( $list ) {
57
+ $list['awaitingmoderation'] = array(
58
+ 'key' => 'awaitingmoderation',
59
+ 'url' => '',
60
  'title' => __( 'Awaiting Moderation', 'wp-super-cache' ),
61
+ 'desc' => __( 'Enables or disables plugin to Remove the text "Your comment is awaiting moderation." when someone leaves a moderated comment.', 'wp-super-cache' ),
62
  );
63
  return $list;
64
  }
65
  add_cacheaction( 'wpsc_filter_list', 'wpsc_awaiting_moderation_list' );
 
plugins/badbehaviour.php CHANGED
@@ -3,8 +3,9 @@
3
  function wp_supercache_badbehaviour( $file ) {
4
  global $cache_badbehaviour;
5
 
6
- if( $cache_badbehaviour != 1 )
7
  return $file;
 
8
  wp_supercache_badbehaviour_include();
9
  return $file;
10
  }
@@ -12,18 +13,20 @@ add_cacheaction( 'wp_cache_served_cache_file', 'wp_supercache_badbehaviour' );
12
 
13
  function wp_supercache_badbehaviour_include() {
14
  $bbfile = get_bb_file_loc();
15
- if( !$bbfile )
16
- require_once( $bbfile );
 
17
  }
18
 
19
  function get_bb_file_loc() {
20
  global $cache_badbehaviour_file;
21
- if( $cache_badbehaviour_file )
22
  return $cache_badbehaviour_file;
 
23
 
24
- if( file_exists( WP_CONTENT_DIR . '/plugins/bad-behavior/bad-behavior-generic.php' ) ) {
25
  $bbfile = WP_CONTENT_DIR . '/plugins/bad-behavior/bad-behavior-generic.php';
26
- } elseif( file_exists( WP_CONTENT_DIR . '/plugins/Bad-Behavior/bad-behavior-generic.php' ) ) {
27
  $bbfile = WP_CONTENT_DIR . '/plugins/Bad-Behavior/bad-behavior-generic.php';
28
  } else {
29
  $bbfile = false;
@@ -34,27 +37,28 @@ function get_bb_file_loc() {
34
  function wp_supercache_badbehaviour_admin() {
35
  global $cache_badbehaviour, $wp_cache_config_file, $valid_nonce;
36
 
37
- $cache_badbehaviour = $cache_badbehaviour == '' ? 0 : $cache_badbehaviour;
38
- if ( $cache_badbehaviour == 'no' )
39
  $cache_badbehaviour = 0;
 
40
 
41
  $err = false;
42
 
43
  if ( isset( $_POST['cache_badbehaviour'] ) && $valid_nonce ) {
44
  $bbfile = get_bb_file_loc();
45
- if( !$bbfile ) {
46
- $_POST[ 'cache_badbehaviour' ] = 0;
47
  $err = __( 'Bad Behaviour not found. Please check your install.', 'wp-super-cache' );
48
  }
49
- if ( $cache_badbehaviour == (int)$_POST['cache_badbehaviour'] ) {
50
  $changed = false;
51
  } else {
52
  $changed = true;
53
  }
54
- $cache_badbehaviour = (int)$_POST['cache_badbehaviour'];
55
- wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = 0;", $wp_cache_config_file);
56
- wp_cache_replace_line('^ *\$cache_badbehaviour', "\$cache_badbehaviour = $cache_badbehaviour;", $wp_cache_config_file);
57
- wp_cache_replace_line('^ *\$cache_badbehaviour_file', "\$cache_badbehaviour_file = '$bbfile';", $wp_cache_config_file);
58
  $changed = true;
59
  }
60
  $id = 'badbehavior-section';
@@ -62,31 +66,33 @@ function wp_supercache_badbehaviour_admin() {
62
  <fieldset id="<?php echo $id; ?>" class="options">
63
  <h4><?php _e( 'Bad Behavior', 'wp-super-cache' ); ?></h4>
64
  <form name="wp_manager" action="" method="post">
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>';
77
- wp_nonce_field('wp-cache');
78
  ?>
79
  </form>
80
  </fieldset>
81
  <?php
82
- if( $err )
83
- echo "<p><strong>" . __( 'Warning!', 'wp-super-cache' ) . "</strong> $err</p>";
 
84
 
85
  }
86
  add_cacheaction( 'cache_admin_page', 'wp_supercache_badbehaviour_admin' );
87
 
88
  function wpsc_badbehaviour_list( $list ) {
89
- $list[ 'badbehaviour' ] = array(
90
  'key' => 'badbehaviour',
91
  'url' => 'http://www.bad-behavior.ioerror.us/',
92
  'title' => __( 'Bad Behavior', 'wp-super-cache' ),
@@ -95,5 +101,3 @@ function wpsc_badbehaviour_list( $list ) {
95
  return $list;
96
  }
97
  add_cacheaction( 'wpsc_filter_list', 'wpsc_badbehaviour_list' );
98
-
99
- ?>
3
  function wp_supercache_badbehaviour( $file ) {
4
  global $cache_badbehaviour;
5
 
6
+ if ( 1 !== $cache_badbehaviour ) {
7
  return $file;
8
+ }
9
  wp_supercache_badbehaviour_include();
10
  return $file;
11
  }
13
 
14
  function wp_supercache_badbehaviour_include() {
15
  $bbfile = get_bb_file_loc();
16
+ if ( ! $bbfile ) {
17
+ require_once $bbfile;
18
+ }
19
  }
20
 
21
  function get_bb_file_loc() {
22
  global $cache_badbehaviour_file;
23
+ if ( $cache_badbehaviour_file ) {
24
  return $cache_badbehaviour_file;
25
+ }
26
 
27
+ if ( file_exists( WP_CONTENT_DIR . '/plugins/bad-behavior/bad-behavior-generic.php' ) ) {
28
  $bbfile = WP_CONTENT_DIR . '/plugins/bad-behavior/bad-behavior-generic.php';
29
+ } elseif ( file_exists( WP_CONTENT_DIR . '/plugins/Bad-Behavior/bad-behavior-generic.php' ) ) {
30
  $bbfile = WP_CONTENT_DIR . '/plugins/Bad-Behavior/bad-behavior-generic.php';
31
  } else {
32
  $bbfile = false;
37
  function wp_supercache_badbehaviour_admin() {
38
  global $cache_badbehaviour, $wp_cache_config_file, $valid_nonce;
39
 
40
+ $cache_badbehaviour = '' === $cache_badbehaviour ? 0 : $cache_badbehaviour;
41
+ if ( 'no' === $cache_badbehaviour ) {
42
  $cache_badbehaviour = 0;
43
+ }
44
 
45
  $err = false;
46
 
47
  if ( isset( $_POST['cache_badbehaviour'] ) && $valid_nonce ) {
48
  $bbfile = get_bb_file_loc();
49
+ if ( ! $bbfile ) {
50
+ $_POST['cache_badbehaviour'] = 0;
51
  $err = __( 'Bad Behaviour not found. Please check your install.', 'wp-super-cache' );
52
  }
53
+ if ( $cache_badbehaviour === (int) $_POST['cache_badbehaviour'] ) {
54
  $changed = false;
55
  } else {
56
  $changed = true;
57
  }
58
+ $cache_badbehaviour = (int) $_POST['cache_badbehaviour'];
59
+ wp_cache_replace_line( '^ *\$cache_compression', "\$cache_compression = 0;", $wp_cache_config_file );
60
+ wp_cache_replace_line( '^ *\$cache_badbehaviour', "\$cache_badbehaviour = $cache_badbehaviour;", $wp_cache_config_file );
61
+ wp_cache_replace_line( '^ *\$cache_badbehaviour_file', "\$cache_badbehaviour_file = '$bbfile';", $wp_cache_config_file );
62
  $changed = true;
63
  }
64
  $id = 'badbehavior-section';
66
  <fieldset id="<?php echo $id; ?>" class="options">
67
  <h4><?php _e( 'Bad Behavior', 'wp-super-cache' ); ?></h4>
68
  <form name="wp_manager" action="" method="post">
69
+ <label><input type="radio" name="cache_badbehaviour" value="1" <?php if ( $cache_badbehaviour ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
70
+ <label><input type="radio" name="cache_badbehaviour" value="0" <?php if ( ! $cache_badbehaviour ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
71
  <p><?php _e( '', 'wp-super-cache' ); ?></p><?php
72
  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>';
73
  if ( isset( $changed ) && $changed ) {
74
+ if ( $cache_badbehaviour ) {
75
+ $status = __( 'enabled', 'wp-super-cache' );
76
+ } else {
77
+ $status = __( 'disable', 'wp-super-cache' );
78
+ }
79
+ echo '<p><strong>' . sprintf( __( 'Bad Behavior support is now %s', 'wp-super-cache' ), $status ) . '</strong></p>';
80
  }
81
+ echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
82
+ wp_nonce_field( 'wp-cache' );
83
  ?>
84
  </form>
85
  </fieldset>
86
  <?php
87
+ if ( $err ) {
88
+ echo '<p><strong>' . __( 'Warning!', 'wp-super-cache' ) . "</strong> $err</p>";
89
+ }
90
 
91
  }
92
  add_cacheaction( 'cache_admin_page', 'wp_supercache_badbehaviour_admin' );
93
 
94
  function wpsc_badbehaviour_list( $list ) {
95
+ $list['badbehaviour'] = array(
96
  'key' => 'badbehaviour',
97
  'url' => 'http://www.bad-behavior.ioerror.us/',
98
  'title' => __( 'Bad Behavior', 'wp-super-cache' ),
101
  return $list;
102
  }
103
  add_cacheaction( 'wpsc_filter_list', 'wpsc_badbehaviour_list' );
 
 
plugins/domain-mapping.php CHANGED
@@ -3,28 +3,31 @@
3
  function domain_mapping_gc_cache( $function, $directory ) {
4
  global $cache_path;
5
 
6
- if ( !function_exists( 'domain_mapping_warning' ) )
7
  return false;
 
8
 
9
  $siteurl = domain_mapping_siteurl( false );
10
- if ( !$siteurl )
11
  return false;
 
12
 
13
- $protocol = ( isset( $_SERVER['HTTPS' ] ) && 'on' == strtolower( $_SERVER['HTTPS' ] ) ) ? 'https://' : 'http://';
14
- $siteurl = trailingslashit( str_replace( $protocol, '', $siteurl ) );
15
 
16
- if ( $directory == 'homepage' )
17
  $directory = '';
 
18
 
19
- switch( $function ) {
20
- case "rebuild":
21
  @wp_cache_rebuild_or_delete( $cache_path . 'supercache/' . $siteurl . $directory . 'index.html' );
22
  @wp_cache_rebuild_or_delete( $cache_path . 'supercache/' . $siteurl . $directory . 'index.html.gz' );
23
- break;
24
- case "prune":
25
  prune_super_cache( $cache_path . 'supercache/' . $siteurl . $directory . 'index.html', true, true );
26
  prune_super_cache( $cache_path . 'supercache/' . $siteurl . $directory . 'index.html.gz', true, true );
27
- break;
28
  }
29
 
30
  return $directory;
@@ -32,21 +35,23 @@ function domain_mapping_gc_cache( $function, $directory ) {
32
 
33
  function domain_mapping_supercachedir( $dir ) {
34
  global $cache_path;
35
- if ( !function_exists( 'domain_mapping_warning' ) )
36
  return $dir;
 
37
 
38
  $siteurl = domain_mapping_siteurl( false );
39
- if ( !$siteurl )
40
  return $dir;
 
41
 
42
- $protocol = ( isset( $_SERVER['HTTPS' ] ) && 'on' == strtolower( $_SERVER['HTTPS' ] ) ) ? 'https://' : 'http://';
43
- $siteurl = str_replace( $protocol, '', $siteurl );
44
  return trailingslashit( $cache_path . 'supercache/' . $siteurl );
45
  }
46
 
47
  function domain_mapping_actions() {
48
  global $cache_domain_mapping;
49
- if( $cache_domain_mapping == '1' ) {
50
  add_filter( 'wp_super_cache_supercachedir', 'domain_mapping_supercachedir' );
51
  add_action( 'gc_cache', 'domain_mapping_gc_cache', 10, 2 );
52
  }
@@ -56,35 +61,37 @@ add_cacheaction( 'add_cacheaction', 'domain_mapping_actions' );
56
  function wp_supercache_domain_mapping_admin() {
57
  global $cache_domain_mapping, $wp_cache_config_file, $valid_nonce;
58
 
59
- $cache_domain_mapping = $cache_domain_mapping == '' ? '0' : $cache_domain_mapping;
60
 
61
- if(isset($_POST['cache_domain_mapping']) && $valid_nonce) {
62
- if ( $cache_domain_mapping == (int)$_POST['cache_domain_mapping'] ) {
63
  $changed = false;
64
  } else {
65
  $changed = true;
66
  }
67
- $cache_domain_mapping = (int)$_POST['cache_domain_mapping'];
68
- wp_cache_replace_line('^ *\$cache_domain_mapping', "\$cache_domain_mapping = '$cache_domain_mapping';", $wp_cache_config_file);
69
  }
70
  $id = 'domain_mapping-section';
71
  ?>
72
  <fieldset id="<?php echo $id; ?>" class="options">
73
  <h4><?php _e( 'Domain Mapping', 'wp-super-cache' ); ?></h4>
74
  <form name="wp_manager" action="" method="post">
75
- <label><input type="radio" name="cache_domain_mapping" value="1" <?php if( $cache_domain_mapping ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
76
- <label><input type="radio" name="cache_domain_mapping" value="0" <?php if( !$cache_domain_mapping ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
77
- <p><?php _e( '', 'wp-super-cache' ); ?></p><?php
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>';
87
- wp_nonce_field('wp-cache');
88
  ?>
89
  </form>
90
  </fieldset>
@@ -94,31 +101,32 @@ 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
  }
100
  function wp_supercache_domain_mapping_exists() {
101
  global $cache_domain_mapping;
102
- if ( $cache_domain_mapping == 1 )
103
  return false;
 
104
 
105
- if ( is_admin() && function_exists( 'domain_mapping_warning' ) )
106
  add_action( 'admin_notices', 'wp_supercache_domain_mapping_notice' );
 
107
  }
108
 
109
- if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wpsupercache' ) {
110
  add_cacheaction( 'add_cacheaction', 'wp_supercache_domain_mapping_exists' );
111
  }
112
 
113
  function wpsc_domain_mapping_list( $list ) {
114
- $list[ 'domain_mapping' ] = array(
115
  'key' => 'domain_mapping',
116
- 'url' => 'http://wordpress.org/extend/plugins/wordpress-mu-domain-mapping/',
117
  'title' => __( 'Domain Mapping', 'wp-super-cache' ),
118
  'desc' => __( 'Provides support for Domain Mapping plugin to map multiple domains to a blog.', 'wp-super-cache' ),
119
  );
120
  return $list;
121
  }
122
  add_cacheaction( 'wpsc_filter_list', 'wpsc_domain_mapping_list' );
123
-
124
- ?>
3
  function domain_mapping_gc_cache( $function, $directory ) {
4
  global $cache_path;
5
 
6
+ if ( ! function_exists( 'domain_mapping_warning' ) ) {
7
  return false;
8
+ }
9
 
10
  $siteurl = domain_mapping_siteurl( false );
11
+ if ( ! $siteurl ) {
12
  return false;
13
+ }
14
 
15
+ $protocol = ( isset( $_SERVER['HTTPS'] ) && 'on' === strtolower( $_SERVER['HTTPS'] ) ) ? 'https://' : 'http://';
16
+ $siteurl = trailingslashit( str_replace( $protocol, '', $siteurl ) );
17
 
18
+ if ( 'homepage' === $directory ) {
19
  $directory = '';
20
+ }
21
 
22
+ switch ( $function ) {
23
+ case 'rebuild':
24
  @wp_cache_rebuild_or_delete( $cache_path . 'supercache/' . $siteurl . $directory . 'index.html' );
25
  @wp_cache_rebuild_or_delete( $cache_path . 'supercache/' . $siteurl . $directory . 'index.html.gz' );
26
+ break;
27
+ case 'prune':
28
  prune_super_cache( $cache_path . 'supercache/' . $siteurl . $directory . 'index.html', true, true );
29
  prune_super_cache( $cache_path . 'supercache/' . $siteurl . $directory . 'index.html.gz', true, true );
30
+ break;
31
  }
32
 
33
  return $directory;
35
 
36
  function domain_mapping_supercachedir( $dir ) {
37
  global $cache_path;
38
+ if ( ! function_exists( 'domain_mapping_warning' ) ) {
39
  return $dir;
40
+ }
41
 
42
  $siteurl = domain_mapping_siteurl( false );
43
+ if ( ! $siteurl ) {
44
  return $dir;
45
+ }
46
 
47
+ $protocol = ( isset( $_SERVER['HTTPS'] ) && 'on' === strtolower( $_SERVER['HTTPS'] ) ) ? 'https://' : 'http://';
48
+ $siteurl = str_replace( $protocol, '', $siteurl );
49
  return trailingslashit( $cache_path . 'supercache/' . $siteurl );
50
  }
51
 
52
  function domain_mapping_actions() {
53
  global $cache_domain_mapping;
54
+ if ( '1' === $cache_domain_mapping ) {
55
  add_filter( 'wp_super_cache_supercachedir', 'domain_mapping_supercachedir' );
56
  add_action( 'gc_cache', 'domain_mapping_gc_cache', 10, 2 );
57
  }
61
  function wp_supercache_domain_mapping_admin() {
62
  global $cache_domain_mapping, $wp_cache_config_file, $valid_nonce;
63
 
64
+ $cache_domain_mapping = '' === $cache_domain_mapping ? '0' : $cache_domain_mapping;
65
 
66
+ if ( isset( $_POST['cache_domain_mapping'] ) && $valid_nonce ) {
67
+ if ( $cache_domain_mapping === (int) $_POST['cache_domain_mapping'] ) {
68
  $changed = false;
69
  } else {
70
  $changed = true;
71
  }
72
+ $cache_domain_mapping = (int) $_POST['cache_domain_mapping'];
73
+ wp_cache_replace_line( '^ *\$cache_domain_mapping', "\$cache_domain_mapping = '$cache_domain_mapping';", $wp_cache_config_file );
74
  }
75
  $id = 'domain_mapping-section';
76
  ?>
77
  <fieldset id="<?php echo $id; ?>" class="options">
78
  <h4><?php _e( 'Domain Mapping', 'wp-super-cache' ); ?></h4>
79
  <form name="wp_manager" action="" method="post">
80
+ <label><input type="radio" name="cache_domain_mapping" value="1" <?php if ( $cache_domain_mapping ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
81
+ <label><input type="radio" name="cache_domain_mapping" value="0" <?php if ( ! $cache_domain_mapping ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
82
+ <p><?php _e( '', 'wp-super-cache' ); ?></p>
83
+ <?php
84
+ echo '<p>' . __( 'Provides support for <a href="https://wordpress.org/plugins/wordpress-mu-domain-mapping/">Domain Mapping</a> plugin to map multiple domains to a blog.', 'wp-super-cache' ) . '</p>';
85
+ if ( isset( $changed ) && $changed ) {
86
+ if ( $cache_domain_mapping ) {
87
+ $status = __( 'enabled', 'wp-super-cache' );
88
+ } else {
89
+ $status = __( 'disabled', 'wp-super-cache' );
90
  }
91
+ echo '<p><strong>' . sprintf( __( 'Domain Mapping support is now %s', 'wp-super-cache' ), $status ) . '</strong></p>';
92
+ }
93
  echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
94
+ wp_nonce_field( 'wp-cache' );
95
  ?>
96
  </form>
97
  </fieldset>
101
 
102
  function wp_supercache_domain_mapping_notice() {
103
  global $cache_enabled;
104
+ if ( $cache_enabled ) {
105
+ 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>';
106
+ }
107
  }
108
  function wp_supercache_domain_mapping_exists() {
109
  global $cache_domain_mapping;
110
+ if ( '1' === $cache_domain_mapping ) {
111
  return false;
112
+ }
113
 
114
+ if ( is_admin() && function_exists( 'domain_mapping_warning' ) ) {
115
  add_action( 'admin_notices', 'wp_supercache_domain_mapping_notice' );
116
+ }
117
  }
118
 
119
+ if ( isset( $_GET['page'] ) && 'wpsupercache' === $_GET['page'] ) {
120
  add_cacheaction( 'add_cacheaction', 'wp_supercache_domain_mapping_exists' );
121
  }
122
 
123
  function wpsc_domain_mapping_list( $list ) {
124
+ $list['domain_mapping'] = array(
125
  'key' => 'domain_mapping',
126
+ 'url' => 'https://wordpress.org/plugins/wordpress-mu-domain-mapping/',
127
  'title' => __( 'Domain Mapping', 'wp-super-cache' ),
128
  'desc' => __( 'Provides support for Domain Mapping plugin to map multiple domains to a blog.', 'wp-super-cache' ),
129
  );
130
  return $list;
131
  }
132
  add_cacheaction( 'wpsc_filter_list', 'wpsc_domain_mapping_list' );
 
 
plugins/dynamic-cache-test.php CHANGED
@@ -23,6 +23,11 @@
23
  * for processing.
24
  *
25
  * **** MAKE SURE YOU KEEP THE TEMPLATE TAG SECRET ****
 
 
 
 
 
26
  */
27
 
28
  /*
@@ -63,26 +68,26 @@
63
  * 4. The wp_footer action fires and the TAG is printed to the page.
64
  * 5. Processing continues and the page is created.
65
  * 6. The output buffer finishes. A WP Super Cache callback function runs
66
- * and saves the output buffer to a cache file. The wpsc_cachedata
67
  * filter is called.
68
  * 7. The function dynamic_cache_test_filter() runs and replaces the TAG in
69
  * the buffer with the "Hello world" string.
70
  * 8. The output buffer is pushed to the browser to be displayed.
71
  */
72
- define( 'DYNAMIC_CACHE_TEST_TAG', '' ); // Change this to a secret placeholder tag
73
- if ( DYNAMIC_CACHE_TEST_TAG != '' ) {
74
  function dynamic_cache_test_safety( $safety ) {
75
  return 1;
76
  }
77
  add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_cache_test_safety' );
78
 
79
- function dynamic_cache_test_filter( &$cachedata) {
80
- return str_replace( DYNAMIC_CACHE_TEST_TAG, "<!-- Hello world at " . date( 'H:i:s' ) . " -->", $cachedata );
81
  }
82
  add_cacheaction( 'wpsc_cachedata', 'dynamic_cache_test_filter' );
83
 
84
  function dynamic_cache_test_template_tag() {
85
- echo DYNAMIC_CACHE_TEST_TAG; // This is the template tag
86
  }
87
 
88
  function dynamic_cache_test_init() {
@@ -133,7 +138,6 @@ if ( DYNAMIC_CACHE_TEST_TAG != '' ) {
133
  * very last line of dynamic_output_buffer_test() replaces the placeholder tag
134
  * with the dynamic content in the cache file.
135
  *
136
- *
137
  * Use an output buffer to capture dynamic content while the page is generated
138
  * and insert into the right place:
139
  * Remember to add the DYNAMIC_OUTPUT_BUFFER_TAG text (as defined below) to
@@ -145,23 +149,25 @@ if ( DYNAMIC_CACHE_TEST_TAG != '' ) {
145
  *
146
  */
147
 
148
- define( 'DYNAMIC_OUTPUT_BUFFER_TAG', '' ); // Change this to a secret placeholder tag
149
 
150
- if ( DYNAMIC_OUTPUT_BUFFER_TAG != '' ) {
151
- function dynamic_output_buffer_test( &$cachedata = 0 ) {
152
- if ( defined( 'DYNAMIC_OB_TEXT' ) )
153
  return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, DYNAMIC_OB_TEXT, $cachedata );
 
154
 
155
  ob_start();
156
  // call the sidebar function, do something dynamic
157
- echo "<p>This is a test. The current time on the server is: " . date( 'H:i:s' ) . "</p>";
158
  $text = ob_get_contents();
159
  ob_end_clean();
160
 
161
- if ( $cachedata === 0 ) { // called directly from the theme so store the output
162
  define( 'DYNAMIC_OB_TEXT', $text );
163
- } else // called via the wpsc_cachedata filter. We only get here in cached pages in wp-cache-phase1.php
164
  return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, $text, $cachedata );
 
165
 
166
  }
167
  add_cacheaction( 'wpsc_cachedata', 'dynamic_output_buffer_test' );
@@ -172,11 +178,11 @@ if ( DYNAMIC_OUTPUT_BUFFER_TAG != '' ) {
172
  add_cacheaction( 'add_cacheaction', 'dynamic_output_buffer_init' );
173
 
174
  function dynamic_output_buffer_test_safety( $safety ) {
175
- if ( defined( 'DYNAMIC_OB_TEXT' ) ) // this is set when you call dynamic_output_buffer_test() from the theme
176
  return 1; // ready to replace tag with dynamic content.
177
- else
178
  return 0; // tag cannot be replaced.
 
179
  }
180
  add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_output_buffer_test_safety' );
181
  }
182
- ?>
23
  * for processing.
24
  *
25
  * **** MAKE SURE YOU KEEP THE TEMPLATE TAG SECRET ****
26
+ * You should probably add 'deny from all' to the .htaccess in the cache directory
27
+ * so visitors can't directly load any cached html files and discover the secret
28
+ * tag. Or you can move the cache directory out of the web path and set the
29
+ * cache location to that new directory on the advanced settings page.
30
+ *
31
  */
32
 
33
  /*
68
  * 4. The wp_footer action fires and the TAG is printed to the page.
69
  * 5. Processing continues and the page is created.
70
  * 6. The output buffer finishes. A WP Super Cache callback function runs
71
+ * and saves the output buffer to a cache file. The wpsc_cachedata
72
  * filter is called.
73
  * 7. The function dynamic_cache_test_filter() runs and replaces the TAG in
74
  * the buffer with the "Hello world" string.
75
  * 8. The output buffer is pushed to the browser to be displayed.
76
  */
77
+ define( 'DYNAMIC_CACHE_TEST_TAG', '' ); // Change this to a secret placeholder tag.
78
+ if ( '' !== DYNAMIC_CACHE_TEST_TAG ) {
79
  function dynamic_cache_test_safety( $safety ) {
80
  return 1;
81
  }
82
  add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_cache_test_safety' );
83
 
84
+ function dynamic_cache_test_filter( $cachedata ) {
85
+ return str_replace( DYNAMIC_CACHE_TEST_TAG, '<!-- Hello world at ' . date( 'H:i:s' ) . ' -->', $cachedata );
86
  }
87
  add_cacheaction( 'wpsc_cachedata', 'dynamic_cache_test_filter' );
88
 
89
  function dynamic_cache_test_template_tag() {
90
+ echo DYNAMIC_CACHE_TEST_TAG; // This is the template tag.
91
  }
92
 
93
  function dynamic_cache_test_init() {
138
  * very last line of dynamic_output_buffer_test() replaces the placeholder tag
139
  * with the dynamic content in the cache file.
140
  *
 
141
  * Use an output buffer to capture dynamic content while the page is generated
142
  * and insert into the right place:
143
  * Remember to add the DYNAMIC_OUTPUT_BUFFER_TAG text (as defined below) to
149
  *
150
  */
151
 
152
+ define( 'DYNAMIC_OUTPUT_BUFFER_TAG', '' ); // Change this to a secret placeholder tag.
153
 
154
+ if ( '' !== DYNAMIC_OUTPUT_BUFFER_TAG ) {
155
+ function dynamic_output_buffer_test( $cachedata = 0 ) {
156
+ if ( defined( 'DYNAMIC_OB_TEXT' ) ) {
157
  return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, DYNAMIC_OB_TEXT, $cachedata );
158
+ }
159
 
160
  ob_start();
161
  // call the sidebar function, do something dynamic
162
+ echo '<p>This is a test. The current time on the server is: ' . date( 'H:i:s' ) . '</p>';
163
  $text = ob_get_contents();
164
  ob_end_clean();
165
 
166
+ if ( 0 === $cachedata ) { // called directly from the theme so store the output.
167
  define( 'DYNAMIC_OB_TEXT', $text );
168
+ } else { // called via the wpsc_cachedata filter. We only get here in cached pages in wp-cache-phase1.php.
169
  return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, $text, $cachedata );
170
+ }
171
 
172
  }
173
  add_cacheaction( 'wpsc_cachedata', 'dynamic_output_buffer_test' );
178
  add_cacheaction( 'add_cacheaction', 'dynamic_output_buffer_init' );
179
 
180
  function dynamic_output_buffer_test_safety( $safety ) {
181
+ if ( defined( 'DYNAMIC_OB_TEXT' ) ) {// this is set when you call dynamic_output_buffer_test() from the theme.
182
  return 1; // ready to replace tag with dynamic content.
183
+ } else {
184
  return 0; // tag cannot be replaced.
185
+ }
186
  }
187
  add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_output_buffer_test_safety' );
188
  }
 
plugins/jetpack.php CHANGED
@@ -3,20 +3,20 @@
3
  function wp_super_cache_jetpack_admin() {
4
  global $cache_jetpack, $wp_cache_config_file, $valid_nonce;
5
 
6
- $cache_jetpack = $cache_jetpack == '' ? '0' : $cache_jetpack;
7
 
8
- if(isset($_POST['cache_jetpack']) && $valid_nonce) {
9
- if ( $cache_jetpack == (int)$_POST['cache_jetpack'] ) {
10
  $changed = false;
11
  } else {
12
  $changed = true;
13
  }
14
- $cache_jetpack = (int)$_POST['cache_jetpack'];
15
- wp_cache_replace_line('^ *\$cache_jetpack', "\$cache_jetpack = '$cache_jetpack';", $wp_cache_config_file);
16
  if ( $changed && $cache_jetpack ) {
17
- wp_cache_replace_line('^ *\$wp_cache_mobile_enabled', '$wp_cache_mobile_enabled = 1;', $wp_cache_config_file);
18
- wp_cache_replace_line('^ *\$wp_cache_mod_rewrite', '$wp_cache_mod_rewrite = 0;', $wp_cache_config_file);
19
- wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = 1;', $wp_cache_config_file);
20
  }
21
  }
22
  $id = 'jetpack-section';
@@ -24,23 +24,25 @@ function wp_super_cache_jetpack_admin() {
24
  <fieldset id="<?php echo $id; ?>" class="options">
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>
32
- <label><input type="radio" name="cache_jetpack" value="0" <?php if( !$cache_jetpack ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
33
  <?php
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>';
43
- wp_nonce_field('wp-cache');
44
  ?>
45
  </form>
46
  <?php } ?>
@@ -50,41 +52,40 @@ function wp_super_cache_jetpack_admin() {
50
  add_cacheaction( 'cache_admin_page', 'wp_super_cache_jetpack_admin' );
51
 
52
  function wp_super_cache_jetpack_cookie_check( $cache_key ) {
53
- if ( function_exists( "jetpack_is_mobile" ) == false ) {
54
 
55
  if ( file_exists( dirname( WPCACHEHOME ) . '/jetpack-dev/class.jetpack-user-agent.php' ) ) {
56
  wp_cache_debug( "wp_super_cache_jetpack_cookie_check: jetpack dev detected. Returning 'normal' to avoid loading Jetpack." );
57
- return "normal";
58
  } elseif ( file_exists( dirname( WPCACHEHOME ) . '/jetpack/class.jetpack-user-agent.php' ) ) {
59
- include_once( dirname( WPCACHEHOME ) . '/jetpack/class.jetpack-user-agent.php' );
60
  } else {
61
- wp_cache_debug( "wp_super_cache_jetpack_cookie_check: jetpack UA file not found." );
62
  }
63
  }
64
 
65
- if ( function_exists( "jetpack_is_mobile" ) ) {
66
- if ( jetpack_is_mobile() )
67
  return 'mobile';
68
- else
69
  return 'normal';
 
70
  } else {
71
- return "normal";
72
  }
73
  }
74
 
75
- if ( isset( $cache_jetpack ) && $cache_jetpack == 1 ) {
76
  add_cacheaction( 'wp_cache_check_mobile', 'wp_super_cache_jetpack_cookie_check' );
77
  }
78
 
79
  function wpsc_cache_jetpack_list( $list ) {
80
- $list[ 'jetpack' ] = array(
81
  'key' => 'jetpack',
82
- 'url' => 'http://wordpress.org/extend/plugins/jetpack/',
83
  'title' => __( 'Jetpack Mobile Theme', 'wp-super-cache' ),
84
  'desc' => __( 'Provides support for the Jetpack mobile theme and plugin. PHP caching mode and mobile support will be enabled too.', 'wp-super-cache' ),
85
  );
86
  return $list;
87
  }
88
  add_cacheaction( 'wpsc_filter_list', 'wpsc_cache_jetpack_list' );
89
-
90
- ?>
3
  function wp_super_cache_jetpack_admin() {
4
  global $cache_jetpack, $wp_cache_config_file, $valid_nonce;
5
 
6
+ $cache_jetpack = '' === $cache_jetpack ? '0' : $cache_jetpack;
7
 
8
+ if ( isset( $_POST['cache_jetpack'] ) && $valid_nonce ) {
9
+ if ( $cache_jetpack === (int) $_POST['cache_jetpack'] ) {
10
  $changed = false;
11
  } else {
12
  $changed = true;
13
  }
14
+ $cache_jetpack = (int) $_POST['cache_jetpack'];
15
+ wp_cache_replace_line( '^ *\$cache_jetpack', "\$cache_jetpack = '$cache_jetpack';", $wp_cache_config_file );
16
  if ( $changed && $cache_jetpack ) {
17
+ wp_cache_replace_line( '^ *\$wp_cache_mobile_enabled', '$wp_cache_mobile_enabled = 1;', $wp_cache_config_file );
18
+ wp_cache_replace_line( '^ *\$wp_cache_mod_rewrite', '$wp_cache_mod_rewrite = 0;', $wp_cache_config_file );
19
+ wp_cache_replace_line( '^ *\$super_cache_enabled', '$super_cache_enabled = 1;', $wp_cache_config_file );
20
  }
21
  }
22
  $id = 'jetpack-section';
24
  <fieldset id="<?php echo $id; ?>" class="options">
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
+ ?>
31
  <form name="wp_manager" action="" method="post">
32
+ <label><input type="radio" name="cache_jetpack" value="1" <?php if ( $cache_jetpack ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
33
+ <label><input type="radio" name="cache_jetpack" value="0" <?php if ( ! $cache_jetpack ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
34
  <?php
35
+ echo '<p>' . __( 'Provides support for the <a href="https://wordpress.org/plugins/jetpack/">Jetpack</a> mobile theme and plugin. PHP caching mode and mobile support will be enabled too.', 'wp-super-cache' ) . '</p>';
36
  if ( isset( $changed ) && $changed ) {
37
+ if ( $cache_jetpack ) {
38
+ $status = __( 'enabled', 'wp-super-cache' );
39
+ } else {
40
+ $status = __( 'disabled', 'wp-super-cache' );
41
+ }
42
+ echo '<p><strong>' . sprintf( __( 'Jetpack Mobile Theme support is now %s', 'wp-super-cache' ), $status ) . '</strong></p>';
43
  }
44
  echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
45
+ wp_nonce_field( 'wp-cache' );
46
  ?>
47
  </form>
48
  <?php } ?>
52
  add_cacheaction( 'cache_admin_page', 'wp_super_cache_jetpack_admin' );
53
 
54
  function wp_super_cache_jetpack_cookie_check( $cache_key ) {
55
+ if ( false === function_exists( 'jetpack_is_mobile' ) ) {
56
 
57
  if ( file_exists( dirname( WPCACHEHOME ) . '/jetpack-dev/class.jetpack-user-agent.php' ) ) {
58
  wp_cache_debug( "wp_super_cache_jetpack_cookie_check: jetpack dev detected. Returning 'normal' to avoid loading Jetpack." );
59
+ return 'normal';
60
  } elseif ( file_exists( dirname( WPCACHEHOME ) . '/jetpack/class.jetpack-user-agent.php' ) ) {
61
+ include_once dirname( WPCACHEHOME ) . '/jetpack/class.jetpack-user-agent.php';
62
  } else {
63
+ wp_cache_debug( 'wp_super_cache_jetpack_cookie_check: jetpack UA file not found.' );
64
  }
65
  }
66
 
67
+ if ( function_exists( 'jetpack_is_mobile' ) ) {
68
+ if ( jetpack_is_mobile() ) {
69
  return 'mobile';
70
+ } else {
71
  return 'normal';
72
+ }
73
  } else {
74
+ return 'normal';
75
  }
76
  }
77
 
78
+ if ( isset( $cache_jetpack ) && '1' === $cache_jetpack ) {
79
  add_cacheaction( 'wp_cache_check_mobile', 'wp_super_cache_jetpack_cookie_check' );
80
  }
81
 
82
  function wpsc_cache_jetpack_list( $list ) {
83
+ $list['jetpack'] = array(
84
  'key' => 'jetpack',
85
+ 'url' => 'https://wordpress.org/plugins/jetpack/',
86
  'title' => __( 'Jetpack Mobile Theme', 'wp-super-cache' ),
87
  'desc' => __( 'Provides support for the Jetpack mobile theme and plugin. PHP caching mode and mobile support will be enabled too.', 'wp-super-cache' ),
88
  );
89
  return $list;
90
  }
91
  add_cacheaction( 'wpsc_filter_list', 'wpsc_cache_jetpack_list' );
 
 
plugins/multisite.php CHANGED
@@ -1,7 +1,8 @@
1
  <?php
2
 
3
- if ( ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) || defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) )
4
  add_cacheaction( 'add_cacheaction', 'wp_super_cache_multisite_init' );
 
5
 
6
  function wp_super_cache_multisite_init() {
7
  add_filter( 'wpmu_blogs_columns', 'wp_super_cache_blogs_col' );
@@ -10,48 +11,52 @@ function wp_super_cache_multisite_init() {
10
  }
11
 
12
  function wp_super_cache_blogs_col( $col ) {
13
- $col[ 'wp_super_cache' ] = __( 'Cached', 'wp-super-cache' );
14
  return $col;
15
  }
16
 
17
  function wp_super_cache_blogs_field( $name, $blog_id ) {
18
- if ( $name != 'wp_super_cache' )
19
  return false;
 
20
 
21
- if ( isset( $_GET[ 'id' ] ) && $blog_id == $_GET[ 'id' ] ) {
22
- $valid_nonce = isset( $_GET[ '_wpnonce' ] ) ? wp_verify_nonce( $_GET[ '_wpnonce' ], 'wp-cache' . $_GET[ 'id' ] ) : false;
23
- if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'disable_cache' ) {
24
- add_blog_option( $_GET[ 'id' ], 'wp_super_cache_disabled', 1 );
25
- } elseif ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'enable_cache' ) {
26
- delete_blog_option( $_GET[ 'id' ], 'wp_super_cache_disabled' );
 
 
27
  }
28
  }
29
 
30
- if ( get_blog_option( $blog_id, 'wp_super_cache_disabled' ) == 1 ) {
31
- echo "<a href='" . wp_nonce_url( add_query_arg( array( 'action' => 'enable_cache', 'id' => $blog_id ) ), 'wp-cache' . $blog_id ) . "'>" . __( 'Enable', 'wp-super-cache' ) . "</a>";
32
  } else {
33
- echo "<a href='" . wp_nonce_url( add_query_arg( array( 'action' => 'disable_cache', 'id' => $blog_id ) ), 'wp-cache' . $blog_id ) . "'>" . __( 'Disable', 'wp-super-cache' ) . "</a>";
34
  }
35
  }
36
 
37
  function wp_super_cache_multisite_notice() {
38
- if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wpsupercache' )
39
  echo '<div class="error"><p><strong>' . __( 'Caching has been disabled on this blog on the Network Admin Sites page.', 'wp-super-cache' ) . '</strong></p></div>';
 
40
  }
41
 
42
  function wp_super_cache_override_on_flag() {
43
  global $cache_enabled, $super_cache_enabled;
44
- if ( $cache_enabled != true )
45
  return false;
 
46
 
47
  if ( get_option( 'wp_super_cache_disabled' ) ) {
48
  $cache_enabled = false;
49
  $super_cache_enabled = false;
50
  define( 'DONOTCACHEPAGE', 1 );
51
- define( "SUBMITDISABLED", 'disabled style="color: #aaa" ' );
52
- if ( is_admin() )
53
  add_action( 'admin_notices', 'wp_super_cache_multisite_notice' );
 
54
  }
55
  }
56
-
57
- ?>
1
  <?php
2
 
3
+ if ( ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) === true ) || defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) ) {
4
  add_cacheaction( 'add_cacheaction', 'wp_super_cache_multisite_init' );
5
+ }
6
 
7
  function wp_super_cache_multisite_init() {
8
  add_filter( 'wpmu_blogs_columns', 'wp_super_cache_blogs_col' );
11
  }
12
 
13
  function wp_super_cache_blogs_col( $col ) {
14
+ $col['wp_super_cache'] = __( 'Cached', 'wp-super-cache' );
15
  return $col;
16
  }
17
 
18
  function wp_super_cache_blogs_field( $name, $blog_id ) {
19
+ if ( 'wp_super_cache' !== $name ) {
20
  return false;
21
+ }
22
 
23
+ if ( isset( $_GET['id'], $_GET['action'], $_GET['_wpnonce'] )
24
+ && $blog_id === intval( $_GET['id'] )
25
+ && wp_verify_nonce( $_GET['_wpnonce'], 'wp-cache' . $blog_id )
26
+ ) {
27
+ if ( 'disable_cache' === $_GET['action'] ) {
28
+ add_blog_option( $_GET['id'], 'wp_super_cache_disabled', 1 );
29
+ } elseif ( 'enable_cache' === $_GET['action'] ) {
30
+ delete_blog_option( $_GET['id'], 'wp_super_cache_disabled' );
31
  }
32
  }
33
 
34
+ if ( get_blog_option( $blog_id, 'wp_super_cache_disabled' ) === 1 ) {
35
+ echo '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'enable_cache', 'id' => $blog_id ) ), 'wp-cache' . $blog_id ) . '">' . __( 'Enable', 'wp-super-cache' ) . '</a>';
36
  } else {
37
+ echo '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'disable_cache', 'id' => $blog_id ) ), 'wp-cache' . $blog_id ) . '">' . __( 'Disable', 'wp-super-cache' ) . '</a>';
38
  }
39
  }
40
 
41
  function wp_super_cache_multisite_notice() {
42
+ if ( isset( $_GET['page'] ) && 'wpsupercache' === $_GET['page'] ) {
43
  echo '<div class="error"><p><strong>' . __( 'Caching has been disabled on this blog on the Network Admin Sites page.', 'wp-super-cache' ) . '</strong></p></div>';
44
+ }
45
  }
46
 
47
  function wp_super_cache_override_on_flag() {
48
  global $cache_enabled, $super_cache_enabled;
49
+ if ( true !== $cache_enabled ) {
50
  return false;
51
+ }
52
 
53
  if ( get_option( 'wp_super_cache_disabled' ) ) {
54
  $cache_enabled = false;
55
  $super_cache_enabled = false;
56
  define( 'DONOTCACHEPAGE', 1 );
57
+ define( 'SUBMITDISABLED', 'disabled style="color: #aaa" ' );
58
+ if ( is_admin() ) {
59
  add_action( 'admin_notices', 'wp_super_cache_multisite_notice' );
60
+ }
61
  }
62
  }
 
 
plugins/searchengine.php CHANGED
@@ -1,32 +1,32 @@
1
  <?php
 
2
  function wp_supercache_searchengine( $string ) {
3
  global $passingthrough, $nevershowads, $cache_no_adverts_for_friends;
4
 
5
  $cache_no_adverts_for_friends = wpsc_get_searchengine_setting();
6
- if ( ! $cache_no_adverts_for_friends )
7
- return $string;
8
-
9
- if( $string != '' )
10
  return $string;
 
11
 
12
- if( isset( $_COOKIE[ '7a1254cba80da02d5478d91cfd0a873a' ] ) && $_COOKIE[ '7a1254cba80da02d5478d91cfd0a873a' ] == 1 ) {
13
  $string = 'searchengine';
14
- } elseif( isset( $_SERVER[ 'HTTP_REFERER' ] ) && $_SERVER[ 'HTTP_REFERER' ] != '' ) {
15
- if( is_array( $passingthrough ) == false )
16
  return $string;
 
17
 
18
- foreach( $passingthrough as $url ) {
19
- if( strpos( $_SERVER[ 'HTTP_REFERER' ], $url ) ) {
20
  reset( $nevershowads );
21
  $se = false;
22
- foreach( $nevershowads as $whitesite ) {
23
- if( false == strpos( $_SERVER[ 'HTTP_REFERER' ], $whitesite ) ) {
24
  $se = true;
25
  }
26
  }
27
- if( $se ) {
28
  $string = 'searchengine';
29
- @setcookie( '7a1254cba80da02d5478d91cfd0a873a', 1, time()+3600, '/' );
30
  }
31
  }
32
  }
@@ -37,7 +37,7 @@ function wp_supercache_searchengine( $string ) {
37
  add_cacheaction( 'wp_cache_get_cookies_values', 'wp_supercache_searchengine' );
38
 
39
  function searchenginesupercache( $user_info ) {
40
- if( $user_info == 'searchengine' && is_single() && is_old_post() ) {
41
  return true;
42
  } else {
43
  return false;
@@ -52,10 +52,10 @@ function wpsc_get_searchengine_setting() {
52
  }
53
 
54
  $changed = false;
55
- if ( $cache_no_adverts_for_friends === 'yes' || $cache_no_adverts_for_friends === '1' ) {
56
  $cache_no_adverts_for_friends = 1;
57
  $changed = true;
58
- } elseif ( $cache_no_adverts_for_friends === 'no' ) {
59
  $cache_no_adverts_for_friends = 0;
60
  $changed = true;
61
  }
@@ -81,13 +81,13 @@ function wp_supercache_searchengine_admin() {
81
 
82
  $cache_no_adverts_for_friends = wpsc_get_searchengine_setting();
83
 
84
- if(isset($_POST['cache_no_adverts_for_friends']) && $valid_nonce) {
85
- if ( $cache_no_adverts_for_friends != (int)$_POST[ 'cache_no_adverts_for_friends' ] ) {
86
  $changed = 1;
87
  } else {
88
  $changed = 0;
89
  }
90
- $cache_no_adverts_for_friends = (int)$_POST[ 'cache_no_adverts_for_friends' ];
91
  wp_cache_setting( 'cache_no_adverts_for_friends', $cache_no_adverts_for_friends );
92
  }
93
  ?>
@@ -99,14 +99,15 @@ function wp_supercache_searchengine_admin() {
99
  <?php
100
  echo '<p>' . __( 'Provides support for <a href="https://odd.blog/no-adverts-for-friends/">No Adverts for Friends</a>.', 'wp-super-cache' ) . '</p>';
101
  if ( isset( $changed ) && $changed ) {
102
- if ( $cache_no_adverts_for_friends )
103
- $status = __( "enabled", 'wp-super-cache' );
104
- else
105
- $status = __( "disabled", 'wp-super-cache' );
106
- echo "<p><strong>" . sprintf( __( "No Adverts for Friends support is now %s", 'wp-super-cache' ), $status ) . "</strong></p>";
 
107
  }
108
  echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
109
- wp_nonce_field('wp-cache');
110
  ?>
111
  </form>
112
  </fieldset>
@@ -116,7 +117,7 @@ function wp_supercache_searchengine_admin() {
116
  add_cacheaction( 'cache_admin_page', 'wp_supercache_searchengine_admin' );
117
 
118
  function wpsc_cache_no_adverts_for_friends_list( $list ) {
119
- $list[ 'no_adverts_for_friends' ] = array(
120
  'key' => 'no_adverts_for_friends',
121
  'url' => 'https://odd.blog/no-adverts-for-friends/',
122
  'title' => __( 'No Adverts for Friends', 'wp-super-cache' ),
@@ -125,5 +126,3 @@ function wpsc_cache_no_adverts_for_friends_list( $list ) {
125
  return $list;
126
  }
127
  add_cacheaction( 'wpsc_filter_list', 'wpsc_cache_no_adverts_for_friends_list' );
128
-
129
- ?>
1
  <?php
2
+
3
  function wp_supercache_searchengine( $string ) {
4
  global $passingthrough, $nevershowads, $cache_no_adverts_for_friends;
5
 
6
  $cache_no_adverts_for_friends = wpsc_get_searchengine_setting();
7
+ if ( ! $cache_no_adverts_for_friends || '' != $string ) {
 
 
 
8
  return $string;
9
+ }
10
 
11
+ if ( isset( $_COOKIE['7a1254cba80da02d5478d91cfd0a873a'] ) && '1' === $_COOKIE['7a1254cba80da02d5478d91cfd0a873a'] ) {
12
  $string = 'searchengine';
13
+ } elseif ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
14
+ if ( is_array( $passingthrough ) === false ) {
15
  return $string;
16
+ }
17
 
18
+ foreach ( $passingthrough as $url ) {
19
+ if ( strpos( $_SERVER['HTTP_REFERER'], $url ) ) {
20
  reset( $nevershowads );
21
  $se = false;
22
+ foreach ( $nevershowads as $whitesite ) {
23
+ if ( false === strpos( $_SERVER['HTTP_REFERER'], $whitesite ) ) {
24
  $se = true;
25
  }
26
  }
27
+ if ( $se ) {
28
  $string = 'searchengine';
29
+ @setcookie( '7a1254cba80da02d5478d91cfd0a873a', 1, time() + 3600, '/' );
30
  }
31
  }
32
  }
37
  add_cacheaction( 'wp_cache_get_cookies_values', 'wp_supercache_searchengine' );
38
 
39
  function searchenginesupercache( $user_info ) {
40
+ if ( 'searchengine' === $user_info && is_single() && is_old_post() ) {
41
  return true;
42
  } else {
43
  return false;
52
  }
53
 
54
  $changed = false;
55
+ if ( 'yes' === $cache_no_adverts_for_friends || '1' === $cache_no_adverts_for_friends ) {
56
  $cache_no_adverts_for_friends = 1;
57
  $changed = true;
58
+ } elseif ( 'no' === $cache_no_adverts_for_friends ) {
59
  $cache_no_adverts_for_friends = 0;
60
  $changed = true;
61
  }
81
 
82
  $cache_no_adverts_for_friends = wpsc_get_searchengine_setting();
83
 
84
+ if ( isset( $_POST['cache_no_adverts_for_friends'] ) && $valid_nonce ) {
85
+ if ( $cache_no_adverts_for_friends !== (int) $_POST['cache_no_adverts_for_friends'] ) {
86
  $changed = 1;
87
  } else {
88
  $changed = 0;
89
  }
90
+ $cache_no_adverts_for_friends = (int) $_POST['cache_no_adverts_for_friends'];
91
  wp_cache_setting( 'cache_no_adverts_for_friends', $cache_no_adverts_for_friends );
92
  }
93
  ?>
99
  <?php
100
  echo '<p>' . __( 'Provides support for <a href="https://odd.blog/no-adverts-for-friends/">No Adverts for Friends</a>.', 'wp-super-cache' ) . '</p>';
101
  if ( isset( $changed ) && $changed ) {
102
+ if ( $cache_no_adverts_for_friends ) {
103
+ $status = __( 'enabled', 'wp-super-cache' );
104
+ } else {
105
+ $status = __( 'disabled', 'wp-super-cache' );
106
+ }
107
+ echo '<p><strong>' . sprintf( __( 'No Adverts for Friends support is now %s', 'wp-super-cache' ), $status ) . '</strong></p>';
108
  }
109
  echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
110
+ wp_nonce_field( 'wp-cache' );
111
  ?>
112
  </form>
113
  </fieldset>
117
  add_cacheaction( 'cache_admin_page', 'wp_supercache_searchengine_admin' );
118
 
119
  function wpsc_cache_no_adverts_for_friends_list( $list ) {
120
+ $list['no_adverts_for_friends'] = array(
121
  'key' => 'no_adverts_for_friends',
122
  'url' => 'https://odd.blog/no-adverts-for-friends/',
123
  'title' => __( 'No Adverts for Friends', 'wp-super-cache' ),
126
  return $list;
127
  }
128
  add_cacheaction( 'wpsc_filter_list', 'wpsc_cache_no_adverts_for_friends_list' );
 
 
plugins/wptouch.php CHANGED
@@ -3,35 +3,36 @@
3
  function wp_super_cache_wptouch_admin() {
4
  global $cache_wptouch, $wp_cache_config_file, $valid_nonce;
5
 
6
- $cache_wptouch = $cache_wptouch == '' ? '0' : $cache_wptouch;
7
 
8
- if(isset($_POST['cache_wptouch']) && $valid_nonce) {
9
- if ( $cache_wptouch == (int)$_POST['cache_wptouch'] ) {
10
  $changed = false;
11
  } else {
12
  $changed = true;
13
  }
14
- $cache_wptouch = (int)$_POST['cache_wptouch'];
15
- wp_cache_replace_line('^ *\$cache_wptouch', "\$cache_wptouch = '$cache_wptouch';", $wp_cache_config_file);
16
  }
17
  $id = 'wptouch-section';
18
  ?>
19
  <fieldset id="<?php echo $id; ?>" class="options">
20
  <h4><?php _e( 'WPTouch', 'wp-super-cache' ); ?></h4>
21
  <form name="wp_manager" action="" method="post">
22
- <label><input type="radio" name="cache_wptouch" value="1" <?php if( $cache_wptouch ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
23
- <label><input type="radio" name="cache_wptouch" value="0" <?php if( !$cache_wptouch ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
24
- <?php
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>';
34
- wp_nonce_field('wp-cache');
35
  ?>
36
  </form>
37
  </fieldset>
@@ -41,36 +42,42 @@ 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
  }
47
  function wp_super_cache_wptouch_exists() {
48
  global $cache_wptouch;
49
- if ( $cache_wptouch == 1 )
50
  return false;
 
51
 
52
- if ( is_admin() && function_exists( 'wptouch_get_plugin_dir_name' ) )
53
  add_action( 'admin_notices', 'wp_super_cache_wptouch_notice' );
 
54
  }
55
 
56
- if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wpsupercache' ) {
57
  add_cacheaction( 'add_cacheaction', 'wp_super_cache_wptouch_exists' );
58
  }
59
 
60
- // disable mobile checking if
61
  function wp_super_cache_maybe_disable_wptouch( $t ) {
62
  global $cache_wptouch, $wptouch_exclude_ua;
63
- if ( $cache_wptouch != 1 )
64
  return false;
 
65
 
66
- if ( ( isset( $_COOKIE[ 'wptouch_switch_toggle' ] ) && $_COOKIE[ 'wptouch_switch_toggle' ] == 'normal' ) ||
67
- ( isset( $_COOKIE[ 'wptouch-pro-view' ] ) && $_COOKIE[ 'wptouch-pro-view' ] == 'desktop' ) )
68
  return true;
 
69
 
70
- $ua = explode( ",", $wptouch_exclude_ua );
71
- foreach( $ua as $agent ) {
72
- if ( preg_match( "#$agent#i", $_SERVER[ 'HTTP_HOST' ] ) )
73
- return true; // disable mobile ua check if matches the exclude list in wptouch
 
74
  }
75
 
76
  return false;
@@ -82,12 +89,13 @@ add_cacheaction( 'disable_mobile_check', 'wp_super_cache_maybe_disable_wptouch'
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;
 
87
 
88
- $browsers = implode( ',', bnc_wptouch_get_exclude_user_agents() ); // hack, support exclude agents too
89
- if ( $browsers != $wptouch_exclude_ua ) {
90
- wp_cache_replace_line('^ *\$wptouch_exclude_ua', "\$wptouch_exclude_ua = '$browsers';", $wp_cache_config_file);
91
  $wptouch_exclude_ua = $browsers;
92
  }
93
 
@@ -95,40 +103,41 @@ function wp_super_cache_wptouch_browsers( $browsers ) {
95
  }
96
 
97
  function wp_super_cache_wptouch_prefixes( $prefixes ) {
98
- return array(); // wptouch doesn't support UA prefixes
99
  }
100
 
101
  function wp_super_cache_wptouch_cookie_check( $cache_key ) {
102
- if ( false == isset( $_COOKIE[ 'wptouch_switch_toggle' ] ) )
103
  return $cache_key;
104
- if ( $_COOKIE[ 'wptouch_switch_toggle' ] == 'normal' || $_COOKIE[ 'wptouch_switch_toggle' ] == 'mobile' )
105
- return $_COOKIE[ 'wptouch_switch_toggle' ];
 
 
106
 
107
- if ( isset( $_COOKIE[ 'wptouch-pro-view' ] ) ) {
108
- if ( $_COOKIE[ 'wptouch-pro-view' ] == 'desktop' )
109
  return 'normal';
110
- else
111
- return $_COOKIE[ 'wptouch-pro-view' ];
 
112
  }
113
 
114
  return $cache_key;
115
  }
116
 
117
- if ( isset( $cache_wptouch ) && $cache_wptouch == 1 ) {
118
  add_cacheaction( 'wp_super_cache_mobile_browsers', 'wp_super_cache_wptouch_browsers' );
119
  add_cacheaction( 'wp_super_cache_mobile_prefixes', 'wp_super_cache_wptouch_prefixes' );
120
  add_cacheaction( 'wp_cache_check_mobile', 'wp_super_cache_wptouch_cookie_check' );
121
  }
122
 
123
  function wpsc_wptouch_list( $list ) {
124
- $list[ 'wptouch' ] = array(
125
  'key' => 'wptouch',
126
- 'url' => 'http://wordpress.org/extend/plugins/wptouch/',
127
  'title' => __( 'WPTouch', 'wp-super-cache' ),
128
  'desc' => __( 'Provides support for WPTouch mobile theme and plugin.', 'wp-super-cache' ),
129
  );
130
  return $list;
131
  }
132
  add_cacheaction( 'wpsc_filter_list', 'wpsc_wptouch_list' );
133
-
134
- ?>
3
  function wp_super_cache_wptouch_admin() {
4
  global $cache_wptouch, $wp_cache_config_file, $valid_nonce;
5
 
6
+ $cache_wptouch = '' === $cache_wptouch ? '0' : $cache_wptouch;
7
 
8
+ if ( isset( $_POST['cache_wptouch'] ) && $valid_nonce ) {
9
+ if ( $cache_wptouch === (int) $_POST['cache_wptouch'] ) {
10
  $changed = false;
11
  } else {
12
  $changed = true;
13
  }
14
+ $cache_wptouch = (int) $_POST['cache_wptouch'];
15
+ wp_cache_replace_line( '^ *\$cache_wptouch', "\$cache_wptouch = '$cache_wptouch';", $wp_cache_config_file );
16
  }
17
  $id = 'wptouch-section';
18
  ?>
19
  <fieldset id="<?php echo $id; ?>" class="options">
20
  <h4><?php _e( 'WPTouch', 'wp-super-cache' ); ?></h4>
21
  <form name="wp_manager" action="" method="post">
22
+ <label><input type="radio" name="cache_wptouch" value="1" <?php if ( $cache_wptouch ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
23
+ <label><input type="radio" name="cache_wptouch" value="0" <?php if ( ! $cache_wptouch ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
24
+ <?php
25
+ echo '<p>' . __( 'Provides support for <a href="https://wordpress.org/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
  }
32
+ echo '<p><strong>' . sprintf( __( 'WPTouch support is now %s', 'wp-super-cache' ), $status ) . '</strong></p>';
33
+ }
34
  echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
35
+ wp_nonce_field( 'wp-cache' );
36
  ?>
37
  </form>
38
  </fieldset>
42
 
43
  function wp_super_cache_wptouch_notice() {
44
  global $cache_enabled;
45
+ if ( $cache_enabled ) {
46
+ 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>';
47
+ }
48
  }
49
  function wp_super_cache_wptouch_exists() {
50
  global $cache_wptouch;
51
+ if ( '1' === $cache_wptouch ) {
52
  return false;
53
+ }
54
 
55
+ if ( is_admin() && function_exists( 'wptouch_get_plugin_dir_name' ) ) {
56
  add_action( 'admin_notices', 'wp_super_cache_wptouch_notice' );
57
+ }
58
  }
59
 
60
+ if ( isset( $_GET['page'] ) && 'wpsupercache' === $_GET['page'] ) {
61
  add_cacheaction( 'add_cacheaction', 'wp_super_cache_wptouch_exists' );
62
  }
63
 
64
+ // disable mobile checking if.
65
  function wp_super_cache_maybe_disable_wptouch( $t ) {
66
  global $cache_wptouch, $wptouch_exclude_ua;
67
+ if ( '1' !== $cache_wptouch ) {
68
  return false;
69
+ }
70
 
71
+ if ( ( isset( $_COOKIE['wptouch_switch_toggle'] ) && 'normal' === $_COOKIE['wptouch_switch_toggle'] ) ||
72
+ ( isset( $_COOKIE['wptouch-pro-view'] ) && 'desktop' === $_COOKIE['wptouch-pro-view'] ) ) {
73
  return true;
74
+ }
75
 
76
+ $ua = explode( ',', $wptouch_exclude_ua );
77
+ foreach ( $ua as $agent ) {
78
+ if ( preg_match( "#$agent#i", $_SERVER['HTTP_HOST'] ) ) {
79
+ return true; // disable mobile ua check if matches the exclude list in wptouch.
80
+ }
81
  }
82
 
83
  return false;
89
  function wp_super_cache_wptouch_browsers( $browsers ) {
90
  global $wptouch_exclude_ua, $wp_cache_config_file;
91
 
92
+ if ( false === function_exists( 'bnc_wptouch_get_exclude_user_agents' ) || false === function_exists( 'bnc_wptouch_get_user_agents' ) ) {
93
  return $browsers;
94
+ }
95
 
96
+ $browsers = implode( ',', bnc_wptouch_get_exclude_user_agents() ); // hack, support exclude agents too.
97
+ if ( $browsers !== $wptouch_exclude_ua ) {
98
+ wp_cache_replace_line( '^ *\$wptouch_exclude_ua', "\$wptouch_exclude_ua = '$browsers';", $wp_cache_config_file );
99
  $wptouch_exclude_ua = $browsers;
100
  }
101
 
103
  }
104
 
105
  function wp_super_cache_wptouch_prefixes( $prefixes ) {
106
+ return array(); // wptouch doesn't support UA prefixes.
107
  }
108
 
109
  function wp_super_cache_wptouch_cookie_check( $cache_key ) {
110
+ if ( false === isset( $_COOKIE['wptouch_switch_toggle'] ) ) {
111
  return $cache_key;
112
+ }
113
+ if ( 'normal' === $_COOKIE['wptouch_switch_toggle'] || 'mobile' === $_COOKIE['wptouch_switch_toggle'] ) {
114
+ return $_COOKIE['wptouch_switch_toggle'];
115
+ }
116
 
117
+ if ( isset( $_COOKIE['wptouch-pro-view'] ) ) {
118
+ if ( 'desktop' === $_COOKIE['wptouch-pro-view'] ) {
119
  return 'normal';
120
+ } else {
121
+ return $_COOKIE['wptouch-pro-view'];
122
+ }
123
  }
124
 
125
  return $cache_key;
126
  }
127
 
128
+ if ( isset( $cache_wptouch ) && '1' === $cache_wptouch ) {
129
  add_cacheaction( 'wp_super_cache_mobile_browsers', 'wp_super_cache_wptouch_browsers' );
130
  add_cacheaction( 'wp_super_cache_mobile_prefixes', 'wp_super_cache_wptouch_prefixes' );
131
  add_cacheaction( 'wp_cache_check_mobile', 'wp_super_cache_wptouch_cookie_check' );
132
  }
133
 
134
  function wpsc_wptouch_list( $list ) {
135
+ $list['wptouch'] = array(
136
  'key' => 'wptouch',
137
+ 'url' => 'https://wordpress.org/plugins/wptouch/',
138
  'title' => __( 'WPTouch', 'wp-super-cache' ),
139
  'desc' => __( 'Provides support for WPTouch mobile theme and plugin.', 'wp-super-cache' ),
140
  );
141
  return $list;
142
  }
143
  add_cacheaction( 'wpsc_filter_list', 'wpsc_wptouch_list' );
 
 
readme.txt CHANGED
@@ -1,20 +1,23 @@
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.
9
 
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
 
@@ -26,8 +29,7 @@ The plugin serves cached files in 3 ways (ranked by speed):
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.
@@ -39,24 +41,233 @@ Garbage collection is the act of cleaning up cache files that are out of date an
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 [commit list](https://github.com/Automattic/wp-super-cache/commits/master) 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
- 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)
@@ -71,15 +282,15 @@ Many bug fixes
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)
77
  * Generate a list of archive feeds that can be deleted when the site is updated. Also fixes corrupted config file issue and fatal error with older versions of WordPress. (#403)
78
 
79
- = 1.5.7 =
80
  * Fix fatal error in plugins/searchengine.php (#398)
81
 
82
- = 1.5.6 =
83
  * REST API: Added /plugins endpoint to handle the plugins settings page. (#382)
84
  * Minor changes to indentaion and spaces to tabs conversion (#371) (#395)
85
  * Don't set $wp_super_cache_comments here as it's not saved. (#379)
@@ -90,14 +301,14 @@ Many bug fixes
90
  * Fix some PHP notices when comments are edited/published/maintained. (#386)
91
  * Minor changes to description on plugins page. (#393)
92
 
93
- = 1.5.5 =
94
  * Catch fatal errors so they're not cached, improve code that catches unknown page types. (#367)
95
  * Fix caching on older WP installs, and if the plugin is inactive on a blog, but still caching, give feeds a short TTL to ensure they're fresh. (#366)
96
  * When preloading don't delete sub-directories, or child pages, when caching pages. (#363)
97
  * Avoid PHP warnings from the REST API for settings that are not yet defined. (#361)
98
  * Added missing settings to the config file. (#360)
99
 
100
- = 1.5.4 =
101
  * Fix messages related to creating advanced-cache.php (#355, #354)
102
  * Deleting the plugin doesn't need to delete the cache directory as it's already done on deactivation. (#323)
103
  * Disable Jetpack mobile detection if Jetpack Beta is detected. (#298)
@@ -117,10 +328,10 @@ Many bug fixes
117
  * Other minor changes to html or typos
118
  (Numbers are [pull requests](https://github.com/Automattic/wp-super-cache/pulls) on Github.)
119
 
120
- = 1.5.3 =
121
  * Fix a critical bug that caused unlink to be run on null while deleting the plugin.
122
 
123
- = 1.5.2 =
124
  * Add a trailing slash to home path. Fixes problems with finding the .htaccess file.
125
  * Delete WPCACHEHOME and WP_CACHE from wp-config.php when plugin deactivated.
126
  * Check that WPCACHEHOME is the right path on each load of the settings page.
@@ -133,19 +344,19 @@ Many bug fixes
133
  * Added more information for when updating the .htaccess file fails.
134
  * "Served by" header is now optional. Enable it by setting $wpsc_served_header to true in the config file.
135
 
136
- = 1.5.1 =
137
  * Don't use anonymous functions in REST API
138
  * Check that REST API Controller is available before loading the REST API.
139
  * Don't use multibyte string functions because some sites don't have it enabled.
140
 
141
- = 1.5.0 =
142
  * REST API settings endpoints.
143
  * Simplified settings page.
144
  * WP-Cache files reorganised.
145
  * Caching of more http headers.
146
  * Lots of bug fixes.
147
 
148
- = 1.4.9 =
149
  * Fixed bug when not running sem_remove after sem_release. See https://github.com/Automattic/wp-super-cache/issues/85
150
  * Fixed a PHP error impacting PHP 7.1.
151
  * Fixed a bug where we cached PUT and DELETE requests. We're treating them like POST requests now.
@@ -160,17 +371,17 @@ Many bug fixes
160
  * Add fix for customizer [#161](https://github.com/Automattic/wp-super-cache/pull/161) and don't cache PUT AND DELETE requests [#178](https://github.com/Automattic/wp-super-cache/pull/178)
161
  * Check for superglobals before using them. [#131](https://github.com/Automattic/wp-super-cache/pull/131)
162
 
163
- = 1.4.8 =
164
  * Removed malware URL in a code comment. (harmless to operation of plugin but gets flagged by A/V software)
165
  * Updated translation file.
166
 
167
- = 1.4.7 =
168
  * Update the settings page for WordPress 4.4. layout changes.
169
 
170
- = 1.4.6 =
171
  * Generate the file cache/.htaccess even when one exists so gzip rules are created and gzipped pages are served correctly. Props Tigertech. https://wordpress.org/support/topic/all-website-pages-downloading-gz-file-after-latest-update?replies=36#post-7494087
172
 
173
- = 1.4.5 =
174
  * Enhancement: Only preload public post types. Props webaware.
175
  * Added an uninstall function that deletes the config file. Deactivate function doesn't delete it any more.
176
  * Possible to deactivate the plugin without visiting the settings page now.
@@ -185,47 +396,47 @@ Many bug fixes
185
  * Hide cache files when servers display directory indexes.
186
  * Prevent PHP object injection through use of serialize().
187
 
188
- = 1.4.4 =
189
  * Fixed fatal error in output handler if GET parameters present in query. Props webaware.
190
  * Fixed debug log. It wasn't logging the right message.
191
 
192
- = 1.4.3 =
193
  * Security release fixing an XSS bug in the settings page. Props Marc Montpas from Sucuri.
194
  * Added wp_debug_log(). Props Jen Heilemann.
195
  * Minor fixes.
196
 
197
- = 1.4.2 =
198
  * Fixed "acceptable file list".
199
  * Fixed "Don't cache GET requests" feature.
200
  * Maybe fixed "304 not modified" problem for some users.
201
  * Fixed some PHP warnings.
202
 
203
- = 1.4.1 =
204
  * Fixed XSS in settings page. Props Simon Waters, Surevine Limited.
205
  * Fix to object cache so entries may now be deleted when posts updated. (object cache still experimental)
206
  * Documentation updates and cleanup of settings page.
207
 
208
- = 1.4 =
209
  * Replace legacy mfunc/mnclude/dynamic-cached-content functionality with a "wpsc_cachedata" cacheaction filter.
210
  * Added dynamic-cache-test.php plugin example wpsc_cachedata filter plugin.
211
  * Delete post, tag and category cache when a post changes from draft to publish or vice versa. Props @Biranit.
212
  * Update advanced-cache.php and wp-config.php if wp-cache-phase1.php doesn't load, usually happening after migrating to a new hosting service.
213
  * Misc bugfixes.
214
 
215
- = 1.3.2 =
216
  * Any mfunc/mclude/dynamic-cached-content tags in comments are now removed.
217
  * Dynamic cached content feature disabled by default and must be enabled on the Advanced Settings page.
218
  * Support for the mobile theme in Jetpack via helper plugin on script's Plugins tab.
219
 
220
- = 1.3.1 =
221
  * Minor updates to documentation
222
  * Fixed XSS in settings page.
223
 
224
- = 1.3 =
225
  * mfunc tags could be executed in comments. Fixed.
226
  * More support for sites that use the LOGGED_IN_COOKIE constant and custom cookies.
227
 
228
- = 1.2 =
229
  * Garbage collection of old cache files is significantly improved. I added a scheduled job that keeps an eye on things and restarts the job if necessary. Also, if you enable caching from the Easy page garbage collection will be enabled too.
230
  * Editors can delete single cached files from the admin bar now.
231
  * Fixed the cached page counter on the settings page.
@@ -238,7 +449,7 @@ Many bug fixes
238
  * Some sites had problems with scheduled posts. For some reason the plugin thought the post was in draft mode and then because it only checked the same post once, when the post magically became published the cache wasn.t cleared. That.s fixed, thanks to the debug logging of several patient users.
239
  * And more bug fixes and translation updates.
240
 
241
- = 1.1 =
242
  * Use $_SERVER[ 'SERVER_NAME' ] to create cache directories.
243
  * Only create blogs cached directories if valid requests and blogs exist.
244
  * Only clear current blog's cache files if navigation menu is modified
@@ -265,7 +476,7 @@ Many bug fixes
265
  * Removed debug level from logging as it wasn't helpful.
266
  * Removed mention of wp-minify.
267
 
268
- = 1.0 =
269
  * Removed AddDefaultCharset .htaccess rule
270
  * Fixed problem with blogs in a folder and don't have a trailing slash
271
  * New scheduling of garbage collection
@@ -279,7 +490,7 @@ Many bug fixes
279
  * Use WP 3.0 variables to detect multisite installs
280
  * Hash filenames so files are served from the same CDNs
281
 
282
- = 0.9.9.9 =
283
  * Fixed typo, is_front_page.
284
  * Serve repeated static files from the same CDN hostname.
285
  * Updated translations.
@@ -288,7 +499,7 @@ Many bug fixes
288
  * Remove 5 second check on age of existing cache files. Should help with posts that get lots of comments and traffic.
289
  * Lots of bugs fixed.
290
 
291
- = 0.9.9.8 =
292
  * CDN updates: can be switched off, multiple CNAMEs.
293
  * Uninstall process improved. It removes generated files and fixes edited files.
294
  * Cached dynamic pages can now be stored in Supercache files and compressed.
@@ -296,20 +507,20 @@ Many bug fixes
296
  * Remove log by email functionality as it caused problems for users who were inundated by email
297
  * Many more minor fixes and changes.
298
 
299
- = 0.9.9.6 =
300
  * Fixed problem serving cached files with PHP
301
  * Added support for 304 "file not modified" header to help browser caching. (PHP caching only)
302
  * Added French & German translations, updated Italian translation and fixed translation strings.
303
  * Sleep 4 seconds between preload urls to reduce load on the server
304
  * Updated docs and FAQs.
305
 
306
- = 0.9.9.5 =
307
  * Disable compression on on easy setup page. Still causes problems on some hosts.
308
  * Remove footerlink on easy setup page.
309
  * Don't delete mod_rewrite rules when caching is disabled.
310
  * Don't stop users using settings page when in safe mode.
311
 
312
- = 0.9.9.4 =
313
  * Settings page split into tabbed pages.
314
  * Added new "Easy" settings page for new users.
315
  * New PHP caching mode to serve supercached files.
@@ -324,16 +535,16 @@ Many bug fixes
324
  * Serve the gzipped page when first cached if the client supports compression.
325
  * Lots more bug fixes..
326
 
327
- = 0.9.9.3 =
328
  * Fixed division by zero error in half on mode.
329
  * Always show "delete cache" button.
330
  * Fixed "Update mod_rewrite rules" button.
331
  * Minor text changes to admin page.
332
 
333
- = 0.9.9.2 =
334
  * Forgot to change version number in wp-cache.php
335
 
336
- = 0.9.9.1 =
337
  * Added preloading of static cache.
338
  * Better mobile plugin support
339
  * .htaccess rules can be updated now. Added wpsc_update_htaccess().
@@ -342,7 +553,7 @@ Many bug fixes
342
  * Added clear_post_supercache() to clear supercache for a single post.
343
  * Put quotes around rewrite rules in case paths have spaces.
344
 
345
- = 0.9.9 =
346
  * Added experimental object cache support.
347
  * Added Chinese(Traditional) translation by Pseric.
348
  * Added FAQ on WP-Cache vs Supercache files.
@@ -358,7 +569,7 @@ Many bug fixes
358
  * Updated Italian translation.
359
  * Link to WP Mobile Edition from admin page for mobile support.
360
 
361
- = 0.9.8 =
362
  * Added Spanish translation by Omi.
363
  * Added Italian translation by Gianni Diurno.
364
  * Addded advanced debug code to check front page for category problem. Enable by setting $wp_super_cache_advanced_debug to 1 in the config file.
@@ -370,7 +581,7 @@ Many bug fixes
370
  * Fixed problem deleting cache file.
371
  * Don't delete cache files when moderated comments are deleted.
372
 
373
- = 0.9.7 =
374
  * Fixed problem with blogs in folders.
375
  * Added cache file listing and delete links to admin page.
376
  * Added "Newest Cached Pages" listing in sidebox.
@@ -386,12 +597,12 @@ Many bug fixes
386
  * Fixed problem with PHP safe_mode detection.
387
  * Various bugfixes and documentation updates. See Changelog.txt
388
 
389
- = 0.9.6.1 =
390
  * Move "not logged in" message init below check for POST.
391
  * Add is_admin() check so plugin definitely can't cache the backend.
392
  * Add "do not cache" page type to admin page.
393
 
394
- = 0.9.6 =
395
  * Add uninstall.php uninstall script.
396
  * Updated cache/.htaccess rules (option to upgrade that)
397
  * Added FAQ about category and static homepage problem.
@@ -399,7 +610,7 @@ Many bug fixes
399
  * Show message for logged in users when caching disable for them.
400
  * Check filemtime on correct supercache file
401
 
402
- = 0.9.5 =
403
  * Show next and last GC times in minutes, not local time.
404
  * Don't serve wp_cache cache files to rejected user agents. Supercache files are still served to them.
405
  * If enabled, mobile support now serves php cached files to mobile clients and static cached files to everyone else.
@@ -407,7 +618,7 @@ Many bug fixes
407
  * Added check for DONOTCACHEPAGE constant to avoid caching a page.
408
  * Use PHP_DOCUMENT_ROOT when creating .htaccess if necessary.
409
 
410
- = 0.9.4.3 =
411
  1. Added "Don't cache for logged in users" option.
412
  2. Display file size stats on admin page.
413
  3. Clear the cache when profile page is updated.
@@ -415,230 +626,6 @@ Many bug fixes
415
  5. Added backslashes to rejected URI regex list.
416
  6. Fixed problems with posts and comments not refreshing.
417
 
418
- == Installation ==
419
- Install like any other plugin, directly from your plugins page but make sure you have custom permalinks enabled. Go to the plugin settings page at Settings->WP Super Cache and enable caching.
420
-
421
- == How to uninstall WP Super Cache ==
422
-
423
- Almost all you have to do is deactivate the plugin on the plugins page. The plugin should clean up most of the files it created and modified, but it doesn't as yet remove the mod_rewrite rules from the .htaccess file. Look for the section in that file marked by SuperCache BEGIN and END tags. The plugin doesn't remove those because some people add the WordPress rules in that block too.
424
-
425
- To manually uninstall:
426
-
427
- 1. Turn off caching on the plugin settings page and clear the cache.
428
- 2. Deactivate the plugin on the plugins page.
429
- 3. Remove the WP_CACHE define from wp-config.php. It looks like `define( 'WP_CACHE', true );`
430
- 4. Remove the Super Cache mod_rewrite rules from your .htaccess file.
431
- 5. Remove the files wp-content/advanced-cache.php and wp-content/wp-cache-config.php
432
- 6. Remove the directory wp-content/cache/
433
- 7. Remove the directory wp-super-cache from your plugins directory.
434
-
435
- == If all else fails and your site is broken ==
436
- 1. Remove the WP_CACHE define from wp-config.php. It looks like `define( 'WP_CACHE', true );`
437
- 2. Remove the rules (see above) that the plugin wrote to the .htaccess file in your root directory.
438
- 3. Delete the wp-super-cache folder in the plugins folder.
439
- 4. Optionally delete advanced-cache.php, wp-cache-config.php and the cache folder in wp-content/.
440
-
441
- == Frequently Asked Questions ==
442
-
443
- = How do I know my blog is being cached? =
444
-
445
- 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.
446
-
447
- 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.
448
- 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.
449
- 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.
450
-
451
- = How do I disable Supercaching? =
452
-
453
- 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.
454
-
455
- = WP-Cache vs Supercache files =
456
-
457
- 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.
458
-
459
- = Will comments and other dynamic parts of my blog update immediately? =
460
-
461
- Comments will show as soon as they are moderated, depending on the comment policy of the blog owner. Other dynamic elements on a page may not update unless they are written in Javascript, Flash, Java or another client side browser language. The plugin really produces static html pages. No PHP is executed when those pages are served. "Popularity Contest" is one such plugin that will not work.
462
-
463
- = Will the Super Cache compression slow down my server? =
464
-
465
- No, it will do the opposite. Super Cache files are compressed and stored that way so the heavy compression is done only once. These files are generally much smaller and are sent to a visitor's browser much more quickly than uncompressed html. As a result, your server spends less time talking over the network which saves CPU time and bandwidth, and can also serve the next request much more quickly.
466
-
467
- = How do I make certain parts of the page stay dynamic? =
468
-
469
- Note: this functionality is disabled by default. You will have to enable it on the Advanced Settings page.
470
-
471
- 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.
472
-
473
- 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.
474
- 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.
475
- 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.
476
- To execute WordPress functions you must enable the 'Late init' feature on the advanced settings page.
477
-
478
- = How do I use WordPress functions in cached dynamic pages? =
479
- = How do I delay serving the cache until the "init" action fires? =
480
-
481
- Cached files are served before almost all of WordPress is loaded. While that's great for performance it's a pain when you want to extend the plugin using a core part of WordPress. Enable 'Late init' mode on the Advanced settings page and cached files will be served when "init" fires. WordPress and it's plugins will be loaded now.
482
-
483
- = Why don't WP UserOnline, Popularity Contest, WP Postratings or plugin X not work or update on my blog now? =
484
-
485
- 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.
486
-
487
- = Why do my WP Super Cache plugins disappear when I upgrade the plugin? =
488
-
489
- 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.
490
-
491
- = What does the Cache Rebuild feature do? =
492
-
493
- 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.
494
-
495
- = Why doesn't the plugin cache requests by search engine bots by default? =
496
-
497
- 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.
498
-
499
- = A category page is showing instead of my homepage =
500
-
501
- A tiny proportion of websites will have problems with the following configuration:
502
-
503
- 1. Uses a static page for the front page.
504
- 2. Uses /%category%/%postname%/ permalink structure.
505
-
506
- 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.
507
-
508
- = Why do I get warnings about caching from http://ismyblogworking.com/ =
509
-
510
- "Your blog doesn't support client caching (no 304 response to If-modified-since)."
511
- "Your feed doesn't support caching (no 304 response to If-modified-since)"
512
-
513
- 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.
514
- Try the Cacheability Engine at http://www.ircache.net/cgi-bin/cacheability.py or http://redbot.org/ for further analysis.
515
-
516
- = How should I best use the utm_source tracking tools in Google Analytics with this plugin? =
517
-
518
- 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.
519
-
520
- = The plugin complains that wp-content is writable! htdocs is writable! =
521
-
522
- It's not good when the web server can write to these directories but sometimes shared hosting accounts are set up in this way to make administration easier. Use `chmod 755 directory` to fix the permissions or find the permissions section of your ftp client. This [Google search](http://www.google.ie/search?sourceid=chrome&ie=UTF-8&q=ftp+fix+directory+permissions+755) will lead you to more information on this topic and there's also [this codex page](http://codex.wordpress.org/Changing_File_Permissions) too. Unfortunately some hosts require that those directories be writable. If that's the case just ignore this warning.
523
-
524
- = How do I delete the WP_CACHE define from wp-config.php? =
525
-
526
- Load your desktop ftp client and connect to your site. Navigate to the root (or the directory below it) of your site where you'll find wp-config.php. Download that file and edit it in a text editor. Delete the line `define( 'WP_CACHE', true );` and save the file. Now upload it, overwriting the wp-config.php on your server.
527
-
528
- = How do I delete the Super Cache rules from the .htaccess file? =
529
-
530
- Load your desktop ftp client and connect to your site. You may need to enable "Show hidden files" in the preferences of the ftp client. Navigate to the root of your site where you'll find the .htaccess file. Download that file and edit it in a text editor. Delete the lines between "# BEGIN WPSuperCache" and "# END WPSuperCache" and save the file. Now upload it, overwriting the .htaccess file on your server.
531
-
532
- = How do I change file permissions? =
533
-
534
- This [page](http://codex.wordpress.org/Changing_File_Permissions) on the WordPress Codex explains everything you need to know about file permissions on your server and various ways of changing them.
535
-
536
- = Why do I get load spikes when new posts are made? =
537
-
538
- You may have the "clear all cached files when new posts are made" option set. Clearing those files can take time plus your visitors will now be visiting uncached pages. Are you using Google Analytics campaign tracking with utm_source in the url? Those pages aren't cached. See the question, "How should I best use the utm_source tracking tools in Google Analytics with this plugin" above for how to use them properly.
539
- Cached pages have to be refreshed when posts are made. Perhaps your server just isn't up to the job of serving the amount of traffic you get. Enable the "cache rebuild" feature as that may help.
540
-
541
- = How many pages can I cache? =
542
-
543
- The only real limit are limits defined by your server. For example, EXT2 and EXT3 allow a maximum of 31,999 sub directories so if you have a flat permalink structure (like /%POSTNAME%/) and more than 32,000 posts you may run into problems. Likewise, if you run a multisite network and have more than 31,999 sites (blogs) you won't be able to cache all of them. Realistically if you had that many active sites you wouldn't be running on one server.
544
-
545
- = How do I serve cached mobile pages to clients on small screens like phones and tablets? =
546
-
547
- 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.
548
-
549
- * [Jetpack's Mobile Theme Module](http://wordpress.org/plugins/jetpack)
550
- * [WPTouch](http://wordpress.org/plugins/wptouch/)
551
- * [WordPress Mobile Edition](http://wordpress.org/plugins/wordpress-mobile-edition/)
552
- * [WordPress Mobile Pack](http://wordpress.org/plugins/wordpress-mobile-pack/) (can't have "Don't cache pages for known users." enabled)
553
-
554
- = Troubleshooting =
555
-
556
- If things don't work when you installed the plugin here are a few things to check:
557
-
558
- 1. Is wp-content writable by the web server?
559
- 2. Is there a wp-content/wp-cache-config.php ? If not, copy the file wp-super-cache/wp-cache-config-sample.php to wp-content/wp-cache-config.php and make sure WPCACHEHOME points at the right place.
560
- 3. Is there a wp-content/advanced-cache.php ? If not, then you must copy wp-super-cache/advanced-cache.php into wp-content/. You must edit the file and change the path so it points at the wp-super-cache folder.
561
- 4. If pages are not cached at all, remove wp-content/advanced-cache.php and recreate it, following the advice above.
562
- 5. Make sure the following line is in wp-config.php and it is ABOVE the "require_once(ABSPATH.'wp-settings.php');" line:
563
-
564
- `define( 'WP_CACHE', true );`
565
- 6. Try the Settings->WP Super Cache page again and enable cache.
566
- 7. Look in wp-content/cache/supercache/. Are there directories and files there?
567
- 8. Anything in your php error_log?
568
- 9. If your browser keeps asking you to save the file after the super cache is installed you must disable Super Cache compression. Go to the Settings->WP Super Cache page and disable it there.
569
- 10. The plugin does not work very well when PHP's safe mode is active. This must be disabled by your administrator.
570
- 11. If pages are randomly super cached and sometimes not, your blog can probably be viewed with and without the "www" prefix on the URL. You should choose one way and install the [Enforce www preference](http://txfx.net/code/wordpress/enforce-www-preference/) plugin if you are using an old WordPress install. The latest versions redirect themselves (you should always be running the latest version of WordPress anyway!)
571
- 12. Private Server users at Dreamhost should edit wp-content/wp-cache-config.php and set the cache dir to "/tmp/" if they are getting errors about increasing CPU usage. See this [discussion](http://wordpress.org/support/topic/145895?replies=42) for more.
572
- 13. File locking errors such as "failed to acquire key 0x152b: Permission denied in..." or "Page not cached by WP Super Cache. Could not get mutex lock." are a sign that you may have to use file locking. Edit wp-content/wp-cache-config.php and uncomment "$use_flock = true" or set $sem_id to a different value. You can also disable file locking from the Admin screen as a last resort.
573
- 14. Make sure cache/wp_cache_mutex.lock is writable by the web server if using coarse file locking.
574
- 15. The cache folder cannot be put on an NFS or Samba or NAS share. It has to be on a local disk. File locking and deleting expired files will not work properly unless the cache folder is on the local machine.
575
- 16. Garbage collection of old cache files won't work if WordPress can't find wp-cron.php. If your hostname resolves to 127.0.0.1 it could be preventing the garbage collection from working. Check your access_logs for wp-cron.php entries. Do they return a 404 (file not found) or 200 code? If it's 404 or you don't see wp-cron.php anywhere WordPress may be looking for that script in the wrong place. You should speak to your server administator to correct this or edit /etc/hosts on Unix servers and remove the following line. Your hostname must resolve to the external IP address other servers on the network/Internet use. See http://yoast.com/wp-cron-issues/ for more. A line like "127.0.0.1 localhost localhost.localdomain" is ok.
576
-
577
- `127.0.0.1 myhostname.com`
578
- 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.
579
- 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.
580
- 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.
581
- 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.
582
-
583
- `umask( 0022 );`
584
- 21. If you see garbage in your browser after enabling compression in the plugin, compression may already be enabled in your web server. In Apache you must disable mod_deflate, or in PHP zlib compression may be enabled. You can disable that in three ways. If you have root access, edit your php.ini and find the zlib.output_compression setting and make sure it's "Off" or add this line to your .htaccess:
585
-
586
- `php_flag zlib.output_compression off`
587
- If that doesn't work, add this line to your wp-config.php:
588
-
589
- `ini_set('zlib.output_compression', 0);`
590
- 22. The "white screen of death" or a blank page when you visit your site is almost always caused by a PHP error but [it may also be caused by APC](http://www.johnberns.com/2010/03/19/wp-super-cache-blank-page-problem-fixed/). Disable that PHP extension if you have trouble and replace with eAccelerator or Xcache.
591
- 23. After uninstalling, your permalinks may break if you remove the WordPress mod_rewrite rules too. Regenerate those rules by visiting the Settings->Permalink page and saving that form again.
592
- 24. If your blog refuses to load make sure your wp-config.php is correct. Are you missing an opening or closing PHP tag?
593
- 25. Your front page is ok but posts and pages give a 404? Go to Settings->permalinks and click "Save" once you've selected a custom permalink structure. You may need to manually update your .htaccess file.
594
- 26. If certain characters do not appear correctly on your website your server may not be configured correctly. You need to tell visitors what character set is used. Go to Settings->Reading and copy the 'Encoding for pages and feeds' value. Edit the .htaccess file with all your Supercache and WordPress rewrite rules and add this at the top, replacing CHARSET with the copied value. (for example, 'UTF-8')
595
-
596
- `AddDefaultCharset CHARSET`
597
- 27. Use [Cron View](http://wordpress.org/plugins/cron-view/) to help diagnose garbage collection and preload problems. Use the plugin to make sure jobs are scheduled and for what time. Look for the wp_cache_gc and wp_cache_full_preload_hook jobs.
598
- 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.
599
- 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.
600
-
601
- == Preloading ==
602
-
603
- 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.
604
- 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.
605
-
606
- == Garbage Collection ==
607
-
608
- 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:
609
- 1. Cache timeout. How long cache files are considered fresh for. After this time they are stale and can be deleted.
610
- 2. Scheduler. Setup how often garbage collection should be done.
611
- 3. Notification emails. You can be informed on garbage collection job progress.
612
- There's no right or wrong settings for garbage collection. It depends on your own site.
613
- If your site gets regular updates, or comments then set the timeout to 1800 seconds, and set the timer to 600 seconds.
614
- If your site is mostly static you can disable garbage collection by entering 0 as the timeout, or use a really large timeout value.
615
-
616
- == CDN ==
617
-
618
- A Content Delivery Network (CDN) is usually a network of computers situated around the world that will serve the content of your website faster by using servers close to you. Static files like images, Javascript and CSS files can be served through these networks to speed up how fast your site loads. You can also create a "poor man's CDN" by using a sub domain of your domain to serve static files too.
619
-
620
- [OSSDL CDN off-linker](http://wordpress.org/plugins/ossdl-cdn-off-linker/) has been integrated into WP Super Cache to provide basic CDN support. It works by rewriting the URLs of files (excluding .php files) in wp-content and wp-includes on your server so they point at a different hostname. Many CDNs support [origin pull](http://www.google.com/search?hl=en&q=%22origin+pull%22). This means the CDN will download the file automatically from your server when it's first requested, and will continue to serve it for a configurable length of time before downloading it again from your server.
621
-
622
- 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.
623
-
624
- == REST API ==
625
-
626
- 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.
627
-
628
- == Custom Caching ==
629
- It is now possible to hook into the caching process using the add_cacheaction() function.
630
-
631
- Three hooks are available:
632
-
633
- 1. 'wp_cache_get_cookies_values' - modify the key used by WP Cache.
634
- 2. 'add_cacheaction' - runs in phase2. Allows a plugin to add WordPress hooks.
635
- 3. 'cache_admin_page' - runs in the admin page. Use it to modify that page, perhaps by adding new configuration options.
636
-
637
- There is one regular WordPress filter too. Use the "do_createsupercache" filter
638
- to customize the checks made before caching. The filter accepts one parameter.
639
- The output of WP-Cache's wp_cache_get_cookies_values() function.
640
-
641
- See plugins/searchengine.php as an example I use for my [No Adverts for Friends](https://odd.blog/no-adverts-for-friends/) plugin.
642
 
643
- == Updates ==
644
- 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.
1
+ # WP Super Cache #
2
+ * Contributors: donncha, automattic, kraftbj
3
+ * Tags: performance, caching, wp-cache, wp-super-cache, cache
4
+ * Tested up to: 4.9.1
5
+ * Stable tag: 1.5.9
6
+ * Requires at least: 3.0
7
+ * Requires PHP: 5.2.4
8
+ * License: GPLv2 or later
9
+ * License URI: https://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  A very fast caching engine for WordPress that produces static html files.
12
 
13
+ ## Description ##
14
  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.
15
 
16
  The static html files will be served to the vast majority of your users:
17
 
18
+ * Users who are not logged in.
19
+ * Users who have not left a comment on your blog.
20
+ * Or users who have not viewed a password protected post.
21
 
22
  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.
23
 
29
 
30
  If you're not comfortable with editing PHP files then use simple mode. It's easy to set up and very fast.
31
 
32
+ ### Recommended Settings ###
 
33
  1. Simple caching.
34
  2. Compress pages.
35
  3. Don't cache pages for known users.
41
 
42
  Consider deleting the contents of the "Rejected User Agents" text box and allow search engines to cache files for you.
43
 
44
+ Preload as many posts as you can and enable "Preload Mode". Garbage collection of old cached files will be disabled. 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.
45
+ Even with preload mode enabled cached files will still be deleted when posts are modified or comments made.
46
 
47
+ ### Development ###
48
+ * Active development of this plugin is handled [on GitHub](https://github.com/Automattic/wp-super-cache).
49
+ * Translation of the plugin into different languages is on the [translation page](https://translate.wordpress.org/projects/wp-plugins/wp-super-cache).
50
 
51
+ ### Documentation ###
52
+ If you need more information than the following, you can have a look at the [Developer documentation](https://odd.blog/wp-super-cache-developers/).
53
 
54
+ #### Preloading ####
55
+ 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.
56
+ 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.
57
 
58
+ #### Garbage Collection ####
59
+ 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:
60
+ 1. Cache timeout. How long cache files are considered fresh for. After this time they are stale and can be deleted.
61
+ 2. Scheduler. Setup how often garbage collection should be done.
62
+ 3. Notification emails. You can be informed on garbage collection job progress.
63
+ There's no right or wrong settings for garbage collection. It depends on your own site.
64
+ If your site gets regular updates, or comments then set the timeout to 1800 seconds, and set the timer to 600 seconds.
65
+ If your site is mostly static you can disable garbage collection by entering 0 as the timeout, or use a really large timeout value.
66
 
67
  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.
68
 
69
+ #### CDN ####
70
+ A Content Delivery Network (CDN) is usually a network of computers situated around the world that will serve the content of your website faster by using servers close to you. Static files like images, Javascript and CSS files can be served through these networks to speed up how fast your site loads. You can also create a "poor man's CDN" by using a sub domain of your domain to serve static files too.
71
+
72
+ [OSSDL CDN off-linker](https://wordpress.org/plugins/ossdl-cdn-off-linker/) has been integrated into WP Super Cache to provide basic CDN support. It works by rewriting the URLs of files (excluding .php files) in wp-content and wp-includes on your server so they point at a different hostname. Many CDNs support [origin pull](https://www.google.com/search?hl=en&q=%22origin+pull%22). This means the CDN will download the file automatically from your server when it's first requested, and will continue to serve it for a configurable length of time before downloading it again from your server.
73
+
74
+ 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.
75
+
76
+ #### REST API ####
77
+ 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.
78
+
79
+ #### Custom Caching ####
80
+ It is now possible to hook into the caching process using the add_cacheaction() function.
81
+
82
+ Three hooks are available:
83
+
84
+ 1. 'wp_cache_get_cookies_values' - modify the key used by WP Cache.
85
+ 2. 'add_cacheaction' - runs in phase2. Allows a plugin to add WordPress hooks.
86
+ 3. 'cache_admin_page' - runs in the admin page. Use it to modify that page, perhaps by adding new configuration options.
87
+
88
+ There is one regular WordPress filter too. Use the "do_createsupercache" filter
89
+ to customize the checks made before caching. The filter accepts one parameter.
90
+ The output of WP-Cache's wp_cache_get_cookies_values() function.
91
+
92
+ See plugins/searchengine.php as an example I use for my [No Adverts for Friends](https://odd.blog/no-adverts-for-friends/) plugin.
93
+
94
+ ### Troubleshooting ###
95
+ If things don't work when you installed the plugin here are a few things to check:
96
+
97
+ 1. Is wp-content writable by the web server?
98
+ 2. Is there a wp-content/wp-cache-config.php ? If not, copy the file wp-super-cache/wp-cache-config-sample.php to wp-content/wp-cache-config.php and make sure WPCACHEHOME points at the right place.
99
+ 3. Is there a wp-content/advanced-cache.php ? If not, then you must copy wp-super-cache/advanced-cache.php into wp-content/. You must edit the file and change the path so it points at the wp-super-cache folder.
100
+ 4. If pages are not cached at all, remove wp-content/advanced-cache.php and recreate it, following the advice above.
101
+ 5. Make sure the following line is in wp-config.php and it is ABOVE the "require_once(ABSPATH.'wp-settings.php');" line:
102
+
103
+ `define( 'WP_CACHE', true );`
104
+ 6. Try the Settings->WP Super Cache page again and enable cache.
105
+ 7. Look in wp-content/cache/supercache/. Are there directories and files there?
106
+ 8. Anything in your php error_log?
107
+ 9. If your browser keeps asking you to save the file after the super cache is installed you must disable Super Cache compression. Go to the Settings->WP Super Cache page and disable it there.
108
+ 10. The plugin does not work very well when PHP's safe mode is active. This must be disabled by your administrator.
109
+ 11. If pages are randomly super cached and sometimes not, your blog can probably be viewed with and without the "www" prefix on the URL. You should choose one way and install the [Enforce www preference](http://txfx.net/code/wordpress/enforce-www-preference/) plugin if you are using an old WordPress install. The latest versions redirect themselves (you should always be running the latest version of WordPress anyway!)
110
+ 12. Private Server users at Dreamhost should edit wp-content/wp-cache-config.php and set the cache dir to "/tmp/" if they are getting errors about increasing CPU usage. See this [discussion](https://wordpress.org/support/topic/145895?replies=42) for more.
111
+ 13. File locking errors such as "failed to acquire key 0x152b: Permission denied in..." or "Page not cached by WP Super Cache. Could not get mutex lock." are a sign that you may have to use file locking. Edit wp-content/wp-cache-config.php and uncomment "$use_flock = true" or set $sem_id to a different value. You can also disable file locking from the Admin screen as a last resort.
112
+ 14. Make sure cache/wp_cache_mutex.lock is writable by the web server if using coarse file locking.
113
+ 15. The cache folder cannot be put on an NFS or Samba or NAS share. It has to be on a local disk. File locking and deleting expired files will not work properly unless the cache folder is on the local machine.
114
+ 16. Garbage collection of old cache files won't work if WordPress can't find wp-cron.php. If your hostname resolves to 127.0.0.1 it could be preventing the garbage collection from working. Check your access_logs for wp-cron.php entries. Do they return a 404 (file not found) or 200 code? If it's 404 or you don't see wp-cron.php anywhere WordPress may be looking for that script in the wrong place. You should speak to your server administator to correct this or edit /etc/hosts on Unix servers and remove the following line. Your hostname must resolve to the external IP address other servers on the network/Internet use. See http://yoast.com/wp-cron-issues/ for more. A line like "127.0.0.1 localhost localhost.localdomain" is ok.
115
+
116
+ `127.0.0.1 example.com`
117
+ 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.
118
+ 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.
119
+ 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.
120
+ 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.
121
+
122
+ `umask( 0022 );`
123
+ 21. If you see garbage in your browser after enabling compression in the plugin, compression may already be enabled in your web server. In Apache you must disable mod_deflate, or in PHP zlib compression may be enabled. You can disable that in three ways. If you have root access, edit your php.ini and find the zlib.output_compression setting and make sure it's "Off" or add this line to your .htaccess:
124
+
125
+ `php_flag zlib.output_compression off`
126
+ If that doesn't work, add this line to your wp-config.php:
127
+
128
+ `ini_set('zlib.output_compression', 0);`
129
+ 22. The "white screen of death" or a blank page when you visit your site is almost always caused by a PHP error but [it may also be caused by APC](http://www.johnberns.com/2010/03/19/wp-super-cache-blank-page-problem-fixed/). Disable that PHP extension if you have trouble and replace with eAccelerator or Xcache.
130
+ 23. After uninstalling, your permalinks may break if you remove the WordPress mod_rewrite rules too. Regenerate those rules by visiting the Settings->Permalink page and saving that form again.
131
+ 24. If your blog refuses to load make sure your wp-config.php is correct. Are you missing an opening or closing PHP tag?
132
+ 25. Your front page is ok but posts and pages give a 404? Go to Settings->permalinks and click "Save" once you've selected a custom permalink structure. You may need to manually update your .htaccess file.
133
+ 26. If certain characters do not appear correctly on your website your server may not be configured correctly. You need to tell visitors what character set is used. Go to Settings->Reading and copy the 'Encoding for pages and feeds' value. Edit the .htaccess file with all your Supercache and WordPress rewrite rules and add this at the top, replacing CHARSET with the copied value. (for example, 'UTF-8')
134
+
135
+ `AddDefaultCharset CHARSET`
136
+ 27. Use [Cron View](https://wordpress.org/plugins/cron-view/) to help diagnose garbage collection and preload problems. Use the plugin to make sure jobs are scheduled and for what time. Look for the wp_cache_gc and wp_cache_full_preload_hook jobs.
137
+ 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.
138
+ 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.
139
+
140
+
141
+ ## Installation ##
142
+ Install like any other plugin, directly from your plugins page but make sure you have custom permalinks enabled. Go to the plugin settings page at Settings->WP Super Cache and enable caching.
143
+
144
+ ### How to uninstall WP Super Cache ###
145
+ Almost all you have to do is deactivate the plugin on the plugins page. The plugin should clean up most of the files it created and modified, but it doesn't as yet remove the mod_rewrite rules from the .htaccess file. Look for the section in that file marked by SuperCache BEGIN and END tags. The plugin doesn't remove those because some people add the WordPress rules in that block too.
146
+
147
+ To manually uninstall:
148
+
149
+ 1. Turn off caching on the plugin settings page and clear the cache.
150
+ 2. Deactivate the plugin on the plugins page.
151
+ 3. Remove the WP_CACHE define from wp-config.php. It looks like `define( 'WP_CACHE', true );`
152
+ 4. Remove the Super Cache mod_rewrite rules from your .htaccess file.
153
+ 5. Remove the files wp-content/advanced-cache.php and wp-content/wp-cache-config.php
154
+ 6. Remove the directory wp-content/cache/
155
+ 7. Remove the directory wp-super-cache from your plugins directory.
156
+
157
+ ### If all else fails and your site is broken ###
158
+ 1. Remove the WP_CACHE define from wp-config.php. It looks like `define( 'WP_CACHE', true );`
159
+ 2. Remove the rules (see above) that the plugin wrote to the .htaccess file in your root directory.
160
+ 3. Delete the wp-super-cache folder in the plugins folder.
161
+ 4. Optionally delete advanced-cache.php, wp-cache-config.php and the cache folder in wp-content/.
162
+
163
+
164
+ ## Frequently Asked Questions ##
165
+
166
+ ### How do I know my blog is being cached? ###
167
+ 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.
168
+
169
+ 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.
170
+ 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.
171
+ 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.
172
+ The pagespeed module for Apache may cause problems when testing. Disable it if you notice any problems running the cache tester.
173
+
174
+ ### How do I disable Supercaching? ###
175
+ 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.
176
+
177
+ ### WP-Cache vs Supercache files ###
178
+ 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.
179
+
180
+ ### Will comments and other dynamic parts of my blog update immediately? ###
181
+ Comments will show as soon as they are moderated, depending on the comment policy of the blog owner. Other dynamic elements on a page may not update unless they are written in Javascript, Flash, Java or another client side browser language. The plugin really produces static html pages. No PHP is executed when those pages are served. "Popularity Contest" is one such plugin that will not work.
182
+
183
+ ### Will the Super Cache compression slow down my server? ###
184
+ No, it will do the opposite. Super Cache files are compressed and stored that way so the heavy compression is done only once. These files are generally much smaller and are sent to a visitor's browser much more quickly than uncompressed html. As a result, your server spends less time talking over the network which saves CPU time and bandwidth, and can also serve the next request much more quickly.
185
+
186
+ ### How do I make certain parts of the page stay dynamic? ###
187
+ Note: this functionality is disabled by default. You will have to enable it on the Advanced Settings page.
188
+
189
+ 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.
190
+
191
+ 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.
192
+ 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.
193
+ 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.
194
+ To execute WordPress functions you must enable the 'Late init' feature on the advanced settings page.
195
+
196
+ ### How do I delay serving the cache until the "init" action fires? ###
197
+ Cached files are served before almost all of WordPress is loaded. While that's great for performance it's a pain when you want to extend the plugin using a core part of WordPress. Enable 'Late init' mode on the Advanced settings page and cached files will be served when "init" fires. WordPress and it's plugins will be loaded now.
198
+
199
+ ### Why don't WP UserOnline, Popularity Contest, WP Postratings or plugin X not work or update on my blog now? ###
200
+ 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.
201
+
202
+ ### Why do my WP Super Cache plugins disappear when I upgrade the plugin? ###
203
+ 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.
204
+
205
+ ### What does the Cache Rebuild feature do? ###
206
+ 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.
207
+
208
+ ### Why doesn't the plugin cache requests by search engine bots by default? ###
209
+ 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.
210
+
211
+ ### A category page is showing instead of my homepage ###
212
+ A tiny proportion of websites will have problems with the following configuration:
213
+
214
+ 1. Uses a static page for the front page.
215
+ 2. Uses /%category%/%postname%/ permalink structure.
216
+
217
+ Sometimes a category page is cached as the homepage of the site instead of the static page. I can't [replicate the problem](https://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.
218
+
219
+ ### Why do I get warnings about caching from http://ismyblogworking.com/ ###
220
+ "Your blog doesn't support client caching (no 304 response to If-modified-since)."
221
+ "Your feed doesn't support caching (no 304 response to If-modified-since)"
222
+
223
+ 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.
224
+ Try the Cacheability Engine at http://www.ircache.net/cgi-bin/cacheability.py or https://redbot.org/ for further analysis.
225
+
226
+ ### How should I best use the utm_source tracking tools in Google Analytics with this plugin? ###
227
+ 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.
228
+
229
+ ### The plugin complains that wp-content is writable! htdocs is writable! ###
230
+ It's not good when the web server can write to these directories but sometimes shared hosting accounts are set up in this way to make administration easier. Use `chmod 755 directory` to fix the permissions or find the permissions section of your ftp client. This [Google search](https://www.google.com/search?sourceid=chrome&ie=UTF-8&q=ftp+fix+directory+permissions+755) will lead you to more information on this topic and there's also [this codex page](https://codex.wordpress.org/Changing_File_Permissions) too. Unfortunately some hosts require that those directories be writable. If that's the case just ignore this warning.
231
+
232
+ ### How do I delete the WP_CACHE define from wp-config.php? ###
233
+ Load your desktop ftp client and connect to your site. Navigate to the root (or the directory below it) of your site where you'll find wp-config.php. Download that file and edit it in a text editor. Delete the line `define( 'WP_CACHE', true );` and save the file. Now upload it, overwriting the wp-config.php on your server.
234
+
235
+ ### How do I delete the Super Cache rules from the .htaccess file? ###
236
+ Load your desktop ftp client and connect to your site. You may need to enable "Show hidden files" in the preferences of the ftp client. Navigate to the root of your site where you'll find the .htaccess file. Download that file and edit it in a text editor. Delete the lines between "# BEGIN WPSuperCache" and "# END WPSuperCache" and save the file. Now upload it, overwriting the .htaccess file on your server.
237
+
238
+ ### How do I change file permissions? ###
239
+ This [page](https://codex.wordpress.org/Changing_File_Permissions) on the WordPress Codex explains everything you need to know about file permissions on your server and various ways of changing them.
240
+
241
+ ### Why do I get load spikes when new posts are made? ###
242
+ You may have the "clear all cached files when new posts are made" option set. Clearing those files can take time plus your visitors will now be visiting uncached pages. Are you using Google Analytics campaign tracking with utm_source in the url? Those pages aren't cached. See the question, "How should I best use the utm_source tracking tools in Google Analytics with this plugin" above for how to use them properly.
243
+ Cached pages have to be refreshed when posts are made. Perhaps your server just isn't up to the job of serving the amount of traffic you get. Enable the "cache rebuild" feature as that may help.
244
+
245
+ ### How many pages can I cache? ###
246
+ The only real limit are limits defined by your server. For example, EXT2 and EXT3 allow a maximum of 31,999 sub directories so if you have a flat permalink structure (like /%POSTNAME%/) and more than 32,000 posts you may run into problems. Likewise, if you run a multisite network and have more than 31,999 sites (blogs) you won't be able to cache all of them. Realistically if you had that many active sites you wouldn't be running on one server.
247
+
248
+ ### I can see that the www version of my site is cached separately. How do I stop that? ###
249
+ WordPress should redirect to the canonical URL of your site but if it doesn't, add this to your .htaccess above the Supercache and WordPress rules. Change example.com to your own hostname.
250
+ `RewriteCond %{HTTP_HOST} www.example.com$ [NC]`
251
+ `RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]`
252
+
253
+ ### How do I serve cached mobile pages to clients on small screens like phones and tablets? ###
254
+ 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.
255
 
256
+ * [Jetpack's Mobile Theme Module](https://wordpress.org/plugins/jetpack/)
257
+ * [WPTouch](https://wordpress.org/plugins/wptouch/)
258
+ * [WordPress Mobile Edition](https://wordpress.org/plugins/wordpress-mobile-edition/)
259
+ * [WordPress Mobile Pack](https://wordpress.org/plugins/wordpress-mobile-pack/) (can't have "Don't cache pages for known users." enabled)
260
+
261
+
262
+ ## Changelog ##
263
+
264
+ ### 1.5.9 ###
265
+ * Fixed fatal error if the debug log was deleted while debugging was enabled and a visitor came to the site.
266
+ * Fixed the dynamic caching test plugin because of PHP7 changes. Dynamic cache mode must be enabled now.
267
+ * Lots of WordPress coding style formatting fixes to the code.
268
+ * All changes: https://github.com/Automattic/wp-super-cache/compare/1.5.8...1.5.9
269
+
270
+ ### 1.5.8 ###
271
  * PHP 7 fixes. (#429)
272
  * Fix debug comments checkbox. (#433)
273
  * Only register uninstall function in admin pages to save queries. (#430)
282
  * Fixed more PHP warnings in #438 and #437
283
  * Hide mod_rewrite warnings for Nginx users. #434
284
 
285
+ ### 1.5.7.1 ###
286
  * If the HTTP HOST is empty then don't use it in strpos to avoid a PHP warning. (#408)
287
  * Don't preload posts with permalinks that contain rejected strings. (#407)
288
  * Generate a list of archive feeds that can be deleted when the site is updated. Also fixes corrupted config file issue and fatal error with older versions of WordPress. (#403)
289
 
290
+ ### 1.5.7 ###
291
  * Fix fatal error in plugins/searchengine.php (#398)
292
 
293
+ ### 1.5.6 ###
294
  * REST API: Added /plugins endpoint to handle the plugins settings page. (#382)
295
  * Minor changes to indentaion and spaces to tabs conversion (#371) (#395)
296
  * Don't set $wp_super_cache_comments here as it's not saved. (#379)
301
  * Fix some PHP notices when comments are edited/published/maintained. (#386)
302
  * Minor changes to description on plugins page. (#393)
303
 
304
+ ### 1.5.5 ###
305
  * Catch fatal errors so they're not cached, improve code that catches unknown page types. (#367)
306
  * Fix caching on older WP installs, and if the plugin is inactive on a blog, but still caching, give feeds a short TTL to ensure they're fresh. (#366)
307
  * When preloading don't delete sub-directories, or child pages, when caching pages. (#363)
308
  * Avoid PHP warnings from the REST API for settings that are not yet defined. (#361)
309
  * Added missing settings to the config file. (#360)
310
 
311
+ ### 1.5.4 ###
312
  * Fix messages related to creating advanced-cache.php (#355, #354)
313
  * Deleting the plugin doesn't need to delete the cache directory as it's already done on deactivation. (#323)
314
  * Disable Jetpack mobile detection if Jetpack Beta is detected. (#298)
328
  * Other minor changes to html or typos
329
  (Numbers are [pull requests](https://github.com/Automattic/wp-super-cache/pulls) on Github.)
330
 
331
+ ### 1.5.3 ###
332
  * Fix a critical bug that caused unlink to be run on null while deleting the plugin.
333
 
334
+ ### 1.5.2 ###
335
  * Add a trailing slash to home path. Fixes problems with finding the .htaccess file.
336
  * Delete WPCACHEHOME and WP_CACHE from wp-config.php when plugin deactivated.
337
  * Check that WPCACHEHOME is the right path on each load of the settings page.
344
  * Added more information for when updating the .htaccess file fails.
345
  * "Served by" header is now optional. Enable it by setting $wpsc_served_header to true in the config file.
346
 
347
+ ### 1.5.1 ###
348
  * Don't use anonymous functions in REST API
349
  * Check that REST API Controller is available before loading the REST API.
350
  * Don't use multibyte string functions because some sites don't have it enabled.
351
 
352
+ ### 1.5.0 ###
353
  * REST API settings endpoints.
354
  * Simplified settings page.
355
  * WP-Cache files reorganised.
356
  * Caching of more http headers.
357
  * Lots of bug fixes.
358
 
359
+ ### 1.4.9 ###
360
  * Fixed bug when not running sem_remove after sem_release. See https://github.com/Automattic/wp-super-cache/issues/85
361
  * Fixed a PHP error impacting PHP 7.1.
362
  * Fixed a bug where we cached PUT and DELETE requests. We're treating them like POST requests now.
371
  * Add fix for customizer [#161](https://github.com/Automattic/wp-super-cache/pull/161) and don't cache PUT AND DELETE requests [#178](https://github.com/Automattic/wp-super-cache/pull/178)
372
  * Check for superglobals before using them. [#131](https://github.com/Automattic/wp-super-cache/pull/131)
373
 
374
+ ### 1.4.8 ###
375
  * Removed malware URL in a code comment. (harmless to operation of plugin but gets flagged by A/V software)
376
  * Updated translation file.
377
 
378
+ ### 1.4.7 ###
379
  * Update the settings page for WordPress 4.4. layout changes.
380
 
381
+ ### 1.4.6 ###
382
  * Generate the file cache/.htaccess even when one exists so gzip rules are created and gzipped pages are served correctly. Props Tigertech. https://wordpress.org/support/topic/all-website-pages-downloading-gz-file-after-latest-update?replies=36#post-7494087
383
 
384
+ ### 1.4.5 ###
385
  * Enhancement: Only preload public post types. Props webaware.
386
  * Added an uninstall function that deletes the config file. Deactivate function doesn't delete it any more.
387
  * Possible to deactivate the plugin without visiting the settings page now.
396
  * Hide cache files when servers display directory indexes.
397
  * Prevent PHP object injection through use of serialize().
398
 
399
+ ### 1.4.4 ###
400
  * Fixed fatal error in output handler if GET parameters present in query. Props webaware.
401
  * Fixed debug log. It wasn't logging the right message.
402
 
403
+ ### 1.4.3 ###
404
  * Security release fixing an XSS bug in the settings page. Props Marc Montpas from Sucuri.
405
  * Added wp_debug_log(). Props Jen Heilemann.
406
  * Minor fixes.
407
 
408
+ ### 1.4.2 ###
409
  * Fixed "acceptable file list".
410
  * Fixed "Don't cache GET requests" feature.
411
  * Maybe fixed "304 not modified" problem for some users.
412
  * Fixed some PHP warnings.
413
 
414
+ ### 1.4.1 ###
415
  * Fixed XSS in settings page. Props Simon Waters, Surevine Limited.
416
  * Fix to object cache so entries may now be deleted when posts updated. (object cache still experimental)
417
  * Documentation updates and cleanup of settings page.
418
 
419
+ ### 1.4 ###
420
  * Replace legacy mfunc/mnclude/dynamic-cached-content functionality with a "wpsc_cachedata" cacheaction filter.
421
  * Added dynamic-cache-test.php plugin example wpsc_cachedata filter plugin.
422
  * Delete post, tag and category cache when a post changes from draft to publish or vice versa. Props @Biranit.
423
  * Update advanced-cache.php and wp-config.php if wp-cache-phase1.php doesn't load, usually happening after migrating to a new hosting service.
424
  * Misc bugfixes.
425
 
426
+ ### 1.3.2 ###
427
  * Any mfunc/mclude/dynamic-cached-content tags in comments are now removed.
428
  * Dynamic cached content feature disabled by default and must be enabled on the Advanced Settings page.
429
  * Support for the mobile theme in Jetpack via helper plugin on script's Plugins tab.
430
 
431
+ ### 1.3.1 ###
432
  * Minor updates to documentation
433
  * Fixed XSS in settings page.
434
 
435
+ ### 1.3 ###
436
  * mfunc tags could be executed in comments. Fixed.
437
  * More support for sites that use the LOGGED_IN_COOKIE constant and custom cookies.
438
 
439
+ ### 1.2 ###
440
  * Garbage collection of old cache files is significantly improved. I added a scheduled job that keeps an eye on things and restarts the job if necessary. Also, if you enable caching from the Easy page garbage collection will be enabled too.
441
  * Editors can delete single cached files from the admin bar now.
442
  * Fixed the cached page counter on the settings page.
449
  * Some sites had problems with scheduled posts. For some reason the plugin thought the post was in draft mode and then because it only checked the same post once, when the post magically became published the cache wasn.t cleared. That.s fixed, thanks to the debug logging of several patient users.
450
  * And more bug fixes and translation updates.
451
 
452
+ ### 1.1 ###
453
  * Use $_SERVER[ 'SERVER_NAME' ] to create cache directories.
454
  * Only create blogs cached directories if valid requests and blogs exist.
455
  * Only clear current blog's cache files if navigation menu is modified
476
  * Removed debug level from logging as it wasn't helpful.
477
  * Removed mention of wp-minify.
478
 
479
+ ### 1.0 ###
480
  * Removed AddDefaultCharset .htaccess rule
481
  * Fixed problem with blogs in a folder and don't have a trailing slash
482
  * New scheduling of garbage collection
490
  * Use WP 3.0 variables to detect multisite installs
491
  * Hash filenames so files are served from the same CDNs
492
 
493
+ ### 0.9.9.9 ###
494
  * Fixed typo, is_front_page.
495
  * Serve repeated static files from the same CDN hostname.
496
  * Updated translations.
499
  * Remove 5 second check on age of existing cache files. Should help with posts that get lots of comments and traffic.
500
  * Lots of bugs fixed.
501
 
502
+ ### 0.9.9.8 ###
503
  * CDN updates: can be switched off, multiple CNAMEs.
504
  * Uninstall process improved. It removes generated files and fixes edited files.
505
  * Cached dynamic pages can now be stored in Supercache files and compressed.
507
  * Remove log by email functionality as it caused problems for users who were inundated by email
508
  * Many more minor fixes and changes.
509
 
510
+ ### 0.9.9.6 ###
511
  * Fixed problem serving cached files with PHP
512
  * Added support for 304 "file not modified" header to help browser caching. (PHP caching only)
513
  * Added French & German translations, updated Italian translation and fixed translation strings.
514
  * Sleep 4 seconds between preload urls to reduce load on the server
515
  * Updated docs and FAQs.
516
 
517
+ ### 0.9.9.5 ###
518
  * Disable compression on on easy setup page. Still causes problems on some hosts.
519
  * Remove footerlink on easy setup page.
520
  * Don't delete mod_rewrite rules when caching is disabled.
521
  * Don't stop users using settings page when in safe mode.
522
 
523
+ ### 0.9.9.4 ###
524
  * Settings page split into tabbed pages.
525
  * Added new "Easy" settings page for new users.
526
  * New PHP caching mode to serve supercached files.
535
  * Serve the gzipped page when first cached if the client supports compression.
536
  * Lots more bug fixes..
537
 
538
+ ### 0.9.9.3 ###
539
  * Fixed division by zero error in half on mode.
540
  * Always show "delete cache" button.
541
  * Fixed "Update mod_rewrite rules" button.
542
  * Minor text changes to admin page.
543
 
544
+ ### 0.9.9.2 ###
545
  * Forgot to change version number in wp-cache.php
546
 
547
+ ### 0.9.9.1 ###
548
  * Added preloading of static cache.
549
  * Better mobile plugin support
550
  * .htaccess rules can be updated now. Added wpsc_update_htaccess().
553
  * Added clear_post_supercache() to clear supercache for a single post.
554
  * Put quotes around rewrite rules in case paths have spaces.
555
 
556
+ ### 0.9.9 ###
557
  * Added experimental object cache support.
558
  * Added Chinese(Traditional) translation by Pseric.
559
  * Added FAQ on WP-Cache vs Supercache files.
569
  * Updated Italian translation.
570
  * Link to WP Mobile Edition from admin page for mobile support.
571
 
572
+ ### 0.9.8 ###
573
  * Added Spanish translation by Omi.
574
  * Added Italian translation by Gianni Diurno.
575
  * Addded advanced debug code to check front page for category problem. Enable by setting $wp_super_cache_advanced_debug to 1 in the config file.
581
  * Fixed problem deleting cache file.
582
  * Don't delete cache files when moderated comments are deleted.
583
 
584
+ ### 0.9.7 ###
585
  * Fixed problem with blogs in folders.
586
  * Added cache file listing and delete links to admin page.
587
  * Added "Newest Cached Pages" listing in sidebox.
597
  * Fixed problem with PHP safe_mode detection.
598
  * Various bugfixes and documentation updates. See Changelog.txt
599
 
600
+ ### 0.9.6.1 ###
601
  * Move "not logged in" message init below check for POST.
602
  * Add is_admin() check so plugin definitely can't cache the backend.
603
  * Add "do not cache" page type to admin page.
604
 
605
+ ### 0.9.6 ###
606
  * Add uninstall.php uninstall script.
607
  * Updated cache/.htaccess rules (option to upgrade that)
608
  * Added FAQ about category and static homepage problem.
610
  * Show message for logged in users when caching disable for them.
611
  * Check filemtime on correct supercache file
612
 
613
+ ### 0.9.5 ###
614
  * Show next and last GC times in minutes, not local time.
615
  * Don't serve wp_cache cache files to rejected user agents. Supercache files are still served to them.
616
  * If enabled, mobile support now serves php cached files to mobile clients and static cached files to everyone else.
618
  * Added check for DONOTCACHEPAGE constant to avoid caching a page.
619
  * Use PHP_DOCUMENT_ROOT when creating .htaccess if necessary.
620
 
621
+ ### 0.9.4.3 ###
622
  1. Added "Don't cache for logged in users" option.
623
  2. Display file size stats on admin page.
624
  3. Clear the cache when profile page is updated.
626
  5. Added backslashes to rejected URI regex list.
627
  6. Fixed problems with posts and comments not refreshing.
628
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
629
 
630
+ ## Upgrade Notice ##
631
+ Fixes rare fatal error when using debug log
rest/class.wp-super-cache-rest-get-settings.php CHANGED
@@ -159,7 +159,7 @@ class WP_Super_Cache_Rest_Get_Settings extends WP_REST_Controller {
159
  * @return int
160
  */
161
  protected function get_is_preload_active() {
162
- if ( wp_next_scheduled( 'wp_cache_preload_hook' ) || wp_next_scheduled( 'wp_cache_full_preload_hook' ) ) {
163
  return true;
164
  } else {
165
  return false;
159
  * @return int
160
  */
161
  protected function get_is_preload_active() {
162
+ if ( wp_next_scheduled( 'wp_cache_preload_hook' ) || wp_next_scheduled( 'wp_cache_full_preload_hook' ) ) {
163
  return true;
164
  } else {
165
  return false;
rest/class.wp-super-cache-rest-test-cache.php CHANGED
@@ -57,7 +57,7 @@ class WP_Super_Cache_Rest_Test_Cache extends WP_REST_Controller {
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;
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;
rest/class.wp-super-cache-rest-update-settings.php CHANGED
@@ -34,10 +34,10 @@ class WP_Super_Cache_Rest_Update_Settings extends WP_REST_Controller {
34
  } else {
35
 
36
  foreach ( $parameters as $name => $value ) {
37
- if ( $has_error = $this->set_value_by_key( $value, $name ) ) {
38
- if ( false == is_numeric( $has_error ) && false == is_bool( $has_error ) ) {
39
- $errors[] = $has_error;
40
- }
41
  }
42
  }
43
 
@@ -46,7 +46,7 @@ class WP_Super_Cache_Rest_Update_Settings extends WP_REST_Controller {
46
  $this->set_debug_settings( $parameters );
47
  }
48
 
49
- if ( count( $errors ) > 0 ) {
50
  return rest_ensure_response( $errors );
51
 
52
  } else {
@@ -67,7 +67,6 @@ class WP_Super_Cache_Rest_Update_Settings extends WP_REST_Controller {
67
  protected function set_value_by_key( $value, $key ) {
68
 
69
  $settings_map = WP_Super_Cache_Settings_Map::$map;
70
- $error = null;
71
 
72
  // If this parameter isn't in the map, then let's ignore it.
73
  if ( ! isset( $settings_map[ $key ] ) ) {
@@ -77,32 +76,25 @@ class WP_Super_Cache_Rest_Update_Settings extends WP_REST_Controller {
77
  $map = $settings_map[ $key ];
78
 
79
  if ( isset( $map['set'] ) ) {
80
- $set_method = $map['set'];
 
81
 
82
- if ( method_exists( $this, $set_method ) ) {
83
- if ( $has_error = $this->$set_method( $value, $key ) ) {
84
- $error = $has_error;
85
- }
86
 
87
- } elseif ( function_exists( $set_method ) ) {
88
- $set_method( $value );
89
  }
90
-
91
  } elseif ( isset( $map['global'] ) ) {
92
 
93
- if ( method_exists( $this, 'set_' . $map['global'] ) ) {
94
- $set_method = 'set_' . $map['global'];
95
-
96
- if ( $has_error = $this->$set_method( $value ) ) {
97
- $error = $has_error;
98
- }
99
- } else {
100
 
101
- $this->set_global( $map['global'], $value );
102
- }
103
  }
104
 
105
- return $error;
106
  }
107
 
108
  /**
34
  } else {
35
 
36
  foreach ( $parameters as $name => $value ) {
37
+ $has_error = $this->set_value_by_key( $value, $name );
38
+
39
+ if ( false == is_numeric( $has_error ) && false == is_bool( $has_error ) ) {
40
+ $errors[] = $has_error;
41
  }
42
  }
43
 
46
  $this->set_debug_settings( $parameters );
47
  }
48
 
49
+ if ( ! empty( $errors ) ) {
50
  return rest_ensure_response( $errors );
51
 
52
  } else {
67
  protected function set_value_by_key( $value, $key ) {
68
 
69
  $settings_map = WP_Super_Cache_Settings_Map::$map;
 
70
 
71
  // If this parameter isn't in the map, then let's ignore it.
72
  if ( ! isset( $settings_map[ $key ] ) ) {
76
  $map = $settings_map[ $key ];
77
 
78
  if ( isset( $map['set'] ) ) {
79
+ if ( method_exists( $this, $map['set'] ) ) {
80
+ $has_error = call_user_func( array( $this, $map['set'] ), $value, $key );
81
 
82
+ } elseif ( function_exists( $map['set'] ) ) {
83
+ $has_error = call_user_func( $map['set'], $value );
 
 
84
 
 
 
85
  }
 
86
  } elseif ( isset( $map['global'] ) ) {
87
 
88
+ $set_method = method_exists( $this, 'set_' . $map['global'] ) ?
89
+ 'set_' . $map['global'] : 'set_global';
90
+ $has_error = call_user_func( array( $this, $set_method ), $value );
91
+ }
 
 
 
92
 
93
+ if ( ! empty( $has_error ) ) {
94
+ return $has_error;
95
  }
96
 
97
+ return null;
98
  }
99
 
100
  /**
wp-cache-base.php CHANGED
@@ -1,34 +1,35 @@
1
  <?php
2
- if ( false == isset( $_SERVER[ 'HTTP_HOST' ] ) ) {
3
- $cache_enabled = false;
4
  $WPSC_HTTP_HOST = '';
5
  } else {
6
- $WPSC_HTTP_HOST = htmlentities( $_SERVER[ 'HTTP_HOST' ] );
7
  }
8
 
9
  // We want to be able to identify each blog in a WordPress MU install
10
  $blogcacheid = '';
11
  if ( ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) || defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) ) {
12
  $blogcacheid = 'blog'; // main blog
13
- if( defined( 'SUBDOMAIN_INSTALL' ) && constant( 'SUBDOMAIN_INSTALL' ) == true ) {
14
  $blogcacheid = $WPSC_HTTP_HOST;
15
  } else {
16
- if ( isset( $base ) == false )
17
  $base = '';
18
- $request_uri = str_replace( '..', '', preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI'] ) );
19
- if( strpos( $request_uri, '/', 1 ) ) {
20
- if( $base == '/' ) {
 
21
  $blogcacheid = substr( $request_uri, 1, strpos( $request_uri, '/', 1 ) - 1 );
22
  } else {
23
  $blogcacheid = str_replace( $base, '', $request_uri );
24
- if ( $blogcacheid != '' )
25
  $blogcacheid = substr( $blogcacheid, 0, strpos( $blogcacheid, '/', 1 ) );
 
 
 
 
26
  }
27
- if ( '/' == substr($blogcacheid, -1))
28
- $blogcacheid = substr($blogcacheid, 0, -1);
29
  }
30
  $blogcacheid = str_replace( '/', '', $blogcacheid );
31
  }
32
  }
33
-
34
- ?>
1
  <?php
2
+ if ( false == isset( $_SERVER['HTTP_HOST'] ) ) {
3
+ $cache_enabled = false;
4
  $WPSC_HTTP_HOST = '';
5
  } else {
6
+ $WPSC_HTTP_HOST = htmlentities( $_SERVER['HTTP_HOST'] );
7
  }
8
 
9
  // We want to be able to identify each blog in a WordPress MU install
10
  $blogcacheid = '';
11
  if ( ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) || defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) ) {
12
  $blogcacheid = 'blog'; // main blog
13
+ if ( defined( 'SUBDOMAIN_INSTALL' ) && constant( 'SUBDOMAIN_INSTALL' ) == true ) {
14
  $blogcacheid = $WPSC_HTTP_HOST;
15
  } else {
16
+ if ( isset( $base ) == false ) {
17
  $base = '';
18
+ }
19
+ $request_uri = str_replace( '..', '', preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI'] ) );
20
+ if ( strpos( $request_uri, '/', 1 ) ) {
21
+ if ( $base == '/' ) {
22
  $blogcacheid = substr( $request_uri, 1, strpos( $request_uri, '/', 1 ) - 1 );
23
  } else {
24
  $blogcacheid = str_replace( $base, '', $request_uri );
25
+ if ( $blogcacheid != '' ) {
26
  $blogcacheid = substr( $blogcacheid, 0, strpos( $blogcacheid, '/', 1 ) );
27
+ }
28
+ }
29
+ if ( '/' == substr( $blogcacheid, -1 ) ) {
30
+ $blogcacheid = substr( $blogcacheid, 0, -1 );
31
  }
 
 
32
  }
33
  $blogcacheid = str_replace( '/', '', $blogcacheid );
34
  }
35
  }
 
 
wp-cache-phase1.php CHANGED
@@ -1,48 +1,49 @@
1
  <?php
2
- //error_reporting(E_ERROR | E_PARSE); // uncomment to debug this file!
3
- // Pre-2.6 compatibility
4
- if( !defined('WP_CONTENT_DIR') )
5
- define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
6
 
7
- if( !@include( WP_CONTENT_DIR . '/wp-cache-config.php' ) )
 
 
 
8
  return false;
 
9
 
10
- if( !defined( 'WPCACHEHOME' ) )
11
- define('WPCACHEHOME', dirname(__FILE__).'/');
 
12
 
13
  if ( defined( 'DISABLE_SUPERCACHE' ) ) {
14
  wp_cache_debug( 'DISABLE_SUPERCACHE set, super_cache disabled.' );
15
  $super_cache_enabled = 0;
16
  }
17
 
18
- include( WPCACHEHOME . 'wp-cache-base.php');
19
 
20
- if( $blogcacheid != '' ) {
21
- $blog_cache_dir = str_replace( '//', '/', $cache_path . "blogs/" . $blogcacheid . '/' );
22
  } else {
23
  $blog_cache_dir = $cache_path;
24
  }
25
 
26
  $wp_cache_phase1_loaded = true;
27
 
28
- $mutex_filename = 'wp_cache_mutex.lock';
29
- $new_cache = false;
30
 
31
- if( !isset( $wp_cache_plugins_dir ) )
32
  $wp_cache_plugins_dir = WPCACHEHOME . 'plugins';
 
33
 
34
- require_once( WPCACHEHOME . 'wp-cache-phase2.php');
35
-
36
- if ( isset( $_GET[ 'donotcachepage' ] ) && isset( $cache_page_secret ) && $_GET[ 'donotcachepage' ] == $cache_page_secret ) {
37
  $cache_enabled = false;
38
  define( 'DONOTCACHEPAGE', 1 );
39
  }
40
 
41
  $plugins = glob( $wp_cache_plugins_dir . '/*.php' );
42
- if( is_array( $plugins ) ) {
43
  foreach ( $plugins as $plugin ) {
44
- if( is_file( $plugin ) )
45
- require_once( $plugin );
 
46
  }
47
  }
48
 
@@ -53,33 +54,26 @@ if ( $wp_cache_not_logged_in && wp_cache_get_cookies_values() ) {
53
  return true;
54
  }
55
 
56
- if ( isset( $wp_cache_make_known_anon ) && $wp_cache_make_known_anon )
57
  wp_supercache_cache_for_admins();
 
58
 
59
  do_cacheaction( 'cache_init' );
60
 
61
 
62
- if ( ! $cache_enabled || ( isset( $_SERVER["REQUEST_METHOD"] ) && in_array( $_SERVER["REQUEST_METHOD"], array( 'POST', 'PUT', 'DELETE' ) ) ) || isset( $_GET['customize_changeset_uuid'] ) ) {
63
  return true;
64
  }
65
 
66
- $file_expired = false;
67
- $cache_filename = '';
68
- $meta_file = '';
69
  $wp_cache_gzip_encoding = '';
70
 
71
  $gzipped = 0;
72
- $gzsize = 0;
73
 
74
- function gzip_accepted(){
75
- if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) // don't compress WP-Cache data files when PHP is already doing it
76
- return false;
77
-
78
- if ( !isset( $_SERVER[ 'HTTP_ACCEPT_ENCODING' ] ) || ( isset( $_SERVER[ 'HTTP_ACCEPT_ENCODING' ] ) && strpos( $_SERVER[ 'HTTP_ACCEPT_ENCODING' ], 'gzip' ) === false ) ) return false;
79
- return 'gzip';
80
- }
81
-
82
- if ($cache_compression) {
83
  $wp_cache_gzip_encoding = gzip_accepted();
84
  }
85
 
@@ -88,983 +82,25 @@ if ( function_exists( 'add_filter' ) ) { // loaded since WordPress 4.6
88
  add_filter( 'supercache_filename_str', 'wp_cache_check_mobile' );
89
  }
90
 
91
- $wp_cache_request_uri = $_SERVER[ 'REQUEST_URI' ]; // Cache this in case any plugin modifies it.
92
 
93
  if ( $wp_cache_object_cache ) {
94
- if ( ! include_once( WP_CONTENT_DIR . '/object-cache.php' ) )
95
  return;
 
96
 
97
  wp_cache_init(); // Note: wp-settings.php calls wp_cache_init() which clobbers the object made here.
98
 
99
- if ( ! is_object( $wp_object_cache ) )
100
  return;
101
- }
102
-
103
- function setup_blog_cache_dir() {
104
- global $blog_cache_dir, $cache_path;
105
- if( false == @is_dir( $blog_cache_dir ) ) {
106
- @mkdir( $cache_path . "blogs" );
107
- @mkdir( $blog_cache_dir );
108
- }
109
-
110
- if( false == @is_dir( $blog_cache_dir . 'meta' ) )
111
- @mkdir( $blog_cache_dir . 'meta' );
112
- }
113
-
114
- function get_wp_cache_key( $url = false ) {
115
- global $wp_cache_request_uri, $wp_cache_gzip_encoding, $WPSC_HTTP_HOST;
116
- if ( ! $url ) {
117
- $url = $wp_cache_request_uri;
118
- }
119
- $server_port = isset( $_SERVER[ 'SERVER_PORT' ] ) ? intval( $_SERVER[ 'SERVER_PORT' ] ) : 0;
120
- return do_cacheaction( 'wp_cache_key', wp_cache_check_mobile( $WPSC_HTTP_HOST . $server_port . preg_replace('/#.*$/', '', str_replace( '/index.php', '/', $url ) ) . $wp_cache_gzip_encoding . wp_cache_get_cookies_values() ) );
121
- }
122
-
123
- function wp_super_cache_init() {
124
- global $wp_cache_key, $key, $blogcacheid, $file_prefix, $blog_cache_dir, $meta_file, $cache_file, $cache_filename, $meta_pathname;
125
-
126
- $wp_cache_key = get_wp_cache_key();
127
- $key = $blogcacheid . md5( $wp_cache_key );
128
- $wp_cache_key = $blogcacheid . $wp_cache_key;
129
-
130
- $cache_filename = $file_prefix . $key . '.php';
131
- $meta_file = $file_prefix . $key . '.php';
132
- $cache_file = wpsc_get_realpath( $blog_cache_dir ) . '/' . $cache_filename;
133
- $meta_pathname = wpsc_get_realpath( $blog_cache_dir . 'meta/' ) . '/' . $meta_file;
134
- return compact( 'key', 'cache_filename', 'meta_file', 'cache_file', 'meta_pathname' );
135
- }
136
-
137
- function wp_cache_serve_cache_file() {
138
- global $key, $blogcacheid, $wp_cache_request_uri, $file_prefix, $blog_cache_dir, $meta_file, $cache_file, $cache_filename, $meta_pathname, $wp_cache_gzip_encoding, $meta;
139
- global $wp_cache_object_cache, $cache_compression, $wp_cache_slash_check, $wp_supercache_304, $wp_cache_home_path, $wp_cache_no_cache_for_get;
140
- global $wp_cache_disable_utf8, $wp_cache_mfunc_enabled, $wpsc_served_header;
141
-
142
- if ( is_admin() ) {
143
- wp_cache_debug( 'Not serving wp-admin requests.', 5 );
144
- return false;
145
- }
146
-
147
- if ( wp_cache_user_agent_is_rejected() ) {
148
- wp_cache_debug( "No wp-cache file served as user agent rejected.", 5 );
149
- return false;
150
- }
151
-
152
- if ( $wp_cache_no_cache_for_get && false == empty( $_GET ) ) {
153
- wp_cache_debug( "Non empty GET request. Caching disabled on settings page. " . json_encode( $_GET ), 1 );
154
- return false;
155
- }
156
-
157
- extract( wp_super_cache_init() ); // $key, $cache_filename, $meta_file, $cache_file, $meta_pathname
158
-
159
- if ( $wp_cache_object_cache && wp_cache_get_cookies_values() == '' ) {
160
- if ( !empty( $_GET ) ) {
161
- wp_cache_debug( "Non empty GET request. Not serving request from object cache. " . json_encode( $_GET ), 1 );
162
- return false;
163
- }
164
-
165
- $oc_key = get_oc_key();
166
- $meta_filename = $oc_key . ".meta";
167
- if ( gzip_accepted() ) {
168
- $oc_key .= ".gz";
169
- $meta_filename .= ".gz";
170
- }
171
- $cache = wp_cache_get( $oc_key, 'supercache' );
172
- $meta = json_decode( wp_cache_get( $meta_filename, 'supercache' ), true );
173
- if ( is_array( $meta ) == false ) {
174
- wp_cache_debug( "Meta array from object cache corrupt. Ignoring cache.", 1 );
175
- return true;
176
- }
177
- } elseif ( ( $cache_file && file_exists( $cache_file ) ) || file_exists( get_current_url_supercache_dir() . 'meta-' . $cache_filename ) ) {
178
- if ( file_exists( get_current_url_supercache_dir() . 'meta-' . $cache_filename ) ) {
179
- $cache_file = get_current_url_supercache_dir() . $cache_filename;
180
- $meta_pathname = get_current_url_supercache_dir() . 'meta-' . $cache_filename;
181
- } elseif ( !file_exists( $cache_file ) ) {
182
- wp_cache_debug( "wp_cache_serve_cache_file: found cache file but then it disappeared!" );
183
- return false;
184
- }
185
-
186
- wp_cache_debug( "wp-cache file exists: $cache_file", 5 );
187
- if ( !( $meta = json_decode( wp_cache_get_legacy_cache( $meta_pathname ), true ) ) ) {
188
- wp_cache_debug( "couldn't load wp-cache meta file", 5 );
189
- return true;
190
- }
191
- if ( is_array( $meta ) == false ) {
192
- wp_cache_debug( "meta array corrupt, deleting $meta_pathname and $cache_file", 1 );
193
- @unlink( $meta_pathname );
194
- @unlink( $cache_file );
195
- return true;
196
- }
197
- } else { // no $cache_file
198
- global $wpsc_save_headers;
199
- // last chance, check if a supercache file exists. Just in case .htaccess rules don't work on this host
200
- $filename = supercache_filename();
201
- $file = get_current_url_supercache_dir() . $filename;
202
- if ( false == file_exists( $file ) ) {
203
- wp_cache_debug( "No Super Cache file found for current URL: $file" );
204
- return false;
205
- } elseif ( false == empty( $_GET ) ) {
206
- wp_cache_debug( "GET array not empty. Cannot serve a supercache file. " . json_encode( $_GET ) );
207
- return false;
208
- } elseif ( wp_cache_get_cookies_values() != '' ) {
209
- wp_cache_debug( "Cookies found. Cannot serve a supercache file. " . wp_cache_get_cookies_values() );
210
- return false;
211
- } elseif ( isset( $wpsc_save_headers ) && $wpsc_save_headers ) {
212
- wp_cache_debug( "Saving headers. Cannot serve a supercache file." );
213
- return false;
214
- }
215
-
216
- if ( isset( $wp_cache_mfunc_enabled ) == false )
217
- $wp_cache_mfunc_enabled = 0;
218
-
219
- if ( false == isset( $wp_cache_home_path ) )
220
- $wp_cache_home_path = '/';
221
-
222
- // make sure ending slashes are ok
223
- if ( $wp_cache_request_uri == $wp_cache_home_path || ( $wp_cache_slash_check && substr( $wp_cache_request_uri, -1 ) == '/' ) || ( $wp_cache_slash_check == 0 && substr( $wp_cache_request_uri, -1 ) != '/' ) ) {
224
-
225
- if ( $wp_cache_mfunc_enabled == 0 ) {
226
- // get data from file
227
- if ( $wp_cache_gzip_encoding ) {
228
- if ( file_exists( $file . '.gz' ) ) {
229
- $cachefiledata = file_get_contents( $file . '.gz' );
230
- wp_cache_debug( "Fetched gzip static page data from supercache file using PHP. File: $file.gz" );
231
- } else {
232
- $cachefiledata = gzencode( file_get_contents( $file ), 6, FORCE_GZIP );
233
- wp_cache_debug( "Fetched static page data from supercache file using PHP and gzipped it. File: $file" );
234
- }
235
- } else {
236
- $cachefiledata = file_get_contents( $file );
237
- wp_cache_debug( "Fetched static page data from supercache file using PHP. File: $file" );
238
- }
239
- } else {
240
- // get dynamic data from filtered file
241
- $cachefiledata = do_cacheaction( 'wpsc_cachedata', file_get_contents( $file ) );
242
- if ( $wp_cache_gzip_encoding ) {
243
- $cachefiledata = gzencode( $cachefiledata, 6, FORCE_GZIP );
244
- wp_cache_debug( "Fetched dynamic page data from supercache file using PHP and gzipped it. File: $file" );
245
- } else {
246
- wp_cache_debug( "Fetched dynamic page data from supercache file using PHP. File: $file" );
247
- }
248
- }
249
-
250
- if ( isset( $wp_cache_disable_utf8 ) == false || $wp_cache_disable_utf8 == 0 )
251
- header( "Content-type: text/html; charset=UTF-8" );
252
-
253
- header( "Vary: Accept-Encoding, Cookie" );
254
- header( "Cache-Control: max-age=3, must-revalidate" );
255
- $size = function_exists( 'mb_strlen' ) ? mb_strlen( $cachefiledata, '8bit' ) : strlen( $cachefiledata );
256
- if ( $wp_cache_gzip_encoding ) {
257
- if ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
258
- header( "X-WP-Super-Cache: Served supercache gzip file from PHP" );
259
- }
260
- header( 'Content-Encoding: ' . $wp_cache_gzip_encoding );
261
- header( 'Content-Length: ' . $size );
262
- } elseif ( $wp_supercache_304 ) {
263
- if ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
264
- header( "X-WP-Super-Cache: Served supercache 304 file from PHP" );
265
- }
266
- header( 'Content-Length: ' . $size );
267
- } else {
268
- if ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
269
- header( "X-WP-Super-Cache: Served supercache file from PHP" );
270
- }
271
- }
272
-
273
- // don't try to match modified dates if using dynamic code.
274
- if ( $wp_cache_mfunc_enabled == 0 && $wp_supercache_304 ) {
275
- if ( function_exists( 'apache_request_headers' ) ) {
276
- $request = apache_request_headers();
277
- $remote_mod_time = ( isset ( $request[ 'If-Modified-Since' ] ) ) ? $request[ 'If-Modified-Since' ] : null;
278
- } else {
279
- if ( isset( $_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ] ) )
280
- $remote_mod_time = $_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ];
281
- else
282
- $remote_mod_time = null;
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 );
290
- }
291
- echo $cachefiledata;
292
- exit();
293
- } else {
294
- wp_cache_debug( "No wp-cache file exists. Must generate a new one." );
295
- return false;
296
- }
297
  }
298
-
299
- $cache_file = do_cacheaction( 'wp_cache_served_cache_file', $cache_file );
300
- // Sometimes the gzip headers are lost. Make sure html returned isn't compressed!
301
- if ( $cache_compression && $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $meta[ 'headers' ] ) ) {
302
- $ungzip = true;
303
- wp_cache_debug( "GZIP headers not found. Force uncompressed output.", 1 );
304
- } else {
305
- $ungzip = false;
306
- }
307
- foreach ($meta[ 'headers' ] as $t => $header) {
308
- // godaddy fix, via http://blog.gneu.org/2008/05/wp-supercache-on-godaddy/ and http://www.littleredrails.com/blog/2007/09/08/using-wp-cache-on-godaddy-500-error/
309
- if( strpos( $header, 'Last-Modified:' ) === false )
310
- header($header);
311
- }
312
- if ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
313
- header( 'X-WP-Super-Cache: Served WPCache cache file' );
314
- }
315
- if ( $wp_cache_object_cache ) {
316
- if ( $cache ) {
317
- if ( $ungzip ) {
318
- // attempt to uncompress the cached file just in case it's gzipped
319
- $uncompressed = gzuncompress( $cache );
320
- if ( $uncompressed ) {
321
- wp_cache_debug( "Uncompressed gzipped cache file from object cache", 1 );
322
- $cache = $uncompressed;
323
- unset( $uncompressed );
324
- }
325
- }
326
- if ( isset( $meta[ 'dynamic' ] ) && $meta[ 'dynamic' ] ) {
327
- wp_cache_debug( "Serving wp-cache dynamic file from object cache", 5 );
328
- echo do_cacheaction( 'wpsc_cachedata', $cache );
329
- } else {
330
- wp_cache_debug( "Serving wp-cache static file from object cache", 5 );
331
- echo $cache;
332
- }
333
- wp_cache_debug( "exit request", 5 );
334
- die();
335
- }
336
- } else {
337
- if ( isset( $meta[ 'dynamic' ] ) ) {
338
- wp_cache_debug( "Serving wp-cache dynamic file", 5 );
339
- if ( $ungzip ) {
340
- // attempt to uncompress the cached file just in case it's gzipped
341
- $cache = wp_cache_get_legacy_cache( $cache_file );
342
- $uncompressed = @gzuncompress( $cache );
343
- if ( $uncompressed ) {
344
- wp_cache_debug( "Uncompressed gzipped cache file from wp-cache", 1 );
345
- unset( $cache );
346
- echo do_cacheaction( 'wpsc_cachedata', $uncompressed );
347
- } else {
348
- echo do_cacheaction( 'wpsc_cachedata', $cache );
349
- }
350
- } else {
351
- echo do_cacheaction( 'wpsc_cachedata', wp_cache_get_legacy_cache( $cache_file ) );
352
- }
353
- } else {
354
- wp_cache_debug( "Serving wp-cache static file", 5 );
355
- if ( $ungzip ) {
356
- $cache = wp_cache_get_legacy_cache( $cache_file );
357
- $uncompressed = gzuncompress( $cache );
358
- if ( $uncompressed ) {
359
- wp_cache_debug( "Uncompressed gzipped cache file from wp-cache", 1 );
360
- echo $uncompressed;
361
- } else {
362
- echo $cache;
363
- }
364
- } else {
365
- echo( wp_cache_get_legacy_cache( $cache_file ) );
366
- }
367
- }
368
- wp_cache_debug( "exit request", 5 );
369
- die();
370
- }
371
- }
372
-
373
- function wp_cache_get_legacy_cache( $cache_file ) {
374
- return substr( @file_get_contents( $cache_file ), 15 );
375
  }
376
 
377
- if(defined('DOING_CRON')) {
378
  extract( wp_super_cache_init() ); // $key, $cache_filename, $meta_file, $cache_file, $meta_pathname
379
  return true;
380
  }
381
 
382
- if ( !isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && false == $wp_super_cache_late_init ) ) {
383
- wp_cache_serve_cache_file();
384
- }
385
-
386
- function wp_cache_postload() {
387
- global $cache_enabled, $wp_super_cache_late_init;
388
-
389
- if ( !$cache_enabled )
390
- return true;
391
-
392
- if ( isset( $wp_super_cache_late_init ) && true == $wp_super_cache_late_init ) {
393
- wp_cache_debug( "Supercache Late Init: add wp_cache_serve_cache_file to init", 3 );
394
- add_action( 'init', 'wp_cache_late_loader', 9999 );
395
- } else {
396
- wp_super_cache_init();
397
- wp_cache_phase2();
398
- }
399
- }
400
-
401
- function wp_cache_late_loader() {
402
- wp_cache_debug( "Supercache Late Loader running on init", 3 );
403
  wp_cache_serve_cache_file();
404
- wp_cache_phase2();
405
- }
406
-
407
- function wp_cache_get_cookies_values() {
408
- static $string = '';
409
-
410
- if ( $string != '' ) {
411
- wp_cache_debug( "wp_cache_get_cookies_values: cached: $string" );
412
- return $string;
413
- }
414
-
415
- if ( defined( 'COOKIEHASH' ) )
416
- $cookiehash = preg_quote( constant( 'COOKIEHASH' ) );
417
- else
418
- $cookiehash = '';
419
- $regex = "/^wp-postpass_$cookiehash|^comment_author_$cookiehash";
420
- if ( defined( 'LOGGED_IN_COOKIE' ) )
421
- $regex .= "|^" . preg_quote( constant( 'LOGGED_IN_COOKIE' ) );
422
- else
423
- $regex .= "|^wordpress_logged_in_$cookiehash";
424
- $regex .= "/";
425
- while ($key = key($_COOKIE)) {
426
- if ( preg_match( $regex, $key ) ) {
427
- wp_cache_debug( "wp_cache_get_cookies_values: $regex Cookie detected: $key", 5 );
428
- $string .= $_COOKIE[ $key ] . ",";
429
- }
430
- next($_COOKIE);
431
- }
432
- reset($_COOKIE);
433
-
434
- // If you use this hook, make sure you update your .htaccess rules with the same conditions
435
- $string = do_cacheaction( 'wp_cache_get_cookies_values', $string );
436
- if ( $string != '' )
437
- $string = md5( $string );
438
-
439
- wp_cache_debug( "wp_cache_get_cookies_values: return: $string", 5 );
440
- return $string;
441
- }
442
-
443
- function add_cacheaction( $action, $func ) {
444
- global $wp_supercache_actions;
445
- $wp_supercache_actions[ $action ][] = $func;
446
- }
447
-
448
- function do_cacheaction( $action, $value = '' ) {
449
- global $wp_supercache_actions;
450
-
451
- if ( !isset( $wp_supercache_actions ) || !is_array( $wp_supercache_actions ) )
452
- return $value;
453
-
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
-
461
- return $value;
462
- }
463
-
464
- function wp_cache_mobile_group( $user_agent ) {
465
- global $wp_cache_mobile_groups;
466
- foreach( (array)$wp_cache_mobile_groups as $name => $group ) {
467
- foreach( (array)$group as $browser ) {
468
- $browser = trim( strtolower( $browser ) );
469
- if ( $browser != '' && strstr( $user_agent, $browser ) ) {
470
- return $browser;
471
- }
472
- }
473
- }
474
- return "mobile";
475
- }
476
-
477
- // From http://wordpress.org/plugins/wordpress-mobile-edition/ by Alex King
478
- function wp_cache_check_mobile( $cache_key ) {
479
- global $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes;
480
- if ( !isset( $wp_cache_mobile_enabled ) || false == $wp_cache_mobile_enabled )
481
- return $cache_key;
482
-
483
- wp_cache_debug( "wp_cache_check_mobile: $cache_key" );
484
-
485
- // allow plugins to short circuit mobile check. Cookie, extra UA checks?
486
- switch( do_cacheaction( 'wp_cache_check_mobile', $cache_key ) ) {
487
- case "normal":
488
- wp_cache_debug( "wp_cache_check_mobile: desktop user agent detected by wp_cache_check_mobile action" );
489
- return $cache_key;
490
- break;
491
- case "mobile":
492
- wp_cache_debug( "wp_cache_check_mobile: mobile user agent detected by wp_cache_check_mobile action" );
493
- return $cache_key . "-mobile";
494
- break;
495
- }
496
-
497
- if ( !isset( $_SERVER[ "HTTP_USER_AGENT" ] ) ) {
498
- return $cache_key;
499
- }
500
-
501
- if ( do_cacheaction( 'disable_mobile_check', false ) ) {
502
- wp_cache_debug( "wp_cache_check_mobile: disable_mobile_check disabled mobile check" );
503
- return $cache_key;
504
- }
505
-
506
- $browsers = explode( ',', $wp_cache_mobile_browsers );
507
- $user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
508
- foreach ($browsers as $browser) {
509
- if ( strstr( $user_agent, trim( strtolower( $browser ) ) ) ) {
510
- wp_cache_debug( "mobile browser detected: " . $_SERVER[ "HTTP_USER_AGENT" ], 5 );
511
- return $cache_key . '-' . wp_cache_mobile_group( $user_agent );
512
- }
513
- }
514
- if (isset($_SERVER['HTTP_X_WAP_PROFILE']) )
515
- return $cache_key . '-' . $_SERVER['HTTP_X_WAP_PROFILE'];
516
- if (isset($_SERVER['HTTP_PROFILE']) )
517
- return $cache_key . '-' . $_SERVER['HTTP_PROFILE'];
518
-
519
- if ( isset( $wp_cache_mobile_prefixes ) ) {
520
- $browsers = explode( ',', $wp_cache_mobile_prefixes );
521
- foreach ($browsers as $browser_prefix) {
522
- if ( substr($user_agent, 0, 4) == $browser_prefix ) {
523
- wp_cache_debug( "mobile browser (prefix) detected: " . $_SERVER[ "HTTP_USER_AGENT" ], 5 );
524
- return $cache_key . '-' . $browser_prefix;
525
- }
526
- }
527
- }
528
- $accept = isset( $_SERVER[ 'HTTP_ACCEPT' ] ) ? strtolower( $_SERVER[ 'HTTP_ACCEPT' ] ) : '';
529
- if (strpos($accept, 'wap') !== false) {
530
- return $cache_key . '-' . 'wap';
531
- }
532
-
533
- if (isset($_SERVER['ALL_HTTP']) && strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false) {
534
- return $cache_key . '-' . 'operamini';
535
- }
536
-
537
- return $cache_key;
538
  }
539
-
540
- /**
541
- * Add a log message to the file, if debugging is turned on
542
- *
543
- * @param $message string The message that should be added to the log
544
- * @param $level int
545
- */
546
- function wp_cache_debug( $message, $level = 1 ) {
547
- global $wp_cache_debug_log, $cache_path, $wp_cache_debug_ip, $wp_super_cache_debug;
548
-
549
- // If either of the debug or log globals aren't set, then we can stop
550
- if ( !isset($wp_super_cache_debug)
551
- || !isset($wp_cache_debug_log) )
552
- return false;
553
-
554
- // If either the debug or log globals are false or empty, we can stop
555
- if ( $wp_super_cache_debug == false
556
- || $wp_cache_debug_log == '' )
557
- return false;
558
-
559
- // If the debug_ip has been set, but it doesn't match the ip of the requester
560
- // then we can stop.
561
- if ( isset($wp_cache_debug_ip)
562
- && $wp_cache_debug_ip != ''
563
- && $wp_cache_debug_ip != $_SERVER[ 'REMOTE_ADDR' ] )
564
- return false;
565
-
566
- // Log message: Date URI Message
567
- $log_message = date('H:i:s') . " " . getmypid() . " {$_SERVER['REQUEST_URI']} {$message}" . PHP_EOL;
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
-
583
- function wp_cache_user_agent_is_rejected() {
584
- global $cache_rejected_user_agent;
585
-
586
- if (!function_exists('apache_request_headers')) return false;
587
- $headers = apache_request_headers();
588
- if (!isset($headers["User-Agent"])) return false;
589
- if ( false == is_array( $cache_rejected_user_agent ) )
590
- return false;
591
- foreach ($cache_rejected_user_agent as $expr) {
592
- if (strlen($expr) > 0 && stristr($headers["User-Agent"], $expr))
593
- return true;
594
- }
595
- return false;
596
- }
597
-
598
- function get_supercache_dir( $blog_id = 0 ) {
599
- global $cache_path;
600
- if ( $blog_id == 0 ) {
601
- $home = get_option( 'home' );
602
- } else {
603
- $home = get_blog_option( $blog_id, 'home' );
604
- }
605
- return trailingslashit( apply_filters( 'wp_super_cache_supercachedir', $cache_path . 'supercache/' . trailingslashit( strtolower( preg_replace( '/:.*$/', '', str_replace( 'http://', '', str_replace( 'https://', '', $home ) ) ) ) ) ) );
606
- }
607
- function get_current_url_supercache_dir( $post_id = 0 ) {
608
- global $cached_direct_pages, $cache_path, $wp_cache_request_uri, $WPSC_HTTP_HOST, $wp_cache_home_path;
609
- static $saved_supercache_dir = array();
610
-
611
- if ( isset( $saved_supercache_dir[ $post_id ] ) ) {
612
- return $saved_supercache_dir[ $post_id ];
613
- }
614
-
615
- $DONOTREMEMBER = 0;
616
- if ( $post_id != 0 ) {
617
- $site_url = site_url();
618
- $permalink = get_permalink( $post_id );
619
- if ( false === strpos( $permalink, $site_url ) ) {
620
- /*
621
- * Sometimes site_url doesn't return the siteurl. See http://wordpress.org/support/topic/wp-super-cache-not-refreshing-post-after-comments-made
622
- */
623
- $DONOTREMEMBER = 1;
624
- wp_cache_debug( "get_current_url_supercache_dir: warning! site_url ($site_url) not found in permalink ($permalink).", 1 );
625
- if ( $WPSC_HTTP_HOST == '' || false === strpos( $permalink, $WPSC_HTTP_HOST ) ) {
626
- wp_cache_debug( "get_current_url_supercache_dir: WARNING! SERVER_NAME ({$WPSC_HTTP_HOST}) not found in permalink ($permalink). ", 1 );
627
- $p = parse_url( $permalink );
628
- if ( is_array( $p ) ) {
629
- $uri = $p[ 'path' ];
630
- wp_cache_debug( "get_current_url_supercache_dir: WARNING! Using $uri as permalink. Used parse_url.", 1 );
631
- } else {
632
- wp_cache_debug( "get_current_url_supercache_dir: WARNING! Permalink ($permalink) could not be understood by parse_url. Using front page.", 1 );
633
- $uri = '';
634
- }
635
- } else {
636
- wp_cache_debug( "get_current_url_supercache_dir: Removing SERVER_NAME ({$WPSC_HTTP_HOST}) from permalink ($permalink). Is the url right?", 1 );
637
- $uri = str_replace( $WPSC_HTTP_HOST, '', $permalink );
638
- $uri = str_replace( 'http://', '', $uri );
639
- $uri = str_replace( 'https://', '', $uri );
640
- }
641
- } else {
642
- $uri = str_replace( $site_url, '', $permalink );
643
- if ( strpos( $uri, $wp_cache_home_path ) !== 0 )
644
- $uri = rtrim( $wp_cache_home_path, '/' ) . $uri;
645
- }
646
- } else {
647
- $uri = strtolower( $wp_cache_request_uri );
648
- }
649
- $uri = wpsc_deep_replace( array( '..', '\\', 'index.php', ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace( "/(\?.*)?$/", '', $uri ) ) );
650
- $dir = preg_replace( '/:.*$/', '', $WPSC_HTTP_HOST ) . $uri; // To avoid XSS attacks
651
- if ( function_exists( "apply_filters" ) ) {
652
- $dir = apply_filters( 'supercache_dir', $dir );
653
- } else {
654
- $dir = do_cacheaction( 'supercache_dir', $dir );
655
- }
656
- $dir = $cache_path . 'supercache/' . $dir . '/';
657
- if( is_array( $cached_direct_pages ) && in_array( $_SERVER[ 'REQUEST_URI' ], $cached_direct_pages ) ) {
658
- $dir = ABSPATH . $uri . '/';
659
- }
660
- $dir = str_replace( '..', '', str_replace( '//', '/', $dir ) );
661
- wp_cache_debug( "supercache dir: $dir", 5 );
662
- if ( $DONOTREMEMBER == 0 )
663
- $saved_supercache_dir[ $post_id ] = $dir;
664
- return $dir;
665
- }
666
-
667
- /*
668
- * Delete (or rebuild) all the files in one directory.
669
- * Checks if it is in the cache directory but doesn't allow files in the following directories to be deleted:
670
- * wp-content/cache/
671
- * wp-content/cache/blogs/
672
- * wp-content/cache/supercache/
673
- *
674
- */
675
- function wpsc_rebuild_files( $dir ) {
676
- return wpsc_delete_files( $dir, false );
677
- }
678
-
679
- // realpath() doesn't always remove the trailing slash
680
- function wpsc_get_realpath( $directory ) {
681
- if ( $directory == '/' ) {
682
- return false;
683
- }
684
-
685
- $original_dir = $directory;
686
- $directory = realpath( $directory );
687
-
688
- if ( ! $directory ) {
689
- wp_cache_debug( "wpsc_get_realpath: directory does not exist - $original_dir" );
690
- return false;
691
- }
692
-
693
- if ( substr( $directory, -1 ) == '/' || substr( $directory, -1 ) == '\\' ) {
694
- $directory = substr( $directory, 0, -1 ); // remove trailing slash
695
- }
696
-
697
- return $directory;
698
- }
699
-
700
- // return true if directory is in the cache directory
701
- function wpsc_is_in_cache_directory( $directory ) {
702
- global $cache_path;
703
- static $rp_cache_path = '';
704
-
705
- if ( $directory == '' ) {
706
- wp_cache_debug( "wpsc_is_in_cache_directory: exiting as directory is blank" );
707
- return false;
708
- }
709
-
710
- if ( $cache_path == '' ) {
711
- wp_cache_debug( "wpsc_is_in_cache_directory: exiting as cache_path is blank" );
712
- return false;
713
- }
714
-
715
- if ( $rp_cache_path == '' ) {
716
- $rp_cache_path = wpsc_get_realpath( $cache_path );
717
- }
718
-
719
- if ( ! $rp_cache_path ) {
720
- wp_cache_debug( "wpsc_is_in_cache_directory: exiting as cache_path directory does not exist" );
721
- return false;
722
- }
723
-
724
- $directory = wpsc_get_realpath( $directory );
725
-
726
- if ( ! $directory ) {
727
- wp_cache_debug( "wpsc_is_in_cache_directory: directory does not exist" );
728
- return false;
729
- }
730
-
731
- if ( substr( $directory, 0, strlen( $rp_cache_path ) ) == $rp_cache_path ) {
732
- return true;
733
- } else {
734
- return false;
735
- }
736
- }
737
-
738
- function wpsc_delete_files( $dir, $delete = true ) {
739
- global $cache_path;
740
- static $protected = '';
741
-
742
- if ( $dir == '' ) {
743
- wp_cache_debug( "wpsc_delete_files: directory is blank" );
744
- return false;
745
- }
746
-
747
- // only do this once, this function will be called many times
748
- if ( $protected == '' ) {
749
- $protected = array( $cache_path, $cache_path . "blogs/", $cache_path . 'supercache' );
750
- foreach( $protected as $id => $directory ) {
751
- $protected[ $id ] = trailingslashit( wpsc_get_realpath( $directory ) );
752
- }
753
- }
754
-
755
- $dir = wpsc_get_realpath( $dir );
756
- if ( ! $dir ) {
757
- wp_cache_debug( "wpsc_delete_files: directory does not exist" );
758
- return false;
759
- }
760
-
761
- $dir = trailingslashit( $dir );
762
-
763
- if ( ! wpsc_is_in_cache_directory( $dir ) ) {
764
- return false;
765
- }
766
-
767
- if ( in_array( $dir, $protected ) )
768
- return false;
769
-
770
- if ( is_dir( $dir ) && $dh = @opendir( $dir ) ) {
771
- while ( ( $file = readdir( $dh ) ) !== false ) {
772
- if ( $file != '.' && $file != '..' && $file != '.htaccess' && is_file( $dir . $file ) )
773
- if ( $delete )
774
- @unlink( $dir . $file );
775
- else
776
- @wp_cache_rebuild_or_delete( $dir . $file );
777
- }
778
- closedir( $dh );
779
-
780
- if ( $delete )
781
- @rmdir( $dir );
782
- }
783
- return true;
784
- }
785
-
786
- function get_all_supercache_filenames( $dir = '' ) {
787
- global $wp_cache_mobile_enabled, $cache_path;
788
-
789
- $dir = wpsc_get_realpath( $dir );
790
- if ( ! $dir ) {
791
- wp_cache_debug( "get_all_supercache_filenames: directory does not exist" );
792
- return array();
793
- }
794
-
795
- if ( ! wpsc_is_in_cache_directory( $dir ) ) {
796
- return array();
797
- }
798
-
799
- $filenames = array( 'index.html', 'index-https.html', 'index.html.php' );
800
-
801
- if ( $dir != '' && isset( $wp_cache_mobile_enabled ) && $wp_cache_mobile_enabled ) {
802
- // open directory and look for index-*.html files
803
- if ( is_dir( $dir ) && $dh = @opendir( $dir ) ) {
804
- while ( ( $file = readdir( $dh ) ) !== false ) {
805
- if ( substr( $file, 0, 6 ) == 'index-' && strpos( $file, '.html' ) )
806
- $filenames[] = $file;
807
- }
808
- closedir( $dh );
809
- }
810
- }
811
-
812
- if ( function_exists( "apply_filters" ) ) {
813
- $filenames = apply_filters( 'all_supercache_filenames', $filenames );
814
- } else {
815
- $filenames = do_cacheaction( 'all_supercache_filenames', $filenames );
816
- }
817
-
818
- foreach( $filenames as $file ) {
819
- $out[] = $file;
820
- $out[] = $file . '.gz';
821
- }
822
-
823
- return $out;
824
- }
825
-
826
- function supercache_filename() {
827
- global $cached_direct_pages;
828
-
829
- //Add support for https and http caching
830
- $is_https = ( ( isset( $_SERVER[ 'HTTPS' ] ) && 'on' == strtolower( $_SERVER[ 'HTTPS' ] ) ) || ( isset( $_SERVER[ 'HTTP_X_FORWARDED_PROTO' ] ) && 'https' == strtolower( $_SERVER[ 'HTTP_X_FORWARDED_PROTO' ] ) ) ); //Also supports https requests coming from an nginx reverse proxy
831
- $extra_str = $is_https ? '-https' : '';
832
-
833
- if ( function_exists( "apply_filters" ) ) {
834
- $extra_str = apply_filters( 'supercache_filename_str', $extra_str );
835
- } else {
836
- $extra_str = do_cacheaction( 'supercache_filename_str', $extra_str );
837
- }
838
-
839
- if ( is_array( $cached_direct_pages ) && in_array( $_SERVER[ 'REQUEST_URI' ], $cached_direct_pages ) ) {
840
- $extra_str = '';
841
- }
842
- $filename = 'index' . $extra_str . '.html';
843
-
844
- return $filename;
845
- }
846
-
847
- function get_oc_version() {
848
- $wp_cache_oc_key = wp_cache_get( "wp_cache_oc_key" );
849
- if ( ! $wp_cache_oc_key ) {
850
- $wp_cache_oc_key[ 'key' ] = reset_oc_version();
851
- } elseif ( $wp_cache_oc_key[ 'ts' ] < time() - 600 )
852
- wp_cache_set( "wp_cache_oc_key", array( 'ts' => time(), 'key' => $wp_cache_oc_key[ 'key' ] ) );
853
- return $wp_cache_oc_key[ 'key' ];
854
- }
855
-
856
- function reset_oc_version( $version = 1 ) {
857
- if ( $version == 1 )
858
- $version = mt_rand();
859
- wp_cache_set( "wp_cache_oc_key", array( 'ts' => time(), 'key' => $version ) );
860
-
861
- return $version;
862
- }
863
-
864
- function get_oc_key( $url = false ) {
865
- global $wp_cache_gzip_encoding, $WPSC_HTTP_HOST;
866
-
867
- if ( $url ) {
868
- $key = intval( $_SERVER[ 'SERVER_PORT' ] ) . strtolower( preg_replace( '/:.*$/', '', $WPSC_HTTP_HOST ) ) . $url;
869
- } else {
870
- $key = get_current_url_supercache_dir();
871
- }
872
- return $key . $wp_cache_gzip_encoding . get_oc_version();
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 ) )
880
- return true;
881
-
882
- if ( $_SERVER[ "REQUEST_METHOD" ] != 'GET' || strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-json/' ) !== false )
883
- return true;
884
-
885
- $cookie_keys = array( 'wordpress_logged_in', 'comment_author_' );
886
- if ( defined( 'LOGGED_IN_COOKIE' ) )
887
- $cookie_keys[] = constant( 'LOGGED_IN_COOKIE' );
888
- reset( $_COOKIE );
889
- foreach( $_COOKIE as $cookie => $val ) {
890
- reset( $cookie_keys );
891
- foreach( $cookie_keys as $key ) {
892
- if ( strpos( $cookie, $key ) !== FALSE ) {
893
- wp_cache_debug( 'Removing auth from $_COOKIE to allow caching for logged in user (' . $cookie . ')', 5 );
894
- unset( $_COOKIE[ $cookie ] );
895
- }
896
- }
897
- }
898
- }
899
-
900
- /* returns true/false depending on location of $dir. */
901
- function wp_cache_confirm_delete( $dir ) {
902
- global $cache_path, $blog_cache_dir;
903
- // don't allow cache_path, blog cache dir, blog meta dir, supercache.
904
- $dir = wpsc_get_realpath( $dir );
905
-
906
- if ( ! $dir ) {
907
- wp_cache_debug( "wp_cache_confirm_delete: directory does not exist" );
908
- return false;
909
- }
910
-
911
- if ( ! wpsc_is_in_cache_directory( $dir ) ) {
912
- return false;
913
- }
914
-
915
- $rp_cache_path = wpsc_get_realpath( $cache_path );
916
-
917
- if ( ! $rp_cache_path ) {
918
- wp_cache_debug( "wp_cache_confirm_delete: cache_path does not exist: $cache_path" );
919
- return false;
920
- }
921
-
922
- if (
923
- $dir == '' ||
924
- $dir == $rp_cache_path ||
925
- $dir == wpsc_get_realpath( $blog_cache_dir ) ||
926
- $dir == wpsc_get_realpath( $blog_cache_dir . "meta/" ) ||
927
- $dir == wpsc_get_realpath( $cache_path . "supercache" )
928
- ) {
929
- return false;
930
- } else {
931
- return true;
932
- }
933
- }
934
-
935
- // copy of _deep_replace() to be used before WordPress loads
936
- function wpsc_deep_replace( $search, $subject ) {
937
- $subject = (string) $subject;
938
-
939
- $count = 1;
940
- while ( $count ) {
941
- $subject = str_replace( $search, '', $subject, $count );
942
- }
943
-
944
- return $subject;
945
- }
946
-
947
- function wpsc_get_protected_directories() {
948
- global $cache_path, $blog_cache_dir;
949
- return apply_filters( 'wpsc_protected_directories', array(
950
- $cache_path . '.htaccess',
951
- $cache_path . "index.html",
952
- $blog_cache_dir,
953
- $blog_cache_dir . "index.html",
954
- $blog_cache_dir . 'meta',
955
- $blog_cache_dir . 'meta/index.html',
956
- $cache_path . 'supercache/index.html',
957
- $cache_path . 'supercache' )
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
- ?>
1
  <?php
 
 
 
 
2
 
3
+ require_once dirname( __FILE__ ) . '/wp-cache-phase2.php';
4
+
5
+ // error_reporting(E_ERROR | E_PARSE); // uncomment to debug this file!
6
+ if ( ! @include WP_CONTENT_DIR . '/wp-cache-config.php' ) {
7
  return false;
8
+ }
9
 
10
+ if ( ! defined( 'WPCACHEHOME' ) ) {
11
+ define( 'WPCACHEHOME', dirname( __FILE__ ) . '/' );
12
+ }
13
 
14
  if ( defined( 'DISABLE_SUPERCACHE' ) ) {
15
  wp_cache_debug( 'DISABLE_SUPERCACHE set, super_cache disabled.' );
16
  $super_cache_enabled = 0;
17
  }
18
 
19
+ require WPCACHEHOME . 'wp-cache-base.php';
20
 
21
+ if ( $blogcacheid != '' ) {
22
+ $blog_cache_dir = str_replace( '//', '/', $cache_path . 'blogs/' . $blogcacheid . '/' );
23
  } else {
24
  $blog_cache_dir = $cache_path;
25
  }
26
 
27
  $wp_cache_phase1_loaded = true;
28
 
29
+ $mutex_filename = 'wp_cache_mutex.lock';
30
+ $new_cache = false;
31
 
32
+ if ( ! isset( $wp_cache_plugins_dir ) ) {
33
  $wp_cache_plugins_dir = WPCACHEHOME . 'plugins';
34
+ }
35
 
36
+ if ( isset( $_GET['donotcachepage'] ) && isset( $cache_page_secret ) && $_GET['donotcachepage'] == $cache_page_secret ) {
 
 
37
  $cache_enabled = false;
38
  define( 'DONOTCACHEPAGE', 1 );
39
  }
40
 
41
  $plugins = glob( $wp_cache_plugins_dir . '/*.php' );
42
+ if ( is_array( $plugins ) ) {
43
  foreach ( $plugins as $plugin ) {
44
+ if ( is_file( $plugin ) ) {
45
+ require_once $plugin;
46
+ }
47
  }
48
  }
49
 
54
  return true;
55
  }
56
 
57
+ if ( isset( $wp_cache_make_known_anon ) && $wp_cache_make_known_anon ) {
58
  wp_supercache_cache_for_admins();
59
+ }
60
 
61
  do_cacheaction( 'cache_init' );
62
 
63
 
64
+ if ( ! $cache_enabled || ( isset( $_SERVER['REQUEST_METHOD'] ) && in_array( $_SERVER['REQUEST_METHOD'], array( 'POST', 'PUT', 'DELETE' ) ) ) || isset( $_GET['customize_changeset_uuid'] ) ) {
65
  return true;
66
  }
67
 
68
+ $file_expired = false;
69
+ $cache_filename = '';
70
+ $meta_file = '';
71
  $wp_cache_gzip_encoding = '';
72
 
73
  $gzipped = 0;
74
+ $gzsize = 0;
75
 
76
+ if ( $cache_compression ) {
 
 
 
 
 
 
 
 
77
  $wp_cache_gzip_encoding = gzip_accepted();
78
  }
79
 
82
  add_filter( 'supercache_filename_str', 'wp_cache_check_mobile' );
83
  }
84
 
85
+ $wp_cache_request_uri = $_SERVER['REQUEST_URI']; // Cache this in case any plugin modifies it.
86
 
87
  if ( $wp_cache_object_cache ) {
88
+ if ( ! include_once WP_CONTENT_DIR . '/object-cache.php' ) {
89
  return;
90
+ }
91
 
92
  wp_cache_init(); // Note: wp-settings.php calls wp_cache_init() which clobbers the object made here.
93
 
94
+ if ( ! is_object( $wp_object_cache ) ) {
95
  return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
98
 
99
+ if ( defined( 'DOING_CRON' ) ) {
100
  extract( wp_super_cache_init() ); // $key, $cache_filename, $meta_file, $cache_file, $meta_pathname
101
  return true;
102
  }
103
 
104
+ if ( ! isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && false == $wp_super_cache_late_init ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  wp_cache_serve_cache_file();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
wp-cache-phase2.php CHANGED
@@ -1,5 +1,1107 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  function wp_cache_phase2() {
4
  global $wp_cache_gzip_encoding, $super_cache_enabled, $cache_rebuild_files, $cache_enabled, $wp_cache_gmt_offset, $wp_cache_blog_charset;
5
 
@@ -10,7 +1112,7 @@ function wp_cache_phase2() {
10
 
11
  wp_cache_debug( 'In WP Cache Phase 2', 5 );
12
 
13
- $wp_cache_gmt_offset = get_option( 'gmt_offset' ); // caching for later use when wpdb is gone. http://wordpress.org/support/topic/224349
14
  $wp_cache_blog_charset = get_option( 'blog_charset' );
15
 
16
  wp_cache_mutex_init();
@@ -46,13 +1148,13 @@ function wp_cache_phase2() {
46
  do_cacheaction( 'add_cacheaction' );
47
  }
48
 
49
- if ( is_admin() ) {
50
  wp_cache_debug( 'Not caching wp-admin requests.', 5 );
51
  return false;
52
  }
53
 
54
- if ( !empty( $_GET ) && !defined( "DOING_CRON" ) ) {
55
- wp_cache_debug( 'Supercache caching disabled. Only using wp-cache. Non empty GET request. ' . json_encode( $_GET ), 5 );
56
  $super_cache_enabled = false;
57
  }
58
 
@@ -169,21 +1271,19 @@ function wpcache_logged_in_message() {
169
  echo '<!-- WP Super Cache did not cache this page because you are logged in and "Don\'t cache pages for logged in users" is enabled. -->';
170
  }
171
 
172
- if ( !function_exists( 'wp_cache_user_agent_is_rejected' ) ) {
173
- function wp_cache_user_agent_is_rejected() {
174
- global $cache_rejected_user_agent;
175
 
176
- if (!function_exists('apache_request_headers')) return false;
177
- $headers = apache_request_headers();
178
- if (!isset($headers["User-Agent"])) return false;
179
- if ( false == is_array( $cache_rejected_user_agent ) )
180
- return false;
181
- foreach ($cache_rejected_user_agent as $expr) {
182
- if (strlen($expr) > 0 && stristr($headers["User-Agent"], $expr))
183
- return true;
184
- }
185
  return false;
 
 
 
186
  }
 
187
  }
188
 
189
  function wp_cache_get_response_headers() {
@@ -460,8 +1560,8 @@ function wp_cache_ob_callback( $buffer ) {
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' ) ) {
467
  wp_cache_debug( 'Not caching POST request.', 5 );
@@ -607,6 +1707,7 @@ function wp_cache_add_to_buffer( &$buffer, $text ) {
607
  $buffer .= "\n<!-- $text -->";
608
  }
609
 
 
610
  /*
611
  * If dynamic caching is enabled then run buffer through wpsc_cachedata filter before returning it.
612
  * or we'll return template tags to visitors.
@@ -821,8 +1922,9 @@ function wp_cache_get_ob(&$buffer) {
821
  wp_cache_set( $oc_key, $buffer, 'supercache', $cache_max_time );
822
  }
823
  $wp_cache_meta[ 'dynamic' ] = true;
824
- if ( do_cacheaction( 'wpsc_cachedata_safety', 0 ) === 1 )
825
  $buffer = do_cacheaction( 'wpsc_cachedata', $buffer ); // dynamic content for display
 
826
 
827
  if ( $cache_compression && $wp_cache_gzip_encoding ) {
828
  wp_cache_debug( "Gzipping dynamic buffer for display.", 5 );
@@ -1617,19 +2719,17 @@ function wp_cache_post_change( $post_id ) {
1617
  wp_cache_debug( "Post change: supercache enabled: deleting cache files in " . $dir );
1618
  wpsc_rebuild_files( $dir );
1619
  do_action( 'gc_cache', 'prune', 'homepage' );
 
 
 
 
 
 
 
 
1620
  } else {
1621
  wp_cache_debug( "wp_cache_post_change: not deleting all pages.", 4 );
1622
  }
1623
- if( $all == true && get_option( 'show_on_front' ) == 'page' ) {
1624
- wp_cache_debug( "Post change: deleting page_on_front and page_for_posts pages.", 4 );
1625
- wp_cache_debug( "Post change: page_on_front " . get_option( 'page_on_front' ), 4 );
1626
- $permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( get_option( 'page_for_posts' ) ) ) );
1627
- wp_cache_debug( "Post change: Deleting files in: " . str_replace( '//', '/', $dir . $permalink ) );
1628
- wpsc_rebuild_files( $dir . $permalink );
1629
- do_action( 'gc_cache', 'prune', $permalink );
1630
- } else {
1631
- wp_cache_debug( "wp_cache_post_change: not deleting front static page.", 4 );
1632
- }
1633
 
1634
  wp_cache_debug( "wp_cache_post_change: checking {$blog_cache_dir}meta/", 4 );
1635
  $supercache_files_deleted = false;
1
  <?php
2
 
3
+ function gzip_accepted(){
4
+ if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) // don't compress WP-Cache data files when PHP is already doing it
5
+ return false;
6
+
7
+ if ( !isset( $_SERVER[ 'HTTP_ACCEPT_ENCODING' ] ) || ( isset( $_SERVER[ 'HTTP_ACCEPT_ENCODING' ] ) && strpos( $_SERVER[ 'HTTP_ACCEPT_ENCODING' ], 'gzip' ) === false ) ) return false;
8
+ return 'gzip';
9
+ }
10
+
11
+ function setup_blog_cache_dir() {
12
+ global $blog_cache_dir, $cache_path;
13
+ if( false == @is_dir( $blog_cache_dir ) ) {
14
+ @mkdir( $cache_path . "blogs" );
15
+ @mkdir( $blog_cache_dir );
16
+ }
17
+
18
+ if( false == @is_dir( $blog_cache_dir . 'meta' ) )
19
+ @mkdir( $blog_cache_dir . 'meta' );
20
+ }
21
+
22
+ function get_wp_cache_key( $url = false ) {
23
+ global $wp_cache_request_uri, $wp_cache_gzip_encoding, $WPSC_HTTP_HOST;
24
+ if ( ! $url ) {
25
+ $url = $wp_cache_request_uri;
26
+ }
27
+ $server_port = isset( $_SERVER[ 'SERVER_PORT' ] ) ? intval( $_SERVER[ 'SERVER_PORT' ] ) : 0;
28
+ return do_cacheaction( 'wp_cache_key', wp_cache_check_mobile( $WPSC_HTTP_HOST . $server_port . preg_replace('/#.*$/', '', str_replace( '/index.php', '/', $url ) ) . $wp_cache_gzip_encoding . wp_cache_get_cookies_values() ) );
29
+ }
30
+
31
+ function wp_super_cache_init() {
32
+ global $wp_cache_key, $key, $blogcacheid, $file_prefix, $blog_cache_dir, $meta_file, $cache_file, $cache_filename, $meta_pathname;
33
+
34
+ $wp_cache_key = get_wp_cache_key();
35
+ $key = $blogcacheid . md5( $wp_cache_key );
36
+ $wp_cache_key = $blogcacheid . $wp_cache_key;
37
+
38
+ $cache_filename = $file_prefix . $key . '.php';
39
+ $meta_file = $file_prefix . $key . '.php';
40
+ $cache_file = wpsc_get_realpath( $blog_cache_dir ) . '/' . $cache_filename;
41
+ $meta_pathname = wpsc_get_realpath( $blog_cache_dir . 'meta/' ) . '/' . $meta_file;
42
+ return compact( 'key', 'cache_filename', 'meta_file', 'cache_file', 'meta_pathname' );
43
+ }
44
+
45
+ function wp_cache_serve_cache_file() {
46
+ global $key, $blogcacheid, $wp_cache_request_uri, $file_prefix, $blog_cache_dir, $meta_file, $cache_file, $cache_filename, $meta_pathname, $wp_cache_gzip_encoding, $meta;
47
+ global $wp_cache_object_cache, $cache_compression, $wp_cache_slash_check, $wp_supercache_304, $wp_cache_home_path, $wp_cache_no_cache_for_get;
48
+ global $wp_cache_disable_utf8, $wp_cache_mfunc_enabled, $wpsc_served_header;
49
+
50
+ if ( wpsc_is_backend() ) {
51
+ wp_cache_debug( 'Not serving wp-admin requests.', 5 );
52
+ return false;
53
+ }
54
+
55
+ if ( wp_cache_user_agent_is_rejected() ) {
56
+ wp_cache_debug( "No wp-cache file served as user agent rejected.", 5 );
57
+ return false;
58
+ }
59
+
60
+ if ( $wp_cache_no_cache_for_get && false == empty( $_GET ) ) {
61
+ wp_cache_debug( "Non empty GET request. Caching disabled on settings page. " . wpsc_dump_get_request(), 1 );
62
+ return false;
63
+ }
64
+
65
+ extract( wp_super_cache_init() ); // $key, $cache_filename, $meta_file, $cache_file, $meta_pathname
66
+
67
+ if ( $wp_cache_object_cache && wp_cache_get_cookies_values() == '' ) {
68
+ if ( !empty( $_GET ) ) {
69
+ wp_cache_debug( "Non empty GET request. Not serving request from object cache. " . wpsc_dump_get_request(), 1 );
70
+ return false;
71
+ }
72
+
73
+ $oc_key = get_oc_key();
74
+ $meta_filename = $oc_key . ".meta";
75
+ if ( gzip_accepted() ) {
76
+ $oc_key .= ".gz";
77
+ $meta_filename .= ".gz";
78
+ }
79
+ $cache = wp_cache_get( $oc_key, 'supercache' );
80
+ $meta = json_decode( wp_cache_get( $meta_filename, 'supercache' ), true );
81
+ if ( is_array( $meta ) == false ) {
82
+ wp_cache_debug( "Meta array from object cache corrupt. Ignoring cache.", 1 );
83
+ return true;
84
+ }
85
+ } elseif ( ( $cache_file && file_exists( $cache_file ) ) || file_exists( get_current_url_supercache_dir() . 'meta-' . $cache_filename ) ) {
86
+ if ( file_exists( get_current_url_supercache_dir() . 'meta-' . $cache_filename ) ) {
87
+ $cache_file = get_current_url_supercache_dir() . $cache_filename;
88
+ $meta_pathname = get_current_url_supercache_dir() . 'meta-' . $cache_filename;
89
+ } elseif ( !file_exists( $cache_file ) ) {
90
+ wp_cache_debug( "wp_cache_serve_cache_file: found cache file but then it disappeared!" );
91
+ return false;
92
+ }
93
+
94
+ wp_cache_debug( "wp-cache file exists: $cache_file", 5 );
95
+ if ( !( $meta = json_decode( wp_cache_get_legacy_cache( $meta_pathname ), true ) ) ) {
96
+ wp_cache_debug( "couldn't load wp-cache meta file", 5 );
97
+ return true;
98
+ }
99
+ if ( is_array( $meta ) == false ) {
100
+ wp_cache_debug( "meta array corrupt, deleting $meta_pathname and $cache_file", 1 );
101
+ @unlink( $meta_pathname );
102
+ @unlink( $cache_file );
103
+ return true;
104
+ }
105
+ } else { // no $cache_file
106
+ global $wpsc_save_headers;
107
+ // last chance, check if a supercache file exists. Just in case .htaccess rules don't work on this host
108
+ $filename = supercache_filename();
109
+ $file = get_current_url_supercache_dir() . $filename;
110
+ if ( false == file_exists( $file ) ) {
111
+ wp_cache_debug( "No Super Cache file found for current URL: $file" );
112
+ return false;
113
+ } elseif ( false == empty( $_GET ) ) {
114
+ wp_cache_debug( "GET array not empty. Cannot serve a supercache file. " . wpsc_dump_get_request() );
115
+ return false;
116
+ } elseif ( wp_cache_get_cookies_values() != '' ) {
117
+ wp_cache_debug( "Cookies found. Cannot serve a supercache file. " . wp_cache_get_cookies_values() );
118
+ return false;
119
+ } elseif ( isset( $wpsc_save_headers ) && $wpsc_save_headers ) {
120
+ wp_cache_debug( "Saving headers. Cannot serve a supercache file." );
121
+ return false;
122
+ }
123
+
124
+ if ( isset( $wp_cache_mfunc_enabled ) == false )
125
+ $wp_cache_mfunc_enabled = 0;
126
+
127
+ if ( false == isset( $wp_cache_home_path ) )
128
+ $wp_cache_home_path = '/';
129
+
130
+ // make sure ending slashes are ok
131
+ if ( $wp_cache_request_uri == $wp_cache_home_path || ( $wp_cache_slash_check && substr( $wp_cache_request_uri, -1 ) == '/' ) || ( $wp_cache_slash_check == 0 && substr( $wp_cache_request_uri, -1 ) != '/' ) ) {
132
+
133
+ if ( $wp_cache_mfunc_enabled == 0 ) {
134
+ // get data from file
135
+ if ( $wp_cache_gzip_encoding ) {
136
+ if ( file_exists( $file . '.gz' ) ) {
137
+ $cachefiledata = file_get_contents( $file . '.gz' );
138
+ wp_cache_debug( "Fetched gzip static page data from supercache file using PHP. File: $file.gz" );
139
+ } else {
140
+ $cachefiledata = gzencode( file_get_contents( $file ), 6, FORCE_GZIP );
141
+ wp_cache_debug( "Fetched static page data from supercache file using PHP and gzipped it. File: $file" );
142
+ }
143
+ } else {
144
+ $cachefiledata = file_get_contents( $file );
145
+ wp_cache_debug( "Fetched static page data from supercache file using PHP. File: $file" );
146
+ }
147
+ } else {
148
+ // get dynamic data from filtered file
149
+ $cachefiledata = do_cacheaction( 'wpsc_cachedata', file_get_contents( $file ) );
150
+ if ( $wp_cache_gzip_encoding ) {
151
+ $cachefiledata = gzencode( $cachefiledata, 6, FORCE_GZIP );
152
+ wp_cache_debug( "Fetched dynamic page data from supercache file using PHP and gzipped it. File: $file" );
153
+ } else {
154
+ wp_cache_debug( "Fetched dynamic page data from supercache file using PHP. File: $file" );
155
+ }
156
+ }
157
+
158
+ if ( isset( $wp_cache_disable_utf8 ) == false || $wp_cache_disable_utf8 == 0 )
159
+ header( "Content-type: text/html; charset=UTF-8" );
160
+
161
+ header( "Vary: Accept-Encoding, Cookie" );
162
+ header( "Cache-Control: max-age=3, must-revalidate" );
163
+ $size = function_exists( 'mb_strlen' ) ? mb_strlen( $cachefiledata, '8bit' ) : strlen( $cachefiledata );
164
+ if ( $wp_cache_gzip_encoding ) {
165
+ if ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
166
+ header( "X-WP-Super-Cache: Served supercache gzip file from PHP" );
167
+ }
168
+ header( 'Content-Encoding: ' . $wp_cache_gzip_encoding );
169
+ header( 'Content-Length: ' . $size );
170
+ } elseif ( $wp_supercache_304 ) {
171
+ if ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
172
+ header( "X-WP-Super-Cache: Served supercache 304 file from PHP" );
173
+ }
174
+ header( 'Content-Length: ' . $size );
175
+ } else {
176
+ if ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
177
+ header( "X-WP-Super-Cache: Served supercache file from PHP" );
178
+ }
179
+ }
180
+
181
+ // don't try to match modified dates if using dynamic code.
182
+ if ( $wp_cache_mfunc_enabled == 0 && $wp_supercache_304 ) {
183
+ if ( function_exists( 'apache_request_headers' ) ) {
184
+ $request = apache_request_headers();
185
+ $remote_mod_time = ( isset ( $request[ 'If-Modified-Since' ] ) ) ? $request[ 'If-Modified-Since' ] : null;
186
+ } else {
187
+ if ( isset( $_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ] ) )
188
+ $remote_mod_time = $_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ];
189
+ else
190
+ $remote_mod_time = null;
191
+ }
192
+ $local_mod_time = gmdate("D, d M Y H:i:s",filemtime( $file )).' GMT';
193
+ if ( !is_null($remote_mod_time) && $remote_mod_time == $local_mod_time ) {
194
+ header( $_SERVER[ 'SERVER_PROTOCOL' ] . " 304 Not Modified" );
195
+ exit();
196
+ }
197
+ header( 'Last-Modified: ' . $local_mod_time );
198
+ }
199
+ echo $cachefiledata;
200
+ exit();
201
+ } else {
202
+ wp_cache_debug( "No wp-cache file exists. Must generate a new one." );
203
+ return false;
204
+ }
205
+ }
206
+
207
+ $cache_file = do_cacheaction( 'wp_cache_served_cache_file', $cache_file );
208
+ // Sometimes the gzip headers are lost. Make sure html returned isn't compressed!
209
+ if ( $cache_compression && $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $meta[ 'headers' ] ) ) {
210
+ $ungzip = true;
211
+ wp_cache_debug( "GZIP headers not found. Force uncompressed output.", 1 );
212
+ } else {
213
+ $ungzip = false;
214
+ }
215
+ foreach ($meta[ 'headers' ] as $t => $header) {
216
+ // godaddy fix, via http://blog.gneu.org/2008/05/wp-supercache-on-godaddy/ and http://www.littleredrails.com/blog/2007/09/08/using-wp-cache-on-godaddy-500-error/
217
+ if( strpos( $header, 'Last-Modified:' ) === false )
218
+ header($header);
219
+ }
220
+ if ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
221
+ header( 'X-WP-Super-Cache: Served WPCache cache file' );
222
+ }
223
+ if ( $wp_cache_object_cache ) {
224
+ if ( $cache ) {
225
+ if ( $ungzip ) {
226
+ // attempt to uncompress the cached file just in case it's gzipped
227
+ $uncompressed = gzuncompress( $cache );
228
+ if ( $uncompressed ) {
229
+ wp_cache_debug( "Uncompressed gzipped cache file from object cache", 1 );
230
+ $cache = $uncompressed;
231
+ unset( $uncompressed );
232
+ }
233
+ }
234
+ if ( isset( $meta[ 'dynamic' ] ) && $meta[ 'dynamic' ] ) {
235
+ wp_cache_debug( "Serving wp-cache dynamic file from object cache", 5 );
236
+ echo do_cacheaction( 'wpsc_cachedata', $cache );
237
+ } else {
238
+ wp_cache_debug( "Serving wp-cache static file from object cache", 5 );
239
+ echo $cache;
240
+ }
241
+ wp_cache_debug( "exit request", 5 );
242
+ die();
243
+ }
244
+ } else {
245
+ if ( isset( $meta[ 'dynamic' ] ) ) {
246
+ wp_cache_debug( "Serving wp-cache dynamic file", 5 );
247
+ if ( $ungzip ) {
248
+ // attempt to uncompress the cached file just in case it's gzipped
249
+ $cache = wp_cache_get_legacy_cache( $cache_file );
250
+ $uncompressed = @gzuncompress( $cache );
251
+ if ( $uncompressed ) {
252
+ wp_cache_debug( "Uncompressed gzipped cache file from wp-cache", 1 );
253
+ unset( $cache );
254
+ echo do_cacheaction( 'wpsc_cachedata', $uncompressed );
255
+ } else {
256
+ echo do_cacheaction( 'wpsc_cachedata', $cache );
257
+ }
258
+ } else {
259
+ echo do_cacheaction( 'wpsc_cachedata', wp_cache_get_legacy_cache( $cache_file ) );
260
+ }
261
+ } else {
262
+ wp_cache_debug( "Serving wp-cache static file", 5 );
263
+ if ( $ungzip ) {
264
+ $cache = wp_cache_get_legacy_cache( $cache_file );
265
+ $uncompressed = gzuncompress( $cache );
266
+ if ( $uncompressed ) {
267
+ wp_cache_debug( "Uncompressed gzipped cache file from wp-cache", 1 );
268
+ echo $uncompressed;
269
+ } else {
270
+ echo $cache;
271
+ }
272
+ } else {
273
+ echo( wp_cache_get_legacy_cache( $cache_file ) );
274
+ }
275
+ }
276
+ wp_cache_debug( "exit request", 5 );
277
+ die();
278
+ }
279
+ }
280
+
281
+ function wp_cache_get_legacy_cache( $cache_file ) {
282
+ return substr( @file_get_contents( $cache_file ), 15 );
283
+ }
284
+
285
+ function wp_cache_postload() {
286
+ global $cache_enabled, $wp_super_cache_late_init;
287
+
288
+ if ( !$cache_enabled )
289
+ return true;
290
+
291
+ if ( isset( $wp_super_cache_late_init ) && true == $wp_super_cache_late_init ) {
292
+ wp_cache_debug( "Supercache Late Init: add wp_cache_serve_cache_file to init", 3 );
293
+ add_action( 'init', 'wp_cache_late_loader', 9999 );
294
+ } else {
295
+ wp_super_cache_init();
296
+ wp_cache_phase2();
297
+ }
298
+ }
299
+
300
+ function wp_cache_late_loader() {
301
+ wp_cache_debug( "Supercache Late Loader running on init", 3 );
302
+ wp_cache_serve_cache_file();
303
+ wp_cache_phase2();
304
+ }
305
+
306
+ function wp_cache_get_cookies_values() {
307
+ static $string = '';
308
+
309
+ if ( $string != '' ) {
310
+ wp_cache_debug( "wp_cache_get_cookies_values: cached: $string" );
311
+ return $string;
312
+ }
313
+
314
+ if ( defined( 'COOKIEHASH' ) )
315
+ $cookiehash = preg_quote( constant( 'COOKIEHASH' ) );
316
+ else
317
+ $cookiehash = '';
318
+ $regex = "/^wp-postpass_$cookiehash|^comment_author_$cookiehash";
319
+ if ( defined( 'LOGGED_IN_COOKIE' ) )
320
+ $regex .= "|^" . preg_quote( constant( 'LOGGED_IN_COOKIE' ) );
321
+ else
322
+ $regex .= "|^wordpress_logged_in_$cookiehash";
323
+ $regex .= "/";
324
+ while ($key = key($_COOKIE)) {
325
+ if ( preg_match( $regex, $key ) ) {
326
+ wp_cache_debug( "wp_cache_get_cookies_values: $regex Cookie detected: $key", 5 );
327
+ $string .= $_COOKIE[ $key ] . ",";
328
+ }
329
+ next($_COOKIE);
330
+ }
331
+ reset($_COOKIE);
332
+
333
+ // If you use this hook, make sure you update your .htaccess rules with the same conditions
334
+ $string = do_cacheaction( 'wp_cache_get_cookies_values', $string );
335
+ if ( $string != '' )
336
+ $string = md5( $string );
337
+
338
+ wp_cache_debug( "wp_cache_get_cookies_values: return: $string", 5 );
339
+ return $string;
340
+ }
341
+
342
+ function add_cacheaction( $action, $func ) {
343
+ global $wp_supercache_actions;
344
+ $wp_supercache_actions[ $action ][] = $func;
345
+ }
346
+
347
+ function do_cacheaction( $action, $value = '' ) {
348
+ global $wp_supercache_actions;
349
+
350
+ if ( !isset( $wp_supercache_actions ) || !is_array( $wp_supercache_actions ) )
351
+ return $value;
352
+
353
+ if( array_key_exists($action, $wp_supercache_actions) && is_array( $wp_supercache_actions[ $action ] ) ) {
354
+ $actions = $wp_supercache_actions[ $action ];
355
+ foreach( $actions as $func ) {
356
+ $value = call_user_func_array( $func, array( $value ) );
357
+ }
358
+ }
359
+
360
+ return $value;
361
+ }
362
+
363
+ function wp_cache_mobile_group( $user_agent ) {
364
+ global $wp_cache_mobile_groups;
365
+ foreach( (array)$wp_cache_mobile_groups as $name => $group ) {
366
+ foreach( (array)$group as $browser ) {
367
+ $browser = trim( strtolower( $browser ) );
368
+ if ( $browser != '' && strstr( $user_agent, $browser ) ) {
369
+ return $browser;
370
+ }
371
+ }
372
+ }
373
+ return "mobile";
374
+ }
375
+
376
+ // From https://wordpress.org/plugins/wordpress-mobile-edition/ by Alex King
377
+ function wp_cache_check_mobile( $cache_key ) {
378
+ global $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes;
379
+ if ( !isset( $wp_cache_mobile_enabled ) || false == $wp_cache_mobile_enabled )
380
+ return $cache_key;
381
+
382
+ wp_cache_debug( "wp_cache_check_mobile: $cache_key" );
383
+
384
+ // allow plugins to short circuit mobile check. Cookie, extra UA checks?
385
+ switch( do_cacheaction( 'wp_cache_check_mobile', $cache_key ) ) {
386
+ case "normal":
387
+ wp_cache_debug( "wp_cache_check_mobile: desktop user agent detected by wp_cache_check_mobile action" );
388
+ return $cache_key;
389
+ break;
390
+ case "mobile":
391
+ wp_cache_debug( "wp_cache_check_mobile: mobile user agent detected by wp_cache_check_mobile action" );
392
+ return $cache_key . "-mobile";
393
+ break;
394
+ }
395
+
396
+ if ( !isset( $_SERVER[ "HTTP_USER_AGENT" ] ) ) {
397
+ return $cache_key;
398
+ }
399
+
400
+ if ( do_cacheaction( 'disable_mobile_check', false ) ) {
401
+ wp_cache_debug( "wp_cache_check_mobile: disable_mobile_check disabled mobile check" );
402
+ return $cache_key;
403
+ }
404
+
405
+ $browsers = explode( ',', $wp_cache_mobile_browsers );
406
+ $user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
407
+ foreach ($browsers as $browser) {
408
+ if ( strstr( $user_agent, trim( strtolower( $browser ) ) ) ) {
409
+ wp_cache_debug( "mobile browser detected: " . $_SERVER[ "HTTP_USER_AGENT" ], 5 );
410
+ return $cache_key . '-' . wp_cache_mobile_group( $user_agent );
411
+ }
412
+ }
413
+ if (isset($_SERVER['HTTP_X_WAP_PROFILE']) )
414
+ return $cache_key . '-' . $_SERVER['HTTP_X_WAP_PROFILE'];
415
+ if (isset($_SERVER['HTTP_PROFILE']) )
416
+ return $cache_key . '-' . $_SERVER['HTTP_PROFILE'];
417
+
418
+ if ( isset( $wp_cache_mobile_prefixes ) ) {
419
+ $browsers = explode( ',', $wp_cache_mobile_prefixes );
420
+ foreach ($browsers as $browser_prefix) {
421
+ if ( substr($user_agent, 0, 4) == $browser_prefix ) {
422
+ wp_cache_debug( "mobile browser (prefix) detected: " . $_SERVER[ "HTTP_USER_AGENT" ], 5 );
423
+ return $cache_key . '-' . $browser_prefix;
424
+ }
425
+ }
426
+ }
427
+ $accept = isset( $_SERVER[ 'HTTP_ACCEPT' ] ) ? strtolower( $_SERVER[ 'HTTP_ACCEPT' ] ) : '';
428
+ if (strpos($accept, 'wap') !== false) {
429
+ return $cache_key . '-' . 'wap';
430
+ }
431
+
432
+ if (isset($_SERVER['ALL_HTTP']) && strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false) {
433
+ return $cache_key . '-' . 'operamini';
434
+ }
435
+
436
+ return $cache_key;
437
+ }
438
+
439
+ /**
440
+ * Add a log message to the file, if debugging is turned on
441
+ *
442
+ * @param $message string The message that should be added to the log
443
+ * @param $level int
444
+ */
445
+ function wp_cache_debug( $message, $level = 1 ) {
446
+ global $wp_cache_debug_log, $cache_path, $wp_cache_debug_ip, $wp_super_cache_debug;
447
+
448
+ // If either of the debug or log globals aren't set, then we can stop
449
+ if ( !isset($wp_super_cache_debug)
450
+ || !isset($wp_cache_debug_log) )
451
+ return false;
452
+
453
+ // If either the debug or log globals are false or empty, we can stop
454
+ if ( $wp_super_cache_debug == false
455
+ || $wp_cache_debug_log == '' )
456
+ return false;
457
+
458
+ // If the debug_ip has been set, but it doesn't match the ip of the requester
459
+ // then we can stop.
460
+ if ( isset($wp_cache_debug_ip)
461
+ && $wp_cache_debug_ip != ''
462
+ && $wp_cache_debug_ip != $_SERVER[ 'REMOTE_ADDR' ] )
463
+ return false;
464
+
465
+ // Log message: Date URI Message
466
+ $log_message = date('H:i:s') . " " . getmypid() . " {$_SERVER['REQUEST_URI']} {$message}" . PHP_EOL;
467
+ // path to the log file in the cache folder
468
+ $log_file = $cache_path . str_replace('/', '', str_replace('..', '', $wp_cache_debug_log));
469
+
470
+ if ( ! file_exists( $log_file ) && function_exists( 'wpsc_create_debug_log' ) ) {
471
+ global $wp_cache_debug_username;
472
+ if ( ! isset( $wp_cache_debug_username ) ) {
473
+ $wp_cache_debug_username = '';
474
+ }
475
+
476
+ wpsc_create_debug_log( $wp_cache_debug_log, $wp_cache_debug_username );
477
+ }
478
+
479
+ error_log( $log_message, 3, $log_file );
480
+ }
481
+
482
+ function wpsc_dump_get_request() {
483
+ static $string;
484
+
485
+ if ( isset( $string) ) {
486
+ return $string;
487
+ }
488
+
489
+ if ( function_exists( 'wp_json_encode' ) ) {
490
+ $string = wp_json_encode( $_GET );
491
+ } else {
492
+ $string = json_encode( $_GET );
493
+ }
494
+
495
+ return $string;
496
+ }
497
+
498
+ function wpsc_is_backend() {
499
+ static $is_backend;
500
+
501
+ if ( isset( $is_backend ) ) {
502
+ return $is_backend;
503
+ }
504
+
505
+ $is_backend = is_admin();
506
+ if ( $is_backend ) {
507
+ return $is_backend;
508
+ }
509
+
510
+ $script = isset( $_SERVER['PHP_SELF'] ) ? basename( $_SERVER['PHP_SELF'] ) : '';
511
+ if ( $script !== 'index.php' ) {
512
+ if ( in_array( $script, array( 'wp-login.php', 'xmlrpc.php', 'wp-cron.php' ) ) ) {
513
+ $is_backend = true;
514
+ } elseif ( defined( 'DOING_CRON' ) && DOING_CRON ) {
515
+ $is_backend = true;
516
+ } elseif ( PHP_SAPI == 'cli' || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
517
+ $is_backend = true;
518
+ }
519
+ }
520
+
521
+ return $is_backend;
522
+ }
523
+
524
+ function get_supercache_dir( $blog_id = 0 ) {
525
+ global $cache_path;
526
+ if ( $blog_id == 0 ) {
527
+ $home = get_option( 'home' );
528
+ } else {
529
+ $home = get_blog_option( $blog_id, 'home' );
530
+ }
531
+ return trailingslashit( apply_filters( 'wp_super_cache_supercachedir', $cache_path . 'supercache/' . trailingslashit( strtolower( preg_replace( '/:.*$/', '', str_replace( 'http://', '', str_replace( 'https://', '', $home ) ) ) ) ) ) );
532
+ }
533
+ function get_current_url_supercache_dir( $post_id = 0 ) {
534
+ global $cached_direct_pages, $cache_path, $wp_cache_request_uri, $WPSC_HTTP_HOST, $wp_cache_home_path;
535
+ static $saved_supercache_dir = array();
536
+
537
+ if ( isset( $saved_supercache_dir[ $post_id ] ) ) {
538
+ return $saved_supercache_dir[ $post_id ];
539
+ }
540
+
541
+ $DONOTREMEMBER = 0;
542
+ if ( $post_id != 0 ) {
543
+ $site_url = site_url();
544
+ $permalink = get_permalink( $post_id );
545
+ if ( false === strpos( $permalink, $site_url ) ) {
546
+ /*
547
+ * Sometimes site_url doesn't return the siteurl. See https://wordpress.org/support/topic/wp-super-cache-not-refreshing-post-after-comments-made
548
+ */
549
+ $DONOTREMEMBER = 1;
550
+ wp_cache_debug( "get_current_url_supercache_dir: WARNING! site_url ($site_url) not found in permalink ($permalink).", 1 );
551
+ if ( preg_match( '`^(https?:)?//([^/]+)(/.*)?$`i', $permalink, $matches ) ) {
552
+ if ( $WPSC_HTTP_HOST != $matches[2] ) {
553
+ wp_cache_debug( "get_current_url_supercache_dir: WARNING! SERVER_NAME ({$WPSC_HTTP_HOST}) not found in permalink ($permalink).", 1 );
554
+ }
555
+ wp_cache_debug( "get_current_url_supercache_dir: Removing SERVER_NAME ({$matches[2]}) from permalink ($permalink). Is the url right?", 1 );
556
+ $uri = isset( $matches[3] ) ? $matches[3] : '';
557
+ } elseif ( preg_match( '`^/([^/]+)(/.*)?$`i', $permalink, $matches ) ) {
558
+ wp_cache_debug( "get_current_url_supercache_dir: WARNING! Permalink ($permalink) looks as absolute path. Is the url right?", 1 );
559
+ $uri = $permalink;
560
+ } else {
561
+ wp_cache_debug( "get_current_url_supercache_dir: WARNING! Permalink ($permalink) could not be understood by parsing url. Using front page.", 1 );
562
+ $uri = '';
563
+ }
564
+ } else {
565
+ $uri = str_replace( $site_url, '', $permalink );
566
+ if ( strpos( $uri, $wp_cache_home_path ) !== 0 )
567
+ $uri = rtrim( $wp_cache_home_path, '/' ) . $uri;
568
+ }
569
+ } else {
570
+ $uri = strtolower( $wp_cache_request_uri );
571
+ }
572
+ $uri = wpsc_deep_replace( array( '..', '\\', 'index.php', ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace( "/(\?.*)?(#.*)?$/", '', $uri ) ) );
573
+ $hostname = $WPSC_HTTP_HOST;
574
+ // Get hostname from wp options for wp-cron, wp-cli and similar requests.
575
+ if ( empty( $hostname ) && function_exists( 'get_option' ) ) {
576
+ $hostname = (string) parse_url( get_option( 'home' ), PHP_URL_HOST );
577
+ }
578
+ $dir = preg_replace( '/:.*$/', '', $hostname ) . $uri; // To avoid XSS attacks
579
+ if ( function_exists( "apply_filters" ) ) {
580
+ $dir = apply_filters( 'supercache_dir', $dir );
581
+ } else {
582
+ $dir = do_cacheaction( 'supercache_dir', $dir );
583
+ }
584
+ $dir = $cache_path . 'supercache/' . $dir . '/';
585
+ if( is_array( $cached_direct_pages ) && in_array( $_SERVER[ 'REQUEST_URI' ], $cached_direct_pages ) ) {
586
+ $dir = ABSPATH . $uri . '/';
587
+ }
588
+ $dir = str_replace( '..', '', str_replace( '//', '/', $dir ) );
589
+ wp_cache_debug( "supercache dir: $dir", 5 );
590
+ if ( $DONOTREMEMBER == 0 )
591
+ $saved_supercache_dir[ $post_id ] = $dir;
592
+ return $dir;
593
+ }
594
+
595
+ /*
596
+ * Delete (or rebuild) all the files in one directory.
597
+ * Checks if it is in the cache directory but doesn't allow files in the following directories to be deleted:
598
+ * wp-content/cache/
599
+ * wp-content/cache/blogs/
600
+ * wp-content/cache/supercache/
601
+ *
602
+ */
603
+ function wpsc_rebuild_files( $dir ) {
604
+ return wpsc_delete_files( $dir, false );
605
+ }
606
+
607
+ // realpath() doesn't always remove the trailing slash
608
+ function wpsc_get_realpath( $directory ) {
609
+ if ( $directory == '/' ) {
610
+ return false;
611
+ }
612
+
613
+ $original_dir = $directory;
614
+ $directory = realpath( $directory );
615
+
616
+ if ( ! $directory ) {
617
+ wp_cache_debug( "wpsc_get_realpath: directory does not exist - $original_dir" );
618
+ return false;
619
+ }
620
+
621
+ if ( substr( $directory, -1 ) == '/' || substr( $directory, -1 ) == '\\' ) {
622
+ $directory = substr( $directory, 0, -1 ); // remove trailing slash
623
+ }
624
+
625
+ return $directory;
626
+ }
627
+
628
+ // return true if directory is in the cache directory
629
+ function wpsc_is_in_cache_directory( $directory ) {
630
+ global $cache_path;
631
+ static $rp_cache_path = '';
632
+
633
+ if ( $directory == '' ) {
634
+ wp_cache_debug( "wpsc_is_in_cache_directory: exiting as directory is blank" );
635
+ return false;
636
+ }
637
+
638
+ if ( $cache_path == '' ) {
639
+ wp_cache_debug( "wpsc_is_in_cache_directory: exiting as cache_path is blank" );
640
+ return false;
641
+ }
642
+
643
+ if ( $rp_cache_path == '' ) {
644
+ $rp_cache_path = wpsc_get_realpath( $cache_path );
645
+ }
646
+
647
+ if ( ! $rp_cache_path ) {
648
+ wp_cache_debug( "wpsc_is_in_cache_directory: exiting as cache_path directory does not exist" );
649
+ return false;
650
+ }
651
+
652
+ $directory = wpsc_get_realpath( $directory );
653
+
654
+ if ( ! $directory ) {
655
+ wp_cache_debug( "wpsc_is_in_cache_directory: directory does not exist" );
656
+ return false;
657
+ }
658
+
659
+ if ( substr( $directory, 0, strlen( $rp_cache_path ) ) == $rp_cache_path ) {
660
+ return true;
661
+ } else {
662
+ return false;
663
+ }
664
+ }
665
+
666
+ function wpsc_delete_files( $dir, $delete = true ) {
667
+ global $cache_path;
668
+ static $protected = '';
669
+
670
+ if ( $dir == '' ) {
671
+ wp_cache_debug( "wpsc_delete_files: directory is blank" );
672
+ return false;
673
+ }
674
+
675
+ // only do this once, this function will be called many times
676
+ if ( $protected == '' ) {
677
+ $protected = array( $cache_path, $cache_path . "blogs/", $cache_path . 'supercache' );
678
+ foreach( $protected as $id => $directory ) {
679
+ $protected[ $id ] = trailingslashit( wpsc_get_realpath( $directory ) );
680
+ }
681
+ }
682
+
683
+ $dir = wpsc_get_realpath( $dir );
684
+ if ( ! $dir ) {
685
+ wp_cache_debug( "wpsc_delete_files: directory does not exist: " . $dir );
686
+ return false;
687
+ }
688
+
689
+ $dir = trailingslashit( $dir );
690
+
691
+ if ( ! wpsc_is_in_cache_directory( $dir ) ) {
692
+ return false;
693
+ }
694
+
695
+ if ( in_array( $dir, $protected ) )
696
+ return false;
697
+
698
+ if ( is_dir( $dir ) && $dh = @opendir( $dir ) ) {
699
+ while ( ( $file = readdir( $dh ) ) !== false ) {
700
+ if ( $file != '.' && $file != '..' && $file != '.htaccess' && is_file( $dir . $file ) )
701
+ if ( $delete )
702
+ @unlink( $dir . $file );
703
+ else
704
+ @wp_cache_rebuild_or_delete( $dir . $file );
705
+ }
706
+ closedir( $dh );
707
+
708
+ if ( $delete )
709
+ @rmdir( $dir );
710
+ }
711
+ return true;
712
+ }
713
+
714
+ function get_all_supercache_filenames( $dir = '' ) {
715
+ global $wp_cache_mobile_enabled, $cache_path;
716
+
717
+ $dir = wpsc_get_realpath( $dir );
718
+ if ( ! $dir ) {
719
+ wp_cache_debug( "get_all_supercache_filenames: directory does not exist" );
720
+ return array();
721
+ }
722
+
723
+ if ( ! wpsc_is_in_cache_directory( $dir ) ) {
724
+ return array();
725
+ }
726
+
727
+ $filenames = array( 'index.html', 'index-https.html', 'index.html.php' );
728
+
729
+ if ( $dir != '' && isset( $wp_cache_mobile_enabled ) && $wp_cache_mobile_enabled ) {
730
+ // open directory and look for index-*.html files
731
+ if ( is_dir( $dir ) && $dh = @opendir( $dir ) ) {
732
+ while ( ( $file = readdir( $dh ) ) !== false ) {
733
+ if ( substr( $file, 0, 6 ) == 'index-' && strpos( $file, '.html' ) )
734
+ $filenames[] = $file;
735
+ }
736
+ closedir( $dh );
737
+ }
738
+ }
739
+
740
+ if ( function_exists( "apply_filters" ) ) {
741
+ $filenames = apply_filters( 'all_supercache_filenames', $filenames );
742
+ } else {
743
+ $filenames = do_cacheaction( 'all_supercache_filenames', $filenames );
744
+ }
745
+
746
+ foreach( $filenames as $file ) {
747
+ $out[] = $file;
748
+ $out[] = $file . '.gz';
749
+ }
750
+
751
+ return $out;
752
+ }
753
+
754
+ function supercache_filename() {
755
+ global $cached_direct_pages;
756
+
757
+ //Add support for https and http caching
758
+ $is_https = ( ( isset( $_SERVER[ 'HTTPS' ] ) && 'on' == strtolower( $_SERVER[ 'HTTPS' ] ) ) || ( isset( $_SERVER[ 'HTTP_X_FORWARDED_PROTO' ] ) && 'https' == strtolower( $_SERVER[ 'HTTP_X_FORWARDED_PROTO' ] ) ) ); //Also supports https requests coming from an nginx reverse proxy
759
+ $extra_str = $is_https ? '-https' : '';
760
+
761
+ if ( function_exists( "apply_filters" ) ) {
762
+ $extra_str = apply_filters( 'supercache_filename_str', $extra_str );
763
+ } else {
764
+ $extra_str = do_cacheaction( 'supercache_filename_str', $extra_str );
765
+ }
766
+
767
+ if ( is_array( $cached_direct_pages ) && in_array( $_SERVER[ 'REQUEST_URI' ], $cached_direct_pages ) ) {
768
+ $extra_str = '';
769
+ }
770
+ $filename = 'index' . $extra_str . '.html';
771
+
772
+ return $filename;
773
+ }
774
+
775
+ function get_oc_version() {
776
+ $wp_cache_oc_key = wp_cache_get( "wp_cache_oc_key" );
777
+ if ( ! $wp_cache_oc_key ) {
778
+ $wp_cache_oc_key[ 'key' ] = reset_oc_version();
779
+ } elseif ( $wp_cache_oc_key[ 'ts' ] < time() - 600 )
780
+ wp_cache_set( "wp_cache_oc_key", array( 'ts' => time(), 'key' => $wp_cache_oc_key[ 'key' ] ) );
781
+ return $wp_cache_oc_key[ 'key' ];
782
+ }
783
+
784
+ function reset_oc_version( $version = 1 ) {
785
+ if ( $version == 1 )
786
+ $version = mt_rand();
787
+ wp_cache_set( "wp_cache_oc_key", array( 'ts' => time(), 'key' => $version ) );
788
+
789
+ return $version;
790
+ }
791
+
792
+ function get_oc_key( $url = false ) {
793
+ global $wp_cache_gzip_encoding, $WPSC_HTTP_HOST;
794
+
795
+ if ( $url ) {
796
+ $key = intval( $_SERVER[ 'SERVER_PORT' ] ) . strtolower( preg_replace( '/:.*$/', '', $WPSC_HTTP_HOST ) ) . $url;
797
+ } else {
798
+ $key = get_current_url_supercache_dir();
799
+ }
800
+ return $key . $wp_cache_gzip_encoding . get_oc_version();
801
+ }
802
+
803
+ function wp_supercache_cache_for_admins() {
804
+ if ( isset( $_GET[ 'preview' ] ) || function_exists( "is_admin" ) && is_admin() || defined( 'DOING_AJAX' ) )
805
+ return true;
806
+
807
+ if ( false == do_cacheaction( 'wp_supercache_remove_cookies', true ) )
808
+ return true;
809
+
810
+ if ( $_SERVER[ "REQUEST_METHOD" ] != 'GET' || strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-json/' ) !== false )
811
+ return true;
812
+
813
+ $cookie_keys = array( 'wordpress_logged_in', 'comment_author_' );
814
+ if ( defined( 'LOGGED_IN_COOKIE' ) )
815
+ $cookie_keys[] = constant( 'LOGGED_IN_COOKIE' );
816
+ reset( $_COOKIE );
817
+ foreach( $_COOKIE as $cookie => $val ) {
818
+ reset( $cookie_keys );
819
+ foreach( $cookie_keys as $key ) {
820
+ if ( strpos( $cookie, $key ) !== FALSE ) {
821
+ wp_cache_debug( 'Removing auth from $_COOKIE to allow caching for logged in user (' . $cookie . ')', 5 );
822
+ unset( $_COOKIE[ $cookie ] );
823
+ }
824
+ }
825
+ }
826
+ }
827
+
828
+ /* returns true/false depending on location of $dir. */
829
+ function wp_cache_confirm_delete( $dir ) {
830
+ global $cache_path, $blog_cache_dir;
831
+ // don't allow cache_path, blog cache dir, blog meta dir, supercache.
832
+ $dir = wpsc_get_realpath( $dir );
833
+
834
+ if ( ! $dir ) {
835
+ wp_cache_debug( "wp_cache_confirm_delete: directory does not exist" );
836
+ return false;
837
+ }
838
+
839
+ if ( ! wpsc_is_in_cache_directory( $dir ) ) {
840
+ return false;
841
+ }
842
+
843
+ $rp_cache_path = wpsc_get_realpath( $cache_path );
844
+
845
+ if ( ! $rp_cache_path ) {
846
+ wp_cache_debug( "wp_cache_confirm_delete: cache_path does not exist: $cache_path" );
847
+ return false;
848
+ }
849
+
850
+ if (
851
+ $dir == '' ||
852
+ $dir == $rp_cache_path ||
853
+ $dir == wpsc_get_realpath( $blog_cache_dir ) ||
854
+ $dir == wpsc_get_realpath( $blog_cache_dir . "meta/" ) ||
855
+ $dir == wpsc_get_realpath( $cache_path . "supercache" )
856
+ ) {
857
+ return false;
858
+ } else {
859
+ return true;
860
+ }
861
+ }
862
+
863
+ // copy of _deep_replace() to be used before WordPress loads
864
+ function wpsc_deep_replace( $search, $subject ) {
865
+ $subject = (string) $subject;
866
+
867
+ $count = 1;
868
+ while ( $count ) {
869
+ $subject = str_replace( $search, '', $subject, $count );
870
+ }
871
+
872
+ return $subject;
873
+ }
874
+
875
+ function wpsc_get_protected_directories() {
876
+ global $cache_path, $blog_cache_dir;
877
+ return apply_filters( 'wpsc_protected_directories', array(
878
+ $cache_path . '.htaccess',
879
+ $cache_path . "index.html",
880
+ $blog_cache_dir,
881
+ $blog_cache_dir . "index.html",
882
+ $blog_cache_dir . 'meta',
883
+ $blog_cache_dir . 'meta/index.html',
884
+ $cache_path . 'supercache/index.html',
885
+ $cache_path . 'supercache' )
886
+ );
887
+ }
888
+
889
+ function wpsc_create_debug_log( $filename = '', $username = '' ) {
890
+ global $cache_path, $wp_cache_debug_username, $wp_cache_debug_log;
891
+ if ( $filename != '' ) {
892
+ $wp_cache_debug_log = $filename;
893
+ } else {
894
+ $wp_cache_debug_log = md5( time() + mt_rand() ) . ".php";
895
+ }
896
+ if ( $username != '' ) {
897
+ $wp_cache_debug_username = $username;
898
+ } else {
899
+ $wp_cache_debug_username = md5( time() + mt_rand() );
900
+ }
901
+
902
+ $msg = '
903
+ if ( !isset( $_SERVER[ "PHP_AUTH_USER" ] ) || ( $_SERVER[ "PHP_AUTH_USER" ] != "' . $wp_cache_debug_username . '" && $_SERVER[ "PHP_AUTH_PW" ] != "' . $wp_cache_debug_username . '" ) ) {
904
+ header( "WWW-Authenticate: Basic realm=\"WP-Super-Cache Debug Log\"" );
905
+ header( $_SERVER[ "SERVER_PROTOCOL" ] . " 401 Unauthorized" );
906
+ echo "You must login to view the debug log";
907
+ exit;
908
+ }' . PHP_EOL;
909
+ $fp = fopen( $cache_path . $wp_cache_debug_log, 'w' );
910
+ if ( $fp ) {
911
+ fwrite( $fp, '<' . "?php\n" );
912
+ fwrite( $fp, $msg );
913
+ fwrite( $fp, '?' . "><pre>" . PHP_EOL );
914
+ fwrite( $fp, '<' . '?php // END HEADER ?' . '>' . PHP_EOL );
915
+ fclose( $fp );
916
+ wp_cache_setting( 'wp_cache_debug_log', $wp_cache_debug_log );
917
+ wp_cache_setting( 'wp_cache_debug_username', $wp_cache_debug_username );
918
+ }
919
+ $fp = fopen( $cache_path . 'view_' . $wp_cache_debug_log, 'w' );
920
+ if ( $fp ) {
921
+ fwrite( $fp, '<' . "?php" . PHP_EOL );
922
+ $msg .= '$debug_log = file( "./' . $wp_cache_debug_log . '" );
923
+ $start_log = 1 + array_search( "<" . "?php // END HEADER ?" . ">" . PHP_EOL, $debug_log );
924
+ if ( $start_log > 1 ) {
925
+ $debug_log = array_slice( $debug_log, $start_log );
926
+ }
927
+ ?' . '><form action="" method="GET"><' . '?php
928
+
929
+ $checks = array( "wp-admin", "exclude_filter", "wp-content", "wp-json" );
930
+ foreach( $checks as $check ) {
931
+ if ( isset( $_GET[ $check ] ) ) {
932
+ $$check = 1;
933
+ } else {
934
+ $$check = 0;
935
+ }
936
+ }
937
+
938
+ if ( isset( $_GET[ "filter" ] ) ) {
939
+ $filter = htmlspecialchars( $_GET[ "filter" ] );
940
+ } else {
941
+ $filter = "";
942
+ }
943
+
944
+ unset( $checks[1] ); // exclude_filter
945
+ ?' . '>
946
+ Exclude requests: <br />
947
+ <' . '?php foreach ( $checks as $check ) { ?>
948
+ <label><input type="checkbox" name="<' . '?php echo $check; ?' . '>" value="1" <' . '?php if ( $$check ) { echo "checked"; } ?' . '> /> <' . '?php echo $check; ?' . '></label><br />
949
+ <' . '?php } ?' . '>
950
+ <br />
951
+ Text to filter by:
952
+
953
+ <input type="text" name="filter" value="<' . '?php echo $filter; ?' . '>" /><br />
954
+ <input type="checkbox" name="exclude_filter" value="1" <' . '?php if ( $exclude_filter ) { echo "checked"; } ?' . '> /> Exclude by filter instead of include.<br />
955
+ <input type="submit" value="Submit" />
956
+ </form>
957
+ <' . '?php
958
+ foreach ( $debug_log as $t => $line ) {
959
+ foreach( $checks as $check ) {
960
+ if ( $$check && false !== strpos( $line, " /$check/" ) ) {
961
+ unset( $debug_log[ $t ] );
962
+ }
963
+ }
964
+ if ( $filter ) {
965
+ if ( false !== strpos( $line, $filter ) && $exclude_filter ) {
966
+ unset( $debug_log[ $t ] );
967
+ } elseif ( false === strpos( $line, $filter ) && ! $exclude_filter ) {
968
+ unset( $debug_log[ $t ] );
969
+ }
970
+ }
971
+ }
972
+ foreach( $debug_log as $line ) {
973
+ echo $line . "<br />";
974
+ }';
975
+ fwrite( $fp, $msg );
976
+ fclose( $fp );
977
+ }
978
+
979
+ return array( 'wp_cache_debug_log' => $wp_cache_debug_log, 'wp_cache_debug_username' => $wp_cache_debug_username );
980
+ }
981
+
982
+ function wpsc_delete_url_cache( $url ) {
983
+ if ( false !== strpos( $url, '?' ) ) {
984
+ wp_cache_debug( 'wpsc_delete_url_cache: URL contains the character "?". Not deleting URL: ' . $url );
985
+ return false;
986
+ }
987
+ $dir = str_replace( get_option( 'home' ), '', $url );
988
+ if ( $dir != '' ) {
989
+ $supercachedir = get_supercache_dir();
990
+ wpsc_delete_files( $supercachedir . $dir );
991
+ prune_super_cache( $supercachedir . $dir . '/page', true );
992
+ return true;
993
+ } else {
994
+ return false;
995
+ }
996
+ }
997
+
998
+ // from legolas558 d0t users dot sf dot net at http://www.php.net/is_writable
999
+ function is_writeable_ACLSafe( $path ) {
1000
+
1001
+ // PHP's is_writable does not work with Win32 NTFS
1002
+
1003
+ if ( $path[ strlen( $path ) - 1 ] == '/' ) { // recursively return a temporary file path
1004
+ return is_writeable_ACLSafe( $path . uniqid( mt_rand() ) . '.tmp' );
1005
+ } elseif ( is_dir( $path ) ) {
1006
+ return is_writeable_ACLSafe( $path . '/' . uniqid( mt_rand() ) . '.tmp' );
1007
+ }
1008
+
1009
+ // check tmp file for read/write capabilities
1010
+ $rm = file_exists( $path );
1011
+ $f = @fopen( $path, 'a' );
1012
+ if ( $f === false )
1013
+ return false;
1014
+ fclose( $f );
1015
+ if ( ! $rm ) {
1016
+ unlink( $path );
1017
+ }
1018
+
1019
+ return true;
1020
+ }
1021
+
1022
+ function wp_cache_setting( $field, $value ) {
1023
+ global $wp_cache_config_file;
1024
+
1025
+ $GLOBALS[ $field ] = $value;
1026
+ if ( is_numeric( $value ) ) {
1027
+ wp_cache_replace_line( '^ *\$' . $field, "\$$field = $value;", $wp_cache_config_file );
1028
+ } elseif ( is_object( $value ) || is_array( $value ) ) {
1029
+ $text = var_export( $value, true );
1030
+ $text = preg_replace( '/[\s]+/', ' ', $text );
1031
+ wp_cache_replace_line( '^ *\$' . $field, "\$$field = $text;", $wp_cache_config_file );
1032
+ } else {
1033
+ wp_cache_replace_line( '^ *\$' . $field, "\$$field = '$value';", $wp_cache_config_file );
1034
+ }
1035
+ }
1036
+
1037
+ function wp_cache_replace_line( $old, $new, $my_file ) {
1038
+ if ( @is_file( $my_file ) == false ) {
1039
+ return false;
1040
+ }
1041
+ if (!is_writeable_ACLSafe($my_file)) {
1042
+ trigger_error( "Error: file $my_file is not writable." );
1043
+ return false;
1044
+ }
1045
+
1046
+ $found = false;
1047
+ $loaded = false;
1048
+ $c = 0;
1049
+ $lines = array();
1050
+ while( ! $loaded ) {
1051
+ $lines = file( $my_file );
1052
+ if ( ! empty( $lines ) && is_array( $lines ) ) {
1053
+ $loaded = true;
1054
+ } else {
1055
+ $c++;
1056
+ if ( $c > 100 ) {
1057
+ trigger_error( "wp_cache_replace_line: Error - file $my_file could not be loaded." );
1058
+ return false;
1059
+ }
1060
+ }
1061
+ }
1062
+ foreach( (array) $lines as $line ) {
1063
+ if ( preg_match("/$old/", $line)) {
1064
+ $found = true;
1065
+ break;
1066
+ }
1067
+ }
1068
+
1069
+ $tmp_file = dirname( $my_file ) . '/' . mt_rand() . '.php';
1070
+ $fd = fopen( $tmp_file, 'w' );
1071
+ if ( ! $fd ) {
1072
+ trigger_error( "wp_cache_replace_line: Error - could not write to $tmp_file" );
1073
+ return false;
1074
+ }
1075
+ if ( $found ) {
1076
+ foreach( (array) $lines as $line ) {
1077
+ if ( ! preg_match( "/$old/", $line ) ) {
1078
+ fputs( $fd, $line );
1079
+ } elseif ( $new != '' ) {
1080
+ fputs( $fd, "$new\n" );
1081
+ }
1082
+ }
1083
+ } else {
1084
+ $done = false;
1085
+ foreach( (array) $lines as $line ) {
1086
+ if ( $done || ! preg_match( '/^(if\ \(\ \!\ )?define|\$|\?>/', $line ) ) {
1087
+ fputs($fd, $line);
1088
+ } else {
1089
+ fputs($fd, "$new\n");
1090
+ fputs($fd, $line);
1091
+ $done = true;
1092
+ }
1093
+ }
1094
+ }
1095
+ fclose( $fd );
1096
+ @rename( $tmp_file, $my_file );
1097
+
1098
+ if ( function_exists( "opcache_invalidate" ) ) {
1099
+ opcache_invalidate( $my_file );
1100
+ }
1101
+
1102
+ return true;
1103
+ }
1104
+
1105
  function wp_cache_phase2() {
1106
  global $wp_cache_gzip_encoding, $super_cache_enabled, $cache_rebuild_files, $cache_enabled, $wp_cache_gmt_offset, $wp_cache_blog_charset;
1107
 
1112
 
1113
  wp_cache_debug( 'In WP Cache Phase 2', 5 );
1114
 
1115
+ $wp_cache_gmt_offset = get_option( 'gmt_offset' ); // caching for later use when wpdb is gone. https://wordpress.org/support/topic/224349
1116
  $wp_cache_blog_charset = get_option( 'blog_charset' );
1117
 
1118
  wp_cache_mutex_init();
1148
  do_cacheaction( 'add_cacheaction' );
1149
  }
1150
 
1151
+ if ( wpsc_is_backend() ) {
1152
  wp_cache_debug( 'Not caching wp-admin requests.', 5 );
1153
  return false;
1154
  }
1155
 
1156
+ if ( ! empty( $_GET ) ) {
1157
+ wp_cache_debug( 'Supercache caching disabled. Only using wp-cache. Non empty GET request. ' . wpsc_dump_get_request(), 5 );
1158
  $super_cache_enabled = false;
1159
  }
1160
 
1271
  echo '<!-- WP Super Cache did not cache this page because you are logged in and "Don\'t cache pages for logged in users" is enabled. -->';
1272
  }
1273
 
1274
+ function wp_cache_user_agent_is_rejected() {
1275
+ global $cache_rejected_user_agent;
 
1276
 
1277
+ if (!function_exists('apache_request_headers')) return false;
1278
+ $headers = apache_request_headers();
1279
+ if (!isset($headers["User-Agent"])) return false;
1280
+ if ( false == is_array( $cache_rejected_user_agent ) )
 
 
 
 
 
1281
  return false;
1282
+ foreach ($cache_rejected_user_agent as $expr) {
1283
+ if (strlen($expr) > 0 && stristr($headers["User-Agent"], $expr))
1284
+ return true;
1285
  }
1286
+ return false;
1287
  }
1288
 
1289
  function wp_cache_get_response_headers() {
1560
  if ( defined( 'DONOTCACHEPAGE' ) ) {
1561
  wp_cache_debug( 'DONOTCACHEPAGE defined. Caching disabled.', 2 );
1562
  $cache_this_page = false;
1563
+ } elseif ( $wp_cache_no_cache_for_get && ! empty( $_GET ) ) {
1564
+ wp_cache_debug( "Non empty GET request. Caching disabled on settings page. " . wpsc_dump_get_request(), 1 );
1565
  $cache_this_page = false;
1566
  } elseif ( $_SERVER["REQUEST_METHOD"] == 'POST' || !empty( $_POST ) || get_option( 'gzipcompression' ) ) {
1567
  wp_cache_debug( 'Not caching POST request.', 5 );
1707
  $buffer .= "\n<!-- $text -->";
1708
  }
1709
 
1710
+
1711
  /*
1712
  * If dynamic caching is enabled then run buffer through wpsc_cachedata filter before returning it.
1713
  * or we'll return template tags to visitors.
1922
  wp_cache_set( $oc_key, $buffer, 'supercache', $cache_max_time );
1923
  }
1924
  $wp_cache_meta[ 'dynamic' ] = true;
1925
+ if ( $wp_cache_mfunc_enabled == 1 && do_cacheaction( 'wpsc_cachedata_safety', 0 ) === 1 ) {
1926
  $buffer = do_cacheaction( 'wpsc_cachedata', $buffer ); // dynamic content for display
1927
+ }
1928
 
1929
  if ( $cache_compression && $wp_cache_gzip_encoding ) {
1930
  wp_cache_debug( "Gzipping dynamic buffer for display.", 5 );
2719
  wp_cache_debug( "Post change: supercache enabled: deleting cache files in " . $dir );
2720
  wpsc_rebuild_files( $dir );
2721
  do_action( 'gc_cache', 'prune', 'homepage' );
2722
+ if ( get_option( 'show_on_front' ) == 'page' ) {
2723
+ wp_cache_debug( "Post change: deleting page_on_front and page_for_posts pages.", 4 );
2724
+ wp_cache_debug( "Post change: page_on_front " . get_option( 'page_on_front' ), 4 );
2725
+ $permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( get_option( 'page_for_posts' ) ) ) );
2726
+ wp_cache_debug( "Post change: Deleting files in: " . str_replace( '//', '/', $dir . $permalink ) );
2727
+ wpsc_rebuild_files( $dir . $permalink );
2728
+ do_action( 'gc_cache', 'prune', $permalink );
2729
+ }
2730
  } else {
2731
  wp_cache_debug( "wp_cache_post_change: not deleting all pages.", 4 );
2732
  }
 
 
 
 
 
 
 
 
 
 
2733
 
2734
  wp_cache_debug( "wp_cache_post_change: checking {$blog_cache_dir}meta/", 4 );
2735
  $supercache_files_deleted = false;
wp-cache.php CHANGED
@@ -3,10 +3,11 @@
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+
 
10
  Text Domain: wp-super-cache
11
  */
12
 
@@ -28,13 +29,10 @@ Text Domain: wp-super-cache
28
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
  */
30
 
 
 
31
  function wpsc_init() {
32
  global $wp_cache_config_file, $wp_cache_config_file_sample, $wp_cache_file, $wp_cache_check_wp_config, $wp_cache_link;
33
- // Pre-2.6 compatibility
34
- if ( !defined('WP_CONTENT_URL') )
35
- define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content');
36
- if ( !defined('WP_CONTENT_DIR') )
37
- define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
38
 
39
  $wp_cache_config_file = WP_CONTENT_DIR . '/wp-cache-config.php';
40
 
@@ -88,29 +86,9 @@ function wp_cache_set_home() {
88
  add_action( 'template_redirect', 'wp_cache_set_home' );
89
 
90
 
91
- // OSSDL CDN plugin (http://wordpress.org/plugins/ossdl-cdn-off-linker/)
92
  include_once( WPCACHEHOME . 'ossdl-cdn.php' );
93
 
94
- // from legolas558 d0t users dot sf dot net at http://www.php.net/is_writable
95
- function is_writeable_ACLSafe($path) {
96
-
97
- // PHP's is_writable does not work with Win32 NTFS
98
-
99
- if ($path{strlen($path)-1}=='/') // recursively return a temporary file path
100
- return is_writeable_ACLSafe($path.uniqid(mt_rand()).'.tmp');
101
- else if (is_dir($path))
102
- return is_writeable_ACLSafe($path.'/'.uniqid(mt_rand()).'.tmp');
103
- // check tmp file for read/write capabilities
104
- $rm = file_exists($path);
105
- $f = @fopen($path, 'a');
106
- if ($f===false)
107
- return false;
108
- fclose($f);
109
- if (!$rm)
110
- unlink($path);
111
- return true;
112
- }
113
-
114
  function get_wpcachehome() {
115
  if( defined( 'WPCACHEHOME' ) == false ) {
116
  if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
@@ -132,11 +110,6 @@ function wpsupercache_uninstall() {
132
  }
133
  }
134
 
135
- if ( !function_exists( 'wp_cache_debug' ) )
136
- include_once( 'wp-cache-phase1.php' );
137
- if ( !function_exists( 'prune_super_cache' ) )
138
- include_once( 'wp-cache-phase2.php' );
139
-
140
  wp_cache_remove_index();
141
 
142
  if ( null !== $cache_path && '' !== $cache_path ) {
@@ -159,10 +132,6 @@ function wpsupercache_deactivate() {
159
  global $wp_cache_config_file, $wp_cache_link, $cache_path;
160
  if ( file_exists( $wp_cache_link ) )
161
  unlink( $wp_cache_link );
162
- if ( !function_exists( 'wp_cache_debug' ) )
163
- include_once( 'wp-cache-phase1.php' );
164
- if ( !function_exists( 'prune_super_cache' ) )
165
- include_once( 'wp-cache-phase2.php' );
166
  prune_super_cache( $cache_path, true );
167
  wp_cache_remove_index();
168
  @unlink( $cache_path . '.htaccess' );
@@ -264,7 +233,7 @@ function wp_cache_manager_error_checks() {
264
  if( substr( $ip, 0, 3 ) == '127' || substr( $ip, 0, 7 ) == '192.168' ) {
265
  ?><div class="notice notice-warning"><h3><?php printf( __( 'Warning! Your hostname "%s" resolves to %s', 'wp-super-cache' ), $hostname, $ip ); ?></h3>
266
  <p><?php printf( __( 'Your server thinks your hostname resolves to %s. Some services such as garbage collection by this plugin, and WordPress scheduled posts may not operate correctly.', 'wp-super-cache' ), $ip ); ?></p>
267
- <p><?php printf( __( 'Please see entry 16 in the <a href="%s">Troubleshooting section</a> of the readme.txt', 'wp-super-cache' ), 'http://wordpress.org/plugins/wp-super-cache/faq/' ); ?></p>
268
  </div>
269
  <?php
270
  return false;
@@ -278,7 +247,7 @@ function wp_cache_manager_error_checks() {
278
  if( $cron[ 'response' ][ 'code' ] == '404' ) {
279
  ?><div class="notice notice-error"><h3>Warning! wp-cron.php not found!</h3>
280
  <p><?php _e( 'Unfortunately, WordPress cannot find the file wp-cron.php. This script is required for the correct operation of garbage collection by this plugin, WordPress scheduled posts as well as other critical activities.', 'wp-super-cache' ); ?></p>
281
- <p><?php printf( __( 'Please see entry 16 in the <a href="%s">Troubleshooting section</a> of the readme.txt', 'wp-super-cache' ), 'http://wordpress.org/plugins/wp-super-cache/faq/' ); ?></p>
282
  </div>
283
  <?php
284
  } else {
@@ -295,6 +264,13 @@ function wp_cache_manager_error_checks() {
295
  return false;
296
  }
297
 
 
 
 
 
 
 
 
298
  if (!wp_cache_check_global_config()) {
299
  return false;
300
  }
@@ -321,7 +297,7 @@ function wp_cache_manager_error_checks() {
321
  ?><div class="notice notice-error"><h3><?php _e( 'Read Only Mode. Configuration cannot be changed.', 'wp-super-cache' ); ?></h3>
322
  <p><?php printf( __( 'The WP Super Cache configuration file is <code>%s/wp-cache-config.php</code> and cannot be modified. That file must be writeable by the web server to make any changes.', 'wp-super-cache' ), WP_CONTENT_DIR ); ?>
323
  <?php _e( 'A simple way of doing that is by changing the permissions temporarily using the CHMOD command or through your ftp client. Make sure it&#8217;s globally writeable and it should be fine.', 'wp-super-cache' ); ?></p>
324
- <p><?php _e( '<a href="http://codex.wordpress.org/Changing_File_Permissions">This page</a> explains how to change file permissions.', 'wp-super-cache' ); ?></p>
325
  <?php _e( 'Writeable:', 'wp-super-cache' ); ?> <code>chmod 666 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code><br />
326
  <?php _e( 'Read-only:', 'wp-super-cache' ); ?> <code>chmod 644 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code></p>
327
  </div><?php
@@ -370,7 +346,7 @@ function wp_cache_manager_error_checks() {
370
  if( substr( $wp_content_mode, -2 ) == '77' ) {
371
  ?><div class="notice notice-warning"><h3><?php printf( __( 'Warning! %s is writeable!', 'wp-super-cache' ), WP_CONTENT_DIR ); ?></h3>
372
  <p><?php printf( __( 'You should change the permissions on %s and make it more restrictive. Use your ftp client, or the following command to fix things:', 'wp-super-cache' ), WP_CONTENT_DIR ); ?> <code>chmod 755 <?php echo WP_CONTENT_DIR; ?>/</code></p>
373
- <p><?php _e( '<a href="http://codex.wordpress.org/Changing_File_Permissions">This page</a> explains how to change file permissions.', 'wp-super-cache' ); ?></p>
374
  <form action="" method="POST">
375
  <input type="hidden" name="action" value="dismiss_readable_warning" />
376
  <input type="hidden" name="page" value="wpsupercache" />
@@ -441,7 +417,7 @@ function wp_cache_manager_error_checks() {
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">
446
  <input type="hidden" name="action" value="dismiss_htaccess_warning" />
447
  <input type="hidden" name="page" value="wpsupercache" />
@@ -494,13 +470,6 @@ function wp_cache_manager_updates() {
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 ) {
@@ -986,7 +955,7 @@ table.wpsc-settings-table {
986
  if ( wp_next_scheduled( 'wp_cache_preload_hook' ) || wp_next_scheduled( 'wp_cache_full_preload_hook' ) ) {
987
  $currently_preloading = true;
988
  }
989
- echo '<div class="submit"><input class="button-primary" type="submit" name="preload" value="' . __( 'Update Settings', 'wp-super-cache' ) . '" />';
990
  echo '</div>';
991
  wp_nonce_field('wp-cache');
992
  echo '</form>';
@@ -1084,8 +1053,8 @@ table.wpsc-settings-table {
1084
  <td>
1085
  <fieldset>
1086
  <legend class="hidden">Advanced</legend>
1087
- <label><input type='checkbox' name='wp_cache_mfunc_enabled' <?php if( $wp_cache_mfunc_enabled ) echo "checked"; ?> value='1' <?php if ( $wp_cache_mod_rewrite ) { echo "disabled='disabled'"; } ?>> <?php _e( 'Enable dynamic caching. (See <a href="http://wordpress.org/plugins/wp-super-cache/faq/">FAQ</a> or wp-super-cache/plugins/dynamic-cache-test.php for example code.)', 'wp-super-cache' ); ?></label><br />
1088
- <label><input type='checkbox' name='wp_cache_mobile_enabled' <?php if( $wp_cache_mobile_enabled ) echo "checked"; ?> value='1'> <?php _e( 'Mobile device support. (External plugin or theme required. See the <a href="http://wordpress.org/plugins/wp-super-cache/faq/">FAQ</a> for further details.)', 'wp-super-cache' ); ?></label><br />
1089
  <?php if ( $wp_cache_mobile_enabled ) {
1090
  echo '<blockquote><h4>' . __( 'Mobile Browsers', 'wp-super-cache' ) . '</h4>' . esc_html( $wp_cache_mobile_browsers ) . "<br /><h4>" . __( 'Mobile Prefixes', 'wp-super-cache' ) . "</h4>" . esc_html( $wp_cache_mobile_prefixes ) . "<br /></blockquote>";
1091
  } ?>
@@ -1141,7 +1110,7 @@ table.wpsc-settings-table {
1141
  <li><?php _e( 'Uninstall this plugin on the plugins page. It will automatically clean up after itself. If manual intervention is required, then simple instructions are provided.', 'wp-super-cache' ); ?></li>
1142
  <li><?php printf( __( 'If uninstalling this plugin, make sure the directory <em>%s</em> is writeable by the webserver so the files <em>advanced-cache.php</em> and <em>cache-config.php</em> can be deleted automatically. (Making sure those files are writeable is probably a good idea!)', 'wp-super-cache' ), WP_CONTENT_DIR ); ?></li>
1143
  <li><?php printf( __( 'Please see the <a href="%1$s/wp-super-cache/readme.txt">readme.txt</a> for instructions on uninstalling this script. Look for the heading, "How to uninstall WP Super Cache".', 'wp-super-cache' ), plugins_url() ); ?></li><?php
1144
- echo "<li><em>" . sprintf( __( 'Need help? Check the <a href="%1$s">Super Cache readme file</a>. It includes installation documentation, a FAQ and Troubleshooting tips. The <a href="%2$s">support forum</a> is also available. Your question may already have been answered.', 'wp-super-cache' ), 'http://wordpress.org/plugins/wp-super-cache/', 'http://wordpress.org/tags/wp-super-cache?forum_id=10' ) . "</em></li>";
1145
  echo "</ol>";
1146
 
1147
  echo "<div class='submit'><input class='button-primary' type='submit' " . SUBMITDISABLED . " value='" . __( 'Update Status', 'wp-super-cache' ) . "' /></div>";
@@ -1282,10 +1251,10 @@ table.wpsc-settings-table {
1282
  <p><?php _e( 'Caching is only one part of making a website faster. Here are some other plugins that will help:', 'wp-super-cache' ); ?></p>
1283
  <ul style="list-style: square; margin-left: 2em;">
1284
  <li><?php printf( __( '<a href="%s">Jetpack</a> provides everything you need to build a successful WordPress website including an image/photo CDN (free) and a video hosting service (paid).', 'wp-super-cache' ), 'https://jetpack.com/redirect/?source=jitm-wpsc-recommended' ); ?></li>
1285
- <li><?php printf( __( '<a href="%s">Yahoo! Yslow</a> is an extension for the Firefox add-on Firebug. It analyzes web pages and suggests ways to improve their performance based on a set of rules for high performance web pages. Also try the performance tools online at <a href="%s">GTMetrix</a>.', 'wp-super-cache' ), 'http://developer.yahoo.com/yslow/', 'http://gtmetrix.com/' ); ?></li>
1286
- <li><?php printf( __( '<a href="%s">Use Google Libraries</a> allows you to load some commonly used Javascript libraries from Google webservers. Ironically, it may reduce your Yslow score.', 'wp-super-cache' ), 'http://wordpress.org/plugins/use-google-libraries/' ); ?></li>
1287
- <li><?php printf( __( '<strong>Advanced users only:</strong> Install an object cache. Choose from <a href="%s">Memcached</a>, <a href="%s">XCache</a>, <a href="%s">eAcccelerator</a> and others.', 'wp-super-cache' ), 'http://wordpress.org/plugins/memcached/', 'http://neosmart.net/dl.php?id=12', 'http://neosmart.net/dl.php?id=13' ); ?></li>
1288
- <li><?php printf( __( '<a href="%s">Cron View</a> is a useful plugin to use when trying to debug garbage collection and preload problems.', 'wp-super-cache' ), 'http://wordpress.org/plugins/cron-view/' ); ?></li>
1289
  </ul>
1290
 
1291
  <?php
@@ -1304,8 +1273,8 @@ table.wpsc-settings-table {
1304
  <h3><?php _e( 'Need Help?', 'wp-super-cache' ); ?></h3>
1305
  <ol>
1306
  <li><?php printf( __( 'Use the <a href="%1$s">Debug tab</a> for diagnostics.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache&tab=debug' ) ); ?></li>
1307
- <li><?php printf( __( 'Check out the <a href="%1$s">support forum</a> and <a href="%2$s">FAQ</a>.', 'wp-super-cache' ), 'https://wordpress.org/support/plugin/wp-super-cache', 'http://wordpress.org/plugins/wp-super-cache/#faq' ); ?></li>
1308
- <li><?php printf( __( 'Visit the <a href="%1$s">plugin homepage</a>.', 'wp-super-cache' ), 'http://wordpress.org/plugins/wp-super-cache/' ); ?></li>
1309
  <li><?php printf( __( 'Try out the <a href="%1$s">development version</a> for the latest fixes (<a href="%2$s">changelog</a>).', 'wp-super-cache' ), 'https://odd.blog/y/2o', 'https://plugins.trac.wordpress.org/log/wp-super-cache/' ); ?></li>
1310
  </ol>
1311
  <h3><?php _e( 'Rate This Plugin', 'wp-super-cache' ); ?></h3>
@@ -1900,7 +1869,7 @@ function wp_cache_edit_rejected_pages() {
1900
  wp_cache_update_rejected_pages();
1901
 
1902
  echo '<a name="rejectpages"></a>';
1903
- echo '<p>' . __( 'Do not cache the following page types. See the <a href="http://codex.wordpress.org/Conditional_Tags">Conditional Tags</a> documentation for a complete discussion on each type.', 'wp-super-cache' ) . '</p>';
1904
  echo '<form name="wp_edit_rejected_pages" action="#rejectpages" method="post">';
1905
  echo '<input type="hidden" name="wp_edit_rejected_pages" value="1" />';
1906
  echo '<label><input type="checkbox" value="1" name="wp_cache_pages[single]" ' . checked( 1, $wp_cache_pages[ 'single' ], false ) . ' /> ' . __( 'Single Posts', 'wp-super-cache' ) . ' (is_single)</label><br />';
@@ -1914,7 +1883,7 @@ function wp_cache_edit_rejected_pages() {
1914
  echo '<label><input type="checkbox" value="1" name="wp_cache_pages[search]" ' . checked( 1, $wp_cache_pages[ 'search' ], false ) . ' /> ' . __( 'Search Pages', 'wp-super-cache' ) . ' (is_search)</label><br />';
1915
  echo '<label><input type="checkbox" value="1" name="wp_cache_pages[author]" ' . checked( 1, $wp_cache_pages[ 'author' ], false ) . ' /> ' . __( 'Author Pages', 'wp-super-cache' ) . ' (is_author)</label><br />';
1916
 
1917
- echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save', 'wp-super-cache' ) . '" /></div>';
1918
  wp_nonce_field('wp-cache');
1919
  echo "</form>\n";
1920
 
@@ -2107,7 +2076,7 @@ function wp_cache_debug_settings() {
2107
 
2108
  echo "</table>\n";
2109
  }
2110
- echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save', 'wp-super-cache' ) . '" /></div>';
2111
  wp_nonce_field('wp-cache');
2112
  echo "</form>\n";
2113
  echo '</fieldset>';
@@ -2181,84 +2150,6 @@ function wp_cache_is_enabled() {
2181
  return false;
2182
  }
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 ) ) {
2191
- $text = var_export( $value, true );
2192
- $text = preg_replace( '/[\s]+/', ' ', $text );
2193
- wp_cache_replace_line( '^ *\$' . $field, "\$$field = $text;", $wp_cache_config_file );
2194
- } else {
2195
- wp_cache_replace_line( '^ *\$' . $field, "\$$field = '$value';", $wp_cache_config_file );
2196
- }
2197
- }
2198
-
2199
- function wp_cache_replace_line($old, $new, $my_file) {
2200
- if ( @is_file( $my_file ) == false ) {
2201
- return false;
2202
- }
2203
- if (!is_writeable_ACLSafe($my_file)) {
2204
- trigger_error( "Error: file $my_file is not writable." );
2205
- return false;
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
-
2262
  function wp_cache_remove_index() {
2263
  global $cache_path;
2264
 
@@ -2282,7 +2173,7 @@ function wp_cache_remove_index() {
2282
  }
2283
  if ( is_dir( $directory . "/meta" ) ) {
2284
  if ( is_file( $directory . "/meta/index.html" ) ) {
2285
- unlink( $directory . "/index.html" );
2286
  }
2287
  }
2288
  }
@@ -2489,7 +2380,7 @@ function wp_cache_verify_config_file() {
2489
  }
2490
  $new = true;
2491
  }
2492
- if( $sem_id == 5419 && $cache_path != '' ) {
2493
  $sem_id = crc32( $WPSC_HTTP_HOST . $cache_path ) & 0x7fffffff;
2494
  wp_cache_replace_line('sem_id', '$sem_id = ' . $sem_id . ';', $wp_cache_config_file);
2495
  }
@@ -2588,7 +2479,7 @@ function wp_cache_check_global_config() {
2588
  }
2589
  return false;
2590
  } else {
2591
- echo "<div class='notice notice-warning'>" . __( '<h3>WP_CACHE constant added to wp-config.php</h3><p>If you continue to see this warning message please see point 5 of the <a href="http://wordpress.org/plugins/wp-super-cache/faq/">Troubleshooting Guide</a>. The WP_CACHE line must be moved up.', 'wp-super-cache' ) . "</p></div>";
2592
  }
2593
  return true;
2594
  }
@@ -3255,7 +3146,7 @@ function wpsc_get_htaccess_info() {
3255
  }
3256
  $content_dir_root = $document_root;
3257
  if ( strpos( $document_root, '/kunden/homepages/' ) === 0 ) {
3258
- // http://wordpress.org/support/topic/plugin-wp-super-cache-how-to-get-mod_rewrite-working-on-1and1-shared-hosting?replies=1
3259
  // On 1and1, PHP's directory structure starts with '/homepages'. The
3260
  // Apache directory structure has an extra '/kunden' before it.
3261
  // Also 1and1 does not support the %{DOCUMENT_ROOT} variable in
@@ -3360,9 +3251,6 @@ function clear_post_supercache( $post_id ) {
3360
  if ( false == @is_dir( $dir ) )
3361
  return false;
3362
 
3363
- if ( !function_exists( 'prune_super_cache' ) )
3364
- include_once( 'wp-cache-phase2.php' );
3365
-
3366
  wp_cache_debug( "clear_post_supercache: deleting files in $dir", 2 );
3367
  if ( get_post_type( $post_id ) != 'page' ) { // don't delete child pages if they exist
3368
  prune_super_cache( $dir, true );
@@ -3380,11 +3268,6 @@ function wp_cron_preload_cache() {
3380
  return true;
3381
  }
3382
 
3383
- if ( !function_exists( 'wp_cache_debug' ) )
3384
- include_once( 'wp-cache-phase1.php' );
3385
- if ( !function_exists( 'prune_super_cache' ) )
3386
- include_once( 'wp-cache-phase2.php' );
3387
-
3388
  $mutex = $cache_path . "preload_mutex.tmp";
3389
  sleep( 3 + mt_rand( 1, 5 ) );
3390
  if ( @file_exists( $mutex ) ) {
@@ -3667,7 +3550,7 @@ function wp_cache_disable_plugin( $delete_config_file = true ) {
3667
  if ( $scrules != '' && insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', array() ) ) {
3668
  $wp_rewrite->flush_rules();
3669
  } elseif( $scrules != '' ) {
3670
- wp_mail( get_option( 'admin_email' ), __( 'Supercache Uninstall Problems', 'wp-super-cache' ), sprintf( __( "Dear User,\n\nWP Super Cache was removed from your blog but the mod_rewrite rules\nin your .htaccess were not.\n\nPlease edit the following file and remove the code\nbetween 'BEGIN WPSuperCache' and 'END WPSuperCache'. Please backup the file first!\n\n%s\n\nRegards,\nWP Super Cache Plugin\nhttp://wordpress.org/plugins/wp-super-cache/", 'wp-super-cache' ), ABSPATH . '/.htaccess' ) );
3671
  }
3672
  }
3673
 
@@ -4011,8 +3894,6 @@ function wpsc_feed_update( $type, $permalink ) {
4011
 
4012
  update_option( 'wpsc_feed_list', array() );
4013
  if ( is_array( $wpsc_feed_list ) && ! empty( $wpsc_feed_list ) ) {
4014
- if ( ! function_exists( 'prune_super_cache' ) )
4015
- include_once( 'wp-cache-phase2.php' );
4016
  foreach( $wpsc_feed_list as $file ) {
4017
  wp_cache_debug( "wpsc_feed_update: deleting feed: $file" );
4018
  prune_super_cache( $file, true );
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.9
7
  Author: Automattic
8
  Author URI: https://automattic.com/
9
  License: GPL2+
10
+ License URI: https://www.gnu.org/licenses/gpl-2.0.txt
11
  Text Domain: wp-super-cache
12
  */
13
 
29
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30
  */
31
 
32
+ require_once( dirname( __FILE__ ) . '/wp-cache-phase2.php');
33
+
34
  function wpsc_init() {
35
  global $wp_cache_config_file, $wp_cache_config_file_sample, $wp_cache_file, $wp_cache_check_wp_config, $wp_cache_link;
 
 
 
 
 
36
 
37
  $wp_cache_config_file = WP_CONTENT_DIR . '/wp-cache-config.php';
38
 
86
  add_action( 'template_redirect', 'wp_cache_set_home' );
87
 
88
 
89
+ // OSSDL CDN plugin (https://wordpress.org/plugins/ossdl-cdn-off-linker/)
90
  include_once( WPCACHEHOME . 'ossdl-cdn.php' );
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  function get_wpcachehome() {
93
  if( defined( 'WPCACHEHOME' ) == false ) {
94
  if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
110
  }
111
  }
112
 
 
 
 
 
 
113
  wp_cache_remove_index();
114
 
115
  if ( null !== $cache_path && '' !== $cache_path ) {
132
  global $wp_cache_config_file, $wp_cache_link, $cache_path;
133
  if ( file_exists( $wp_cache_link ) )
134
  unlink( $wp_cache_link );
 
 
 
 
135
  prune_super_cache( $cache_path, true );
136
  wp_cache_remove_index();
137
  @unlink( $cache_path . '.htaccess' );
233
  if( substr( $ip, 0, 3 ) == '127' || substr( $ip, 0, 7 ) == '192.168' ) {
234
  ?><div class="notice notice-warning"><h3><?php printf( __( 'Warning! Your hostname "%s" resolves to %s', 'wp-super-cache' ), $hostname, $ip ); ?></h3>
235
  <p><?php printf( __( 'Your server thinks your hostname resolves to %s. Some services such as garbage collection by this plugin, and WordPress scheduled posts may not operate correctly.', 'wp-super-cache' ), $ip ); ?></p>
236
+ <p><?php printf( __( 'Please see entry 16 in the <a href="%s">Troubleshooting section</a> of the readme.txt', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-super-cache/faq/' ); ?></p>
237
  </div>
238
  <?php
239
  return false;
247
  if( $cron[ 'response' ][ 'code' ] == '404' ) {
248
  ?><div class="notice notice-error"><h3>Warning! wp-cron.php not found!</h3>
249
  <p><?php _e( 'Unfortunately, WordPress cannot find the file wp-cron.php. This script is required for the correct operation of garbage collection by this plugin, WordPress scheduled posts as well as other critical activities.', 'wp-super-cache' ); ?></p>
250
+ <p><?php printf( __( 'Please see entry 16 in the <a href="%s">Troubleshooting section</a> of the readme.txt', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-super-cache/faq/' ); ?></p>
251
  </div>
252
  <?php
253
  } else {
264
  return false;
265
  }
266
 
267
+ if ( false == function_exists( 'wpsc_deep_replace' ) ) {
268
+ $msg = __( 'Warning! You must set WP_CACHE and WPCACHEHOME in your wp-config.php for this plugin to work correctly:' ) . '<br />';
269
+ $msg .= "<code>define( 'WP_CACHE', true );</code><br />";
270
+ $msg .= "<code>define( 'WPCACHEHOME', '" . dirname( __FILE__ ) . "' );</code><br />";
271
+ wp_die( $msg );
272
+ }
273
+
274
  if (!wp_cache_check_global_config()) {
275
  return false;
276
  }
297
  ?><div class="notice notice-error"><h3><?php _e( 'Read Only Mode. Configuration cannot be changed.', 'wp-super-cache' ); ?></h3>
298
  <p><?php printf( __( 'The WP Super Cache configuration file is <code>%s/wp-cache-config.php</code> and cannot be modified. That file must be writeable by the web server to make any changes.', 'wp-super-cache' ), WP_CONTENT_DIR ); ?>
299
  <?php _e( 'A simple way of doing that is by changing the permissions temporarily using the CHMOD command or through your ftp client. Make sure it&#8217;s globally writeable and it should be fine.', 'wp-super-cache' ); ?></p>
300
+ <p><?php _e( '<a href="https://codex.wordpress.org/Changing_File_Permissions">This page</a> explains how to change file permissions.', 'wp-super-cache' ); ?></p>
301
  <?php _e( 'Writeable:', 'wp-super-cache' ); ?> <code>chmod 666 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code><br />
302
  <?php _e( 'Read-only:', 'wp-super-cache' ); ?> <code>chmod 644 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code></p>
303
  </div><?php
346
  if( substr( $wp_content_mode, -2 ) == '77' ) {
347
  ?><div class="notice notice-warning"><h3><?php printf( __( 'Warning! %s is writeable!', 'wp-super-cache' ), WP_CONTENT_DIR ); ?></h3>
348
  <p><?php printf( __( 'You should change the permissions on %s and make it more restrictive. Use your ftp client, or the following command to fix things:', 'wp-super-cache' ), WP_CONTENT_DIR ); ?> <code>chmod 755 <?php echo WP_CONTENT_DIR; ?>/</code></p>
349
+ <p><?php _e( '<a href="https://codex.wordpress.org/Changing_File_Permissions">This page</a> explains how to change file permissions.', 'wp-super-cache' ); ?></p>
350
  <form action="" method="POST">
351
  <input type="hidden" name="action" value="dismiss_readable_warning" />
352
  <input type="hidden" name="page" value="wpsupercache" />
417
  $disable_supercache_htaccess_warning = false;
418
  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' ) ) {
419
  ?><div class="notice notice-info"><h3><?php _e( '.htaccess file may need to be moved', 'wp-super-cache' ); ?></h3>
420
+ <p><?php _e( 'It appears you have WordPress installed in a sub directory as described <a href="https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory">here</a>. Unfortunately, WordPress writes to the .htaccess in the install directory, not where your site is served from.<br />When you update the rewrite rules in this plugin you will have to copy the file to where your site is hosted. This will be fixed in the future.', 'wp-super-cache' ); ?></p>
421
  <form action="" method="POST">
422
  <input type="hidden" name="action" value="dismiss_htaccess_warning" />
423
  <input type="hidden" name="page" value="wpsupercache" />
470
  if ( $valid_nonce == false )
471
  return false;
472
 
 
 
 
 
 
 
 
473
  if ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'easysetup' ) {
474
  $_POST[ 'action' ] = 'scupdates';
475
  if( isset( $_POST[ 'wp_cache_easy_on' ] ) && $_POST[ 'wp_cache_easy_on' ] == 1 ) {
955
  if ( wp_next_scheduled( 'wp_cache_preload_hook' ) || wp_next_scheduled( 'wp_cache_full_preload_hook' ) ) {
956
  $currently_preloading = true;
957
  }
958
+ echo '<div class="submit"><input class="button-primary" type="submit" name="preload" value="' . __( 'Save Settings', 'wp-super-cache' ) . '" />';
959
  echo '</div>';
960
  wp_nonce_field('wp-cache');
961
  echo '</form>';
1053
  <td>
1054
  <fieldset>
1055
  <legend class="hidden">Advanced</legend>
1056
+ <label><input type='checkbox' name='wp_cache_mfunc_enabled' <?php if( $wp_cache_mfunc_enabled ) echo "checked"; ?> value='1' <?php if ( $wp_cache_mod_rewrite ) { echo "disabled='disabled'"; } ?>> <?php _e( 'Enable dynamic caching. (See <a href="https://wordpress.org/plugins/wp-super-cache/faq/">FAQ</a> or wp-super-cache/plugins/dynamic-cache-test.php for example code.)', 'wp-super-cache' ); ?></label><br />
1057
+ <label><input type='checkbox' name='wp_cache_mobile_enabled' <?php if( $wp_cache_mobile_enabled ) echo "checked"; ?> value='1'> <?php _e( 'Mobile device support. (External plugin or theme required. See the <a href="https://wordpress.org/plugins/wp-super-cache/faq/">FAQ</a> for further details.)', 'wp-super-cache' ); ?></label><br />
1058
  <?php if ( $wp_cache_mobile_enabled ) {
1059
  echo '<blockquote><h4>' . __( 'Mobile Browsers', 'wp-super-cache' ) . '</h4>' . esc_html( $wp_cache_mobile_browsers ) . "<br /><h4>" . __( 'Mobile Prefixes', 'wp-super-cache' ) . "</h4>" . esc_html( $wp_cache_mobile_prefixes ) . "<br /></blockquote>";
1060
  } ?>
1110
  <li><?php _e( 'Uninstall this plugin on the plugins page. It will automatically clean up after itself. If manual intervention is required, then simple instructions are provided.', 'wp-super-cache' ); ?></li>
1111
  <li><?php printf( __( 'If uninstalling this plugin, make sure the directory <em>%s</em> is writeable by the webserver so the files <em>advanced-cache.php</em> and <em>cache-config.php</em> can be deleted automatically. (Making sure those files are writeable is probably a good idea!)', 'wp-super-cache' ), WP_CONTENT_DIR ); ?></li>
1112
  <li><?php printf( __( 'Please see the <a href="%1$s/wp-super-cache/readme.txt">readme.txt</a> for instructions on uninstalling this script. Look for the heading, "How to uninstall WP Super Cache".', 'wp-super-cache' ), plugins_url() ); ?></li><?php
1113
+ echo "<li><em>" . sprintf( __( 'Need help? Check the <a href="%1$s">Super Cache readme file</a>. It includes installation documentation, a FAQ and Troubleshooting tips. The <a href="%2$s">support forum</a> is also available. Your question may already have been answered.', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-super-cache/', 'https://wordpress.org/support/topic-tag/wp-super-cache/?forum_id=10' ) . "</em></li>";
1114
  echo "</ol>";
1115
 
1116
  echo "<div class='submit'><input class='button-primary' type='submit' " . SUBMITDISABLED . " value='" . __( 'Update Status', 'wp-super-cache' ) . "' /></div>";
1251
  <p><?php _e( 'Caching is only one part of making a website faster. Here are some other plugins that will help:', 'wp-super-cache' ); ?></p>
1252
  <ul style="list-style: square; margin-left: 2em;">
1253
  <li><?php printf( __( '<a href="%s">Jetpack</a> provides everything you need to build a successful WordPress website including an image/photo CDN (free) and a video hosting service (paid).', 'wp-super-cache' ), 'https://jetpack.com/redirect/?source=jitm-wpsc-recommended' ); ?></li>
1254
+ <li><?php printf( __( '<a href="%s">Yahoo! Yslow</a> is an extension for the Firefox add-on Firebug. It analyzes web pages and suggests ways to improve their performance based on a set of rules for high performance web pages. Also try the performance tools online at <a href="%s">GTMetrix</a>.', 'wp-super-cache' ), 'http://yslow.org/', 'https://gtmetrix.com/' ); ?></li>
1255
+ <li><?php printf( __( '<a href="%s">Use Google Libraries</a> allows you to load some commonly used Javascript libraries from Google webservers. Ironically, it may reduce your Yslow score.', 'wp-super-cache' ), 'https://wordpress.org/plugins/use-google-libraries/' ); ?></li>
1256
+ <li><?php printf( __( '<strong>Advanced users only:</strong> Install an object cache. Choose from <a href="%s">Memcached</a>, <a href="%s">XCache</a>, <a href="%s">eAcccelerator</a> and others.', 'wp-super-cache' ), 'https://wordpress.org/plugins/memcached/', 'https://neosmart.net/WP/XCache/', 'https://neosmart.net/WP/eAccelerator/' ); ?></li>
1257
+ <li><?php printf( __( '<a href="%s">Cron View</a> is a useful plugin to use when trying to debug garbage collection and preload problems.', 'wp-super-cache' ), 'https://wordpress.org/plugins/cron-view/' ); ?></li>
1258
  </ul>
1259
 
1260
  <?php
1273
  <h3><?php _e( 'Need Help?', 'wp-super-cache' ); ?></h3>
1274
  <ol>
1275
  <li><?php printf( __( 'Use the <a href="%1$s">Debug tab</a> for diagnostics.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache&tab=debug' ) ); ?></li>
1276
+ <li><?php printf( __( 'Check out the <a href="%1$s">support forum</a> and <a href="%2$s">FAQ</a>.', 'wp-super-cache' ), 'https://wordpress.org/support/plugin/wp-super-cache', 'https://wordpress.org/plugins/wp-super-cache/#faq' ); ?></li>
1277
+ <li><?php printf( __( 'Visit the <a href="%1$s">plugin homepage</a>.', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-super-cache/' ); ?></li>
1278
  <li><?php printf( __( 'Try out the <a href="%1$s">development version</a> for the latest fixes (<a href="%2$s">changelog</a>).', 'wp-super-cache' ), 'https://odd.blog/y/2o', 'https://plugins.trac.wordpress.org/log/wp-super-cache/' ); ?></li>
1279
  </ol>
1280
  <h3><?php _e( 'Rate This Plugin', 'wp-super-cache' ); ?></h3>
1869
  wp_cache_update_rejected_pages();
1870
 
1871
  echo '<a name="rejectpages"></a>';
1872
+ echo '<p>' . __( 'Do not cache the following page types. See the <a href="https://codex.wordpress.org/Conditional_Tags">Conditional Tags</a> documentation for a complete discussion on each type.', 'wp-super-cache' ) . '</p>';
1873
  echo '<form name="wp_edit_rejected_pages" action="#rejectpages" method="post">';
1874
  echo '<input type="hidden" name="wp_edit_rejected_pages" value="1" />';
1875
  echo '<label><input type="checkbox" value="1" name="wp_cache_pages[single]" ' . checked( 1, $wp_cache_pages[ 'single' ], false ) . ' /> ' . __( 'Single Posts', 'wp-super-cache' ) . ' (is_single)</label><br />';
1883
  echo '<label><input type="checkbox" value="1" name="wp_cache_pages[search]" ' . checked( 1, $wp_cache_pages[ 'search' ], false ) . ' /> ' . __( 'Search Pages', 'wp-super-cache' ) . ' (is_search)</label><br />';
1884
  echo '<label><input type="checkbox" value="1" name="wp_cache_pages[author]" ' . checked( 1, $wp_cache_pages[ 'author' ], false ) . ' /> ' . __( 'Author Pages', 'wp-super-cache' ) . ' (is_author)</label><br />';
1885
 
1886
+ echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save Settings', 'wp-super-cache' ) . '" /></div>';
1887
  wp_nonce_field('wp-cache');
1888
  echo "</form>\n";
1889
 
2076
 
2077
  echo "</table>\n";
2078
  }
2079
+ echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save Settings', 'wp-super-cache' ) . '" /></div>';
2080
  wp_nonce_field('wp-cache');
2081
  echo "</form>\n";
2082
  echo '</fieldset>';
2150
  return false;
2151
  }
2152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2153
  function wp_cache_remove_index() {
2154
  global $cache_path;
2155
 
2173
  }
2174
  if ( is_dir( $directory . "/meta" ) ) {
2175
  if ( is_file( $directory . "/meta/index.html" ) ) {
2176
+ unlink( $directory . "/meta/index.html" );
2177
  }
2178
  }
2179
  }
2380
  }
2381
  $new = true;
2382
  }
2383
+ if ( $sem_id == 5419 && $cache_path != '' && $WPSC_HTTP_HOST != '' ) {
2384
  $sem_id = crc32( $WPSC_HTTP_HOST . $cache_path ) & 0x7fffffff;
2385
  wp_cache_replace_line('sem_id', '$sem_id = ' . $sem_id . ';', $wp_cache_config_file);
2386
  }
2479
  }
2480
  return false;
2481
  } else {
2482
+ echo "<div class='notice notice-warning'>" . __( '<h3>WP_CACHE constant added to wp-config.php</h3><p>If you continue to see this warning message please see point 5 of the <a href="https://wordpress.org/plugins/wp-super-cache/faq/">Troubleshooting Guide</a>. The WP_CACHE line must be moved up.', 'wp-super-cache' ) . "</p></div>";
2483
  }
2484
  return true;
2485
  }
3146
  }
3147
  $content_dir_root = $document_root;
3148
  if ( strpos( $document_root, '/kunden/homepages/' ) === 0 ) {
3149
+ // https://wordpress.org/support/topic/plugin-wp-super-cache-how-to-get-mod_rewrite-working-on-1and1-shared-hosting?replies=1
3150
  // On 1and1, PHP's directory structure starts with '/homepages'. The
3151
  // Apache directory structure has an extra '/kunden' before it.
3152
  // Also 1and1 does not support the %{DOCUMENT_ROOT} variable in
3251
  if ( false == @is_dir( $dir ) )
3252
  return false;
3253
 
 
 
 
3254
  wp_cache_debug( "clear_post_supercache: deleting files in $dir", 2 );
3255
  if ( get_post_type( $post_id ) != 'page' ) { // don't delete child pages if they exist
3256
  prune_super_cache( $dir, true );
3268
  return true;
3269
  }
3270
 
 
 
 
 
 
3271
  $mutex = $cache_path . "preload_mutex.tmp";
3272
  sleep( 3 + mt_rand( 1, 5 ) );
3273
  if ( @file_exists( $mutex ) ) {
3550
  if ( $scrules != '' && insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', array() ) ) {
3551
  $wp_rewrite->flush_rules();
3552
  } elseif( $scrules != '' ) {
3553
+ wp_mail( get_option( 'admin_email' ), __( 'Supercache Uninstall Problems', 'wp-super-cache' ), sprintf( __( "Dear User,\n\nWP Super Cache was removed from your blog but the mod_rewrite rules\nin your .htaccess were not.\n\nPlease edit the following file and remove the code\nbetween 'BEGIN WPSuperCache' and 'END WPSuperCache'. Please backup the file first!\n\n%s\n\nRegards,\nWP Super Cache Plugin\nhttps://wordpress.org/plugins/wp-super-cache/", 'wp-super-cache' ), ABSPATH . '/.htaccess' ) );
3554
  }
3555
  }
3556
 
3894
 
3895
  update_option( 'wpsc_feed_list', array() );
3896
  if ( is_array( $wpsc_feed_list ) && ! empty( $wpsc_feed_list ) ) {
 
 
3897
  foreach( $wpsc_feed_list as $file ) {
3898
  wp_cache_debug( "wpsc_feed_update: deleting feed: $file" );
3899
  prune_super_cache( $file, true );