WP Super Cache - Version 1.6.5

Version Description

Download this release

Release Info

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

Code changes from version 1.6.4 to 1.6.5

ossdl-cdn.php CHANGED
@@ -2,36 +2,92 @@
2
 
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
  /**
@@ -44,25 +100,29 @@ if ( $arr_of_cnames[0] == '' ) {
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
  }
50
  }
 
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
 
@@ -72,28 +132,26 @@ function scossdl_string_mod( $str, $mod ) {
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];
@@ -105,28 +163,47 @@ function scossdl_off_rewriter( $match ) {
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
 
@@ -135,28 +212,41 @@ function scossdl_off_filter( $content ) {
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;
@@ -166,78 +256,119 @@ function scossdl_off_update() {
166
  }
167
  }
168
 
 
 
 
169
  function scossdl_off_options() {
170
- global $ossdlcdn, $ossdl_off_blog_url;
 
171
 
172
  scossdl_off_update();
173
 
174
- $example_cdn_uri = str_replace( 'http://', 'http://cdn.', str_replace( 'www.', '', get_option( 'siteurl' ) ) );
175
- $example_cnames = str_replace( 'http://cdn.', 'http://cdn1.', $example_cdn_uri );
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>
185
 
186
- <?php if ( $ossdl_off_blog_url != get_home_url() ) { ?>
187
  <p><?php printf( __( '<strong style="color: red">WARNING:</strong> Your siteurl and homeurl are different. The plugin is using %s as the homepage URL of your site but if that is wrong please use the filter "ossdl_off_blog_url" to fix it.', 'wp-super-cache' ), '<code>' . esc_html( $ossdl_off_blog_url ) . '</code>' ); ?></p>
188
  <?php } ?>
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>
200
  <tr valign="top">
201
- <th scope="row"><label for="ossdl_off_cdn_url"><?php _e( 'Site URL', 'wp-super-cache' ); ?></label></th>
202
  <td>
203
- <input type="text" name="ossdl_off_blog_url" value="<?php echo esc_url( untrailingslashit( get_option( 'ossdl_off_blog_url' ) ) ); ?>" size="64" class="regular-text code" /><br />
204
  <span class="description"><?php _e( 'The URL of your site. No trailing <code>/</code> please.', 'wp-super-cache' ); ?></span>
205
  </td>
206
  </tr>
207
  <tr valign="top">
208
- <th scope="row"><label for="ossdl_off_cdn_url"><?php _e( 'Off-site URL', 'wp-super-cache' ); ?></label></th>
209
  <td>
210
- <input type="text" name="ossdl_off_cdn_url" value="<?php echo esc_url( get_option( 'ossdl_off_cdn_url' ) ); ?>" size="64" class="regular-text code" /><br />
211
- <span class="description"><?php printf( __( 'The new URL to be used in place of %1$s for rewriting. No trailing <code>/</code> please.<br />Example: <code>%2$s</code>.', 'wp-super-cache' ), esc_html( get_option( 'siteurl' ) ), esc_html( $example_cdn_uri ) ); ?></span>
212
  </td>
213
  </tr>
214
  <tr valign="top">
215
- <th scope="row"><label for="ossdl_off_include_dirs"><?php _e( 'Include directories', 'wp-super-cache' ); ?></label></th>
216
  <td>
217
- <input type="text" name="ossdl_off_include_dirs" value="<?php echo esc_attr( get_option( 'ossdl_off_include_dirs' ) ); ?>" size="64" class="regular-text code" /><br />
218
  <span class="description"><?php _e( 'Directories to include in static file matching. Use a comma as the delimiter. Default is <code>wp-content, wp-includes</code>, which will be enforced if this field is left empty.', 'wp-super-cache' ); ?></span>
219
  </td>
220
  </tr>
221
  <tr valign="top">
222
- <th scope="row"><label for="ossdl_off_exclude"><?php _e( 'Exclude if substring', 'wp-super-cache' ); ?></label></th>
223
  <td>
224
- <input type="text" name="ossdl_off_exclude" value="<?php echo esc_attr( get_option( 'ossdl_off_exclude' ) ); ?>" size="64" class="regular-text code" /><br />
225
  <span class="description"><?php _e( 'Excludes something from being rewritten if one of the above strings is found in the URL. Use a comma as the delimiter like this, <code>.php, .flv, .do</code>, and always include <code>.php</code> (default).', 'wp-super-cache' ); ?></span>
226
  </td>
227
  </tr>
228
  <tr valign="top">
229
- <th scope="row"><label for="ossdl_cname"><?php _e( 'Additional CNAMES', 'wp-super-cache' ); ?></label></th>
230
  <td>
231
- <input type="text" name="ossdl_cname" value="<?php echo esc_attr( get_option( 'ossdl_cname' ) ); ?>" size="64" class="regular-text code" /><br />
232
- <span class="description"><?php printf( __( 'These <a href="http://en.wikipedia.org/wiki/CNAME_record">CNAMES</a> will be used in place of %1$s for rewriting (in addition to the off-site URL above). Use a comma as the delimiter. For pages with a large number of static files, this can improve browser performance. CNAMEs may also need to be configured on your CDN.<br />Example: %2$s', 'wp-super-cache' ), esc_html( get_option( 'siteurl' ) ), esc_html( $example_cnames ) ); ?></span>
233
  </td>
234
  </tr>
235
  <tr valign="top">
236
- <th scope="row" colspan='2'><label><input type='checkbox' name='ossdl_https' value='1' <?php if ( get_option( 'ossdl_https' ) ) { echo 'checked'; } ?> /> <?php _e( 'Skip https URLs to avoid "mixed content" errors', 'wp-super-cache' ); ?></label></th>
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
2
 
3
  /* Taken from OSSDL CDN off-linker, a plugin by W-Mark Kubacki (http://mark.ossdl.de/) and used with permission */
4
 
5
+ if ( ! isset( $ossdlcdn ) ) {
6
+ $ossdlcdn = 1; // have to default to on for existing users.
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  }
8
+
9
+ if ( 1 === $ossdlcdn && ! is_admin() ) {
10
+ add_action( 'init', 'do_scossdl_off_ob_start' );
 
11
  }
12
 
13
+ /**
14
+ * Set up some defaults.
15
+ *
16
+ * @global string $ossdl_off_blog_url
17
+ * @global string $ossdl_off_cdn_url
18
+ * @global string $ossdl_cname
19
+ * @global int $ossdl_https
20
+ * @global array $ossdl_off_include_dirs
21
+ * @global array $ossdl_off_excludes
22
+ * @global array $ossdl_arr_of_cnames
23
+ *
24
+ * @return void
25
+ */
26
+ function scossdl_off_get_options() {
27
+ global $ossdl_off_blog_url, $ossdl_off_cdn_url, $ossdl_cname, $ossdl_https;
28
+ global $ossdl_off_include_dirs, $ossdl_off_excludes, $ossdl_arr_of_cnames;
29
+
30
+ $ossdl_off_blog_url = get_option( 'ossdl_off_blog_url' );
31
+ if ( false === $ossdl_off_blog_url ) {
32
+ $ossdl_off_blog_url = untrailingslashit( get_site_url() );
33
+ add_option( 'ossdl_off_blog_url', $ossdl_off_blog_url );
34
+ }
35
+
36
+ if ( has_filter( 'ossdl_off_blog_url' ) ) {
37
+ $ossdl_off_blog_url = untrailingslashit( apply_filters( 'ossdl_off_blog_url', $ossdl_off_blog_url ) );
38
+ }
39
+
40
+ $ossdl_off_cdn_url = get_option( 'ossdl_off_cdn_url' );
41
+ if ( false === $ossdl_off_cdn_url ) {
42
+ $ossdl_off_cdn_url = untrailingslashit( get_site_url() );
43
+ add_option( 'ossdl_off_cdn_url', $ossdl_off_cdn_url );
44
+ }
45
+
46
+ $include_dirs = get_option( 'ossdl_off_include_dirs' );
47
+ if ( false !== $include_dirs ) {
48
+ $ossdl_off_include_dirs = array_filter( array_map( 'trim', explode( ',', $include_dirs ) ) );
49
+ } else {
50
+ $ossdl_off_include_dirs = scossdl_off_default_inc_dirs();
51
+ add_option( 'ossdl_off_include_dirs', implode( ',', $ossdl_off_include_dirs ) );
52
+ }
53
+
54
+ $exclude = get_option( 'ossdl_off_exclude' );
55
+ if ( false !== $exclude ) {
56
+ $ossdl_off_excludes = array_filter( array_map( 'trim', explode( ',', $exclude ) ) );
57
+ } else {
58
+ $ossdl_off_excludes = array( '.php' );
59
+ add_option( 'ossdl_off_exclude', implode( ',', $ossdl_off_excludes ) );
60
+ }
61
+
62
+ $ossdl_cname = get_option( 'ossdl_cname' );
63
+ if ( false !== $ossdl_cname ) {
64
+ $ossdl_cname = trim( $ossdl_cname );
65
+ } else {
66
+ $ossdl_cname = '';
67
+ add_option( 'ossdl_cname', $ossdl_cname );
68
+ }
69
+ $ossdl_arr_of_cnames = array_filter( array_map( 'trim', explode( ',', $ossdl_cname ) ) );
70
+
71
+ $ossdl_https = intval( get_option( 'ossdl_https' ) );
72
  }
73
+
74
+ /**
75
+ * Get default directories.
76
+ *
77
+ * @return array
78
+ */
79
+ function scossdl_off_default_inc_dirs() {
80
+
81
+ $home_path = trailingslashit( (string) parse_url( get_option( 'siteurl' ), PHP_URL_PATH ) );
82
+ $inc_dirs = array();
83
+
84
+ foreach ( array( content_url(), includes_url() ) as $dir ) {
85
+ $dir = wp_make_link_relative( $dir );
86
+ $dir = preg_replace( '`^' . preg_quote( $home_path, '`' ) . '`', '', $dir );
87
+ $inc_dirs[] = trim( $dir, '/' );
88
+ }
89
+
90
+ return $inc_dirs;
91
  }
92
 
93
  /**
100
  */
101
  function scossdl_off_exclude_match( $match, $excludes ) {
102
  foreach ( $excludes as $badword ) {
103
+ if ( false !== stripos( $match, $badword ) ) {
104
  return true;
105
  }
106
  }
107
+
108
  return false;
109
  }
110
 
111
  /**
112
  * Compute string modulo, based on SHA1 hash
113
  *
114
+ * @param string $str The string.
115
+ * @param int $mod The divisor.
116
  *
117
+ * @return int The remainder.
118
  */
119
  function scossdl_string_mod( $str, $mod ) {
120
+ /**
121
+ * The full SHA1 is too large for PHP integer types.
122
+ * This should be enough for our purpose.
123
+ */
124
  $num = hexdec( substr( sha1( $str ), 0, 5 ) );
125
+
126
  return $num % $mod;
127
  }
128
 
132
  * Called by #scossdl_off_filter.
133
  */
134
  function scossdl_off_rewriter( $match ) {
135
+ global $ossdl_off_blog_url, $ossdl_https, $ossdl_off_excludes, $ossdl_arr_of_cnames;
136
+ static $count_cnames = null, $include_dirs = null;
137
 
138
+ // Set up static variables. Run once only.
139
+ if ( ! isset( $count_cnames ) ) {
140
+ $count_cnames = count( $ossdl_arr_of_cnames );
141
+ $include_dirs = scossdl_off_additional_directories();
142
  }
143
 
144
+ if ( $ossdl_https && 0 === strpos( $match[0], 'https' ) ) {
145
  return $match[0];
146
  }
147
 
148
+ if ( scossdl_off_exclude_match( $match[0], $ossdl_off_excludes ) ) {
 
 
 
 
149
  return $match[0];
150
  }
151
 
152
+ if ( preg_match( '`(' . $include_dirs . ')`', $match[0] ) ) {
153
+ $offset = scossdl_string_mod( $match[1], $count_cnames );
154
+ return str_replace( $ossdl_off_blog_url, $ossdl_arr_of_cnames[ $offset ], $match[0] );
 
155
  }
156
 
157
  return $match[0];
163
  * @return String with the pattern with {@literal |} as prefix, or empty
164
  */
165
  function scossdl_off_additional_directories() {
166
+ global $ossdl_off_include_dirs;
167
 
168
+ $arr_dirs = array();
169
+ foreach ( $ossdl_off_include_dirs as $dir ) {
170
+ $arr_dirs[] = preg_quote( trim( $dir ), '`' );
171
+ }
172
 
173
+ return implode( '|', $arr_dirs );
174
  }
175
 
176
  /**
177
  * Output filter which runs the actual plugin logic.
178
+ *
179
+ * @param string $content The content of the output buffer.
180
+ *
181
+ * @return string The rewritten content.
182
  */
183
  function scossdl_off_filter( $content ) {
184
  global $ossdl_off_blog_url, $ossdl_off_cdn_url;
185
+ global $ossdl_off_include_dirs, $ossdl_off_excludes, $ossdl_arr_of_cnames;
186
+
187
+ if ( empty( $content ) || empty( $ossdl_off_cdn_url ) ||
188
+ $ossdl_off_blog_url === $ossdl_off_cdn_url
189
+ ) {
190
+ return $content; // no rewrite needed.
191
+ }
192
+
193
+ if ( empty( $ossdl_off_include_dirs ) || ! is_array( $ossdl_off_include_dirs ) ) {
194
+ $ossdl_off_include_dirs = scossdl_off_default_inc_dirs();
195
+ }
196
 
197
+ if ( empty( $ossdl_off_excludes ) || ! is_array( $ossdl_off_excludes ) ) {
198
+ $ossdl_off_excludes = array();
199
+ }
200
+
201
+ if ( ! in_array( $ossdl_off_cdn_url, (array) $ossdl_arr_of_cnames, true ) ) {
202
+ $ossdl_arr_of_cnames = array_merge( array( $ossdl_off_cdn_url ), (array) $ossdl_arr_of_cnames );
203
  }
204
 
205
  $dirs = scossdl_off_additional_directories();
206
+ $regex = '`(?<=[(\"\'])' . preg_quote( $ossdl_off_blog_url, '`' ) . '/(?:((?:' . $dirs . ')[^\"\')]+)|([^/\"\']+\.[^/\"\')]+))(?=[\"\')])`';
207
  return preg_replace_callback( $regex, 'scossdl_off_rewriter', $content );
208
  }
209
 
212
  */
213
  function do_scossdl_off_ob_start() {
214
  global $ossdl_off_blog_url, $ossdl_off_cdn_url;
215
+
216
+ if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) {
217
+ return;
218
+ }
219
+
220
+ scossdl_off_get_options();
221
+
222
+ if ( ! empty( $ossdl_off_cdn_url ) &&
223
+ $ossdl_off_blog_url !== $ossdl_off_cdn_url
224
+ ) {
225
  add_filter( 'wp_cache_ob_callback_filter', 'scossdl_off_filter' );
226
  }
227
  }
 
 
 
 
 
 
228
 
229
+ /**
230
+ * Update CDN settings to the options database table.
231
+ */
232
  function scossdl_off_update() {
233
 
234
  if ( isset( $_POST['action'], $_POST['_wpnonce'] )
235
+ && 'update_ossdl_off' === $_POST['action'] // WPCS: sanitization ok.
236
  && wp_verify_nonce( $_POST['_wpnonce'], 'wp-cache' )
237
  ) {
238
+ update_option( 'ossdl_off_cdn_url', untrailingslashit( wp_unslash( $_POST['ossdl_off_cdn_url'] ) ) ); // WPSC: sanitization ok.
239
+ update_option( 'ossdl_off_blog_url', untrailingslashit( wp_unslash( $_POST['ossdl_off_blog_url'] ) ) ); // WPSC: sanitization ok.
240
+
241
+ if ( empty( $_POST['ossdl_off_include_dirs'] ) ) {
242
+ $include_dirs = implode( ',', scossdl_off_default_inc_dirs() );
243
+ } else {
244
+ $include_dirs = sanitize_text_field( wp_unslash( $_POST['ossdl_off_include_dirs'] ) ); // WPSC: validation ok,sanitization ok.
245
+ }
246
+ update_option( 'ossdl_off_include_dirs', $include_dirs );
247
+
248
+ update_option( 'ossdl_off_exclude', sanitize_text_field( wp_unslash( $_POST['ossdl_off_exclude'] ) ) ); // WPSC: sanitization ok.
249
+ update_option( 'ossdl_cname', sanitize_text_field( wp_unslash( $_POST['ossdl_cname'] ) ) ); // WPSC: sanitization ok.
250
 
251
  $ossdl_https = empty( $_POST['ossdl_https'] ) ? 0 : 1;
252
  $ossdlcdn = empty( $_POST['ossdlcdn'] ) ? 0 : 1;
256
  }
257
  }
258
 
259
+ /**
260
+ * Show CDN settings.
261
+ */
262
  function scossdl_off_options() {
263
+ global $ossdlcdn, $ossdl_off_blog_url, $ossdl_off_cdn_url, $ossdl_cname, $ossdl_https;
264
+ global $ossdl_off_include_dirs, $ossdl_off_excludes;
265
 
266
  scossdl_off_update();
267
 
268
+ scossdl_off_get_options();
269
+
270
+ $example_cdn_uri = ( is_ssl() ? 'https' : 'http' ) . '://cdn.' . preg_replace( '`^(https?:)?//(www\.)?`', '', get_site_url() );
271
+ $example_cnames = str_replace( '://cdn.', '://cdn1.', $example_cdn_uri );
272
+ $example_cnames .= ',' . str_replace( '://cdn.', '://cdn2.', $example_cdn_uri );
273
+ $example_cnames .= ',' . str_replace( '://cdn.', '://cdn3.', $example_cdn_uri );
274
 
275
+ $example_cdn_uri = ( get_site_url() === $ossdl_off_cdn_url ) ? $example_cdn_uri : $ossdl_off_cdn_url;
276
  $example_cdn_uri .= '/wp-includes/js/jquery/jquery-migrate.js';
277
  $example_cdn_uri = esc_url( $example_cdn_uri );
278
  ?>
279
+ <h3><?php _e( 'Jetpack CDN' ); ?></h3>
280
+ <p><?php printf(
281
+ __( 'The free %1$sJetpack plugin%2$s has a %3$sSite Accelerator%2$s feature that is easier to use than the CDN functionality in this plugin. However files will be cached "forever" and will not update if you update the local file. Files will need to be renamed to refresh them. The %3$sJetpack documentation%2$s explains more about this.', 'wp-super-cache' ),
282
+ '<a href="https://jetpack.com/">',
283
+ '</a>',
284
+ '<a href="https://jetpack.com/support/site-accelerator/">'
285
+ ); ?></p>
286
+ <?php
287
+ if ( class_exists( 'Jetpack' ) ) {
288
+ if ( Jetpack::is_module_active( 'photon' ) ) {
289
+ ?><p><strong><?php printf(
290
+ __( 'You already have Jetpack installed and %1$sSite Accelerator%2$s enabled on this blog. The CDN here is disabled to avoid conflicts with Jetpack.', 'wp-super-cache' ),
291
+ '<a href="https://jetpack.com/support/site-accelerator/">',
292
+ '</a>'
293
+ ); ?></strong></p><?php
294
+ } else {
295
+ ?><p><?php printf(
296
+ __( 'You already have Jetpack installed but %1$sSite Accelerator%2$s is disabled on this blog. Enable it on the %3$sJetpack settings page%2$s.', 'wp-super-cache' ),
297
+ '<a href="https://jetpack.com/support/site-accelerator/">',
298
+ '</a>',
299
+ '<a href="' . admin_url( 'admin.php?page=jetpack#/settings' ) . '">'
300
+ ); ?></p><?php
301
+ }
302
+ } else {
303
+ ?><p><strong><?php printf(
304
+ __( '%1$sJetpack%2$s was not found on your site but %3$syou can install it%2$s. The Site Accelerator feature is free to use on any WordPress site and offers the same benefit as other CDN services. You should give it a try!', 'wp-super-cache' ),
305
+ '<a href="https://jetpack.com/">',
306
+ '</a>',
307
+ '<a href="' . admin_url( 'plugin-install.php?s=jetpack&tab=search&type=term' ) . '">'
308
+ ); ?></strong></p><?php
309
+ }
310
+ if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) {
311
+ return;
312
+ }
313
+ ?>
314
+ <h3><?php _e( 'Simple CDN' ); ?></h3>
315
  <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>
316
  <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>
317
 
318
+ <?php if ( get_home_url() !== $ossdl_off_blog_url ) { ?>
319
  <p><?php printf( __( '<strong style="color: red">WARNING:</strong> Your siteurl and homeurl are different. The plugin is using %s as the homepage URL of your site but if that is wrong please use the filter "ossdl_off_blog_url" to fix it.', 'wp-super-cache' ), '<code>' . esc_html( $ossdl_off_blog_url ) . '</code>' ); ?></p>
320
  <?php } ?>
321
+ <p><?php esc_html_e( 'You can define different CDN URLs for each site on a multsite network.', 'wp-super-cache' ); ?></p>
 
322
  <p><form method="post" action="">
323
  <?php wp_nonce_field( 'wp-cache' ); ?>
324
  <table class="form-table"><tbody>
325
  <tr valign="top">
326
  <td style='text-align: right'>
327
+ <input id='ossdlcdn' type="checkbox" name="ossdlcdn" value="1" <?php checked( $ossdlcdn ); ?> />
328
  </td>
329
+ <th scope="row"><label for="ossdlcdn"><?php esc_html_e( 'Enable CDN Support', 'wp-super-cache' ); ?></label></th>
330
  </tr>
331
  <tr valign="top">
332
+ <th scope="row"><label for="ossdl_off_cdn_url"><?php esc_html_e( 'Site URL', 'wp-super-cache' ); ?></label></th>
333
  <td>
334
+ <input type="text" name="ossdl_off_blog_url" value="<?php echo esc_attr( untrailingslashit( $ossdl_off_blog_url ) ); ?>" size="64" class="regular-text code" /><br />
335
  <span class="description"><?php _e( 'The URL of your site. No trailing <code>/</code> please.', 'wp-super-cache' ); ?></span>
336
  </td>
337
  </tr>
338
  <tr valign="top">
339
+ <th scope="row"><label for="ossdl_off_cdn_url"><?php esc_html_e( 'Off-site URL', 'wp-super-cache' ); ?></label></th>
340
  <td>
341
+ <input type="text" name="ossdl_off_cdn_url" value="<?php echo esc_attr( $ossdl_off_cdn_url ); ?>" size="64" class="regular-text code" /><br />
342
+ <span class="description"><?php printf( __( 'The new URL to be used in place of %1$s for rewriting. No trailing <code>/</code> please.<br />Example: <code>%2$s</code>.', 'wp-super-cache' ), esc_html( get_site_url() ), esc_html( $example_cdn_uri ) ); ?></span>
343
  </td>
344
  </tr>
345
  <tr valign="top">
346
+ <th scope="row"><label for="ossdl_off_include_dirs"><?php esc_html_e( 'Include directories', 'wp-super-cache' ); ?></label></th>
347
  <td>
348
+ <input type="text" name="ossdl_off_include_dirs" value="<?php echo esc_attr( implode( ',', $ossdl_off_include_dirs ) ); ?>" size="64" class="regular-text code" /><br />
349
  <span class="description"><?php _e( 'Directories to include in static file matching. Use a comma as the delimiter. Default is <code>wp-content, wp-includes</code>, which will be enforced if this field is left empty.', 'wp-super-cache' ); ?></span>
350
  </td>
351
  </tr>
352
  <tr valign="top">
353
+ <th scope="row"><label for="ossdl_off_exclude"><?php esc_html_e( 'Exclude if substring', 'wp-super-cache' ); ?></label></th>
354
  <td>
355
+ <input type="text" name="ossdl_off_exclude" value="<?php echo esc_attr( implode( ',', $ossdl_off_excludes ) ); ?>" size="64" class="regular-text code" /><br />
356
  <span class="description"><?php _e( 'Excludes something from being rewritten if one of the above strings is found in the URL. Use a comma as the delimiter like this, <code>.php, .flv, .do</code>, and always include <code>.php</code> (default).', 'wp-super-cache' ); ?></span>
357
  </td>
358
  </tr>
359
  <tr valign="top">
360
+ <th scope="row"><label for="ossdl_cname"><?php esc_html_e( 'Additional CNAMES', 'wp-super-cache' ); ?></label></th>
361
  <td>
362
+ <input type="text" name="ossdl_cname" value="<?php echo esc_attr( $ossdl_cname ); ?>" size="64" class="regular-text code" /><br />
363
+ <span class="description"><?php printf( __( 'These <a href="https://www.wikipedia.org/wiki/CNAME_record">CNAMES</a> will be used in place of %1$s for rewriting (in addition to the off-site URL above). Use a comma as the delimiter. For pages with a large number of static files, this can improve browser performance. CNAMEs may also need to be configured on your CDN.<br />Example: %2$s', 'wp-super-cache' ), esc_html( get_site_url() ), esc_html( $example_cnames ) ); ?></span>
364
  </td>
365
  </tr>
366
  <tr valign="top">
367
+ <th scope="row" colspan='2'><label><input type='checkbox' name='ossdl_https' value='1' <?php checked( $ossdl_https ); ?> /><?php esc_html_e( 'Skip https URLs to avoid "mixed content" errors', 'wp-super-cache' ); ?></label></th>
368
  </tr>
369
  </tbody></table>
370
  <input type="hidden" name="action" value="update_ossdl_off" />
371
+ <p class="submit"><input type="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'wp-super-cache' ); ?>" /></p>
372
  </form></p>
373
  <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>
374
  <?php
plugins/domain-mapping.php CHANGED
@@ -4,16 +4,15 @@ 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 = '';
@@ -21,20 +20,17 @@ function domain_mapping_gc_cache( $function, $directory ) {
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;
34
  }
35
 
36
  function domain_mapping_supercachedir( $dir ) {
37
  global $cache_path;
 
38
  if ( ! function_exists( 'domain_mapping_warning' ) ) {
39
  return $dir;
40
  }
@@ -44,56 +40,62 @@ function domain_mapping_supercachedir( $dir ) {
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
  }
 
 
 
58
  }
59
  add_cacheaction( 'add_cacheaction', 'domain_mapping_actions' );
60
 
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>
98
  <?php
99
  }
@@ -101,14 +103,17 @@ add_cacheaction( 'cache_admin_page', 'wp_supercache_domain_mapping_admin' );
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' ) ) {
@@ -124,8 +129,8 @@ 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
  }
4
  global $cache_path;
5
 
6
  if ( ! function_exists( 'domain_mapping_warning' ) ) {
7
+ return;
8
  }
9
 
10
  $siteurl = domain_mapping_siteurl( false );
11
  if ( ! $siteurl ) {
12
+ return;
13
  }
14
 
15
+ $sitedir = trailingslashit( preg_replace( '`^(https?:)?//`', '', $siteurl ) );
 
16
 
17
  if ( 'homepage' === $directory ) {
18
  $directory = '';
20
 
21
  switch ( $function ) {
22
  case 'rebuild':
23
+ wpsc_rebuild_files( $cache_path . 'supercache/' . $sitedir . $directory );
 
24
  break;
25
  case 'prune':
26
+ wpsc_delete_files( $cache_path . 'supercache/' . $sitedir . $directory );
 
27
  break;
28
  }
 
 
29
  }
30
 
31
  function domain_mapping_supercachedir( $dir ) {
32
  global $cache_path;
33
+
34
  if ( ! function_exists( 'domain_mapping_warning' ) ) {
35
  return $dir;
36
  }
40
  return $dir;
41
  }
42
 
43
+ $sitedir = trailingslashit( preg_replace( '`^(https?:)?//`', '', $siteurl ) );
44
+
45
+ return trailingslashit( $cache_path . 'supercache/' . $sitedir );
46
  }
47
 
48
  function domain_mapping_actions() {
49
  global $cache_domain_mapping;
50
+
51
+ $cache_domain_mapping = (int) $cache_domain_mapping;
52
+ if ( 1 !== $cache_domain_mapping ) {
53
+ return;
54
  }
55
+
56
+ add_filter( 'wp_super_cache_supercachedir', 'domain_mapping_supercachedir' );
57
+ add_action( 'gc_cache', 'domain_mapping_gc_cache', 10, 2 );
58
  }
59
  add_cacheaction( 'add_cacheaction', 'domain_mapping_actions' );
60
 
61
  function wp_supercache_domain_mapping_admin() {
62
  global $cache_domain_mapping, $wp_cache_config_file, $valid_nonce;
63
 
64
+ $requested_state = isset( $_POST['cache_domain_mapping'] ) ? (int) $_POST['cache_domain_mapping'] : null;
65
+ $cache_domain_mapping = (int) $cache_domain_mapping;
66
 
67
+ $changed = false;
68
+ if ( null !== $requested_state && $valid_nonce ) {
69
+ $cache_domain_mapping = $requested_state;
70
+
71
+ wp_cache_replace_line( '^\s*\$cache_domain_mapping\s*=', '$cache_domain_mapping = ' . intval( $cache_domain_mapping ) . ';', $wp_cache_config_file );
72
+ $changed = true;
 
 
73
  }
74
+
75
  $id = 'domain_mapping-section';
76
  ?>
77
+ <fieldset id="<?php echo esc_attr( $id ); ?>" class="options">
78
+
79
+ <h4><?php esc_html_e( 'Domain Mapping', 'wp-super-cache' ); ?></h4>
80
+
81
  <form name="wp_manager" action="" method="post">
82
+ <label><input type="radio" name="cache_domain_mapping" value="1" <?php checked( $cache_domain_mapping ); ?>/> <?php esc_html_e( 'Enabled', 'wp-super-cache' ); ?></label>
83
+ <label><input type="radio" name="cache_domain_mapping" value="0" <?php checked( ! $cache_domain_mapping ); ?>/> <?php esc_html_e( 'Disabled', 'wp-super-cache' ); ?></label>
84
+ <?php
85
+ 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>';
86
+
87
+ if ( $changed ) {
88
+ echo '<p><strong>' . sprintf(
89
+ esc_html__( 'Domain Mapping support is now %s', 'wp-super-cache' ),
90
+ esc_html( $cache_domain_mapping ? __( 'enabled', 'wp-super-cache' ) : __( 'disabled', 'wp-super-cache' ) )
91
+ ) . '</strong></p>';
92
  }
93
+
94
+ echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . ' type="submit" value="' . esc_html__( 'Update', 'wp-super-cache' ) . '" /></div>';
95
+ wp_nonce_field( 'wp-cache' );
96
+ ?>
97
+ </form>
98
+
99
  </fieldset>
100
  <?php
101
  }
103
 
104
  function wp_supercache_domain_mapping_notice() {
105
  global $cache_enabled;
106
+
107
  if ( $cache_enabled ) {
108
+ echo '<div class="error"><p><strong>' . esc_html__( 'Domain Mapping plugin detected! Please go to the Supercache plugins page and enable the domain mapping helper plugin.', 'wp-super-cache' ) . '</strong></p></div>';
109
  }
110
  }
111
  function wp_supercache_domain_mapping_exists() {
112
  global $cache_domain_mapping;
113
+
114
+ $cache_domain_mapping = (int) $cache_domain_mapping;
115
+ if ( 1 === $cache_domain_mapping ) {
116
+ return;
117
  }
118
 
119
  if ( is_admin() && function_exists( 'domain_mapping_warning' ) ) {
129
  $list['domain_mapping'] = array(
130
  'key' => 'domain_mapping',
131
  'url' => 'https://wordpress.org/plugins/wordpress-mu-domain-mapping/',
132
+ 'title' => esc_html__( 'Domain Mapping', 'wp-super-cache' ),
133
+ 'desc' => esc_html__( 'Provides support for Domain Mapping plugin to map multiple domains to a blog.', 'wp-super-cache' ),
134
  );
135
  return $list;
136
  }
plugins/multisite.php CHANGED
@@ -1,6 +1,6 @@
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
 
1
  <?php
2
 
3
+ if ( is_multisite() ) {
4
  add_cacheaction( 'add_cacheaction', 'wp_super_cache_multisite_init' );
5
  }
6
 
readme.txt CHANGED
@@ -1,8 +1,8 @@
1
  # WP Super Cache #
2
  * Contributors: donncha, automattic, kraftbj
3
  * Tags: performance, caching, wp-cache, wp-super-cache, cache
4
- * Tested up to: 4.9.8
5
- * Stable tag: 1.6.4
6
  * Requires at least: 3.1
7
  * Requires PHP: 5.2.4
8
  * License: GPLv2 or later
@@ -266,6 +266,28 @@ Your theme is probably responsive which means it resizes the page to suit whatev
266
 
267
  ## Changelog ##
268
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  ### 1.6.4 ###
270
  * Changes between [1.6.3 and 1.6.4](https://github.com/Automattic/wp-super-cache/compare/1.6.3...1.6.4)
271
  * Fixes for WP-CLI (#587) (#592)
@@ -691,4 +713,4 @@ Your theme is probably responsive which means it resizes the page to suit whatev
691
 
692
 
693
  ## Upgrade Notice ##
694
- Bug fixes
1
  # WP Super Cache #
2
  * Contributors: donncha, automattic, kraftbj
3
  * Tags: performance, caching, wp-cache, wp-super-cache, cache
4
+ * Tested up to: 5.1.1
5
+ * Stable tag: 1.6.5
6
  * Requires at least: 3.1
7
  * Requires PHP: 5.2.4
8
  * License: GPLv2 or later
266
 
267
  ## Changelog ##
268
 
269
+ ### 1.6.5 ###
270
+ * Check advanced-cache.php was created by the plugin before modifying/deleting it. (#666)
271
+ * When saving settings, save blank lines. Fixes problems with WP_CACHE and WPCACHEHOME in wp-config.php. Related to #652. (#667)
272
+ * Update outdated code and use is_multisite() (#600)
273
+ * Fix the delete cache button in the admin bar. (#603)
274
+ * Code cleanup in #602
275
+ * Use get_post_status instead of post_status (#623)
276
+ * Fixes button - Update Direct Pages (#622)
277
+ * Removes apache_response_headers and uses only headers_list (#618)
278
+ * Function is_site_admin has been deprecated (#611)
279
+ * Fixes action urls in wp_cache_manager (#610)
280
+ * Remove the link to the HibbsLupusTrust tweet. (#635)
281
+ * Don't load wp-cache-config.php if it's already loaded (#605)
282
+ * PHPCS fixes and optimization for plugins/domain-mapping.php (#615)
283
+ * Introduces PHP_VERSION_ID for faster checking (#604)
284
+ * Fixes regex and optimizes ossdl-cdn.php (#596)
285
+ * Only update new settings and use a temporary file to avoid corruption. (#652)
286
+ * Serve cached files to rejected user agents, don't cache them. (#658)
287
+ * Combine multiple headers with the same name (#641)
288
+ * Open ‘Delete Cache’ link in same window (#656)
289
+ * Promote the Jetpack Site Accelerator on the CDN page. (#636)
290
+
291
  ### 1.6.4 ###
292
  * Changes between [1.6.3 and 1.6.4](https://github.com/Automattic/wp-super-cache/compare/1.6.3...1.6.4)
293
  * Fixes for WP-CLI (#587) (#592)
713
 
714
 
715
  ## Upgrade Notice ##
716
+ Many bug fixes
wp-cache-base.php CHANGED
@@ -1,8 +1,9 @@
1
  <?php
2
- global $WPSC_HTTP_HOST, $blogcacheid;
3
 
4
  if ( ! empty( $_SERVER['HTTP_HOST'] ) ) {
5
- $WPSC_HTTP_HOST = htmlentities( $_SERVER['HTTP_HOST'] );
 
6
  } elseif ( PHP_SAPI === 'cli' && function_exists( 'get_option' ) ) {
7
  $WPSC_HTTP_HOST = (string) parse_url( get_option( 'home' ), PHP_URL_HOST );
8
  } else {
@@ -11,29 +12,36 @@ if ( ! empty( $_SERVER['HTTP_HOST'] ) ) {
11
  }
12
 
13
  // We want to be able to identify each blog in a WordPress MU install
14
- $blogcacheid = '';
15
- if ( ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) || defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) ) {
16
- $blogcacheid = 'blog'; // main blog
17
- if ( defined( 'SUBDOMAIN_INSTALL' ) && constant( 'SUBDOMAIN_INSTALL' ) == true ) {
 
 
 
 
 
18
  $blogcacheid = $WPSC_HTTP_HOST;
19
  } else {
20
- if ( isset( $base ) == false ) {
21
- $base = '';
22
- }
23
  $request_uri = str_replace( '..', '', preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI'] ) );
24
- if ( strlen( $request_uri ) > 0 && strpos( $request_uri, '/', 1 ) ) {
25
- if ( $base == '/' ) {
26
- $blogcacheid = substr( $request_uri, 1, strpos( $request_uri, '/', 1 ) - 1 );
27
- } else {
28
- $blogcacheid = str_replace( $base, '', $request_uri );
29
- if ( $blogcacheid != '' ) {
30
- $blogcacheid = substr( $blogcacheid, 0, strpos( $blogcacheid, '/', 1 ) );
31
- }
32
- }
33
- if ( '/' == substr( $blogcacheid, -1 ) ) {
34
- $blogcacheid = substr( $blogcacheid, 0, -1 );
35
- }
36
  }
37
- $blogcacheid = str_replace( '/', '', $blogcacheid );
 
 
 
 
 
 
 
 
 
 
38
  }
 
39
  }
1
  <?php
2
+ global $WPSC_HTTP_HOST, $cache_enabled, $cache_path, $blogcacheid, $blog_cache_dir;
3
 
4
  if ( ! empty( $_SERVER['HTTP_HOST'] ) ) {
5
+ $WPSC_HTTP_HOST = function_exists( 'mb_strtolower' ) ? mb_strtolower( $_SERVER['HTTP_HOST'] ) : strtolower( $_SERVER['HTTP_HOST'] );
6
+ $WPSC_HTTP_HOST = htmlentities( $WPSC_HTTP_HOST );
7
  } elseif ( PHP_SAPI === 'cli' && function_exists( 'get_option' ) ) {
8
  $WPSC_HTTP_HOST = (string) parse_url( get_option( 'home' ), PHP_URL_HOST );
9
  } else {
12
  }
13
 
14
  // We want to be able to identify each blog in a WordPress MU install
15
+ $blogcacheid = '';
16
+ $blog_cache_dir = $cache_path;
17
+
18
+ if ( is_multisite() ) {
19
+ global $current_blog;
20
+
21
+ if ( is_object( $current_blog ) && function_exists( 'is_subdomain_install' ) ) {
22
+ $blogcacheid = is_subdomain_install() ? $current_blog->domain : trim( $current_blog->path, '/' );
23
+ } elseif ( ( defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) || ( defined( 'VHOST' ) && VHOST === 'yes' ) ) {
24
  $blogcacheid = $WPSC_HTTP_HOST;
25
  } else {
 
 
 
26
  $request_uri = str_replace( '..', '', preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI'] ) );
27
+ $request_uri = str_replace( '//', '/', $request_uri );
28
+
29
+ $wpsc_path_segs = array_filter( explode( '/', trim( $request_uri, '/' ) ) );
30
+ $wpsc_base_count = defined( 'PATH_CURRENT_SITE' ) ? count( array_filter( explode( '/', trim( PATH_CURRENT_SITE, '/' ) ) ) ) : 0;
31
+ if ( '/' !== substr( $request_uri, -1 ) ) {
32
+ $wpsc_path_segs = array_slice( $wpsc_path_segs, 0, -1 );
 
 
 
 
 
 
33
  }
34
+
35
+ if ( count( $wpsc_path_segs ) > $wpsc_base_count &&
36
+ ( ! defined( 'PATH_CURRENT_SITE' ) || 0 === strpos( $request_uri, PATH_CURRENT_SITE ) )
37
+ ) {
38
+ $blogcacheid = $wpsc_path_segs[ $wpsc_base_count ];
39
+ }
40
+ }
41
+
42
+ // If blogcacheid is empty then set it to main blog.
43
+ if ( empty( $blogcacheid ) ) {
44
+ $blogcacheid = 'blog';
45
  }
46
+ $blog_cache_dir = str_replace( '//', '/', $cache_path . 'blogs/' . $blogcacheid . '/' );
47
  }
wp-cache-config-sample.php CHANGED
@@ -76,7 +76,6 @@ $wp_cache_pages[ "author" ] = 0;
76
  $wp_cache_hide_donation = 0;
77
  $wp_cache_not_logged_in = 0;
78
  $wp_cache_clear_on_post_edit = 0;
79
- $wp_cache_hello_world = 0;
80
  $wp_cache_mobile_enabled = 0;
81
  $wp_cache_cron_check = 0;
82
  $wp_cache_mfunc_enabled = 0;
76
  $wp_cache_hide_donation = 0;
77
  $wp_cache_not_logged_in = 0;
78
  $wp_cache_clear_on_post_edit = 0;
 
79
  $wp_cache_mobile_enabled = 0;
80
  $wp_cache_cron_check = 0;
81
  $wp_cache_mfunc_enabled = 0;
wp-cache-phase2.php CHANGED
@@ -52,11 +52,6 @@ function wp_cache_serve_cache_file() {
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;
@@ -226,10 +221,11 @@ function wp_cache_serve_cache_file() {
226
  } else {
227
  $ungzip = false;
228
  }
229
- foreach ($meta[ 'headers' ] as $t => $header) {
230
  // 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/
231
- if( strpos( $header, 'Last-Modified:' ) === false )
232
- header($header);
 
233
  }
234
  if ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
235
  header( 'X-WP-Super-Cache: Served WPCache cache file' );
@@ -825,7 +821,7 @@ function get_oc_key( $url = false ) {
825
  global $wp_cache_gzip_encoding, $WPSC_HTTP_HOST;
826
 
827
  if ( $url ) {
828
- $key = intval( $_SERVER[ 'SERVER_PORT' ] ) . strtolower( preg_replace( '/:.*$/', '', $WPSC_HTTP_HOST ) ) . $url;
829
  } else {
830
  $key = get_current_url_supercache_dir();
831
  }
@@ -1109,13 +1105,23 @@ function wp_cache_replace_line( $old, $new, $my_file ) {
1109
  }
1110
  }
1111
  foreach( (array) $lines as $line ) {
1112
- if ( preg_match("/$old/", $line)) {
 
 
 
 
 
 
 
1113
  $found = true;
1114
- break;
1115
  }
1116
  }
1117
 
1118
- $fd = fopen( $my_file, 'w' );
 
 
 
 
1119
  if ( ! $fd ) {
1120
  if ( function_exists( 'set_transient' ) ) {
1121
  set_transient( 'wpsc_config_error', 'config_file_ro', 10 );
@@ -1144,6 +1150,8 @@ function wp_cache_replace_line( $old, $new, $my_file ) {
1144
  }
1145
  }
1146
  fclose( $fd );
 
 
1147
 
1148
  if ( function_exists( "opcache_invalidate" ) ) {
1149
  @opcache_invalidate( $my_file );
@@ -1160,6 +1168,11 @@ function wp_cache_phase2() {
1160
  return false;
1161
  }
1162
 
 
 
 
 
 
1163
  wp_cache_debug( 'In WP Cache Phase 2', 5 );
1164
 
1165
  $wp_cache_gmt_offset = get_option( 'gmt_offset' ); // caching for later use when wpdb is gone. https://wordpress.org/support/topic/224349
@@ -1374,79 +1387,83 @@ function wp_cache_user_agent_is_rejected() {
1374
 
1375
  function wp_cache_get_response_headers() {
1376
  static $known_headers = array(
1377
- 'Access-Control-Allow-Origin',
1378
- 'Accept-Ranges',
1379
- 'Age',
1380
- 'Allow',
1381
- 'Cache-Control',
1382
- 'Connection',
1383
- 'Content-Encoding',
1384
- 'Content-Language',
1385
- 'Content-Length',
1386
- 'Content-Location',
1387
- 'Content-MD5',
1388
- 'Content-Disposition',
1389
- 'Content-Range',
1390
- 'Content-Type',
1391
- 'Date',
1392
- 'ETag',
1393
- 'Expires',
1394
- 'Last-Modified',
1395
- 'Link',
1396
- 'Location',
1397
- 'P3P',
1398
- 'Pragma',
1399
- 'Proxy-Authenticate',
1400
- "Referrer-Policy",
1401
- 'Refresh',
1402
- 'Retry-After',
1403
- 'Server',
1404
- 'Status',
1405
- 'Strict-Transport-Security',
1406
- 'Trailer',
1407
- 'Transfer-Encoding',
1408
- 'Upgrade',
1409
- 'Vary',
1410
- 'Via',
1411
- 'Warning',
1412
- 'WWW-Authenticate',
1413
- 'X-Frame-Options',
1414
- 'Public-Key-Pins',
1415
- 'X-XSS-Protection',
1416
- 'Content-Security-Policy',
1417
- "X-Pingback",
1418
- 'X-Content-Security-Policy',
1419
- 'X-WebKit-CSP',
1420
- 'X-Content-Type-Options',
1421
- 'X-Powered-By',
1422
- 'X-UA-Compatible',
1423
- 'X-Robots-Tag',
1424
- );
 
 
 
 
1425
 
1426
  $known_headers = apply_filters( 'wpsc_known_headers', $known_headers );
1427
 
1428
- if ( ! isset( $known_headers[ 'age' ] ) ) {
1429
  $known_headers = array_map( 'strtolower', $known_headers );
1430
  }
1431
 
1432
  $headers = array();
1433
- if ( function_exists( 'apache_response_headers' ) ) {
1434
- $headers = apache_response_headers();
1435
- }
1436
- if ( empty( $headers ) && function_exists( 'headers_list' ) ) {
1437
- $headers = array();
1438
- foreach( headers_list() as $hdr ) {
1439
- $header_parts = explode( ':', $hdr, 2 );
1440
- $header_name = isset( $header_parts[0] ) ? trim( $header_parts[0] ) : '';
1441
- $header_value = isset( $header_parts[1] ) ? trim( $header_parts[1] ) : '';
1442
 
1443
- $headers[$header_name] = $header_value;
 
1444
  }
1445
- }
1446
 
1447
- foreach( $headers as $key => $value ) {
1448
- if ( ! in_array( strtolower( $key ), $known_headers ) ) {
1449
- unset( $headers[ $key ] );
 
 
 
 
 
 
 
1450
  }
1451
  }
1452
 
@@ -2760,7 +2777,7 @@ function wp_cache_post_edit( $post_id ) {
2760
 
2761
  // Some users are inexplicibly seeing this error on scheduled posts.
2762
  // define this constant to disable the post status check.
2763
- if ( false == defined( 'WPSCFORCEUPDATE' ) && !in_array($post->post_status, array( 'publish', 'private' ) ) ) {
2764
  wp_cache_debug( 'wp_cache_post_edit: draft post, not deleting any cache files. status: ' . $post->post_status, 4 );
2765
  return $post_id;
2766
  }
@@ -2825,17 +2842,24 @@ function wp_cache_post_change( $post_id ) {
2825
  wp_cache_debug( "wp_cache_post_change(${action}): Already processed post $post_id.", 4 );
2826
  return $post_id;
2827
  }
2828
- $post = get_post( $post_id );
 
 
 
 
 
 
2829
  // Some users are inexplicibly seeing this error on scheduled posts.
2830
  // define this constant to disable the post status check.
2831
- if ( false == defined( 'WPSCFORCEUPDATE' ) && is_object( $post ) && !in_array($post->post_status, array( 'publish', 'private' ) ) ) {
2832
  wp_cache_debug( 'wp_cache_post_change: draft post, not deleting any cache files.', 4 );
2833
  return $post_id;
2834
  }
2835
  $last_processed = $post_id;
2836
 
2837
- if( !wp_cache_writers_entry() )
2838
  return $post_id;
 
2839
 
2840
  if (
2841
  isset( $wp_cache_refresh_single_only ) &&
52
  return false;
53
  }
54
 
 
 
 
 
 
55
  if ( $wp_cache_no_cache_for_get && false == empty( $_GET ) ) {
56
  wp_cache_debug( 'Non empty GET request. Caching disabled on settings page. ' . wpsc_dump_get_request(), 1 );
57
  return false;
221
  } else {
222
  $ungzip = false;
223
  }
224
+ foreach ( $meta['headers'] as $t => $header ) {
225
  // 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/
226
+ if ( strpos( $header, 'Last-Modified:' ) === false ) {
227
+ header( $header );
228
+ }
229
  }
230
  if ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
231
  header( 'X-WP-Super-Cache: Served WPCache cache file' );
821
  global $wp_cache_gzip_encoding, $WPSC_HTTP_HOST;
822
 
823
  if ( $url ) {
824
+ $key = intval( $_SERVER[ 'SERVER_PORT' ] ) . preg_replace( '/:.*$/', '', $WPSC_HTTP_HOST ) . $url;
825
  } else {
826
  $key = get_current_url_supercache_dir();
827
  }
1105
  }
1106
  }
1107
  foreach( (array) $lines as $line ) {
1108
+ if (
1109
+ trim( $new ) != '' &&
1110
+ trim( $new ) == trim( $line )
1111
+ ) {
1112
+ wp_cache_debug( "wp_cache_replace_line: setting not changed - $new" );
1113
+ return false;
1114
+ } elseif ( preg_match( "/$old/", $line ) ) {
1115
+ wp_cache_debug( "wp_cache_replace_line: changing line " . trim( $line ) . " to *$new*" );
1116
  $found = true;
 
1117
  }
1118
  }
1119
 
1120
+ $tmp_config_filename = tempnam( $GLOBALS['cache_path'], 'wpsc' );
1121
+ rename( $tmp_config_filename, $tmp_wpcache_filename . ".php" );
1122
+ $tmp_config_filename .= ".php";
1123
+ wp_cache_debug( 'wp_cache_replace_line: writing to ' . $tmp_config_filename );
1124
+ $fd = fopen( $tmp_config_filename, 'w' );
1125
  if ( ! $fd ) {
1126
  if ( function_exists( 'set_transient' ) ) {
1127
  set_transient( 'wpsc_config_error', 'config_file_ro', 10 );
1150
  }
1151
  }
1152
  fclose( $fd );
1153
+ rename( $tmp_config_filename, $my_file );
1154
+ wp_cache_debug( 'wp_cache_replace_line: moved ' . $tmp_config_filename . ' to ' . $my_file );
1155
 
1156
  if ( function_exists( "opcache_invalidate" ) ) {
1157
  @opcache_invalidate( $my_file );
1168
  return false;
1169
  }
1170
 
1171
+ if ( wp_cache_user_agent_is_rejected() ) {
1172
+ wp_cache_debug( 'wp_cache_phase2: No caching to do as user agent rejected.' );
1173
+ return false;
1174
+ }
1175
+
1176
  wp_cache_debug( 'In WP Cache Phase 2', 5 );
1177
 
1178
  $wp_cache_gmt_offset = get_option( 'gmt_offset' ); // caching for later use when wpdb is gone. https://wordpress.org/support/topic/224349
1387
 
1388
  function wp_cache_get_response_headers() {
1389
  static $known_headers = array(
1390
+ 'Access-Control-Allow-Origin',
1391
+ 'Accept-Ranges',
1392
+ 'Age',
1393
+ 'Allow',
1394
+ 'Cache-Control',
1395
+ 'Connection',
1396
+ 'Content-Encoding',
1397
+ 'Content-Language',
1398
+ 'Content-Length',
1399
+ 'Content-Location',
1400
+ 'Content-MD5',
1401
+ 'Content-Disposition',
1402
+ 'Content-Range',
1403
+ 'Content-Type',
1404
+ 'Date',
1405
+ 'ETag',
1406
+ 'Expires',
1407
+ 'Last-Modified',
1408
+ 'Link',
1409
+ 'Location',
1410
+ 'P3P',
1411
+ 'Pragma',
1412
+ 'Proxy-Authenticate',
1413
+ 'Referrer-Policy',
1414
+ 'Refresh',
1415
+ 'Retry-After',
1416
+ 'Server',
1417
+ 'Status',
1418
+ 'Strict-Transport-Security',
1419
+ 'Trailer',
1420
+ 'Transfer-Encoding',
1421
+ 'Upgrade',
1422
+ 'Vary',
1423
+ 'Via',
1424
+ 'Warning',
1425
+ 'WWW-Authenticate',
1426
+ 'X-Frame-Options',
1427
+ 'Public-Key-Pins',
1428
+ 'X-XSS-Protection',
1429
+ 'Content-Security-Policy',
1430
+ 'X-Pingback',
1431
+ 'X-Content-Security-Policy',
1432
+ 'X-WebKit-CSP',
1433
+ 'X-Content-Type-Options',
1434
+ 'X-Powered-By',
1435
+ 'X-UA-Compatible',
1436
+ 'X-Robots-Tag',
1437
+ );
1438
+
1439
+ if ( ! function_exists( 'headers_list' ) ) {
1440
+ return array();
1441
+ }
1442
 
1443
  $known_headers = apply_filters( 'wpsc_known_headers', $known_headers );
1444
 
1445
+ if ( ! isset( $known_headers['age'] ) ) {
1446
  $known_headers = array_map( 'strtolower', $known_headers );
1447
  }
1448
 
1449
  $headers = array();
1450
+ foreach ( headers_list() as $hdr ) {
1451
+ $ptr = strpos( $hdr, ':' );
 
 
 
 
 
 
 
1452
 
1453
+ if ( empty( $ptr ) ) {
1454
+ continue;
1455
  }
 
1456
 
1457
+ $hdr_key = rtrim( substr( $hdr, 0, $ptr ) );
1458
+
1459
+ if ( in_array( strtolower( $hdr_key ), $known_headers, true ) ) {
1460
+ $hdr_val = ltrim( substr( $hdr, $ptr + 1 ) );
1461
+
1462
+ if ( ! empty( $headers[ $hdr_key ] ) ) {
1463
+ $hdr_val = $headers[ $hdr_key ] . ', ' . $hdr_val;
1464
+ }
1465
+
1466
+ $headers[ $hdr_key ] = $hdr_val;
1467
  }
1468
  }
1469
 
2777
 
2778
  // Some users are inexplicibly seeing this error on scheduled posts.
2779
  // define this constant to disable the post status check.
2780
+ if ( ! defined( 'WPSCFORCEUPDATE' ) && ! in_array( get_post_status( $post ), array( 'publish', 'private' ), true ) ) {
2781
  wp_cache_debug( 'wp_cache_post_edit: draft post, not deleting any cache files. status: ' . $post->post_status, 4 );
2782
  return $post_id;
2783
  }
2842
  wp_cache_debug( "wp_cache_post_change(${action}): Already processed post $post_id.", 4 );
2843
  return $post_id;
2844
  }
2845
+
2846
+ $post = get_post( $post_id );
2847
+ $ptype = is_object( $post ) ? get_post_type_object( $post->post_type ) : null;
2848
+ if ( empty( $ptype ) || ! $ptype->public ) {
2849
+ return $post_id;
2850
+ }
2851
+
2852
  // Some users are inexplicibly seeing this error on scheduled posts.
2853
  // define this constant to disable the post status check.
2854
+ if ( ! defined( 'WPSCFORCEUPDATE' ) && ! in_array( get_post_status( $post ), array( 'publish', 'private' ), true ) ) {
2855
  wp_cache_debug( 'wp_cache_post_change: draft post, not deleting any cache files.', 4 );
2856
  return $post_id;
2857
  }
2858
  $last_processed = $post_id;
2859
 
2860
+ if ( ! wp_cache_writers_entry() ) {
2861
  return $post_id;
2862
+ }
2863
 
2864
  if (
2865
  isset( $wp_cache_refresh_single_only ) &&
wp-cache.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP Super Cache
4
  Plugin URI: https://wordpress.org/plugins/wp-super-cache/
5
  Description: Very fast caching plugin for WordPress.
6
- Version: 1.6.4
7
  Author: Automattic
8
  Author URI: https://automattic.com/
9
  License: GPL2+
@@ -33,6 +33,13 @@ if ( ! function_exists( 'wp_cache_phase2' ) ) {
33
  require_once( dirname( __FILE__ ) . '/wp-cache-phase2.php');
34
  }
35
 
 
 
 
 
 
 
 
36
  function wpsc_init() {
37
  global $wp_cache_config_file, $wp_cache_config_file_sample, $wp_cache_file, $wp_cache_check_wp_config, $wp_cache_link;
38
 
@@ -76,17 +83,13 @@ global $wp_cache_preload_email_me, $wp_cache_preload_email_volume;
76
  global $wp_cache_mobile, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes;
77
  global $wp_cache_config_file, $wp_cache_config_file_sample;
78
 
79
- // WP-CLI: Hotfix for $blog_cache_dir for single site. It'll be removed after merging #590
80
- if ( empty( $GLOBALS['blog_cache_dir'] ) && ! is_multisite() ) {
81
- $GLOBALS['blog_cache_dir'] = $cache_path;
82
- }
83
-
84
- if( !@include($wp_cache_config_file) ) {
85
- get_wpcachehome();
86
- $wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
87
- @include($wp_cache_config_file_sample);
88
- } else {
89
- get_wpcachehome();
90
  }
91
 
92
  include(WPCACHEHOME . 'wp-cache-base.php');
@@ -116,25 +119,42 @@ add_action( 'template_redirect', 'wp_cache_set_home' );
116
  include_once( WPCACHEHOME . 'ossdl-cdn.php' );
117
 
118
  function get_wpcachehome() {
119
- if( defined( 'WPCACHEHOME' ) == false ) {
120
- if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
121
- define( 'WPCACHEHOME', trailingslashit( dirname(__FILE__) ) );
122
- } elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
123
- define( 'WPCACHEHOME', dirname(__FILE__) . '/wp-super-cache/' );
 
 
 
 
124
  } else {
125
- die( sprintf( __( 'Please create %s /wp-cache-config.php from wp-super-cache/wp-cache-config-sample.php', 'wp-super-cache' ), WP_CONTENT_DIR ) );
126
  }
127
  }
128
  }
129
 
130
- function wpsupercache_uninstall() {
131
- global $wp_cache_config_file, $wp_cache_link, $cache_path;
132
- $files = array( $wp_cache_config_file, $wp_cache_link );
133
- foreach( $files as $file ) {
134
- if ( null !== $file && '' !== $file && file_exists( $file ) ) {
135
- unlink( $file );
 
 
 
136
  }
137
  }
 
 
 
 
 
 
 
 
 
 
138
 
139
  wp_cache_remove_index();
140
 
@@ -157,9 +177,7 @@ if ( is_admin() ) {
157
  function wpsupercache_deactivate() {
158
  global $wp_cache_config_file, $wp_cache_link, $cache_path;
159
 
160
- if ( file_exists( $wp_cache_link ) ) {
161
- unlink( $wp_cache_link );
162
- }
163
 
164
  if ( ! empty( $cache_path ) ) {
165
  prune_super_cache( $cache_path, true );
@@ -202,29 +220,23 @@ register_activation_hook( __FILE__, 'wpsupercache_activate' );
202
  function wpsupercache_site_admin() {
203
  global $wp_version;
204
 
205
- if ( version_compare( "4.8", $wp_version, "<=" ) ) {
206
  return current_user_can( 'setup_network' );
207
  }
208
 
209
- if ( function_exists( 'is_super_admin' ) ) {
210
- return is_super_admin();
211
- } elseif ( function_exists( 'is_site_admin' ) ) {
212
- return is_site_admin();
213
- } else {
214
- return true;
215
- }
216
  }
217
 
218
  function wp_cache_add_pages() {
219
- global $wpmu_version;
220
- if ( wpsupercache_site_admin() ) { // in single or MS mode add this menu item too, but only for superadmins in MS mode.
221
- add_options_page( 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
222
  }
223
  }
224
- add_action('admin_menu', 'wp_cache_add_pages');
225
 
226
  function wp_cache_network_pages() {
227
- add_submenu_page('settings.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
228
  }
229
  add_action( 'network_admin_menu', 'wp_cache_network_pages' );
230
 
@@ -233,17 +245,18 @@ function wp_cache_manager_error_checks() {
233
  global $dismiss_htaccess_warning, $dismiss_readable_warning, $dismiss_gc_warning, $wp_cache_shutdown_gc, $is_nginx;
234
  global $htaccess_path;
235
 
236
- if ( !wpsupercache_site_admin() )
237
  return false;
 
238
 
239
- if ( version_compare( PHP_VERSION, '5.3.0', '<' ) && ( 1 == ini_get( 'safe_mode' ) || "on" == strtolower( ini_get( 'safe_mode' ) ) ) ) {
240
- echo '<div class="notice notice-error"><h4>' . __( 'Warning! PHP Safe Mode Enabled!', 'wp-super-cache' ) . '</h4><p>' .
241
- __( 'You may experience problems running this plugin because SAFE MODE is enabled.', 'wp-super-cache' ) . '<br />';
242
-
243
 
244
- if( !ini_get( 'safe_mode_gid' ) ) {
245
- echo __( 'Your server is set up to check the owner of PHP scripts before allowing them to read and write files.', 'wp-super-cache' ) . '<br />';
246
- printf( __( 'You or an administrator may be able to make it work by changing the group owner of the plugin scripts to match that of the web server user. The group owner of the %s/cache/ directory must also be changed. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details.', 'wp-super-cache' ), WP_CONTENT_DIR );
 
247
  } else {
248
  _e( 'You or an administrator must disable this. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details. This cannot be disabled in a .htaccess file unfortunately. It must be done in the php.ini config file.', 'wp-super-cache' );
249
  }
@@ -481,21 +494,23 @@ add_filter( 'wp_super_cache_error_checking', 'wp_cache_manager_error_checks' );
481
  */
482
  function admin_bar_delete_page() {
483
 
484
- if ( function_exists( 'current_user_can' ) && false == current_user_can( 'delete_others_posts' ) ) {
485
  return false;
486
  }
487
 
488
- $req_path = filter_input( INPUT_GET, 'path' );
489
  $referer = wp_get_referer();
490
  $valid_nonce = ( $req_path && isset( $_GET['_wpnonce'] ) ) ? wp_verify_nonce( $_GET['_wpnonce'], 'delete-cache' ) : false;
491
 
492
  $path = $valid_nonce ? realpath( trailingslashit( get_supercache_dir() . str_replace( '..', '', preg_replace( '/:.*$/', '', $req_path ) ) ) ) : false;
493
 
494
  if ( $path ) {
495
- $path = trailingslashit( $path );
496
  $supercachepath = realpath( get_supercache_dir() );
497
 
498
- if ( false == wp_cache_confirm_delete( $path ) || substr( $path, 0, strlen( $supercachepath ) ) != $supercachepath ) {
 
 
499
  wp_die( 'Could not delete directory' );
500
  }
501
 
@@ -503,7 +518,7 @@ function admin_bar_delete_page() {
503
  }
504
 
505
  if ( $referer && $req_path && ( false !== stripos( $referer, $req_path ) || 0 === stripos( $referer, wp_login_url() ) ) ) {
506
- wp_redirect( site_url( preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $req_path ) ) );
507
  exit;
508
  }
509
  }
@@ -512,7 +527,7 @@ if ( 'delcachepage' === filter_input( INPUT_GET, 'action' ) ) {
512
  }
513
 
514
  function wp_cache_manager_updates() {
515
- global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_hello_world, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $cache_path, $wp_cache_object_cache, $_wp_using_ext_object_cache, $wp_cache_refresh_single_only, $cache_compression, $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get;
516
  global $cache_schedule_type, $cache_max_time, $cache_time_interval, $wp_cache_shutdown_gc, $wpsc_save_headers;
517
 
518
  if ( !wpsupercache_site_admin() )
@@ -557,7 +572,7 @@ function wp_cache_manager_updates() {
557
  wp_clear_scheduled_hook( 'wp_cache_gc' );
558
  wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
559
  }
560
- $advanced_settings = array( 'wp_super_cache_late_init', 'wp_cache_disable_utf8', 'wp_cache_no_cache_for_get', 'wp_supercache_304', 'wp_cache_mfunc_enabled', 'wp_cache_mobile_enabled', 'wp_cache_front_page_checks', 'wp_supercache_cache_list', 'wp_cache_hello_world', 'wp_cache_clear_on_post_edit', 'wp_cache_not_logged_in', 'wp_cache_make_known_anon','wp_cache_object_cache', 'wp_cache_refresh_single_only', 'cache_compression' );
561
  foreach( $advanced_settings as $setting ) {
562
  if ( isset( $GLOBALS[ $setting ] ) && $GLOBALS[ $setting ] == 1 ) {
563
  $_POST[ $setting ] = 1;
@@ -661,13 +676,6 @@ function wp_cache_manager_updates() {
661
  }
662
  wp_cache_setting( 'wp_cache_mod_rewrite', $wp_cache_mod_rewrite );
663
 
664
- if( isset( $_POST[ 'wp_cache_hello_world' ] ) ) {
665
- $wp_cache_hello_world = 1;
666
- } else {
667
- $wp_cache_hello_world = 0;
668
- }
669
- wp_cache_replace_line('^ *\$wp_cache_hello_world', '$wp_cache_hello_world = ' . $wp_cache_hello_world . ";", $wp_cache_config_file);
670
-
671
  if( isset( $_POST[ 'wp_cache_clear_on_post_edit' ] ) ) {
672
  $wp_cache_clear_on_post_edit = 1;
673
  } else {
@@ -760,7 +768,7 @@ if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wpsupercache' )
760
  add_action( 'admin_init', 'wp_cache_manager_updates' );
761
 
762
  function wp_cache_manager() {
763
- global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled, $wp_cache_hello_world;
764
  global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_no_cache_for_get;
765
  global $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_supercache_cache_list, $cache_page_secret;
766
  global $wp_super_cache_front_page_check, $wp_cache_object_cache, $_wp_using_ext_object_cache, $wp_cache_refresh_single_only, $wp_cache_mobile_prefixes;
@@ -849,23 +857,25 @@ table.wpsc-settings-table {
849
  echo '<div class="wrap">';
850
  echo '<h3>' . __( 'WP Super Cache Settings', 'wp-super-cache' ) . '</h3>';
851
 
852
- // set a default
853
- if ( $cache_enabled == false && isset( $wp_cache_mod_rewrite ) == false ) {
854
  $wp_cache_mod_rewrite = 0;
855
- } elseif ( !isset( $wp_cache_mod_rewrite ) && $cache_enabled && $super_cache_enabled ) {
856
  $wp_cache_mod_rewrite = 1;
857
  }
858
 
859
- if ( ! isset( $_GET[ 'tab' ] ) && $cache_enabled && ( $wp_cache_mod_rewrite || $super_cache_enabled == false ) ) {
860
- $_GET[ 'tab' ] = 'settings';
861
- echo '<div class="notice notice-info is-dismissible"><p>' . __( 'Notice: <em>Expert mode caching enabled</em>. Showing Advanced Settings Page by default.', 'wp-super-cache' ) . '</p></div>';
862
- }
863
- if ( ! isset( $_GET[ 'tab' ] ) ) {
864
- $_GET[ 'tab' ] = 'easy';
 
 
865
  }
866
 
867
- if ( $_GET[ 'tab' ] == 'preload' ) {
868
- if ( $super_cache_enabled == true && false == defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
869
  global $wp_cache_preload_interval, $wp_cache_preload_on, $wp_cache_preload_taxonomies, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $wp_cache_preload_posts, $wpdb;
870
  $count = wpsc_post_count();
871
  if ( $count > 1000 ) {
@@ -874,31 +884,33 @@ table.wpsc-settings-table {
874
  $min_refresh_interval = 30;
875
  }
876
  $return = wpsc_preload_settings( $min_refresh_interval );
877
- $msg = '';
878
  if ( empty( $return ) == false ) {
879
- foreach( $return as $message ) {
880
  $msg .= $message;
881
  }
882
  }
883
  $currently_preloading = false;
884
 
885
  $preload_counter = get_option( 'preload_cache_counter' );
886
- if ( isset( $preload_counter[ 'first' ] ) ) // converted from int to array
887
- update_option( 'preload_cache_counter', array( 'c' => $preload_counter[ 'c' ], 't' => time() ) );
888
- if ( is_array( $preload_counter ) && $preload_counter[ 'c' ] > 0 ) {
889
- $msg .= '<p>' . sprintf( __( 'Currently caching from post %d to %d.', 'wp-super-cache' ), ( $preload_counter[ 'c' ] - 100 ), $preload_counter[ 'c' ] ) . '</p>';
 
 
890
  $currently_preloading = true;
891
- if ( @file_exists( $cache_path . "preload_permalink.txt" ) ) {
892
- $url = file_get_contents( $cache_path . "preload_permalink.txt" );
893
- $msg .="<p>" . sprintf( __( "<strong>Page last cached:</strong> %s", 'wp-super-cache' ), $url ) . "</p>";
894
  }
895
  if ( $msg != '' ) {
896
- echo '<div class="notice notice-warning"><h4>' . __( 'Preload Active', 'wp-super-cache' ) . '</h4>' . $msg;
897
- echo '<form name="do_preload" action="" method="POST">';
898
  echo '<input type="hidden" name="action" value="preload" />';
899
  echo '<input type="hidden" name="page" value="wpsupercache" />';
900
- echo '<p><input class="button-primary" type="submit" name="preload_off" value="' . __( 'Cancel Cache Preload', 'wp-super-cache' ) . '" /></p>';
901
- wp_nonce_field('wp-cache');
902
  echo '</form>';
903
  echo '</div>';
904
  }
@@ -909,60 +921,63 @@ table.wpsc-settings-table {
909
  }
910
  }
911
 
 
912
 
913
- wpsc_admin_tabs();
914
-
915
- if ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 1 && !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
916
- wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
917
  wp_cache_debug( 'scheduled wp_cache_check_site_hook for 360 seconds time.', 2 );
918
  }
919
 
920
- if(isset($_REQUEST['wp_restore_config']) && $valid_nonce) {
921
- unlink($wp_cache_config_file);
922
- echo '<strong>' . __( 'Configuration file changed, some values might be wrong. Load the page again from the "Settings" menu to reset them.', 'wp-super-cache' ) . '</strong>';
923
  }
924
 
925
  if ( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
926
- wp_cache_replace_line('^ *\$wp_cache_slash_check', "\$wp_cache_slash_check = 1;", $wp_cache_config_file);
927
  } else {
928
- wp_cache_replace_line('^ *\$wp_cache_slash_check', "\$wp_cache_slash_check = 0;", $wp_cache_config_file);
929
  }
930
  $home_path = parse_url( site_url() );
931
- $home_path = trailingslashit( array_key_exists( 'path', $home_path ) ? $home_path[ 'path' ] : '' );
932
- if (! isset( $wp_cache_home_path ) ) {
933
  $wp_cache_home_path = '/';
934
  wp_cache_setting( 'wp_cache_home_path', '/' );
935
  }
936
- if ( "$home_path" != "$wp_cache_home_path" )
937
  wp_cache_setting( 'wp_cache_home_path', $home_path );
 
938
 
939
-
940
- if( $wp_cache_mobile_enabled == 1 ) {
941
  update_cached_mobile_ua_list( $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $mobile_groups );
942
  }
943
 
944
- ?> <table class="wpsc-settings-table"><td valign='top'><?php
945
- switch( $_GET[ 'tab' ] ) {
946
- case "cdn":
947
- scossdl_off_options();
948
- break;
949
- case "tester":
950
- case "contents":
951
- echo '<a name="test"></a>';
952
- wp_cache_files();
953
- break;
954
- case "preload":
955
- if ( !$cache_enabled )
956
- wp_die( __( 'Caching must be enabled to use this feature', 'wp-super-cache' ) );
957
- echo '<a name="preload"></a>';
 
 
 
 
958
  if ( $super_cache_enabled == true && false == defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
959
  echo '<p>' . __( 'This will cache every published post and page on your site. It will create supercache static files so unknown visitors (including bots) will hit a cached page. This will probably help your Google ranking as they are using speed as a metric when judging websites now.', 'wp-super-cache' ) . '</p>';
960
  echo '<p>' . __( 'Preloading creates lots of files however. Caching is done from the newest post to the oldest so please consider only caching the newest if you have lots (10,000+) of posts. This is especially important on shared hosting.', 'wp-super-cache' ) . '</p>';
961
  echo '<p>' . __( 'In &#8217;Preload Mode&#8217; regular garbage collection will be disabled so that old cache files are not deleted. This is a recommended setting when the cache is preloaded.', 'wp-super-cache' ) . '</p>';
962
- echo '<form name="cache_filler" action="" method="POST">';
963
  echo '<input type="hidden" name="action" value="preload" />';
964
  echo '<input type="hidden" name="page" value="wpsupercache" />';
965
- echo '<p>' . sprintf( __( 'Refresh preloaded cache files every %s minutes. (0 to disable, minimum %d minutes.)', 'wp-super-cache' ), "<input type='text' size=4 name='wp_cache_preload_interval' value='" . (int)$wp_cache_preload_interval . "' />", $min_refresh_interval ) . '</p>';
966
  if ( $count > 100 ) {
967
  $step = (int)( $count / 10 );
968
 
@@ -1014,9 +1029,9 @@ table.wpsc-settings-table {
1014
  }
1015
  echo '<div class="submit"><input class="button-primary" type="submit" name="preload" value="' . __( 'Save Settings', 'wp-super-cache' ) . '" />';
1016
  echo '</div>';
1017
- wp_nonce_field('wp-cache');
1018
  echo '</form>';
1019
- echo '<form name="do_preload" action="" method="POST">';
1020
  echo '<input type="hidden" name="action" value="preload" />';
1021
  echo '<input type="hidden" name="page" value="wpsupercache" />';
1022
  echo '<div class="submit">';
@@ -1026,25 +1041,27 @@ table.wpsc-settings-table {
1026
  echo '<input class="button-primary" type="submit" name="preload_off" value="' . __( 'Cancel Cache Preload', 'wp-super-cache' ) . '" />';
1027
  }
1028
  echo '</div>';
1029
- wp_nonce_field('wp-cache');
1030
  echo '</form>';
1031
  } else {
1032
  echo '<div class="notice notice-warning"><p>' . __( 'Preloading of cache disabled. Please make sure simple or expert mode is enabled or talk to your host administrator.', 'wp-super-cache' ) . '</p></div>';
1033
  }
1034
- break;
1035
  case 'plugins':
1036
- wpsc_plugins_tab();
1037
- break;
1038
  case 'debug':
1039
- wp_cache_debug_settings();
1040
- break;
1041
  case 'settings':
1042
- if ( isset( $wp_cache_front_page_checks ) == false )
1043
- $wp_cache_front_page_checks = true;
1044
- echo '<form name="wp_manager" action="' . esc_url( add_query_arg( array( 'page' => 'wpsupercache', 'tab' => 'settings' ) ) ) . '" method="post">';
1045
- wp_nonce_field('wp-cache');
1046
- echo '<input type="hidden" name="action" value="scupdates" />';
1047
- ?><table class="form-table">
 
 
1048
  <tr valign="top">
1049
  <th scope="row"><label for="wp_cache_enabled"><?php _e( 'Caching', 'wp-super-cache' ); ?></label></th>
1050
  <td>
@@ -1067,44 +1084,44 @@ table.wpsc-settings-table {
1067
  </fieldset>
1068
  </td>
1069
  </tr>
1070
- <tr valign="top">
1071
- <th scope="row"><label for="wp_cache_status"><?php _e( 'Miscellaneous', 'wp-super-cache' ); ?></label></th>
1072
- <td>
1073
- <fieldset>
1074
- <legend class="hidden">Miscellaneous</legend>
1075
- <label><input type='checkbox' name='wp_cache_not_logged_in' <?php if ( $wp_cache_not_logged_in ) echo "checked"; ?> value='1'> <?php _e( 'Don&#8217;t cache pages for <acronym title="Logged in users and those that comment">known users</acronym>.', 'wp-super-cache' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br />
1076
- <label><input type='checkbox' name='wp_cache_no_cache_for_get' <?php if( $wp_cache_no_cache_for_get ) echo "checked"; ?> value='1'> <?php _e( 'Don&#8217;t cache pages with GET parameters. (?x=y at the end of a url)', 'wp-super-cache' ); ?></label><br />
1077
- <?php if ( false == defined( 'WPSC_DISABLE_COMPRESSION' ) ) { ?>
1078
- <?php if ( false == function_exists( 'gzencode' ) ) { ?>
1079
- <em><?php _e( 'Warning! Compression is disabled as gzencode() function was not found.', 'wp-super-cache' ); ?></em><br />
1080
- <?php } else { ?>
1081
- <label><input type='checkbox' name='cache_compression' <?php if( $cache_compression ) echo "checked"; ?> value='1'> <?php _e( 'Compress pages so they&#8217;re served more quickly to visitors.', 'wp-super-cache' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br />
1082
- <em><?php _e( 'Compression is disabled by default because some hosts have problems with compressed files. Switching it on and off clears the cache.', 'wp-super-cache' ); ?></em><br />
1083
- <?php }
1084
- }
1085
- ?>
1086
- <label><input type='checkbox' name='wpsc_save_headers' <?php if ( $wpsc_save_headers ) echo "checked"; ?> value='1' /> <?php _e( 'Cache HTTP headers with page content.', 'wp-super-cache' ); ?></label><br />
1087
- <label><input type='checkbox' name='cache_rebuild_files' <?php if ( $cache_rebuild_files ) echo "checked"; ?> value='1'> <?php _e( 'Cache rebuild. Serve a supercache file to anonymous users while a new file is being generated.', 'wp-super-cache' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br />
1088
  <?php
1089
  $disable_304 = true;
1090
  if ( 0 == $wp_cache_mod_rewrite )
1091
  $disable_304 = false;
1092
  if ( $disable_304 )
1093
  echo "<strike>";
1094
- ?><label><input <?php if ( $disable_304 ) { echo "disabled"; } ?> type='checkbox' name='wp_supercache_304' <?php if( $wp_supercache_304 ) echo "checked"; ?> value='1'> <?php _e( '304 Not Modified browser caching. Indicate when a page has not been modified since it was last requested.', 'wp-super-cache' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br /><?php
1095
- if ( $disable_304 ) {
1096
- echo "</strike>";
1097
- echo "<p><strong>" . __( 'Warning! 304 browser caching is only supported when mod_rewrite caching is not used.', 'wp-super-cache' ) . "</strong></p>";
1098
- } else {
1099
- ?><em><?php _e( '304 support is disabled by default because some hosts have had problems with the headers used in the past.', 'wp-super-cache' ); ?></em><br /><?php
1100
- }
1101
- ?>
1102
- <label><input type='checkbox' name='wp_cache_make_known_anon' <?php if( $wp_cache_make_known_anon ) echo "checked"; ?> value='1'> <?php _e( 'Make known users anonymous so they&#8217;re served supercached static files.', 'wp-super-cache' ); ?></label><br />
1103
- <label><input type='checkbox' name='wp_cache_hello_world' <?php if( $wp_cache_hello_world ) echo "checked"; ?> value='1'> <?php printf( __( 'Proudly tell the world your server is <a href="%s">Stephen Fry proof</a>! (places a message in your blog&#8217;s footer)', 'wp-super-cache' ), 'https://twitter.com/#!/HibbsLupusTrust/statuses/136429993059291136' ); ?></label><br />
1104
- </legend>
1105
- </fieldset>
1106
- </td>
1107
- </tr>
 
1108
  <tr valign="top">
1109
  <th scope="row"><label for="wp_cache_status"><?php _e( 'Advanced', 'wp-super-cache' ); ?></label></th>
1110
  <td>
@@ -1162,85 +1179,90 @@ table.wpsc-settings-table {
1162
  </td>
1163
  </tr>
1164
  </table>
1165
- <h4><?php _e( 'Note:', 'wp-super-cache' ); ?></h4>
1166
- <ol>
1167
- <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>
1168
- <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>
1169
- <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
1170
- 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>";
1171
- echo "</ol>";
1172
 
1173
- echo "<div class='submit'><input class='button-primary' type='submit' " . SUBMITDISABLED . " value='" . __( 'Update Status', 'wp-super-cache' ) . "' /></div>";
1174
- wp_nonce_field('wp-cache');
1175
- ?> </form> <?php
1176
- wsc_mod_rewrite();
 
 
 
1177
 
1178
- wp_cache_edit_max_time();
1179
 
1180
- echo '<a name="files"></a><fieldset class="options"><h4>' . __( 'Accepted Filenames &amp; Rejected URIs', 'wp-super-cache' ) . '</h4>';
1181
- wp_cache_edit_rejected_pages();
1182
- echo "\n";
1183
- wp_cache_edit_rejected();
1184
- echo "\n";
1185
- wp_cache_edit_accepted();
1186
- echo '</fieldset>';
1187
 
1188
- wp_cache_edit_rejected_ua();
1189
 
1190
- wp_lock_down();
1191
 
1192
- wp_cache_restore();
1193
 
1194
- break;
1195
- case "easy":
1196
  default:
1197
- echo '<form name="wp_manager" action="" method="post">';
1198
  echo '<input type="hidden" name="action" value="easysetup" />';
1199
- wp_nonce_field('wp-cache');
1200
- ?><table class="form-table">
 
1201
  <tr valign="top">
1202
- <th scope="row"><label for="wp_cache_status"><?php _e( 'Caching', 'wp-super-cache' ); ?></label></th>
1203
  <td>
1204
  <fieldset>
1205
- <label><input type='radio' name='wp_cache_easy_on' value='1' <?php if ( $cache_enabled == true ) { echo 'checked=checked'; } ?>> <?php _e( 'Caching On', 'wp-super-cache' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br />
1206
- <label><input type='radio' name='wp_cache_easy_on' value='0' <?php if ( $cache_enabled == false ) { echo 'checked=checked'; } ?>> <?php _e( 'Caching Off', 'wp-super-cache' ); ?></label><br />
1207
  </fieldset>
1208
  </td>
1209
  </tr>
1210
- </table>
1211
  <?php
1212
- if ( ! $is_nginx && $cache_enabled && !$wp_cache_mod_rewrite ) {
1213
  $scrules = trim( implode( "\n", extract_from_markers( trailingslashit( get_home_path() ) . '.htaccess', 'WPSuperCache' ) ) );
1214
- if ( $scrules != '' ) {
1215
- echo "<p><strong>" . __( 'Notice: Simple caching enabled but Supercache mod_rewrite rules from expert mode detected. Cached files will be served using those rules. If your site is working ok, please ignore this message. Otherwise, you can edit the .htaccess file in the root of your install and remove the SuperCache rules.', 'wp-super-cache' ) . '</strong></p>';
1216
  }
1217
  }
1218
- echo "<div class='submit'><input class='button-primary' type='submit' " . SUBMITDISABLED . " value='" . __( 'Update Status', 'wp-super-cache' ) . "' /></div></form>";
1219
  if ( $cache_enabled ) {
1220
- echo "<h4>" . __( 'Cache Tester', 'wp-super-cache' ) . "</h4>";
1221
- echo '<p>' . __( 'Test your cached website by clicking the test button below.', 'wp-super-cache' ) . '</p>';
1222
  echo '<p>' . __( 'Note: if you use Cloudflare or other transparent front-end proxy service this test may fail.<ol><li> If you have Cloudflare minification enabled this plugin may detect differences in the pages and report an error.</li><li> Try using the development mode of Cloudflare to perform the test. You can disable development mode afterwards if the test succeeds.</li></ol>', 'wp-super-cache' ) . '</p>';
1223
- if ( array_key_exists('action', $_POST) && $_POST[ 'action' ] == 'test' && $valid_nonce ) {
1224
  $url = trailingslashit( get_bloginfo( 'url' ) );
1225
- if ( isset( $_POST[ 'httponly' ] ) )
1226
  $url = str_replace( 'https://', 'http://', $url );
1227
- $test_messages = array( __( 'Fetching %s to prime cache: ', 'wp-super-cache' ), __( 'Fetching first copy of %s: ', 'wp-super-cache' ), __( 'Fetching second copy of %s: ', 'wp-super-cache' ) );
1228
- $c = 0;
 
1229
  $cache_test_error = false;
1230
- $page = array();
1231
- foreach( $test_messages as $message ) {
1232
- echo "<p>" . sprintf( $message, $url );
1233
- $page[ $c ] = wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
1234
- if ( !is_wp_error( $page[ $c ] ) ) {
1235
- $fp = fopen( $cache_path . $c . ".html", "w" );
1236
- fwrite( $fp, $page[ $c ][ 'body' ] );
1237
  fclose( $fp );
1238
- echo '<span style="color: #0a0; font-weight: bold;">' . __( 'OK', 'wp-super-cache' ) . "</span> (<a href='" . WP_CONTENT_URL . "/cache/" . $c . ".html'>" . $c . ".html</a>)</p>";
1239
  sleep( 1 );
1240
  } else {
1241
  $cache_test_error = true;
1242
- echo '<span style="color: #a00; font-weight: bold;">' . __( 'FAILED', 'wp-super-cache' ) . "</span></p>";
1243
- $errors = '';
1244
  $messages = '';
1245
  foreach ( $page[ $c ]->get_error_codes() as $code ) {
1246
  $severity = $page[ $c ]->get_error_data( $code );
@@ -1248,64 +1270,67 @@ table.wpsc-settings-table {
1248
  $errors .= $severity . ': ' . $err . "<br />\n";
1249
  }
1250
  }
1251
- if ( '' != $errors )
1252
- echo "<p>" . sprintf( __( '<strong>Errors:</strong> %s', 'wp-super-cache' ), $errors ) . "</p>";
 
1253
  }
1254
  $c ++;
1255
  }
1256
 
1257
  if ( false == $cache_test_error ) {
1258
- echo '<ul><li>' . sprintf( __( 'Page %d: %d (%s)', 'wp-super-cache' ), 1, $page[ 1 ][ 'response' ][ 'code' ], $page[ 1 ][ 'response' ][ 'message' ] ) . '</li>';
1259
- echo '<li>' . sprintf( __( 'Page %d: %d (%s)', 'wp-super-cache' ), 2, $page[ 2 ][ 'response' ][ 'code' ], $page[ 2 ][ 'response' ][ 'message' ] ) . '</li></ul>';
1260
  }
1261
 
1262
- if ( false == $cache_test_error && 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 ) &&
1263
- 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 ) && $matches1[2] == $matches2[2] ) {
1264
- echo '<p>' . sprintf( __( 'Page 1: %s', 'wp-super-cache' ), $matches1[ 2 ] ) . '</p>';
1265
- echo '<p>' . sprintf( __( 'Page 2: %s', 'wp-super-cache' ), $matches2[ 2 ] ) . '</p>';
1266
- echo '<p><span style="color: #0a0; font-weight: bold;">' . __( 'The timestamps on both pages match!', 'wp-super-cache' ) . '</span></p>';
 
1267
  } else {
1268
- echo '<p><strong>' . __( 'The pages do not match! Timestamps differ or were not found!', 'wp-super-cache' ) . '</strong></p>';
1269
- echo '<p>' . __( 'Things you can do:', 'wp-super-cache' ) . '</p>';
1270
- echo '<ol><li>' . __( 'Load your homepage in a logged out browser, check the timestamp at the end of the html source. Load the page again and compare the timestamp. Caching is working if the timestamps match.', 'wp-super-cache' ) . '</li>';
1271
- echo '<li>' . __( 'Enable logging on the Debug page here. That should help you track down the problem.', 'wp-super-cache' ) . '</li>';
1272
- echo '<li>' . __( 'You should check Page 1 and Page 2 above for errors. Your local server configuration may not allow your website to access itself.', 'wp-super-cache' ) . '</li>';
1273
- echo "</ol>";
1274
  }
1275
  }
1276
- echo '<form name="cache_tester" action="" method="post">';
1277
  echo '<input type="hidden" name="action" value="test" />';
1278
- if ( isset( $_SERVER['HTTPS' ] ) && 'on' == strtolower( $_SERVER['HTTPS' ] ) )
1279
- echo "<input type='checkbox' name='httponly' checked='checked' value='1' /> " . __( 'Send non-secure (non https) request for homepage', 'wp-super-cache' );
 
1280
 
1281
  if ( isset( $wp_super_cache_comments ) && $wp_super_cache_comments == 0 ) {
1282
- echo "<p>" . __( '<strong>Warning!</strong> Cache comments are currently disabled. Please go to the Debug page and enable Cache Status Messages there. You should clear the cache before testing.', 'wp-super-cache' ) . "</p>";
1283
- echo '<div class="submit"><input disabled style="color: #aaa" class="button-secondary" type="submit" name="test" value="' . __( 'Test Cache', 'wp-super-cache' ) . '" /></div>';
1284
  } else {
1285
  echo '<div class="submit"><input class="button-secondary" type="submit" name="test" value="' . __( 'Test Cache', 'wp-super-cache' ) . '" /></div>';
1286
  }
1287
 
1288
- wp_nonce_field('wp-cache');
1289
  echo '</form>';
1290
  }
1291
- echo "<h4>" . __( "Delete Cached Pages", 'wp-super-cache' ) . "</h4>";
1292
- echo "<p>" . __( "Cached pages are stored on your server as html and PHP files. If you need to delete them, use the button below.", 'wp-super-cache' ) . "</p>";
1293
- echo '<form name="wp_cache_content_delete" action="?page=wpsupercache&tab=contents" method="post">';
1294
  echo '<input type="hidden" name="wp_delete_cache" />';
1295
- echo '<div class="submit"><input id="deletepost" class="button-secondary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Cache', 'wp-super-cache' ) . ' " /></div>';
1296
- wp_nonce_field('wp-cache');
1297
  echo "</form>\n";
1298
 
1299
- if ( ( defined( 'VHOST' ) || defined( 'SUBDOMAIN_INSTALL' ) || defined( 'SUNRISE' ) || ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) ) && wpsupercache_site_admin() ) {
1300
- echo '<form name="wp_cache_content_delete" action="#listfiles" method="post">';
1301
  echo '<input type="hidden" name="wp_delete_all_cache" />';
1302
- echo '<div class="submit"><input id="deleteallpost" class="button-secondary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Cache On All Blogs', 'wp-super-cache' ) . '" /></div>';
1303
- wp_nonce_field('wp-cache');
1304
  echo "</form><br />\n";
1305
  }
1306
  ?>
1307
- <h4 class="clear"><?php _e( 'Recommended Links and Plugins', 'wp-super-cache' ); ?></h4>
1308
- <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>
1309
  <ul style="list-style: square; margin-left: 2em;">
1310
  <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>
1311
  <li><?php printf( __( '<a href="%s">Yahoo! Yslow</a> analyzes web pages and suggests ways to improve their performance based on a set of rules for high performance web pages. Also try the performance tools online at <a href="%s">GTMetrix</a>.', 'wp-super-cache' ), 'http://yslow.org/', 'https://gtmetrix.com/' ); ?></li>
@@ -1313,12 +1338,12 @@ table.wpsc-settings-table {
1313
  <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>
1314
  <li><?php printf( __( '<a href="%s">WP Crontrol</a> is a useful plugin to use when trying to debug garbage collection and preload problems.', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-crontrol/' ); ?></li>
1315
  </ul>
1316
-
1317
  <?php
1318
- break;
1319
- }
1320
 
 
 
1321
  ?>
 
1322
  </fieldset>
1323
  </td><td valign='top' style='width: 300px'>
1324
  <div style='background: #ffc; border: 1px solid #333; margin: 2px; padding: 3px 15px'>
@@ -1334,25 +1359,26 @@ table.wpsc-settings-table {
1334
  <li><?php printf( __( 'Visit the <a href="%1$s">plugin homepage</a>.', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-super-cache/' ); ?></li>
1335
  <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>
1336
  </ol>
1337
- <h4><?php _e( 'Rate This Plugin', 'wp-super-cache' ); ?></h4>
1338
  <p><?php printf( __( 'Please <a href="%s">rate us</a> and give feedback.', 'wp-super-cache' ), 'https://wordpress.org/support/plugin/wp-super-cache/reviews?rate=5#new-post' ); ?></p>
1339
 
1340
  <?php
1341
  if ( isset( $wp_supercache_cache_list ) && $wp_supercache_cache_list ) {
1342
  $start_date = get_option( 'wpsupercache_start' );
1343
- if ( !$start_date ) {
1344
  $start_date = time();
1345
  }
1346
  ?>
1347
  <p><?php printf( __( 'Cached pages since %1$s : <strong>%2$s</strong>', 'wp-super-cache' ), date( 'M j, Y', $start_date ), number_format( get_option( 'wpsupercache_count' ) ) ); ?></p>
1348
  <p><?php _e( 'Newest Cached Pages:', 'wp-super-cache' ); ?><ol>
1349
- <?php
1350
- foreach( array_reverse( (array)get_option( 'supercache_last_cached' ) ) as $url ) {
1351
- $since = time() - strtotime( $url[ 'date' ] );
1352
- echo "<li><a title='" . sprintf( __( 'Cached %s seconds ago', 'wp-super-cache' ), $since ) . "' href='" . site_url( $url[ 'url' ] ) . "'>" . substr( $url[ 'url' ], 0, 20 ) . "</a></li>\n";
1353
- }
1354
- ?></ol>
1355
- <small><?php _e( '(may not always be accurate on busy sites)', 'wp-super-cache' ); ?></small>
 
1356
  </p><?php
1357
  } elseif ( false == get_option( 'wpsupercache_start' ) ) {
1358
  update_option( 'wpsupercache_start', time() );
@@ -1368,51 +1394,55 @@ table.wpsc-settings-table {
1368
  }
1369
 
1370
  function wpsc_plugins_tab() {
1371
- echo '<p>' . __( 'Cache plugins are PHP scripts you\'ll find in a dedicated folder inside the WP Super Cache folder (wp-super-cache/plugins/). They load at the same time as WP Super Cache, and before regular WordPress plugins.', 'wp-super-cache' ) . '</p>';
1372
- echo '<p>' . __( 'Keep in mind that cache plugins are for advanced users only. To create and manage them, you\'ll need extensive knowledge of both PHP and WordPress actions.', 'wp-super-cache' ) . '</p>';
1373
  echo '<p>' . sprintf( __( '<strong>Warning</strong>! Due to the way WordPress upgrades plugins, the ones you upload to the WP Super Cache folder (wp-super-cache/plugins/) will be deleted when you upgrade WP Super Cache. To avoid this loss, load your cache plugins from a different location. When you set <strong>$wp_cache_plugins_dir</strong> to the new location in wp-config.php, WP Super Cache will look there instead. <br />You can find additional details in the <a href="%s">developer documentation</a>.', 'wp-super-cache' ), 'https://odd.blog/wp-super-cache-developers/' ) . '</p>';
1374
  ob_start();
1375
- if( defined( 'WP_CACHE' ) ) {
1376
- if( function_exists( 'do_cacheaction' ) ) {
1377
  do_cacheaction( 'cache_admin_page' );
1378
  }
1379
  }
1380
  $out = ob_get_contents();
1381
  ob_end_clean();
1382
- if( SUBMITDISABLED == ' ' && $out != '' ) {
1383
- echo '<h4>' . __( 'Available Plugins', 'wp-super-cache' ) . '</h4>';
1384
- echo "<ol>";
 
1385
  echo $out;
1386
- echo "</ol>";
1387
  }
1388
-
1389
  }
1390
 
1391
- function wpsc_admin_tabs( $current = 0 ) {
1392
- global $wp_db_version;
1393
- if ( $current == 0 ) {
1394
- if ( isset( $_GET[ 'tab' ] ) ) {
1395
- $current = $_GET[ 'tab' ];
1396
- } else {
1397
- $current = 'easy';
1398
- }
1399
- }
1400
- $tabs = array( 'easy' => __( 'Easy', 'wp-super-cache' ), 'settings' => __( 'Advanced', 'wp-super-cache' ), 'cdn' => __( 'CDN', 'wp-super-cache' ), 'contents' => __( 'Contents', 'wp-super-cache' ), 'preload' => __( 'Preload', 'wp-super-cache' ), 'plugins' => __( 'Plugins', 'wp-super-cache' ), 'debug' => __( 'Debug', 'wp-super-cache' ) );
1401
- $links = array();
1402
- foreach( $tabs as $tab => $name ) {
1403
- if ( $current == $tab ) {
1404
- $links[] = "<a class='nav-tab nav-tab-active' href='?page=wpsupercache&tab=$tab'>$name</a>";
1405
- } else {
1406
- $links[] = "<a class='nav-tab' href='?page=wpsupercache&tab=$tab'>$name</a>";
1407
- }
1408
  }
1409
- if ( $wp_db_version >= 15477 ) {
1410
- echo '<div id="nav"><h3 class="themes-php">';
1411
- echo implode( "", $links );
1412
- echo '</div></h3>';
1413
- } else {
1414
- echo implode( " | ", $links );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1415
  }
 
 
1416
  }
1417
 
1418
  function wsc_mod_rewrite() {
@@ -1482,8 +1512,9 @@ function wsc_mod_rewrite() {
1482
  }
1483
 
1484
  function wp_cache_restore() {
 
1485
  echo '<fieldset class="options"><h4>' . __( 'Fix Configuration', 'wp-super-cache' ) . '</h4>';
1486
- echo '<form name="wp_restore" action="#top" method="post">';
1487
  echo '<input type="hidden" name="wp_restore_config" />';
1488
  echo '<div class="submit"><input class="button-secondary" type="submit" ' . SUBMITDISABLED . 'id="deletepost" value="' . __( 'Restore Default Configuration', 'wp-super-cache' ) . '" /></div>';
1489
  wp_nonce_field('wp-cache');
@@ -1596,6 +1627,7 @@ function wpsc_update_direct_pages() {
1596
  function wp_lock_down() {
1597
  global $cached_direct_pages, $cache_enabled, $super_cache_enabled;
1598
 
 
1599
  $wp_lock_down = wp_update_lock_down();
1600
 
1601
  ?><a name='lockdown'></a>
@@ -1614,11 +1646,11 @@ function wp_lock_down() {
1614
  }
1615
  $new_lockdown = $wp_lock_down == '1' ? '0' : '1';
1616
  $new_lockdown_desc = $wp_lock_down == '1' ? __( 'Disable', 'wp-super-cache' ) : __( 'Enable', 'wp-super-cache' );
1617
- echo '<form name="wp_lock_down" action="#lockdown" method="post">';
1618
  echo "<input type='hidden' name='wp_lock_down' value='{$new_lockdown}' />";
1619
- echo "<div class='submit'><input class='button-primary' type='submit' " . SUBMITDISABLED . " value='{$new_lockdown_desc} " . __( 'Lock Down', 'wp-super-cache' ) . "' /></div>";
1620
- wp_nonce_field('wp-cache');
1621
- echo "</form>\n";
1622
 
1623
  ?></fieldset><?php
1624
  if( $cache_enabled == true && $super_cache_enabled == true ) {
@@ -1639,7 +1671,7 @@ function wp_lock_down() {
1639
  ?><p style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><strong><?php _e( 'Warning!', 'wp-super-cache' ); ?></strong> <?php printf( __( '%s is writable. Please make it readonly after your page is generated as this is a security risk.', 'wp-super-cache' ), ABSPATH ); ?></p><?php
1640
  }
1641
  }
1642
- echo '<form name="direct_page" action="#direct" method="post">';
1643
  if( is_array( $cached_direct_pages ) ) {
1644
  $out = '';
1645
  foreach( $cached_direct_pages as $page ) {
@@ -1655,20 +1687,27 @@ function wp_lock_down() {
1655
  echo "$out</table>";
1656
  }
1657
  }
1658
- if( $readonly != 'READONLY' )
1659
- echo __( "Add direct page:", 'wp-super-cache' ) . "<input type='text' $readonly name='new_direct_page' size='30' value='' />";
1660
 
1661
- echo "<p>" . sprintf( __( "Directly cached files are files created directly off %s where your blog lives. This feature is only useful if you are expecting a major Digg or Slashdot level of traffic to one post or page.", 'wp-super-cache' ), ABSPATH ) . "</p>";
1662
- if( $readonly != 'READONLY' ) {
1663
- echo "<p>" . sprintf( __( 'For example: to cache <em>%1$sabout/</em>, you would enter %1$sabout/ or /about/. The cached file will be generated the next time an anonymous user visits that page.', 'wp-super-cache' ), trailingslashit( get_option( 'siteurl' ) ) ) . "</p>";
1664
- echo "<p>" . __( 'Make the textbox blank to remove it from the list of direct pages and delete the cached file.', 'wp-super-cache' ) . "</p>";
1665
  }
 
 
 
 
 
 
 
 
 
1666
 
1667
- wp_nonce_field('wp-cache');
1668
- if( $readonly != 'READONLY' )
1669
- echo "<div class='submit'><input class='button-primary' type='submit' ' . SUBMITDISABLED . 'value='" . __( 'Update Direct Pages', 'wp-super-cache' ) . "' /></div>";
1670
- echo "</form>\n";
1671
- ?></fieldset><?php
 
 
1672
  } // if $super_cache_enabled
1673
  }
1674
 
@@ -1769,6 +1808,7 @@ function wp_cache_time_update() {
1769
  function wp_cache_edit_max_time() {
1770
  global $cache_max_time, $wp_cache_config_file, $valid_nonce, $super_cache_enabled, $cache_schedule_type, $cache_scheduled_time, $cache_schedule_interval, $cache_time_interval, $cache_gc_email_me, $wp_cache_preload_on;
1771
 
 
1772
  $timezone_format = _x('Y-m-d G:i:s', 'timezone date format');
1773
 
1774
  wp_cache_time_update();
@@ -1803,7 +1843,7 @@ function wp_cache_edit_max_time() {
1803
  });
1804
  });";
1805
  echo "</script>";
1806
- echo '<form name="wp_edit_max_time" action="#expirytime" method="post">';
1807
  echo '<input name="action" value="expirytime" type="hidden" />';
1808
  echo '<table class="form-table">';
1809
  echo '<tr><td><label for="wp_max_time"><strong>' . __( 'Cache Timeout', 'wp-super-cache' ) . '</strong></label></td>';
@@ -1873,13 +1913,16 @@ function wp_cache_update_rejected_ua() {
1873
  function wp_cache_edit_rejected_ua() {
1874
  global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce;
1875
 
1876
- if ( !function_exists( 'apache_request_headers' ) ) return;
 
 
1877
 
 
1878
  wp_cache_update_rejected_ua();
1879
 
1880
  echo '<a name="useragents"></a><fieldset class="options"><h4>' . __( 'Rejected User Agents', 'wp-super-cache' ) . '</h4>';
1881
  echo "<p>" . __( 'Strings in the HTTP &#8217;User Agent&#8217; header that prevent WP-Cache from caching bot, spiders, and crawlers&#8217; requests. Note that super cached files are still sent to these agents if they already exists.', 'wp-super-cache' ) . "</p>\n";
1882
- echo '<form name="wp_edit_rejected_user_agent" action="#useragents" method="post">';
1883
  echo '<textarea name="wp_rejected_user_agent" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
1884
  foreach( $cache_rejected_user_agent as $ua ) {
1885
  echo esc_html( $ua ) . "\n";
@@ -1911,11 +1954,12 @@ function wp_cache_update_rejected_pages() {
1911
  function wp_cache_edit_rejected_pages() {
1912
  global $wp_cache_config_file, $valid_nonce, $wp_cache_pages;
1913
 
 
1914
  wp_cache_update_rejected_pages();
1915
 
1916
  echo '<a name="rejectpages"></a>';
1917
  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>';
1918
- echo '<form name="wp_edit_rejected_pages" action="#rejectpages" method="post">';
1919
  echo '<input type="hidden" name="wp_edit_rejected_pages" value="1" />';
1920
  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 />';
1921
  echo '<label><input type="checkbox" value="1" name="wp_cache_pages[pages]" ' . checked( 1, $wp_cache_pages[ 'pages' ], false ) . ' /> ' . __( 'Pages', 'wp-super-cache' ) . ' (is_page)</label><br />';
@@ -1947,10 +1991,11 @@ function wp_cache_update_rejected_strings() {
1947
  function wp_cache_edit_rejected() {
1948
  global $cache_rejected_uri;
1949
 
 
1950
  wp_cache_update_rejected_strings();
1951
 
1952
  echo '<a name="rejecturi"></a>';
1953
- echo '<form name="wp_edit_rejected" action="#rejecturi" method="post">';
1954
  echo "<p>" . __( 'Add here strings (not a filename) that forces a page not to be cached. For example, if your URLs include year and you dont want to cache last year posts, it&#8217;s enough to specify the year, i.e. &#8217;/2004/&#8217;. WP-Cache will search if that string is part of the URI and if so, it will not cache that page.', 'wp-super-cache' ) . "</p>\n";
1955
  echo '<textarea name="wp_rejected_uri" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
1956
  foreach ($cache_rejected_uri as $file) {
@@ -1975,9 +2020,10 @@ function wp_cache_edit_accepted() {
1975
  global $cache_acceptable_files;
1976
 
1977
  wp_cache_update_accepted_strings();
 
1978
 
1979
  echo '<a name="cancache"></a>';
1980
- echo '<div style="clear:both"></div><form name="wp_edit_accepted" action="#cancache" method="post">';
1981
  echo "<p>" . __( 'Add here those filenames that can be cached, even if they match one of the rejected substring specified above.', 'wp-super-cache' ) . "</p>\n";
1982
  echo '<textarea name="wp_accepted_files" cols="40" rows="8" style="width: 50%; font-size: 12px;" class="code">';
1983
  foreach ($cache_acceptable_files as $file) {
@@ -2076,6 +2122,7 @@ function wp_cache_debug_settings() {
2076
  global $wp_cache_debug_username;
2077
 
2078
  extract( wpsc_update_debug_settings() ); // $wp_super_cache_debug, $wp_cache_debug_log, $wp_cache_debug_ip, $wp_super_cache_comments, $wp_super_cache_front_page_check, $wp_super_cache_front_page_clear, $wp_super_cache_front_page_text, $wp_super_cache_front_page_notification, $wp_super_cache_advanced_debug, $wp_cache_debug_username
 
2079
 
2080
  echo '<a name="debug"></a>';
2081
  echo '<fieldset class="options">';
@@ -2092,12 +2139,13 @@ function wp_cache_debug_settings() {
2092
  }
2093
  echo "<p>" . sprintf( __( 'Username/Password: %s', 'wp-super-cache' ), $wp_cache_debug_username ) . "</p>";
2094
 
2095
- echo '<form name="wpsc_delete" action="" method="post">';
2096
  wp_nonce_field('wp-cache');
2097
  echo "<input type='hidden' name='wpsc_delete_log' value='1' />";
2098
  submit_button( __( 'Delete', 'wp-super-cache' ), 'delete', 'wpsc_delete_log_form', false );
2099
  echo "</form>";
2100
- echo '<form name="wpsc_delete" action="" method="post">';
 
2101
  if ( ! isset( $wp_super_cache_debug ) || $wp_super_cache_debug == 0 ) {
2102
  $debug_status_message = __( 'Enable Logging', 'wp-super-cache' );
2103
  $not_status = 1;
@@ -2109,7 +2157,8 @@ function wp_cache_debug_settings() {
2109
  wp_nonce_field('wp-cache');
2110
  submit_button( $debug_status_message, 'primary', 'wpsc_log_status', true );
2111
  echo "</form>";
2112
- echo '<form name="wp_cache_debug" action="" method="post">';
 
2113
  echo "<input type='hidden' name='wp_cache_debug' value='1' /><br />";
2114
  echo "<table class='form-table'>";
2115
  echo "<tr><th>" . __( 'IP Address', 'wp-super-cache' ) . "</th><td> <input type='text' size='20' name='wp_cache_debug_ip' value='{$wp_cache_debug_ip}' /> " . sprintf( __( '(only log requests from this IP address. Your IP is %s)', 'wp-super-cache' ), $_SERVER[ 'REMOTE_ADDR' ] ) . "</td></tr>";
@@ -2120,15 +2169,15 @@ function wp_cache_debug_settings() {
2120
  &lt;!-- super cache --></pre></td></tr>";
2121
  echo "</table>\n";
2122
  if ( isset( $wp_super_cache_advanced_debug ) ) {
2123
- echo "<h5>" . __( 'Advanced', 'wp-super-cache' ) . "</h5><p>" . __( 'In very rare cases two problems may arise on some blogs:<ol><li> The front page may start downloading as a zip file.</li><li> The wrong page is occasionally cached as the front page if your blog uses a static front page and the permalink structure is <em>/%category%/%postname%/</em>.</li></ol>', 'wp-super-cache' ) . '</p>';
2124
- echo "<p>" . __( 'I&#8217;m 99% certain that they aren&#8217;t bugs in WP Super Cache and they only happen in very rare cases but you can run a simple check once every 5 minutes to verify that your site is ok if you&#8217;re worried. You will be emailed if there is a problem.', 'wp-super-cache' ) . "</p>";
2125
- echo "<table class='form-table'>";
2126
- echo "<tr><td valign='top' colspan='2'><input type='checkbox' name='wp_super_cache_front_page_check' value='1' " . checked( 1, $wp_super_cache_front_page_check, false ) . " /> " . __( 'Check front page every 5 minutes.', 'wp-super-cache' ) . "</td></tr>";
2127
- echo "<tr><td valign='top'>" . __( 'Front page text', 'wp-super-cache' ) . "</td><td> <input type='text' size='30' name='wp_super_cache_front_page_text' value='{$wp_super_cache_front_page_text}' /> (" . __( 'Text to search for on your front page. If this text is missing, the cache will be cleared. Leave blank to disable.', 'wp-super-cache' ) . ")</td></tr>";
2128
- echo "<tr><td valign='top' colspan='2'><input type='checkbox' name='wp_super_cache_front_page_clear' value='1' " . checked( 1, $wp_super_cache_front_page_clear, false ) . " /> " . __( 'Clear cache on error.', 'wp-super-cache' ) . "</td></tr>";
2129
- echo "<tr><td valign='top' colspan='2'><input type='checkbox' name='wp_super_cache_front_page_notification' value='1' " . checked( 1, $wp_super_cache_front_page_notification, false ) . " /> " . __( 'Email the blog admin when checks are made. (useful for testing)', 'wp-super-cache' ) . "</td></tr>";
2130
 
2131
- echo "</table>\n";
2132
  }
2133
  echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save Settings', 'wp-super-cache' ) . '" /></div>';
2134
  wp_nonce_field('wp-cache');
@@ -2523,6 +2572,16 @@ function wp_cache_create_advanced_cache() {
2523
  }
2524
  $ret = true;
2525
 
 
 
 
 
 
 
 
 
 
 
2526
  $file = file_get_contents( $wp_cache_file );
2527
  $fp = @fopen( $wp_cache_link, 'w' );
2528
  if( $fp ) {
@@ -2543,11 +2602,7 @@ function wp_cache_check_link() {
2543
  if( strpos( $file, "WP SUPER CACHE 0.8.9.1" ) || strpos( $file, "WP SUPER CACHE 1.2" ) ) {
2544
  return true;
2545
  } else {
2546
- if( !@unlink($wp_cache_link) ) {
2547
- $ret = false;
2548
- } else {
2549
- $ret = wp_cache_create_advanced_cache();
2550
- }
2551
  }
2552
  } else {
2553
  $ret = wp_cache_create_advanced_cache();
@@ -2845,19 +2900,21 @@ function wp_cache_files() {
2845
 
2846
  function wp_cache_delete_buttons() {
2847
 
2848
- echo '<form name="wp_cache_content_expired" action="#listfiles" method="post">';
 
 
2849
  echo '<input type="hidden" name="wp_delete_expired" />';
2850
  echo '<div class="submit" style="float:left"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Expired', 'wp-super-cache' ) . '" /></div>';
2851
  wp_nonce_field('wp-cache');
2852
  echo "</form>\n";
2853
 
2854
- echo '<form name="wp_cache_content_delete" action="#listfiles" method="post">';
2855
  echo '<input type="hidden" name="wp_delete_cache" />';
2856
  echo '<div class="submit" style="float:left;margin-left:10px"><input id="deletepost" class="button-secondary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Cache', 'wp-super-cache' ) . '" /></div>';
2857
  wp_nonce_field('wp-cache');
2858
  echo "</form>\n";
2859
- if ( ( defined( 'VHOST' ) || defined( 'SUBDOMAIN_INSTALL' ) || defined( 'SUNRISE' ) || ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) ) && wpsupercache_site_admin() ) {
2860
- echo '<form name="wp_cache_content_delete" action="#listfiles" method="post">';
2861
  echo '<input type="hidden" name="wp_delete_all_cache" />';
2862
  echo '<div class="submit" style="float:left;margin-left:10px"><input id="deleteallpost" class="button-secondary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Cache On All Blogs', 'wp-super-cache' ) . '" /></div>';
2863
  wp_nonce_field('wp-cache');
@@ -2992,6 +3049,8 @@ function wp_cache_clean_legacy_files( $dir, $file_prefix ) {
2992
  return false;
2993
 
2994
  if ( $handle = @opendir( $dir ) ) {
 
 
2995
  while ( false !== ( $file = readdir( $handle ) ) ) {
2996
  if ( is_file( $dir . $file ) == false || $file == 'index.html' ) {
2997
  continue;
@@ -3004,8 +3063,9 @@ function wp_cache_clean_legacy_files( $dir, $file_prefix ) {
3004
  @unlink( $dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
3005
  } else {
3006
  $meta = json_decode( wp_cache_get_legacy_cache( $dir . 'meta/' . $file ), true );
3007
- if ( ( defined( 'VHOST' ) || defined( 'SUBDOMAIN_INSTALL' ) || defined( 'SUNRISE' ) || ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) ) && $meta[ 'blog_id' ] != $wpdb->blogid )
3008
  continue;
 
3009
  @unlink( $dir . $file);
3010
  @unlink( $dir . 'meta/' . $file);
3011
  }
@@ -3084,12 +3144,6 @@ function wpsc_remove_marker( $filename, $marker ) {
3084
  }
3085
  }
3086
 
3087
- function wp_super_cache_footer() {
3088
- ?><p id='supercache'><?php printf( __( '%1$s is Stephen Fry proof thanks to caching by %2$s', 'wp-super-cache' ), get_bloginfo( 'name', 'display' ), '<a href="https://odd.blog/wp-super-cache/">WP Super Cache</a>' ); ?></p><?php
3089
- }
3090
- if( isset( $wp_cache_hello_world ) && $wp_cache_hello_world )
3091
- add_action( 'wp_footer', 'wp_super_cache_footer' );
3092
-
3093
  if( get_option( 'gzipcompression' ) )
3094
  update_option( 'gzipcompression', 0 );
3095
 
@@ -3144,8 +3198,9 @@ function wp_cache_admin_notice() {
3144
  echo '<div class="notice notice-info"><p><strong>' . sprintf( __('WP Super Cache is disabled. Please go to the <a href="%s">plugin admin page</a> to enable caching.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '</strong></p></div>';
3145
 
3146
  if ( defined( 'WP_CACHE' ) && WP_CACHE == true && ( defined( 'ADVANCEDCACHEPROBLEM' ) || ( $cache_enabled && false == isset( $wp_cache_phase1_loaded ) ) ) ) {
3147
- echo '<div class="notice notice-error"><p>' . sprintf( __( 'Warning! WP Super Cache caching <strong>was</strong> broken but has been <strong>fixed</strong>! The script advanced-cache.php could not load wp-cache-phase1.php.<br /><br />The file %1$s/advanced-cache.php has been recreated and WPCACHEHOME fixed in your wp-config.php. Reload to hide this message.', 'wp-super-cache' ), WP_CONTENT_DIR ) . '</p></div>';
3148
- wp_cache_create_advanced_cache();
 
3149
  }
3150
  }
3151
  add_action( 'admin_notices', 'wp_cache_admin_notice' );
@@ -3218,6 +3273,7 @@ function wpsc_update_htaccess() {
3218
  function wpsc_update_htaccess_form( $short_form = true ) {
3219
  global $wpmu_version;
3220
 
 
3221
  extract( wpsc_get_htaccess_info() ); // $document_root, $apache_root, $home_path, $home_root, $home_root_lc, $inst_root, $wprules, $scrules, $condition_rules, $rules, $gziprules
3222
  if( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) {
3223
  echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><h5>" . __( 'Cannot update .htaccess', 'wp-super-cache' ) . "</h5><p>" . sprintf( __( 'The file <code>%s.htaccess</code> cannot be modified by the web server. Please correct this using the chmod command or your ftp client.', 'wp-super-cache' ), $home_path ) . "</p><p>" . __( 'Refresh this page when the file permissions have been modified.' ) . "</p><p>" . sprintf( __( 'Alternatively, you can edit your <code>%s.htaccess</code> file manually and add the following code (before any WordPress rules):', 'wp-super-cache' ), $home_path ) . "</p>";
@@ -3236,7 +3292,7 @@ function wpsc_update_htaccess_form( $short_form = true ) {
3236
  echo "</div>";
3237
  }
3238
  if ( !isset( $wpmu_version ) || $wpmu_version == '' ) {
3239
- echo '<form name="updatehtaccess" action="#modrewrite" method="post">';
3240
  echo '<input type="hidden" name="updatehtaccess" value="1" />';
3241
  echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'id="updatehtaccess" value="' . __( 'Update Mod_Rewrite Rules', 'wp-super-cache' ) . '" /></div>';
3242
  wp_nonce_field('wp-cache');
@@ -3760,7 +3816,7 @@ function wpsc_admin_bar_render( $wp_admin_bar ) {
3760
  'id' => 'delete-cache',
3761
  'title' => __( 'Delete Cache', 'wp-super-cache' ),
3762
  'meta' => array( 'title' => __( 'Delete cache of the current page', 'wp-super-cache' ) ),
3763
- 'href' => wp_nonce_url( admin_url( 'index.php?action=delcachepage&path=' . urlencode( $path ) ), 'delete-cache' )
3764
  ) );
3765
  }
3766
 
@@ -3769,7 +3825,7 @@ function wpsc_admin_bar_render( $wp_admin_bar ) {
3769
  'parent' => '',
3770
  'id' => 'delete-cache',
3771
  'title' => __( 'Delete Cache', 'wp-super-cache' ),
3772
- 'meta' => array( 'title' => __( 'Delete Super Cache cached files (opens in new window)', 'wp-super-cache' ), 'target' => '_blank' ),
3773
  'href' => wp_nonce_url( admin_url( 'options-general.php?page=wpsupercache&tab=contents&wp_delete_cache=1' ), 'wp-cache' )
3774
  ) );
3775
  }
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.6.5
7
  Author: Automattic
8
  Author URI: https://automattic.com/
9
  License: GPL2+
33
  require_once( dirname( __FILE__ ) . '/wp-cache-phase2.php');
34
  }
35
 
36
+ if ( ! defined( 'PHP_VERSION_ID' ) ) {
37
+ // For versions of PHP below 5.2.7, this constant doesn't exist.
38
+ $wpsc_php_version = explode( '.', PHP_VERSION );
39
+ define( 'PHP_VERSION_ID', intval( $wpsc_php_version[0] * 10000 + $wpsc_php_version[1] * 100 + $wpsc_php_version[2] ) );
40
+ unset( $wpsc_php_version );
41
+ }
42
+
43
  function wpsc_init() {
44
  global $wp_cache_config_file, $wp_cache_config_file_sample, $wp_cache_file, $wp_cache_check_wp_config, $wp_cache_link;
45
 
83
  global $wp_cache_mobile, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes;
84
  global $wp_cache_config_file, $wp_cache_config_file_sample;
85
 
86
+ // Check is cache config already loaded.
87
+ if ( ! isset( $cache_enabled, $super_cache_enabled, $wp_cache_mod_rewrite, $cache_path ) &&
88
+ empty( $wp_cache_phase1_loaded ) &&
89
+ // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
90
+ ! @include( $wp_cache_config_file )
91
+ ) {
92
+ @include $wp_cache_config_file_sample; // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
 
 
 
 
93
  }
94
 
95
  include(WPCACHEHOME . 'wp-cache-base.php');
119
  include_once( WPCACHEHOME . 'ossdl-cdn.php' );
120
 
121
  function get_wpcachehome() {
122
+ if ( function_exists( '_deprecated_function' ) ) {
123
+ _deprecated_function( __FUNCTION__, 'WP Super Cache 1.6.5' );
124
+ }
125
+
126
+ if ( ! defined( 'WPCACHEHOME' ) ) {
127
+ if ( is_file( dirname( __FILE__ ) . '/wp-cache-config-sample.php' ) ) {
128
+ define( 'WPCACHEHOME', trailingslashit( dirname( __FILE__ ) ) );
129
+ } elseif ( is_file( dirname( __FILE__ ) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
130
+ define( 'WPCACHEHOME', dirname( __FILE__ ) . '/wp-super-cache/' );
131
  } else {
132
+ die( sprintf( esc_html__( 'Please create %s /wp-cache-config.php from wp-super-cache/wp-cache-config-sample.php', 'wp-super-cache' ), esc_attr( WP_CONTENT_DIR ) ) );
133
  }
134
  }
135
  }
136
 
137
+ function wpsc_remove_advanced_cache() {
138
+ global $wp_cache_link;
139
+ if ( file_exists( $wp_cache_link ) ) {
140
+ $file = file_get_contents( $wp_cache_link );
141
+ if (
142
+ strpos( $file, "WP SUPER CACHE 0.8.9.1" ) ||
143
+ strpos( $file, "WP SUPER CACHE 1.2" )
144
+ ) {
145
+ unlink( $wp_cache_link );
146
  }
147
  }
148
+ }
149
+
150
+ function wpsupercache_uninstall() {
151
+ global $wp_cache_config_file, $cache_path;
152
+
153
+ wpsc_remove_advanced_cache();
154
+
155
+ if ( file_exists( $wp_cache_config_file ) ) {
156
+ unlink( $wp_cache_config_file );
157
+ }
158
 
159
  wp_cache_remove_index();
160
 
177
  function wpsupercache_deactivate() {
178
  global $wp_cache_config_file, $wp_cache_link, $cache_path;
179
 
180
+ wpsc_remove_advanced_cache();
 
 
181
 
182
  if ( ! empty( $cache_path ) ) {
183
  prune_super_cache( $cache_path, true );
220
  function wpsupercache_site_admin() {
221
  global $wp_version;
222
 
223
+ if ( version_compare( $wp_version, '4.8', '>=' ) ) {
224
  return current_user_can( 'setup_network' );
225
  }
226
 
227
+ return is_super_admin();
 
 
 
 
 
 
228
  }
229
 
230
  function wp_cache_add_pages() {
231
+ if ( wpsupercache_site_admin() ) {
232
+ // In single or MS mode add this menu item too, but only for superadmins in MS mode.
233
+ add_options_page( 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager' );
234
  }
235
  }
236
+ add_action( 'admin_menu', 'wp_cache_add_pages' );
237
 
238
  function wp_cache_network_pages() {
239
+ add_submenu_page( 'settings.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager' );
240
  }
241
  add_action( 'network_admin_menu', 'wp_cache_network_pages' );
242
 
245
  global $dismiss_htaccess_warning, $dismiss_readable_warning, $dismiss_gc_warning, $wp_cache_shutdown_gc, $is_nginx;
246
  global $htaccess_path;
247
 
248
+ if ( ! wpsupercache_site_admin() ) {
249
  return false;
250
+ }
251
 
252
+ if ( PHP_VERSION_ID < 50300 && ( ini_get( 'safe_mode' ) === '1' || strtolower( ini_get( 'safe_mode' ) ) === 'on' ) ) { // @codingStandardsIgnoreLine
253
+ echo '<div class="notice notice-error"><h4>' . esc_html__( 'Warning! PHP Safe Mode Enabled!', 'wp-super-cache' ) . '</h4>';
254
+ echo '<p>' . esc_html__( 'You may experience problems running this plugin because SAFE MODE is enabled.', 'wp-super-cache' ) . '<br />';
 
255
 
256
+ if ( ! ini_get( 'safe_mode_gid' ) ) { // @codingStandardsIgnoreLine
257
+ esc_html_e( 'Your server is set up to check the owner of PHP scripts before allowing them to read and write files.', 'wp-super-cache' );
258
+ echo '<br />';
259
+ printf( __( 'You or an administrator may be able to make it work by changing the group owner of the plugin scripts to match that of the web server user. The group owner of the %s/cache/ directory must also be changed. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details.', 'wp-super-cache' ), esc_attr( WP_CONTENT_DIR ) );
260
  } else {
261
  _e( 'You or an administrator must disable this. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details. This cannot be disabled in a .htaccess file unfortunately. It must be done in the php.ini config file.', 'wp-super-cache' );
262
  }
494
  */
495
  function admin_bar_delete_page() {
496
 
497
+ if ( ! current_user_can( 'delete_others_posts' ) ) {
498
  return false;
499
  }
500
 
501
+ $req_path = isset( $_GET['path'] ) ? sanitize_text_field( stripslashes( $_GET['path'] ) ) : '';
502
  $referer = wp_get_referer();
503
  $valid_nonce = ( $req_path && isset( $_GET['_wpnonce'] ) ) ? wp_verify_nonce( $_GET['_wpnonce'], 'delete-cache' ) : false;
504
 
505
  $path = $valid_nonce ? realpath( trailingslashit( get_supercache_dir() . str_replace( '..', '', preg_replace( '/:.*$/', '', $req_path ) ) ) ) : false;
506
 
507
  if ( $path ) {
508
+ $path = trailingslashit( $path );
509
  $supercachepath = realpath( get_supercache_dir() );
510
 
511
+ if ( false === wp_cache_confirm_delete( $path ) ||
512
+ 0 !== strpos( $path, $supercachepath )
513
+ ) {
514
  wp_die( 'Could not delete directory' );
515
  }
516
 
518
  }
519
 
520
  if ( $referer && $req_path && ( false !== stripos( $referer, $req_path ) || 0 === stripos( $referer, wp_login_url() ) ) ) {
521
+ wp_safe_redirect( esc_url_raw( home_url( $req_path ) ) );
522
  exit;
523
  }
524
  }
527
  }
528
 
529
  function wp_cache_manager_updates() {
530
+ global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $cache_path, $wp_cache_object_cache, $_wp_using_ext_object_cache, $wp_cache_refresh_single_only, $cache_compression, $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get;
531
  global $cache_schedule_type, $cache_max_time, $cache_time_interval, $wp_cache_shutdown_gc, $wpsc_save_headers;
532
 
533
  if ( !wpsupercache_site_admin() )
572
  wp_clear_scheduled_hook( 'wp_cache_gc' );
573
  wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
574
  }
575
+ $advanced_settings = array( 'wp_super_cache_late_init', 'wp_cache_disable_utf8', 'wp_cache_no_cache_for_get', 'wp_supercache_304', 'wp_cache_mfunc_enabled', 'wp_cache_mobile_enabled', 'wp_cache_front_page_checks', 'wp_supercache_cache_list', 'wp_cache_clear_on_post_edit', 'wp_cache_not_logged_in', 'wp_cache_make_known_anon','wp_cache_object_cache', 'wp_cache_refresh_single_only', 'cache_compression' );
576
  foreach( $advanced_settings as $setting ) {
577
  if ( isset( $GLOBALS[ $setting ] ) && $GLOBALS[ $setting ] == 1 ) {
578
  $_POST[ $setting ] = 1;
676
  }
677
  wp_cache_setting( 'wp_cache_mod_rewrite', $wp_cache_mod_rewrite );
678
 
 
 
 
 
 
 
 
679
  if( isset( $_POST[ 'wp_cache_clear_on_post_edit' ] ) ) {
680
  $wp_cache_clear_on_post_edit = 1;
681
  } else {
768
  add_action( 'admin_init', 'wp_cache_manager_updates' );
769
 
770
  function wp_cache_manager() {
771
+ global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled;
772
  global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_no_cache_for_get;
773
  global $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_supercache_cache_list, $cache_page_secret;
774
  global $wp_super_cache_front_page_check, $wp_cache_object_cache, $_wp_using_ext_object_cache, $wp_cache_refresh_single_only, $wp_cache_mobile_prefixes;
857
  echo '<div class="wrap">';
858
  echo '<h3>' . __( 'WP Super Cache Settings', 'wp-super-cache' ) . '</h3>';
859
 
860
+ // Set a default.
861
+ if ( false === $cache_enabled && ! isset( $wp_cache_mod_rewrite ) ) {
862
  $wp_cache_mod_rewrite = 0;
863
+ } elseif ( ! isset( $wp_cache_mod_rewrite ) && $cache_enabled && $super_cache_enabled ) {
864
  $wp_cache_mod_rewrite = 1;
865
  }
866
 
867
+ $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
868
+ $curr_tab = ! empty( $_GET['tab'] ) ? sanitize_text_field( stripslashes( $_GET['tab'] ) ) : ''; // WPCS: sanitization ok.
869
+ if ( empty( $curr_tab ) ) {
870
+ $curr_tab = 'easy';
871
+ if ( $wp_cache_mod_rewrite ) {
872
+ $curr_tab = 'settings';
873
+ echo '<div class="notice notice-info is-dismissible"><p>' . __( 'Notice: <em>Expert mode caching enabled</em>. Showing Advanced Settings Page by default.', 'wp-super-cache' ) . '</p></div>';
874
+ }
875
  }
876
 
877
+ if ( 'preload' === $curr_tab ) {
878
+ if ( true === $super_cache_enabled && ! defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
879
  global $wp_cache_preload_interval, $wp_cache_preload_on, $wp_cache_preload_taxonomies, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $wp_cache_preload_posts, $wpdb;
880
  $count = wpsc_post_count();
881
  if ( $count > 1000 ) {
884
  $min_refresh_interval = 30;
885
  }
886
  $return = wpsc_preload_settings( $min_refresh_interval );
887
+ $msg = '';
888
  if ( empty( $return ) == false ) {
889
+ foreach ( $return as $message ) {
890
  $msg .= $message;
891
  }
892
  }
893
  $currently_preloading = false;
894
 
895
  $preload_counter = get_option( 'preload_cache_counter' );
896
+ if ( isset( $preload_counter['first'] ) ) { // converted from int to array
897
+ update_option( 'preload_cache_counter', array( 'c' => $preload_counter['c'], 't' => time() ) );
898
+ }
899
+
900
+ if ( is_array( $preload_counter ) && $preload_counter['c'] > 0 ) {
901
+ $msg .= '<p>' . sprintf( esc_html__( 'Currently caching from post %d to %d.', 'wp-super-cache' ), ( $preload_counter['c'] - 100 ), $preload_counter['c'] ) . '</p>';
902
  $currently_preloading = true;
903
+ if ( @file_exists( $cache_path . 'preload_permalink.txt' ) ) {
904
+ $url = file_get_contents( $cache_path . 'preload_permalink.txt' );
905
+ $msg .= '<p>' . sprintf( __( '<strong>Page last cached:</strong> %s', 'wp-super-cache' ), $url ) . '</p>';
906
  }
907
  if ( $msg != '' ) {
908
+ echo '<div class="notice notice-warning"><h4>' . esc_html__( 'Preload Active', 'wp-super-cache' ) . '</h4>' . $msg;
909
+ echo '<form name="do_preload" action="' . esc_url_raw( add_query_arg( 'tab', 'preload', $admin_url ) ) . '" method="POST">';
910
  echo '<input type="hidden" name="action" value="preload" />';
911
  echo '<input type="hidden" name="page" value="wpsupercache" />';
912
+ echo '<p><input class="button-primary" type="submit" name="preload_off" value="' . esc_html__( 'Cancel Cache Preload', 'wp-super-cache' ) . '" /></p>';
913
+ wp_nonce_field( 'wp-cache' );
914
  echo '</form>';
915
  echo '</div>';
916
  }
921
  }
922
  }
923
 
924
+ wpsc_admin_tabs( $curr_tab );
925
 
926
+ if ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 1 && ! wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
927
+ wp_schedule_single_event( time() + 360, 'wp_cache_check_site_hook' );
 
 
928
  wp_cache_debug( 'scheduled wp_cache_check_site_hook for 360 seconds time.', 2 );
929
  }
930
 
931
+ if ( isset( $_REQUEST['wp_restore_config'] ) && $valid_nonce ) {
932
+ unlink( $wp_cache_config_file );
933
+ echo '<strong>' . esc_html__( 'Configuration file changed, some values might be wrong. Load the page again from the "Settings" menu to reset them.', 'wp-super-cache' ) . '</strong>';
934
  }
935
 
936
  if ( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
937
+ wp_cache_replace_line( '^ *\$wp_cache_slash_check', "\$wp_cache_slash_check = 1;", $wp_cache_config_file );
938
  } else {
939
+ wp_cache_replace_line( '^ *\$wp_cache_slash_check', "\$wp_cache_slash_check = 0;", $wp_cache_config_file );
940
  }
941
  $home_path = parse_url( site_url() );
942
+ $home_path = trailingslashit( array_key_exists( 'path', $home_path ) ? $home_path['path'] : '' );
943
+ if ( ! isset( $wp_cache_home_path ) ) {
944
  $wp_cache_home_path = '/';
945
  wp_cache_setting( 'wp_cache_home_path', '/' );
946
  }
947
+ if ( "$home_path" != "$wp_cache_home_path" ) {
948
  wp_cache_setting( 'wp_cache_home_path', $home_path );
949
+ }
950
 
951
+ if ( $wp_cache_mobile_enabled == 1 ) {
 
952
  update_cached_mobile_ua_list( $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $mobile_groups );
953
  }
954
 
955
+ ?>
956
+ <table class="wpsc-settings-table"><td valign="top">
957
+ <?php
958
+
959
+ switch ( $curr_tab ) {
960
+ case 'cdn':
961
+ scossdl_off_options();
962
+ break;
963
+ case 'tester':
964
+ case 'contents':
965
+ echo '<a name="test"></a>';
966
+ wp_cache_files();
967
+ break;
968
+ case 'preload':
969
+ if ( ! $cache_enabled ) {
970
+ wp_die( esc_html__( 'Caching must be enabled to use this feature', 'wp-super-cache' ) );
971
+ }
972
+ echo '<a name="preload"></a>';
973
  if ( $super_cache_enabled == true && false == defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
974
  echo '<p>' . __( 'This will cache every published post and page on your site. It will create supercache static files so unknown visitors (including bots) will hit a cached page. This will probably help your Google ranking as they are using speed as a metric when judging websites now.', 'wp-super-cache' ) . '</p>';
975
  echo '<p>' . __( 'Preloading creates lots of files however. Caching is done from the newest post to the oldest so please consider only caching the newest if you have lots (10,000+) of posts. This is especially important on shared hosting.', 'wp-super-cache' ) . '</p>';
976
  echo '<p>' . __( 'In &#8217;Preload Mode&#8217; regular garbage collection will be disabled so that old cache files are not deleted. This is a recommended setting when the cache is preloaded.', 'wp-super-cache' ) . '</p>';
977
+ echo '<form name="cache_filler" action="' . esc_url_raw( add_query_arg( 'tab', 'preload', $admin_url ) ) . '" method="POST">';
978
  echo '<input type="hidden" name="action" value="preload" />';
979
  echo '<input type="hidden" name="page" value="wpsupercache" />';
980
+ echo '<p>' . sprintf( __( 'Refresh preloaded cache files every %s minutes. (0 to disable, minimum %d minutes.)', 'wp-super-cache' ), "<input type='text' size=4 name='wp_cache_preload_interval' value='" . (int) $wp_cache_preload_interval . "' />", $min_refresh_interval ) . '</p>';
981
  if ( $count > 100 ) {
982
  $step = (int)( $count / 10 );
983
 
1029
  }
1030
  echo '<div class="submit"><input class="button-primary" type="submit" name="preload" value="' . __( 'Save Settings', 'wp-super-cache' ) . '" />';
1031
  echo '</div>';
1032
+ wp_nonce_field( 'wp-cache' );
1033
  echo '</form>';
1034
+ echo '<form name="do_preload" action="' . esc_url_raw( add_query_arg( 'tab', 'preload', $admin_url ) ) . '" method="POST">';
1035
  echo '<input type="hidden" name="action" value="preload" />';
1036
  echo '<input type="hidden" name="page" value="wpsupercache" />';
1037
  echo '<div class="submit">';
1041
  echo '<input class="button-primary" type="submit" name="preload_off" value="' . __( 'Cancel Cache Preload', 'wp-super-cache' ) . '" />';
1042
  }
1043
  echo '</div>';
1044
+ wp_nonce_field( 'wp-cache' );
1045
  echo '</form>';
1046
  } else {
1047
  echo '<div class="notice notice-warning"><p>' . __( 'Preloading of cache disabled. Please make sure simple or expert mode is enabled or talk to your host administrator.', 'wp-super-cache' ) . '</p></div>';
1048
  }
1049
+ break;
1050
  case 'plugins':
1051
+ wpsc_plugins_tab();
1052
+ break;
1053
  case 'debug':
1054
+ wp_cache_debug_settings();
1055
+ break;
1056
  case 'settings':
1057
+ if ( isset( $wp_cache_front_page_checks ) == false ) {
1058
+ $wp_cache_front_page_checks = true;
1059
+ }
1060
+ echo '<form name="wp_manager" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) ) . '" method="post">';
1061
+ wp_nonce_field( 'wp-cache' );
1062
+ echo '<input type="hidden" name="action" value="scupdates" />';
1063
+ ?>
1064
+ <table class="form-table">
1065
  <tr valign="top">
1066
  <th scope="row"><label for="wp_cache_enabled"><?php _e( 'Caching', 'wp-super-cache' ); ?></label></th>
1067
  <td>
1084
  </fieldset>
1085
  </td>
1086
  </tr>
1087
+ <tr valign="top">
1088
+ <th scope="row"><label for="wp_cache_status"><?php esc_html_e( 'Miscellaneous', 'wp-super-cache' ); ?></label></th>
1089
+ <td>
1090
+ <fieldset>
1091
+ <legend class="hidden">Miscellaneous</legend>
1092
+ <label><input type='checkbox' name='wp_cache_not_logged_in' <?php checked( $wp_cache_not_logged_in ); ?> value='1'> <?php echo __( 'Don&#8217;t cache pages for <acronym title="Logged in users and those that comment">known users</acronym>.', 'wp-super-cache' ) . ' <em>(' . esc_html__( 'Recommended', 'wp-super-cache' ) . ')</em>'; ?></label><br />
1093
+ <label><input type='checkbox' name='wp_cache_no_cache_for_get' <?php checked( $wp_cache_no_cache_for_get ); ?> value='1'> <?php _e( 'Don&#8217;t cache pages with GET parameters. (?x=y at the end of a url)', 'wp-super-cache' ); ?></label><br />
1094
+ <?php if ( ! defined( 'WPSC_DISABLE_COMPRESSION' ) ) : ?>
1095
+ <?php if ( ! function_exists( 'gzencode' ) ) : ?>
1096
+ <em><?php esc_html_e( 'Warning! Compression is disabled as gzencode() function was not found.', 'wp-super-cache' ); ?></em><br />
1097
+ <?php else : ?>
1098
+ <label><input type='checkbox' name='cache_compression' <?php checked( $cache_compression ); ?> value='1'> <?php echo __( 'Compress pages so they&#8217;re served more quickly to visitors.', 'wp-super-cache' ) . ' <em>(' . esc_html__( 'Recommended', 'wp-super-cache' ) . ')</em>'; ?></label><br />
1099
+ <em><?php esc_html_e( 'Compression is disabled by default because some hosts have problems with compressed files. Switching it on and off clears the cache.', 'wp-super-cache' ); ?></em><br />
1100
+ <?php endif; ?>
1101
+ <?php endif; ?>
1102
+ <label><input type='checkbox' name='wpsc_save_headers' <?php checked( $wpsc_save_headers ); ?> value='1' /> <?php esc_html_e( 'Cache HTTP headers with page content.', 'wp-super-cache' ); ?></label><br />
1103
+ <label><input type='checkbox' name='cache_rebuild_files' <?php checked( $cache_rebuild_files ); ?> value='1'> <?php echo esc_html__( 'Cache rebuild. Serve a supercache file to anonymous users while a new file is being generated.', 'wp-super-cache' ) . ' <em>(' . esc_html__( 'Recommended', 'wp-super-cache' ) . ')</em>'; ?></label><br />
 
1104
  <?php
1105
  $disable_304 = true;
1106
  if ( 0 == $wp_cache_mod_rewrite )
1107
  $disable_304 = false;
1108
  if ( $disable_304 )
1109
  echo "<strike>";
1110
+ ?>
1111
+ <label><input <?php disabled( $disable_304 ); ?> type='checkbox' name='wp_supercache_304' <?php checked( $wp_supercache_304 ); ?> value='1'> <?php echo esc_html__( '304 Not Modified browser caching. Indicate when a page has not been modified since it was last requested.', 'wp-super-cache' ) . ' <em>(' . esc_html__( 'Recommended', 'wp-super-cache' ) . ')</em>'; ?></label><br />
1112
+ <?php
1113
+ if ( $disable_304 ) {
1114
+ echo '</strike>';
1115
+ echo '<p><strong>' . esc_html__( 'Warning! 304 browser caching is only supported when mod_rewrite caching is not used.', 'wp-super-cache' ) . '</strong></p>';
1116
+ } else {
1117
+ echo '<em>' . esc_html__( '304 support is disabled by default because some hosts have had problems with the headers used in the past.', 'wp-super-cache' ) . '</em><br />';
1118
+ }
1119
+ ?>
1120
+ <label><input type='checkbox' name='wp_cache_make_known_anon' <?php checked( $wp_cache_make_known_anon ); ?> value='1'> <?php _e( 'Make known users anonymous so they&#8217;re served supercached static files.', 'wp-super-cache' ); ?></label><br />
1121
+ </legend>
1122
+ </fieldset>
1123
+ </td>
1124
+ </tr>
1125
  <tr valign="top">
1126
  <th scope="row"><label for="wp_cache_status"><?php _e( 'Advanced', 'wp-super-cache' ); ?></label></th>
1127
  <td>
1179
  </td>
1180
  </tr>
1181
  </table>
1182
+ <h4><?php esc_html_e( 'Note:', 'wp-super-cache' ); ?></h4>
1183
+ <ol>
1184
+ <li><?php esc_html_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>
1185
+ <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' ), esc_attr( WP_CONTENT_DIR ) ); ?></li>
1186
+ <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>
1187
+ <li><?php echo '<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>
1188
+ </ol>
1189
 
1190
+ <?php
1191
+ echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . ' value="' . esc_html__( 'Update Status', 'wp-super-cache' ) . '" /></div>';
1192
+ wp_nonce_field( 'wp-cache' );
1193
+
1194
+ ?></form><?php
1195
+
1196
+ wsc_mod_rewrite();
1197
 
1198
+ wp_cache_edit_max_time();
1199
 
1200
+ echo '<a name="files"></a><fieldset class="options"><h4>' . __( 'Accepted Filenames &amp; Rejected URIs', 'wp-super-cache' ) . '</h4>';
1201
+ wp_cache_edit_rejected_pages();
1202
+ echo "\n";
1203
+ wp_cache_edit_rejected();
1204
+ echo "\n";
1205
+ wp_cache_edit_accepted();
1206
+ echo '</fieldset>';
1207
 
1208
+ wp_cache_edit_rejected_ua();
1209
 
1210
+ wp_lock_down();
1211
 
1212
+ wp_cache_restore();
1213
 
1214
+ break;
1215
+ case 'easy':
1216
  default:
1217
+ echo '<form name="wp_manager" action="' . esc_url_raw( add_query_arg( 'tab', 'easy', $admin_url ) ) . '" method="post">';
1218
  echo '<input type="hidden" name="action" value="easysetup" />';
1219
+ wp_nonce_field( 'wp-cache' );
1220
+ ?>
1221
+ <table class="form-table">
1222
  <tr valign="top">
1223
+ <th scope="row"><label for="wp_cache_status"><?php esc_html_e( 'Caching', 'wp-super-cache' ); ?></label></th>
1224
  <td>
1225
  <fieldset>
1226
+ <label><input type='radio' name='wp_cache_easy_on' value='1' <?php checked( $cache_enabled ); ?> ><?php echo esc_html__( 'Caching On', 'wp-super-cache' ) . ' <em>(' . esc_html__( 'Recommended', 'wp-super-cache' ) . ')</em>'; ?></label><br />
1227
+ <label><input type='radio' name='wp_cache_easy_on' value='0' <?php checked( ! $cache_enabled ); ?> ><?php esc_html_e( 'Caching Off', 'wp-super-cache' ); ?></label><br />
1228
  </fieldset>
1229
  </td>
1230
  </tr>
1231
+ </table>
1232
  <?php
1233
+ if ( ! $is_nginx && $cache_enabled && ! $wp_cache_mod_rewrite ) {
1234
  $scrules = trim( implode( "\n", extract_from_markers( trailingslashit( get_home_path() ) . '.htaccess', 'WPSuperCache' ) ) );
1235
+ if ( ! empty( $scrules ) ) {
1236
+ echo '<p><strong>' . esc_html__( 'Notice: Simple caching enabled but Supercache mod_rewrite rules from expert mode detected. Cached files will be served using those rules. If your site is working ok, please ignore this message. Otherwise, you can edit the .htaccess file in the root of your install and remove the SuperCache rules.', 'wp-super-cache' ) . '</strong></p>';
1237
  }
1238
  }
1239
+ echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . ' value="' . esc_html__( 'Update Status', 'wp-super-cache' ) . '" /></div></form>';
1240
  if ( $cache_enabled ) {
1241
+ echo '<h4>' . esc_html__( 'Cache Tester', 'wp-super-cache' ) . '</h4>';
1242
+ echo '<p>' . esc_html__( 'Test your cached website by clicking the test button below.', 'wp-super-cache' ) . '</p>';
1243
  echo '<p>' . __( 'Note: if you use Cloudflare or other transparent front-end proxy service this test may fail.<ol><li> If you have Cloudflare minification enabled this plugin may detect differences in the pages and report an error.</li><li> Try using the development mode of Cloudflare to perform the test. You can disable development mode afterwards if the test succeeds.</li></ol>', 'wp-super-cache' ) . '</p>';
1244
+ if ( array_key_exists( 'action', $_POST ) && 'test' === $_POST['action'] && $valid_nonce ) {
1245
  $url = trailingslashit( get_bloginfo( 'url' ) );
1246
+ if ( isset( $_POST['httponly'] ) ) {
1247
  $url = str_replace( 'https://', 'http://', $url );
1248
+ }
1249
+ $test_messages = array( esc_html__( 'Fetching %s to prime cache: ', 'wp-super-cache' ), esc_html__( 'Fetching first copy of %s: ', 'wp-super-cache' ), esc_html__( 'Fetching second copy of %s: ', 'wp-super-cache' ) );
1250
+ $c = 0;
1251
  $cache_test_error = false;
1252
+ $page = array();
1253
+ foreach ( $test_messages as $message ) {
1254
+ echo '<p>' . sprintf( $message, $url );
1255
+ $page[ $c ] = wp_remote_get( $url, array( 'timeout' => 60, 'blocking' => true ) );
1256
+ if ( ! is_wp_error( $page[ $c ] ) ) {
1257
+ $fp = fopen( $cache_path . $c . '.html', 'w' );
1258
+ fwrite( $fp, $page[ $c ]['body'] );
1259
  fclose( $fp );
1260
+ echo '<span style="color: #0a0; font-weight: bold;">' . esc_html__( 'OK', 'wp-super-cache' ) . "</span> (<a href='" . esc_url_raw( WP_CONTENT_URL . '/cache/' . $c . '.html' ) . "'>" . $c . '.html</a>)</p>';
1261
  sleep( 1 );
1262
  } else {
1263
  $cache_test_error = true;
1264
+ echo '<span style="color: #a00; font-weight: bold;">' . esc_html__( 'FAILED', 'wp-super-cache' ) . '</span></p>';
1265
+ $errors = '';
1266
  $messages = '';
1267
  foreach ( $page[ $c ]->get_error_codes() as $code ) {
1268
  $severity = $page[ $c ]->get_error_data( $code );
1270
  $errors .= $severity . ': ' . $err . "<br />\n";
1271
  }
1272
  }
1273
+ if ( ! empty( $errors ) ) {
1274
+ echo '<p>' . sprintf( __( '<strong>Errors:</strong> %s', 'wp-super-cache' ), $errors ) . '</p>';
1275
+ }
1276
  }
1277
  $c ++;
1278
  }
1279
 
1280
  if ( false == $cache_test_error ) {
1281
+ echo '<ul><li>' . sprintf( esc_html__( 'Page %d: %d (%s)', 'wp-super-cache' ), 1, intval( $page[1]['response']['code'] ), esc_attr( $page[1]['response']['message'] ) ) . '</li>';
1282
+ echo '<li>' . sprintf( esc_html__( 'Page %d: %d (%s)', 'wp-super-cache' ), 2, intval( $page[2]['response']['code'] ), esc_attr( $page[2]['response']['message'] ) ) . '</li></ul>';
1283
  }
1284
 
1285
+ if ( false == $cache_test_error && 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 ) &&
1286
+ 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 ) && $matches1[2] == $matches2[2]
1287
+ ) {
1288
+ echo '<p>' . sprintf( esc_html__( 'Page 1: %s', 'wp-super-cache' ), $matches1[2] ) . '</p>';
1289
+ echo '<p>' . sprintf( esc_html__( 'Page 2: %s', 'wp-super-cache' ), $matches2[2] ) . '</p>';
1290
+ echo '<p><span style="color: #0a0; font-weight: bold;">' . esc_html__( 'The timestamps on both pages match!', 'wp-super-cache' ) . '</span></p>';
1291
  } else {
1292
+ echo '<p><strong>' . esc_html__( 'The pages do not match! Timestamps differ or were not found!', 'wp-super-cache' ) . '</strong></p>';
1293
+ echo '<p>' . esc_html__( 'Things you can do:', 'wp-super-cache' ) . '</p>';
1294
+ echo '<ol><li>' . esc_html__( 'Load your homepage in a logged out browser, check the timestamp at the end of the html source. Load the page again and compare the timestamp. Caching is working if the timestamps match.', 'wp-super-cache' ) . '</li>';
1295
+ echo '<li>' . esc_html__( 'Enable logging on the Debug page here. That should help you track down the problem.', 'wp-super-cache' ) . '</li>';
1296
+ echo '<li>' . esc_html__( 'You should check Page 1 and Page 2 above for errors. Your local server configuration may not allow your website to access itself.', 'wp-super-cache' ) . '</li>';
1297
+ echo '</ol>';
1298
  }
1299
  }
1300
+ echo '<form name="cache_tester" action="' . esc_url_raw( add_query_arg( 'tab', 'easy', $admin_url ) ) . '" method="post">';
1301
  echo '<input type="hidden" name="action" value="test" />';
1302
+ if ( ! empty( $_SERVER['HTTPS'] ) && 'on' === strtolower( $_SERVER['HTTPS'] ) ) {
1303
+ echo '<input type="checkbox" name="httponly" checked="checked" value="1" /> ' . esc_html__( 'Send non-secure (non https) request for homepage', 'wp-super-cache' );
1304
+ }
1305
 
1306
  if ( isset( $wp_super_cache_comments ) && $wp_super_cache_comments == 0 ) {
1307
+ echo '<p>' . __( '<strong>Warning!</strong> Cache comments are currently disabled. Please go to the Debug page and enable Cache Status Messages there. You should clear the cache before testing.', 'wp-super-cache' ) . '</p>';
1308
+ echo '<div class="submit"><input disabled style="color: #aaa" class="button-secondary" type="submit" name="test" value="' . esc_html__( 'Test Cache', 'wp-super-cache' ) . '" /></div>';
1309
  } else {
1310
  echo '<div class="submit"><input class="button-secondary" type="submit" name="test" value="' . __( 'Test Cache', 'wp-super-cache' ) . '" /></div>';
1311
  }
1312
 
1313
+ wp_nonce_field( 'wp-cache' );
1314
  echo '</form>';
1315
  }
1316
+ echo '<h4>' . esc_html__( 'Delete Cached Pages', 'wp-super-cache' ) . '</h4>';
1317
+ echo '<p>' . esc_html__( 'Cached pages are stored on your server as html and PHP files. If you need to delete them, use the button below.', 'wp-super-cache' ) . '</p>';
1318
+ echo '<form name="wp_cache_content_delete" action="' . esc_url_raw( add_query_arg( 'tab', 'contents', $admin_url ) ) . '" method="post">';
1319
  echo '<input type="hidden" name="wp_delete_cache" />';
1320
+ echo '<div class="submit"><input id="deletepost" class="button-secondary" type="submit" ' . SUBMITDISABLED . 'value="' . esc_html__( 'Delete Cache', 'wp-super-cache' ) . ' " /></div>';
1321
+ wp_nonce_field( 'wp-cache' );
1322
  echo "</form>\n";
1323
 
1324
+ if ( is_multisite() && wpsupercache_site_admin() ) {
1325
+ echo '<form name="wp_cache_content_delete" action="' . esc_url_raw( add_query_arg( 'tab', 'contents', $admin_url ) . '#listfiles' ) . '" method="post">';
1326
  echo '<input type="hidden" name="wp_delete_all_cache" />';
1327
+ echo '<div class="submit"><input id="deleteallpost" class="button-secondary" type="submit" ' . SUBMITDISABLED . 'value="' . esc_html__( 'Delete Cache On All Blogs', 'wp-super-cache' ) . '" /></div>';
1328
+ wp_nonce_field( 'wp-cache' );
1329
  echo "</form><br />\n";
1330
  }
1331
  ?>
1332
+ <h4 class="clear"><?php esc_html_e( 'Recommended Links and Plugins', 'wp-super-cache' ); ?></h4>
1333
+ <p><?php esc_html_e( 'Caching is only one part of making a website faster. Here are some other plugins that will help:', 'wp-super-cache' ); ?></p>
1334
  <ul style="list-style: square; margin-left: 2em;">
1335
  <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>
1336
  <li><?php printf( __( '<a href="%s">Yahoo! Yslow</a> analyzes web pages and suggests ways to improve their performance based on a set of rules for high performance web pages. Also try the performance tools online at <a href="%s">GTMetrix</a>.', 'wp-super-cache' ), 'http://yslow.org/', 'https://gtmetrix.com/' ); ?></li>
1338
  <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>
1339
  <li><?php printf( __( '<a href="%s">WP Crontrol</a> is a useful plugin to use when trying to debug garbage collection and preload problems.', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-crontrol/' ); ?></li>
1340
  </ul>
 
1341
  <?php
 
 
1342
 
1343
+ break;
1344
+ }
1345
  ?>
1346
+
1347
  </fieldset>
1348
  </td><td valign='top' style='width: 300px'>
1349
  <div style='background: #ffc; border: 1px solid #333; margin: 2px; padding: 3px 15px'>
1359
  <li><?php printf( __( 'Visit the <a href="%1$s">plugin homepage</a>.', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-super-cache/' ); ?></li>
1360
  <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>
1361
  </ol>
1362
+ <h4><?php esc_html_e( 'Rate This Plugin', 'wp-super-cache' ); ?></h4>
1363
  <p><?php printf( __( 'Please <a href="%s">rate us</a> and give feedback.', 'wp-super-cache' ), 'https://wordpress.org/support/plugin/wp-super-cache/reviews?rate=5#new-post' ); ?></p>
1364
 
1365
  <?php
1366
  if ( isset( $wp_supercache_cache_list ) && $wp_supercache_cache_list ) {
1367
  $start_date = get_option( 'wpsupercache_start' );
1368
+ if ( ! $start_date ) {
1369
  $start_date = time();
1370
  }
1371
  ?>
1372
  <p><?php printf( __( 'Cached pages since %1$s : <strong>%2$s</strong>', 'wp-super-cache' ), date( 'M j, Y', $start_date ), number_format( get_option( 'wpsupercache_count' ) ) ); ?></p>
1373
  <p><?php _e( 'Newest Cached Pages:', 'wp-super-cache' ); ?><ol>
1374
+ <?php
1375
+ foreach ( array_reverse( (array) get_option( 'supercache_last_cached' ) ) as $url ) {
1376
+ $since = time() - strtotime( $url['date'] );
1377
+ echo "<li><a title='" . sprintf( esc_html__( 'Cached %s seconds ago', 'wp-super-cache' ), (int) $since ) . "' href='" . site_url( $url['url'] ) . "'>" . substr( $url['url'], 0, 20 ) . "</a></li>\n";
1378
+ }
1379
+ ?>
1380
+ </ol>
1381
+ <small><?php esc_html_e( '(may not always be accurate on busy sites)', 'wp-super-cache' ); ?></small>
1382
  </p><?php
1383
  } elseif ( false == get_option( 'wpsupercache_start' ) ) {
1384
  update_option( 'wpsupercache_start', time() );
1394
  }
1395
 
1396
  function wpsc_plugins_tab() {
1397
+ echo '<p>' . esc_html__( 'Cache plugins are PHP scripts you\'ll find in a dedicated folder inside the WP Super Cache folder (wp-super-cache/plugins/). They load at the same time as WP Super Cache, and before regular WordPress plugins.', 'wp-super-cache' ) . '</p>';
1398
+ echo '<p>' . esc_html__( 'Keep in mind that cache plugins are for advanced users only. To create and manage them, you\'ll need extensive knowledge of both PHP and WordPress actions.', 'wp-super-cache' ) . '</p>';
1399
  echo '<p>' . sprintf( __( '<strong>Warning</strong>! Due to the way WordPress upgrades plugins, the ones you upload to the WP Super Cache folder (wp-super-cache/plugins/) will be deleted when you upgrade WP Super Cache. To avoid this loss, load your cache plugins from a different location. When you set <strong>$wp_cache_plugins_dir</strong> to the new location in wp-config.php, WP Super Cache will look there instead. <br />You can find additional details in the <a href="%s">developer documentation</a>.', 'wp-super-cache' ), 'https://odd.blog/wp-super-cache-developers/' ) . '</p>';
1400
  ob_start();
1401
+ if ( defined( 'WP_CACHE' ) ) {
1402
+ if ( function_exists( 'do_cacheaction' ) ) {
1403
  do_cacheaction( 'cache_admin_page' );
1404
  }
1405
  }
1406
  $out = ob_get_contents();
1407
  ob_end_clean();
1408
+
1409
+ if ( SUBMITDISABLED == ' ' && $out != '' ) {
1410
+ echo '<h4>' . esc_html__( 'Available Plugins', 'wp-super-cache' ) . '</h4>';
1411
+ echo '<ol>';
1412
  echo $out;
1413
+ echo '</ol>';
1414
  }
 
1415
  }
1416
 
1417
+ function wpsc_admin_tabs( $current = '' ) {
1418
+ global $cache_enabled, $super_cache_enabled, $wp_cache_mod_rewrite;
1419
+
1420
+ if ( '' === $current ) {
1421
+ $current = ! empty( $_GET['tab'] ) ? stripslashes( $_GET['tab'] ) : ''; // WPCS: CSRF ok, sanitization ok.
 
 
 
 
 
 
 
 
 
 
 
 
1422
  }
1423
+
1424
+ $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
1425
+ $admin_tabs = array(
1426
+ 'easy' => __( 'Easy', 'wp-super-cache' ),
1427
+ 'settings' => __( 'Advanced', 'wp-super-cache' ),
1428
+ 'cdn' => __( 'CDN', 'wp-super-cache' ),
1429
+ 'contents' => __( 'Contents', 'wp-super-cache' ),
1430
+ 'preload' => __( 'Preload', 'wp-super-cache' ),
1431
+ 'plugins' => __( 'Plugins', 'wp-super-cache' ),
1432
+ 'debug' => __( 'Debug', 'wp-super-cache' ),
1433
+ );
1434
+
1435
+ echo '<div id="nav"><h3 class="themes-php">';
1436
+
1437
+ foreach ( $admin_tabs as $tab => $name ) {
1438
+ printf( '<a class="%s" href="%s">%s</a>',
1439
+ esc_attr( $tab === $current ? 'nav-tab nav-tab-active' : 'nav-tab' ),
1440
+ esc_url_raw( add_query_arg( 'tab', $tab, $admin_url ) ),
1441
+ esc_html( $name )
1442
+ );
1443
  }
1444
+
1445
+ echo '</div></h3>';
1446
  }
1447
 
1448
  function wsc_mod_rewrite() {
1512
  }
1513
 
1514
  function wp_cache_restore() {
1515
+ $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
1516
  echo '<fieldset class="options"><h4>' . __( 'Fix Configuration', 'wp-super-cache' ) . '</h4>';
1517
+ echo '<form name="wp_restore" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#top' ) . '" method="post">';
1518
  echo '<input type="hidden" name="wp_restore_config" />';
1519
  echo '<div class="submit"><input class="button-secondary" type="submit" ' . SUBMITDISABLED . 'id="deletepost" value="' . __( 'Restore Default Configuration', 'wp-super-cache' ) . '" /></div>';
1520
  wp_nonce_field('wp-cache');
1627
  function wp_lock_down() {
1628
  global $cached_direct_pages, $cache_enabled, $super_cache_enabled;
1629
 
1630
+ $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
1631
  $wp_lock_down = wp_update_lock_down();
1632
 
1633
  ?><a name='lockdown'></a>
1646
  }
1647
  $new_lockdown = $wp_lock_down == '1' ? '0' : '1';
1648
  $new_lockdown_desc = $wp_lock_down == '1' ? __( 'Disable', 'wp-super-cache' ) : __( 'Enable', 'wp-super-cache' );
1649
+ echo '<form name="wp_lock_down" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#lockdown' ) . '" method="post">';
1650
  echo "<input type='hidden' name='wp_lock_down' value='{$new_lockdown}' />";
1651
+ echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . ' value="' . esc_attr( $new_lockdown_desc . ' ' . __( 'Lock Down', 'wp-super-cache' ) ) . '" /></div>';
1652
+ wp_nonce_field( 'wp-cache' );
1653
+ echo '</form>';
1654
 
1655
  ?></fieldset><?php
1656
  if( $cache_enabled == true && $super_cache_enabled == true ) {
1671
  ?><p style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><strong><?php _e( 'Warning!', 'wp-super-cache' ); ?></strong> <?php printf( __( '%s is writable. Please make it readonly after your page is generated as this is a security risk.', 'wp-super-cache' ), ABSPATH ); ?></p><?php
1672
  }
1673
  }
1674
+ echo '<form name="direct_page" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#direct' ) . '" method="post">';
1675
  if( is_array( $cached_direct_pages ) ) {
1676
  $out = '';
1677
  foreach( $cached_direct_pages as $page ) {
1687
  echo "$out</table>";
1688
  }
1689
  }
 
 
1690
 
1691
+ if ( 'READONLY' !== $readonly ) {
1692
+ echo esc_html__( 'Add direct page:', 'wp-super-cache' ) . '<input type="text" name="new_direct_page" size="30" value="" />';
 
 
1693
  }
1694
+ echo '<p>' . sprintf(
1695
+ esc_html__( 'Directly cached files are files created directly off %s where your blog lives. This feature is only useful if you are expecting a major Digg or Slashdot level of traffic to one post or page.', 'wp-super-cache' ),
1696
+ esc_attr( ABSPATH )
1697
+ ) . '</p>';
1698
+ if ( 'READONLY' !== $readonly ) {
1699
+ echo '<p>' . sprintf( __( 'For example: to cache <em>%1$sabout/</em>, you would enter %1$sabout/ or /about/. The cached file will be generated the next time an anonymous user visits that page.', 'wp-super-cache' ),
1700
+ esc_attr( trailingslashit( get_option( 'siteurl' ) ) )
1701
+ ) . '</p>';
1702
+ echo '<p>' . esc_html__( 'Make the textbox blank to remove it from the list of direct pages and delete the cached file.', 'wp-super-cache' ) . '</p>';
1703
 
1704
+ echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . ' value="' . esc_attr__( 'Update Direct Pages', 'wp-super-cache' ) . '" /></div>';
1705
+ }
1706
+ wp_nonce_field( 'wp-cache' );
1707
+ echo '</form>';
1708
+ ?>
1709
+ </fieldset>
1710
+ <?php
1711
  } // if $super_cache_enabled
1712
  }
1713
 
1808
  function wp_cache_edit_max_time() {
1809
  global $cache_max_time, $wp_cache_config_file, $valid_nonce, $super_cache_enabled, $cache_schedule_type, $cache_scheduled_time, $cache_schedule_interval, $cache_time_interval, $cache_gc_email_me, $wp_cache_preload_on;
1810
 
1811
+ $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
1812
  $timezone_format = _x('Y-m-d G:i:s', 'timezone date format');
1813
 
1814
  wp_cache_time_update();
1843
  });
1844
  });";
1845
  echo "</script>";
1846
+ echo '<form name="wp_edit_max_time" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#expirytime' ) . '" method="post">';
1847
  echo '<input name="action" value="expirytime" type="hidden" />';
1848
  echo '<table class="form-table">';
1849
  echo '<tr><td><label for="wp_max_time"><strong>' . __( 'Cache Timeout', 'wp-super-cache' ) . '</strong></label></td>';
1913
  function wp_cache_edit_rejected_ua() {
1914
  global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce;
1915
 
1916
+ if ( ! function_exists( 'apache_request_headers' ) ) {
1917
+ return;
1918
+ }
1919
 
1920
+ $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
1921
  wp_cache_update_rejected_ua();
1922
 
1923
  echo '<a name="useragents"></a><fieldset class="options"><h4>' . __( 'Rejected User Agents', 'wp-super-cache' ) . '</h4>';
1924
  echo "<p>" . __( 'Strings in the HTTP &#8217;User Agent&#8217; header that prevent WP-Cache from caching bot, spiders, and crawlers&#8217; requests. Note that super cached files are still sent to these agents if they already exists.', 'wp-super-cache' ) . "</p>\n";
1925
+ echo '<form name="wp_edit_rejected_user_agent" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#useragents' ) . '" method="post">';
1926
  echo '<textarea name="wp_rejected_user_agent" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
1927
  foreach( $cache_rejected_user_agent as $ua ) {
1928
  echo esc_html( $ua ) . "\n";
1954
  function wp_cache_edit_rejected_pages() {
1955
  global $wp_cache_config_file, $valid_nonce, $wp_cache_pages;
1956
 
1957
+ $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
1958
  wp_cache_update_rejected_pages();
1959
 
1960
  echo '<a name="rejectpages"></a>';
1961
  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>';
1962
+ echo '<form name="wp_edit_rejected_pages" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#rejectpages' ) . '" method="post">';
1963
  echo '<input type="hidden" name="wp_edit_rejected_pages" value="1" />';
1964
  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 />';
1965
  echo '<label><input type="checkbox" value="1" name="wp_cache_pages[pages]" ' . checked( 1, $wp_cache_pages[ 'pages' ], false ) . ' /> ' . __( 'Pages', 'wp-super-cache' ) . ' (is_page)</label><br />';
1991
  function wp_cache_edit_rejected() {
1992
  global $cache_rejected_uri;
1993
 
1994
+ $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
1995
  wp_cache_update_rejected_strings();
1996
 
1997
  echo '<a name="rejecturi"></a>';
1998
+ echo '<form name="wp_edit_rejected" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#rejecturi' ) . '" method="post">';
1999
  echo "<p>" . __( 'Add here strings (not a filename) that forces a page not to be cached. For example, if your URLs include year and you dont want to cache last year posts, it&#8217;s enough to specify the year, i.e. &#8217;/2004/&#8217;. WP-Cache will search if that string is part of the URI and if so, it will not cache that page.', 'wp-super-cache' ) . "</p>\n";
2000
  echo '<textarea name="wp_rejected_uri" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
2001
  foreach ($cache_rejected_uri as $file) {
2020
  global $cache_acceptable_files;
2021
 
2022
  wp_cache_update_accepted_strings();
2023
+ $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
2024
 
2025
  echo '<a name="cancache"></a>';
2026
+ echo '<div style="clear:both"></div><form name="wp_edit_accepted" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#cancache' ) . '" method="post">';
2027
  echo "<p>" . __( 'Add here those filenames that can be cached, even if they match one of the rejected substring specified above.', 'wp-super-cache' ) . "</p>\n";
2028
  echo '<textarea name="wp_accepted_files" cols="40" rows="8" style="width: 50%; font-size: 12px;" class="code">';
2029
  foreach ($cache_acceptable_files as $file) {
2122
  global $wp_cache_debug_username;
2123
 
2124
  extract( wpsc_update_debug_settings() ); // $wp_super_cache_debug, $wp_cache_debug_log, $wp_cache_debug_ip, $wp_super_cache_comments, $wp_super_cache_front_page_check, $wp_super_cache_front_page_clear, $wp_super_cache_front_page_text, $wp_super_cache_front_page_notification, $wp_super_cache_advanced_debug, $wp_cache_debug_username
2125
+ $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
2126
 
2127
  echo '<a name="debug"></a>';
2128
  echo '<fieldset class="options">';
2139
  }
2140
  echo "<p>" . sprintf( __( 'Username/Password: %s', 'wp-super-cache' ), $wp_cache_debug_username ) . "</p>";
2141
 
2142
+ echo '<form name="wpsc_delete" action="' . esc_url_raw( add_query_arg( 'tab', 'debug', $admin_url ) ) . '" method="post">';
2143
  wp_nonce_field('wp-cache');
2144
  echo "<input type='hidden' name='wpsc_delete_log' value='1' />";
2145
  submit_button( __( 'Delete', 'wp-super-cache' ), 'delete', 'wpsc_delete_log_form', false );
2146
  echo "</form>";
2147
+
2148
+ echo '<form name="wpsc_delete" action="' . esc_url_raw( add_query_arg( 'tab', 'debug', $admin_url ) ) . '" method="post">';
2149
  if ( ! isset( $wp_super_cache_debug ) || $wp_super_cache_debug == 0 ) {
2150
  $debug_status_message = __( 'Enable Logging', 'wp-super-cache' );
2151
  $not_status = 1;
2157
  wp_nonce_field('wp-cache');
2158
  submit_button( $debug_status_message, 'primary', 'wpsc_log_status', true );
2159
  echo "</form>";
2160
+
2161
+ echo '<form name="wp_cache_debug" action="' . esc_url_raw( add_query_arg( 'tab', 'debug', $admin_url ) ) . '" method="post">';
2162
  echo "<input type='hidden' name='wp_cache_debug' value='1' /><br />";
2163
  echo "<table class='form-table'>";
2164
  echo "<tr><th>" . __( 'IP Address', 'wp-super-cache' ) . "</th><td> <input type='text' size='20' name='wp_cache_debug_ip' value='{$wp_cache_debug_ip}' /> " . sprintf( __( '(only log requests from this IP address. Your IP is %s)', 'wp-super-cache' ), $_SERVER[ 'REMOTE_ADDR' ] ) . "</td></tr>";
2169
  &lt;!-- super cache --></pre></td></tr>";
2170
  echo "</table>\n";
2171
  if ( isset( $wp_super_cache_advanced_debug ) ) {
2172
+ echo "<h5>" . __( 'Advanced', 'wp-super-cache' ) . "</h5><p>" . __( 'In very rare cases two problems may arise on some blogs:<ol><li> The front page may start downloading as a zip file.</li><li> The wrong page is occasionally cached as the front page if your blog uses a static front page and the permalink structure is <em>/%category%/%postname%/</em>.</li></ol>', 'wp-super-cache' ) . '</p>';
2173
+ echo "<p>" . __( 'I&#8217;m 99% certain that they aren&#8217;t bugs in WP Super Cache and they only happen in very rare cases but you can run a simple check once every 5 minutes to verify that your site is ok if you&#8217;re worried. You will be emailed if there is a problem.', 'wp-super-cache' ) . "</p>";
2174
+ echo "<table class='form-table'>";
2175
+ echo "<tr><td valign='top' colspan='2'><input type='checkbox' name='wp_super_cache_front_page_check' value='1' " . checked( 1, $wp_super_cache_front_page_check, false ) . " /> " . __( 'Check front page every 5 minutes.', 'wp-super-cache' ) . "</td></tr>";
2176
+ echo "<tr><td valign='top'>" . __( 'Front page text', 'wp-super-cache' ) . "</td><td> <input type='text' size='30' name='wp_super_cache_front_page_text' value='{$wp_super_cache_front_page_text}' /> (" . __( 'Text to search for on your front page. If this text is missing, the cache will be cleared. Leave blank to disable.', 'wp-super-cache' ) . ")</td></tr>";
2177
+ echo "<tr><td valign='top' colspan='2'><input type='checkbox' name='wp_super_cache_front_page_clear' value='1' " . checked( 1, $wp_super_cache_front_page_clear, false ) . " /> " . __( 'Clear cache on error.', 'wp-super-cache' ) . "</td></tr>";
2178
+ echo "<tr><td valign='top' colspan='2'><input type='checkbox' name='wp_super_cache_front_page_notification' value='1' " . checked( 1, $wp_super_cache_front_page_notification, false ) . " /> " . __( 'Email the blog admin when checks are made. (useful for testing)', 'wp-super-cache' ) . "</td></tr>";
2179
 
2180
+ echo "</table>\n";
2181
  }
2182
  echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save Settings', 'wp-super-cache' ) . '" /></div>';
2183
  wp_nonce_field('wp-cache');
2572
  }
2573
  $ret = true;
2574
 
2575
+ if ( file_exists( $wp_cache_link ) ) {
2576
+ $file = file_get_contents( $wp_cache_link );
2577
+ if (
2578
+ ! strpos( $file, "WP SUPER CACHE 0.8.9.1" ) &&
2579
+ ! strpos( $file, "WP SUPER CACHE 1.2" )
2580
+ ) {
2581
+ wp_die( '<div class="notice notice-error"><h4>' . __( 'Warning!', 'wp-super-cache' ) . "</h4><p>" . sprintf( __( 'The file %s already exists. Please manually delete it before using this plugin.', 'wp-super-cache' ), $wp_cache_link ) . "</p></div>" );
2582
+ }
2583
+ }
2584
+
2585
  $file = file_get_contents( $wp_cache_file );
2586
  $fp = @fopen( $wp_cache_link, 'w' );
2587
  if( $fp ) {
2602
  if( strpos( $file, "WP SUPER CACHE 0.8.9.1" ) || strpos( $file, "WP SUPER CACHE 1.2" ) ) {
2603
  return true;
2604
  } else {
2605
+ $ret = wp_cache_create_advanced_cache();
 
 
 
 
2606
  }
2607
  } else {
2608
  $ret = wp_cache_create_advanced_cache();
2900
 
2901
  function wp_cache_delete_buttons() {
2902
 
2903
+ $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
2904
+
2905
+ echo '<form name="wp_cache_content_expired" action="' . esc_url_raw( add_query_arg( 'tab', 'contents', $admin_url ) . '#listfiles' ) . '" method="post">';
2906
  echo '<input type="hidden" name="wp_delete_expired" />';
2907
  echo '<div class="submit" style="float:left"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Expired', 'wp-super-cache' ) . '" /></div>';
2908
  wp_nonce_field('wp-cache');
2909
  echo "</form>\n";
2910
 
2911
+ echo '<form name="wp_cache_content_delete" action="' . esc_url_raw( add_query_arg( 'tab', 'contents', $admin_url ) . '#listfiles' ) . '" method="post">';
2912
  echo '<input type="hidden" name="wp_delete_cache" />';
2913
  echo '<div class="submit" style="float:left;margin-left:10px"><input id="deletepost" class="button-secondary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Cache', 'wp-super-cache' ) . '" /></div>';
2914
  wp_nonce_field('wp-cache');
2915
  echo "</form>\n";
2916
+ if ( is_multisite() && wpsupercache_site_admin() ) {
2917
+ echo '<form name="wp_cache_content_delete" action="' . esc_url_raw( add_query_arg( 'tab', 'contents', $admin_url ) . '#listfiles' ) . '" method="post">';
2918
  echo '<input type="hidden" name="wp_delete_all_cache" />';
2919
  echo '<div class="submit" style="float:left;margin-left:10px"><input id="deleteallpost" class="button-secondary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Cache On All Blogs', 'wp-super-cache' ) . '" /></div>';
2920
  wp_nonce_field('wp-cache');
3049
  return false;
3050
 
3051
  if ( $handle = @opendir( $dir ) ) {
3052
+ $curr_blog_id = is_multisite() ? get_current_blog_id() : false;
3053
+
3054
  while ( false !== ( $file = readdir( $handle ) ) ) {
3055
  if ( is_file( $dir . $file ) == false || $file == 'index.html' ) {
3056
  continue;
3063
  @unlink( $dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
3064
  } else {
3065
  $meta = json_decode( wp_cache_get_legacy_cache( $dir . 'meta/' . $file ), true );
3066
+ if ( $curr_blog_id && $curr_blog_id !== (int)$meta['blog_id'] ) {
3067
  continue;
3068
+ }
3069
  @unlink( $dir . $file);
3070
  @unlink( $dir . 'meta/' . $file);
3071
  }
3144
  }
3145
  }
3146
 
 
 
 
 
 
 
3147
  if( get_option( 'gzipcompression' ) )
3148
  update_option( 'gzipcompression', 0 );
3149
 
3198
  echo '<div class="notice notice-info"><p><strong>' . sprintf( __('WP Super Cache is disabled. Please go to the <a href="%s">plugin admin page</a> to enable caching.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '</strong></p></div>';
3199
 
3200
  if ( defined( 'WP_CACHE' ) && WP_CACHE == true && ( defined( 'ADVANCEDCACHEPROBLEM' ) || ( $cache_enabled && false == isset( $wp_cache_phase1_loaded ) ) ) ) {
3201
+ if ( wp_cache_create_advanced_cache() ) {
3202
+ echo '<div class="notice notice-error"><p>' . sprintf( __( 'Warning! WP Super Cache caching <strong>was</strong> broken but has been <strong>fixed</strong>! The script advanced-cache.php could not load wp-cache-phase1.php.<br /><br />The file %1$s/advanced-cache.php has been recreated and WPCACHEHOME fixed in your wp-config.php. Reload to hide this message.', 'wp-super-cache' ), WP_CONTENT_DIR ) . '</p></div>';
3203
+ }
3204
  }
3205
  }
3206
  add_action( 'admin_notices', 'wp_cache_admin_notice' );
3273
  function wpsc_update_htaccess_form( $short_form = true ) {
3274
  global $wpmu_version;
3275
 
3276
+ $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
3277
  extract( wpsc_get_htaccess_info() ); // $document_root, $apache_root, $home_path, $home_root, $home_root_lc, $inst_root, $wprules, $scrules, $condition_rules, $rules, $gziprules
3278
  if( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) {
3279
  echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><h5>" . __( 'Cannot update .htaccess', 'wp-super-cache' ) . "</h5><p>" . sprintf( __( 'The file <code>%s.htaccess</code> cannot be modified by the web server. Please correct this using the chmod command or your ftp client.', 'wp-super-cache' ), $home_path ) . "</p><p>" . __( 'Refresh this page when the file permissions have been modified.' ) . "</p><p>" . sprintf( __( 'Alternatively, you can edit your <code>%s.htaccess</code> file manually and add the following code (before any WordPress rules):', 'wp-super-cache' ), $home_path ) . "</p>";
3292
  echo "</div>";
3293
  }
3294
  if ( !isset( $wpmu_version ) || $wpmu_version == '' ) {
3295
+ echo '<form name="updatehtaccess" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#modrewrite' ) . '" method="post">';
3296
  echo '<input type="hidden" name="updatehtaccess" value="1" />';
3297
  echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'id="updatehtaccess" value="' . __( 'Update Mod_Rewrite Rules', 'wp-super-cache' ) . '" /></div>';
3298
  wp_nonce_field('wp-cache');
3816
  'id' => 'delete-cache',
3817
  'title' => __( 'Delete Cache', 'wp-super-cache' ),
3818
  'meta' => array( 'title' => __( 'Delete cache of the current page', 'wp-super-cache' ) ),
3819
+ 'href' => wp_nonce_url( admin_url( 'index.php?action=delcachepage&path=' . rawurlencode( $path ) ), 'delete-cache' )
3820
  ) );
3821
  }
3822
 
3825
  'parent' => '',
3826
  'id' => 'delete-cache',
3827
  'title' => __( 'Delete Cache', 'wp-super-cache' ),
3828
+ 'meta' => array( 'title' => __( 'Delete Super Cache cached files', 'wp-super-cache' ) ),
3829
  'href' => wp_nonce_url( admin_url( 'options-general.php?page=wpsupercache&tab=contents&wp_delete_cache=1' ), 'wp-cache' )
3830
  ) );
3831
  }