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();