Varnish HTTP Purge - Version 4.5.0

Version Description

  • May 2018
  • Remote storage of problem plugins/themes
  • Prevent auto-loading of scan for improved disclosure and compliance
  • Changed colour of the purge button for improved visibility
  • Support for nginx proxy headers

=

Download this release

Release Info

Developer Ipstenu
Plugin Icon 128x128 Varnish HTTP Purge
Version 4.5.0
Comparing to
See all releases

Code changes from version 4.4.0 to 4.5.0

Files changed (7) hide show
  1. changelog.txt +6 -0
  2. debug.php +204 -148
  3. readme.txt +80 -60
  4. status.php +21 -17
  5. style.css +3 -0
  6. varnish-http-purge.php +61 -26
  7. wp-cli.php +4 -4
changelog.txt CHANGED
@@ -1,3 +1,9 @@
 
 
 
 
 
 
1
  = 4.4.0 =
2
  * March 2018
3
  * Improve translations
1
+ ## CHANGELOG
2
+
3
+ = 4.5.0 =
4
+ * May 2018
5
+ * Remote storage of problem plugins/themes
6
+
7
  = 4.4.0 =
8
  * March 2018
9
  * Improve translations
debug.php CHANGED
@@ -38,7 +38,7 @@ class VarnishDebug {
38
  'redirection' => 10,
39
  )
40
  );
41
-
42
  $response = wp_remote_get( $url, $args );
43
 
44
  return $response;
@@ -102,40 +102,60 @@ class VarnishDebug {
102
  */
103
  static function varnish_results( $headers = '' ) {
104
 
105
- // Set the defaults
106
- $return = array(
107
- 'icon' => 'good',
108
- 'message' => __( 'Varnish is running properly and caching is happening.', 'varnish-http-purge' ),
109
- );
110
-
111
  if ( $headers == '' ) {
112
  $kronk = false;
113
  } else {
114
  $kronk = true;
115
 
116
  // Check if the headers are set AND if the values are valid
117
- $x_cachable = ( isset( $headers['X-Cacheable'] ) && strpos( $headers['X-Cacheable'] ,'YES') !== false )? true : false;
118
  $x_varnish = ( isset( $headers['X-Varnish'] ) )? true : false;
119
  $x_via = ( is_numeric( strpos( $headers['Via'], 'arnish' ) ) )? true : false;
120
- $x_age = ( isset( $headers[ 'Age' ] ) && $headers[ 'Age' ] > 0 )? true : false;
121
-
 
 
 
 
 
122
  // If this is TRUE it's NOT Cachable
123
- $not_cachable = ( ( isset( $headers['X-Cacheable'] ) && strpos( $headers['X-Cacheable'] ,'NO') !== false ) || ( isset( $headers['Pragma'] ) && strpos( $headers['Pragma'] ,'no-cache') !== false ) || !$x_age )? true : false;
 
 
 
 
 
 
 
124
  $cacheheaders_set = ( isset( $headers['X-Cacheable'] ) || isset( $headers['X-Varnish'] ) || isset( $headers['X-Cache'] ) || $x_via )? true : false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  }
126
 
127
  if ( !$kronk ) {
128
  $return['icon'] = 'bad';
129
- $return['message'] = __( 'Something went very wrong with this request. Please try again.', 'varnish-http-purge' );
130
  } elseif ( !$cacheheaders_set ) {
131
  $return['icon'] = 'warning';
132
- $return['message'] = __( 'We were unable find Varnish active for this domain. Please review the output below to understand why.', 'varnish-http-purge' );
133
  } elseif ( !$not_cachable && ( $x_cachable || $x_varnish ) ) {
134
  $return['icon'] = 'awesome';
135
- $return['message'] = __( 'Varnish is running properly and caching is happening.', 'varnish-http-purge' );
136
  } else {
137
  $return['icon'] = 'warning';
138
- $return['message'] = __( 'Varnish is running but is unable to cache your site. Please review the following output to diagnose the issue.', 'varnish-http-purge' );
139
  }
140
 
141
  return $return;
@@ -156,17 +176,17 @@ class VarnishDebug {
156
  if ( $remote_ip == false && !empty( $varniship) ) {
157
  $return = array(
158
  'icon' => 'warning',
159
- 'message' => sprintf( __( 'You have a Varnish IP set but a proxy like Cloudflare or Sucuri has not been detected. This is mostly harmless, but if you have issues with your cache not emptying when you make a post, you may need to <a href="%s">erase your Varnish IP</a>. Please check with your webhost or server admin before doing so.', 'varnish-http-purge' ), '#configure' )
160
  );
161
  } elseif ( $remote_ip !== false && $remote_ip !== $varniship ) {
162
  $return = array(
163
  'icon' => 'warning',
164
- 'message' => sprintf( __( 'You\'re using a Custom Varnish IP that doesn\'t appear to match your server IP address. If you\'re using multiple Varnish servers or IPv6, this is fine. Please make sure you\'ve <a href="%s">properly configured it</a> according to your webhost\'s specifications.', 'varnish-http-purge' ), '#configure' ),
165
  );
166
  } else {
167
  $return = array(
168
  'icon' => 'awesome',
169
- 'message' => __( 'Your server IP setup looks good.', 'varnish-http-purge' ),
170
  );
171
  }
172
 
@@ -186,50 +206,58 @@ class VarnishDebug {
186
  $return = array();
187
 
188
  if ( isset( $headers['Server'] ) ) {
 
 
 
 
 
 
 
 
189
  // nginx
190
- if ( strpos( $varnish_headers['Server'] ,'nginx') !== false && strpos( $varnish_headers['Server'] ,'cloudflare') == false ) {
191
- $return['nginx'] = array(
192
- 'icon' => 'awkward',
193
- 'message' => __( 'Your server is running nginx and Apache was expected. This may be fine, especially if you use a passthrough proxy, but keep it in mind.', 'varnish-http-purge' )
194
  );
195
  }
196
 
197
  // Cloudflare
198
  if ( strpos( $headers['Server'] ,'cloudflare') !== false ) {
199
- $return['cloudflare'] = array(
200
  'icon' => 'warning',
201
- 'message' => sprintf( __( 'CloudFlare has been detected. While this is generally fine, you may experience some cache oddities. Make sure you <a href="%s">configure WordPress for Cloudflare</a>.', 'varnish-http-purge' ), '#configure' ),
202
  );
203
  }
204
 
205
  // HHVM: Note, WP is dropping support so ...
206
  if ( isset( $headers['X-Powered-By'] ) && strpos( $headers['X-Powered-By'] ,'HHVM') !== false ) {
207
- $return['hhvm'] = array(
208
  'icon' => 'awkward',
209
  'message' => __( 'You are running HHVM instead of PHP. While that is compatible with Varnish, you should consider PHP 7. WordPress will cease support for HHVM in 2018.', 'varnish-http-purge' ),
210
  );
211
  }
212
 
213
  // Pagely
214
- if ( strpos( $varnish_headers['Server'] ,'Pagely') !== false ) {
215
- $return['pagely'] = array(
216
  'icon' => 'good',
217
- 'message' => __( 'This site is hosted on Pagely.', 'varnish-http-purge' ),
218
  );
219
  }
220
  }
221
 
222
- if ( isset( $varnish_headers['X-hacker'] ) ) {
223
- $return['wordpresscom'] = array(
224
  'icon' => 'bad',
225
- 'message' => __( 'This site is hosted on WordPress.com, which is cool but, last we checked, they don\'t use Varnish.', 'varnish-http-purge' ),
226
  );
227
  }
228
 
229
- if ( isset( $varnish_headers['X-Backend'] ) && strpos( $varnish_headers['X-Backend'] ,'wpaas_web_') !== false ) {
230
- $return['godaddy'] = array(
231
  'icon' => 'good',
232
- 'message' => __( 'This site is hosted on GoDaddy.', 'varnish-http-purge' ),
233
  );
234
  }
235
 
@@ -260,7 +288,7 @@ class VarnishDebug {
260
  if ( strpos( $headers['Content-Encoding'] ,'Fastly') !== false ) {
261
  $return = array(
262
  'icon' => 'good',
263
- 'message' => sprintf( __( '<a href="%s">Fastly</a> is speeding up your site. Keep in mind, it may cache your CSS and images longer than Varnish does. Remember to empty all caches in all locations.', 'varnish-http-purge' ), esc_url( 'https://fastly.com' ) ),
264
  );
265
  }
266
 
@@ -277,58 +305,52 @@ class VarnishDebug {
277
  static function cookie_results( $headers ) {
278
 
279
  // Defaults
280
- $return = $cookies = array();
 
 
 
281
 
282
- // Set the default returns
283
- $cookie_warning = array(
284
  'icon' => 'warning',
285
- 'message' => __( 'Cookies have been detected on your site. This can cause Varnish to not properly cache unless it\'s configured specially to accommodate. Since it\'s impossible to cover all possible situations, please take the following alerts with a grain of salt. If you know certain cookies are safe on your server, this is fine. If you aren\'t sure, pass the details on to your webhost.', 'varnish-http-purge' ),
286
- );
287
- $default = array(
288
- 'phpsessid' => array( 'icon' => 'bad', 'message' => __( 'A plugin or theme is setting a PHPSESSID cookie on every pageload. This makes Varnish not deliver cached pages.', 'varnish-http-purge' ) ),
289
- 'edd_wp_session' => array( 'icon' => 'bad', 'message' => sprintf( __( '<a href="%s">Easy Digital Downloads</a> is being used with cookie sessions. This may cause your cache to misbehave. If you have issues, please set <code>define( "EDD_USE_PHP_SESSIONS", true );</code> in your <code>wp-config.php</code> file.', 'varnish-http-purge' ), esc_url('https://wordpress.org/plugins/easy-digital-downloads/') ) ),
290
- 'edd_items_in_cart' => array( 'icon' => 'warning', 'message' => sprintf( __( '<a href="%s">Easy Digital Downloads</a> is putting down a shopping cart cookie on every page load. Make sure Varnish is set up to ignore that when it\'s empty.', 'varnish-http-purge' ), esc_url('https://wordpress.org/plugins/easy-digital-downloads/') ) ),
291
- 'wfvt' => array( 'icon' => 'bad', 'message' => sprintf( __( '<a href="%s">Wordfence</a> is putting down cookies on every page load. Please check "Disable WordFence Cookies" under <a href="%s">General Wordfence Options</a> to resolve.', 'varnish-http-purge' ), esc_url('https://wordpress.org/plugins/wordfence/'), admin_url( 'admin.php?page=WordfenceOptions' ) ) ),
292
- 'invite_anyone' => array( 'icon' => 'bad', 'message' => sprintf( __( '<a href="%s">Invite Anyone</a>, a plugin for BuddyPress, is putting down a cookie on every page load.', 'varnish-http-purge' ), esc_url('https://wordpress.org/plugins/invite-anyone/') ) ),
293
- 'charitable_sessions' => array( 'icon' => 'bad', 'message' => sprintf( __( '<a href="%s">Charitable</a> is putting down a cookie on every page load. This has been fixed as of version 1.5.0, so please upgrade to the latest version.', 'varnish-http-purge' ), esc_url('https://wordpress.org/plugins/charitable/') ) ),
294
  );
295
 
296
- if ( isset( $headers['Set-Cookie'] ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
  // If cookies are an array, scan the whole thing. Otherwise, we can use strpos.
298
  if ( is_array( $headers['Set-Cookie'] ) ) {
299
- $cookies = array(
300
- 'phpsessid' => in_array( 'PHPSESSID', $headers['Set-Cookie'], true ),
301
- 'edd_wp_session' => in_array( 'edd_wp_session', $headers['Set-Cookie'], true ),
302
- 'edd_items_in_cart' => in_array( 'edd_items_in_cart', $headers['Set-Cookie'], true ),
303
- 'wfvt' => in_array( 'wfvt_', $headers['Set-Cookie'], true ),
304
- 'invite_anyone' => in_array( 'invite-anyone', $headers['Set-Cookie'], true ),
305
- 'charitable_sessions' => in_array( 'charitable_sessions', $headers['Set-Cookie'], true ),
306
- );
307
  } else {
308
- $cookies = array(
309
- 'phpsessid' => strpos( $headers['Set-Cookie'], 'PHPSESSID'),
310
- 'edd_wp_session' => strpos( $headers['Set-Cookie'], 'edd_wp_session' ),
311
- 'edd_items_in_cart' => strpos( $headers['Set-Cookie'], 'edd_items_in_cart' ),
312
- 'wfvt' => strpos( $headers['Set-Cookie'], 'wfvt_' ),
313
- 'invite_anyone' => strpos( $headers['Set-Cookie'], 'invite-anyone' ),
314
- 'charitable_sessions' => strpos( $varnish_headers['Set-Cookie'], 'charitable_sessions' ),
315
- );
316
  }
317
 
318
- foreach ( $cookies as $name => $value ) {
319
- if ( $value !== false ) {
320
- $return[ $name ] = array( 'icon' => $default[ $name]['icon'], 'message' => $default[ $name]['message'] );
321
- }
322
  }
323
  }
324
 
325
- // If there's data in the array, add a Cookie Monster Warning to the top
326
- if ( !empty( $return ) ) array_unshift( $return, $cookie_warning );
327
-
328
  return $return;
329
  }
330
 
331
-
332
  /**
333
  * Cache
334
  *
@@ -343,36 +365,50 @@ class VarnishDebug {
343
  // Cache Control
344
  if ( isset( $headers['Cache-Control'] ) ) {
345
 
 
 
 
 
 
 
 
 
346
  // No-Cache Set
347
- if ( strpos( $headers['Cache-Control'], 'no-cache' ) !== false ) {
348
  $return['no_cache'] = array(
349
  'icon' => 'bad',
350
- 'message' => __( 'Something is setting the header Cache-Control to "no-cache" which means visitors will never get cached pages.', 'varnish-http-purge' ),
351
  );
352
  }
353
 
354
  // Max-Age is 0
355
- if ( strpos( $headers['Cache-Control'], 'max-age=0' ) !== false ) {
356
  $return['max_age'] = array(
357
  'icon' => 'bad',
358
- 'message' => __( 'Something is setting the header Cache-Control to "max-age=0" which means a page can be no older than 0 seconds before it needs to regenerate the cache.', 'varnish-http-purge' ),
359
  );
360
  }
361
  }
362
 
363
  // Age Headers
364
  if ( !isset( $headers['Age'] ) ) {
365
- $return['age'] = array(
366
  'icon' => 'bad',
367
  'message' => __( 'Your domain does not report an "Age" header, which means we can\'t tell if the page is actually serving from cache.', 'varnish-http-purge' ),
368
  );
369
- } elseif( $headers['Age'] <= 0 || $headers['Age'] == 0 ) {
370
- $return['age'] = array(
 
371
  'icon' => 'warning',
372
- 'message' => __( 'The "Age" header is set to less than 1, which means you checked right when Varnish cleared the cache for that url or Varnish is not serving cached content for that url. Check again but if it happens again, then either the URL is intentionally excluded from caching, or a theme or plugin is sending cache headers or cookies that instruct varnish not to cache.', 'varnish-http-purge' ),
 
 
 
 
 
373
  );
374
  } else {
375
- $return['age'] = array(
376
  'icon' => 'good',
377
  'message' => __( 'Your site is returning proper "Age" headers.', 'varnish-http-purge' ),
378
  );
@@ -380,31 +416,31 @@ class VarnishDebug {
380
 
381
  // Pragma
382
  if ( isset( $headers['Pragma'] ) && strpos( $headers['Pragma'] ,'no-cache') !== false ) {
383
- $return['pragma'] = array(
384
  'icon' => 'bad',
385
- 'message' => __( 'Something is setting the header Pragma to "no-cache" which means visitors will never get cached pages. This is usually done by plugins.', 'varnish-http-purge' ),
386
  );
387
  }
388
 
389
  // X-Cache
390
  if ( isset( $headers['X-Cache-Status'] ) && strpos( $headers['X-Cache-Status'] ,'MISS') !== false ) {
391
- $return['X-Cache'] = array(
392
  'icon' => 'bad',
393
- 'message' => __( 'X-Cache missed, which means it was not able to serve this page as cached. This may be resolved by rerunning the scan. If not, then a plugin or theme is forcing this setting.', 'varnish-http-purge' ),
394
  );
395
  }
396
 
397
  // Mod-PageSpeed
398
  if ( isset( $headers['X-Mod-Pagespeed'] ) ) {
399
  if ( strpos( $headers['X-Cacheable'] , 'YES:Forced') !== false ) {
400
- $return['mod_pagespeed'] = array(
401
  'icon' => 'good',
402
- 'message' => __( 'Mod Pagespeed is active and configured to work properly with Varnish.', 'varnish-http-purge' ),
403
  );
404
  } else {
405
- $return['mod_pagespeed'] = array(
406
  'icon' => 'bad',
407
- 'message' => __( 'Mod Pagespeed is active but it looks like your caching headers may not be right. This may be a false negative if other parts of your site are overwriting headers. Fix all other errors listed, then come back to this. If you are still having errors, you will need to look into using htaccess or nginx to override the Pagespeed headers.', 'varnish-http-purge' ),
408
  );
409
  }
410
  }
@@ -413,69 +449,85 @@ class VarnishDebug {
413
  }
414
 
415
  /**
416
- * Bad Actors
417
  *
418
- * Plugins and themes known to be problematic
419
  *
420
- * @since 4.4.0
421
  */
422
- static function bad_actors_results( ) {
423
 
424
- $return = array();
 
425
 
426
- $themes = array(
427
- 'divi' => __( 'Divi themes use sessions in their headers for many of their themes. To check, change your theme and re-run this test. If this warning goes away, it\'s your theme.', 'varnish-http-purge' ),
428
- 'enfold' => __( 'The Enfold theme uses sessions for every call of shortcodes in certain situations. To check, change your theme and re-run this test. If this warning goes away, it\'s your theme.', 'varnish-http-purge' ),
429
- 'prophoto6' => __( 'Prophoto version 6 requires you to be on version 6.21.8 or higher to work properly with Varnish. Please make sure you site is up to date.', 'varnish-http-purge' ),
430
- );
431
 
432
- $plugins = array(
433
- 'bad-behavior' => array(
434
- 'path' => 'bad-behavior/bad-behavior.php',
435
- 'message' => sprintf( __( '<a href="%s">Bad Behavior</a> may cause unexpected results with Varnish and not function properly.', 'varnish-http-purge' ), 'https://wordpress.org/plugins/bad-behavior/' ),
436
- ),
437
- 'pie-register' => array(
438
- 'path' => 'pie-register/pie-register.php',
439
- 'message' => sprintf( __( '<a href="%s">Pie Register</a> sets output buffering in the header of every page load, which enforces sessions. There is no known fix at this time.', 'varnish-http-purge' ), 'https://wordpress.org/plugins/pie-register/' ),
440
- ),
441
- 'quick-cache' => array(
442
- 'path' => 'quick-cache/quick-cache.php',
443
- 'message' => __( 'Quick Cache does not play well with Varnish.', 'varnish-http-purge' )
444
- ),
445
- 'simple-session-support' => array(
446
- 'path' => 'simple-session-support/simple-session-support.php',
447
- 'message' => sprintf( __( '<a href="%s">Simple Session Support</a> forces PHP Sessions. It\'s also no longer updated and not recommended for use.', 'varnish-http-purge' ), 'https://wordpress.org/plugins/simple-session-support/' ),
448
- ),
449
- 'tweet-blender' => array(
450
- 'path' => 'tweet-blender/tweet-blender.php',
451
- 'message' => sprintf( __( '<a href="%s">Tweet Blender</a> conflicts with most server based caching. It also has not been updated since 2014.', 'varnish-http-purge' ), 'https://wordpress.org/plugins/tweet-blender/' ),
452
- ),
453
- 'wp-cache' => array(
454
- 'path' => 'wp-cache/wp-cache.php',
455
- 'message' => sprintf( __( '<a href="%s">WP Cache</a> is not necessary when using a Varnish based caching, and can cause redundancy in caches, resulting in unexpected data load.', 'varnish-http-purge' ), 'https://wordpress.org/plugins/wp-cache/' ),
456
- ),
457
- 'wp-file-cache' => array(
458
- 'path' => 'wp-file-cache/file-cache.php',
459
- 'message' => sprintf( __( '<a href="%s">WP Files Cache</a> is not necessary when using a Varnish based caching, and can cause redundancy in caches, resulting in unexpected data load.', 'varnish-http-purge' ), 'https://wordpress.org/plugins/wp-file-cache/' ),
460
- ),
461
- 'wp-super-cache' => array(
462
- 'path' => 'wp-super-cache/wp-cache.php',
463
- 'message' => sprintf( __( '<a href="%s">WP Super Cache</a> is not necessary when using a Varnish based caching, and can cause redundancy in caches, resulting in unexpected data load.', 'varnish-http-purge' ), 'https://wordpress.org/plugins/wp-super-cache/' ),
464
- ),
465
- );
466
 
467
  // Check all the themes. If one of the questionable ones are active, warn
468
- foreach ( $themes as $theme => $message ) {
469
  $my_theme = wp_get_theme( $theme );
 
 
470
  if ( $my_theme->exists() ) {
471
- $return[ $theme ] = array( 'icon' => 'warning', 'message' => $message );
472
  }
473
  }
474
 
475
- // Check the plugins
476
- foreach ( $plugins as $plugin => $data ) {
477
- if ( is_plugin_active( $data['path'] ) ) {
478
- $return[ $plugin ] = array( 'icon' => 'warning', 'message' => $data['message'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
479
  }
480
  }
481
 
@@ -491,12 +543,12 @@ class VarnishDebug {
491
  */
492
  static function get_all_the_results( $headers, $remote_ip, $varniship ) {
493
  $output = array();
494
- $output['varnish'] = self::varnish_results( $headers );
495
- $output['remote_ip'] = self::remote_ip_results( $remote_ip, $varniship );
496
 
497
  // Server Results
498
- $sever_results = self::server_results( $remote_ip, $varniship );
499
- $output = array_merge( $output, $sever_results );
500
 
501
  // Cache Results
502
  $cache_results = self::cache_results( $headers );
@@ -506,13 +558,17 @@ class VarnishDebug {
506
  $cookie_results = self::cookie_results( $headers );
507
  $output = array_merge( $output, $cookie_results );
508
 
509
- // Bad Actors (plugins and themes that don't play nicely with Varnish)
510
- $bad_actors_results = self::bad_actors_results( $headers );
511
- $output = array_merge( $output, $bad_actors_results );
512
-
 
 
 
 
513
  return $output;
514
  }
515
 
516
  }
517
 
518
- if ( class_exists( 'VarnishDebug' ) ) $varnish_debug = new VarnishDebug();
38
  'redirection' => 10,
39
  )
40
  );
41
+
42
  $response = wp_remote_get( $url, $args );
43
 
44
  return $response;
102
  */
103
  static function varnish_results( $headers = '' ) {
104
 
105
+ // If we have headers:
 
 
 
 
 
106
  if ( $headers == '' ) {
107
  $kronk = false;
108
  } else {
109
  $kronk = true;
110
 
111
  // Check if the headers are set AND if the values are valid
112
+ $x_cachable = ( isset( $headers['X-Cacheable'] ) && strpos( $headers['X-Cacheable'], 'YES') !== false )? true : false;
113
  $x_varnish = ( isset( $headers['X-Varnish'] ) )? true : false;
114
  $x_via = ( is_numeric( strpos( $headers['Via'], 'arnish' ) ) )? true : false;
115
+ $x_nginx = ( isset( $headers['server'] ) && strpos( $headers['server'], 'nginx') !== false )? true : false;
116
+
117
+ $x_age = ( isset( $headers['Age'] ) && $headers['Age'] > 0 )? true : false;
118
+
119
+ $x_cache = ( isset( $headers['x-cache-status'] ) && strpos( $headers['x-cache-status'], 'HIT') !== false )? true : false;
120
+ $x_p_cache = ( isset( $headers['X-Proxy-Cache'] ) && strpos( $headers['X-Proxy-Cache'], 'HIT') !== false )? true : false;
121
+
122
  // If this is TRUE it's NOT Cachable
123
+ $not_cachable = (
124
+ ( isset( $headers['X-Cacheable'] ) && strpos( $headers['X-Cacheable'] ,'NO') !== false ) ||
125
+ ( isset( $headers['Pragma'] ) && strpos( $headers['Pragma'] ,'no-cache') !== false ) ||
126
+ ( isset( $headers['X-Proxy-Cache'] ) && strpos( $headers['X-Proxy-Cache'] ,'HIT') !== false ) ||
127
+ !$x_age
128
+ )? true : false;
129
+
130
+ // Are cache HEADERS set?
131
  $cacheheaders_set = ( isset( $headers['X-Cacheable'] ) || isset( $headers['X-Varnish'] ) || isset( $headers['X-Cache'] ) || $x_via )? true : false;
132
+
133
+ // Which service are we?
134
+ $cache_service = ' ';
135
+ if ( $x_varnish && $x_nginx ) {
136
+ $cache_service = ' Nginx ';
137
+ } elseif ( $x_varnish && !$x_nginx ) {
138
+ $cache_service = ' Varnish ';
139
+ }
140
+
141
+ // Set the default message:
142
+ $return = array(
143
+ 'icon' => 'good',
144
+ 'message' => __( 'Your' . $cache_service . 'caching service appears to be running properly.', 'varnish-http-purge' ),
145
+ );
146
  }
147
 
148
  if ( !$kronk ) {
149
  $return['icon'] = 'bad';
150
+ $return['message'] = __( 'Something went very wrong with this request. Please contact your webhost if it happens again.', 'varnish-http-purge' );
151
  } elseif ( !$cacheheaders_set ) {
152
  $return['icon'] = 'warning';
153
+ $return['message'] = __( 'We were unable find a caching service active for this domain. This can occur if you use a proxy service (such as CloudFlare or Sucuri) in front of your domain, or if you\'re in the middle of a DNS move.', 'varnish-http-purge' );
154
  } elseif ( !$not_cachable && ( $x_cachable || $x_varnish ) ) {
155
  $return['icon'] = 'awesome';
 
156
  } else {
157
  $return['icon'] = 'warning';
158
+ $return['message'] = __( 'A caching service is running but is unable to cache your site.', 'varnish-http-purge' );
159
  }
160
 
161
  return $return;
176
  if ( $remote_ip == false && !empty( $varniship) ) {
177
  $return = array(
178
  'icon' => 'warning',
179
+ 'message' => __( 'You have a Varnish IP address set but a proxy like Cloudflare or Sucuri has not been detected. This is mostly harmless, but if you have issues with your cache not emptying when you make a post, you may need to remove your Varnish IP. Please check with your webhost or server admin before doing so.', 'varnish-http-purge' ),
180
  );
181
  } elseif ( $remote_ip !== false && $remote_ip !== $varniship ) {
182
  $return = array(
183
  'icon' => 'warning',
184
+ 'message' => __( 'You\'re using a custom Varnish IP that doesn\'t appear to match your server IP address. If you\'re using multiple caching servers or IPv6, this is fine. Please make sure you\'ve properly configured it according to your webhost\'s specifications.', 'varnish-http-purge' ),
185
  );
186
  } else {
187
  $return = array(
188
  'icon' => 'awesome',
189
+ 'message' => __( 'Your server IP setup looks good.', 'varnish-http-purge' ),
190
  );
191
  }
192
 
206
  $return = array();
207
 
208
  if ( isset( $headers['Server'] ) ) {
209
+ // Apache
210
+ if ( strpos( $headers['Server'] ,'Apache') !== false && strpos( $headers['Server'] ,'cloudflare') == false ) {
211
+ $return['Apache'] = array(
212
+ 'icon' => 'awesome',
213
+ 'message' => __( 'Your server is running Apache.', 'varnish-http-purge' )
214
+ );
215
+ }
216
+
217
  // nginx
218
+ if ( strpos( $headers['Server'] ,'nginx') !== false && strpos( $headers['Server'] ,'cloudflare') == false ) {
219
+ $return['Nginx'] = array(
220
+ 'icon' => 'awesome',
221
+ 'message' => __( 'Your server is running Nginx.', 'varnish-http-purge' )
222
  );
223
  }
224
 
225
  // Cloudflare
226
  if ( strpos( $headers['Server'] ,'cloudflare') !== false ) {
227
+ $return['CloudFlare'] = array(
228
  'icon' => 'warning',
229
+ 'message' => __( 'CloudFlare has been detected. Make sure you configure WordPress properly by adding your Varnish IP and to flush the CloudFlare cache if you see inconsistencies.', 'varnish-http-purge' ),
230
  );
231
  }
232
 
233
  // HHVM: Note, WP is dropping support so ...
234
  if ( isset( $headers['X-Powered-By'] ) && strpos( $headers['X-Powered-By'] ,'HHVM') !== false ) {
235
+ $return['HHVM'] = array(
236
  'icon' => 'awkward',
237
  'message' => __( 'You are running HHVM instead of PHP. While that is compatible with Varnish, you should consider PHP 7. WordPress will cease support for HHVM in 2018.', 'varnish-http-purge' ),
238
  );
239
  }
240
 
241
  // Pagely
242
+ if ( strpos( $headers['Server'] ,'Pagely') !== false ) {
243
+ $return['Pagely'] = array(
244
  'icon' => 'good',
245
+ 'message' => __( 'This site is hosted on Pagely. The results of this scan may not be accurate.', 'varnish-http-purge' ),
246
  );
247
  }
248
  }
249
 
250
+ if ( isset( $headers['X-hacker'] ) ) {
251
+ $return['WordPress.com'] = array(
252
  'icon' => 'bad',
253
+ 'message' => __( 'This site is hosted on WordPress.com. The results of this scan may not be accurate.', 'varnish-http-purge' ),
254
  );
255
  }
256
 
257
+ if ( isset( $headers['X-Backend'] ) && strpos( $headers['X-Backend'] ,'wpaas_web_') !== false ) {
258
+ $return['GoDaddy'] = array(
259
  'icon' => 'good',
260
+ 'message' => __( 'This site is hosted on GoDaddy. The results of this scan may not be accurate.', 'varnish-http-purge' ),
261
  );
262
  }
263
 
288
  if ( strpos( $headers['Content-Encoding'] ,'Fastly') !== false ) {
289
  $return = array(
290
  'icon' => 'good',
291
+ 'message' => __( 'Fastly is speeding up your site. Remember to empty all caches in all locations when necessary.', 'varnish-http-purge' ),
292
  );
293
  }
294
 
305
  static function cookie_results( $headers ) {
306
 
307
  // Defaults
308
+ $return = $almost = array();
309
+
310
+ // Early check. If there are no cookies, skip!
311
+ if ( !isset( $headers['Set-Cookie'] ) ) return $return;
312
 
313
+ // We have at least one cookie, so let's set this now:
314
+ $return['Cookies Active'] = array(
315
  'icon' => 'warning',
316
+ 'message' => __( 'Cookies have been detected. Unless your caching service is configured properly for the specific cookies, it may not cache properly. Please contact your webhost or administrator with information about the cookies found.', 'varnish-http-purge' ),
 
 
 
 
 
 
 
 
317
  );
318
 
319
+ // Call the cookies!
320
+ $request = wp_remote_get( 'https://varnish-http-purge.objects-us-east-1.dream.io/cookies.json' );
321
+
322
+ if( is_wp_error( $request ) ) return $return; // Bail if we can't hit the server
323
+
324
+ $body = wp_remote_retrieve_body( $request );
325
+ $cookies = json_decode( $body );
326
+
327
+ if( empty( $cookies ) ) {
328
+ if ( WP_DEBUG ) {
329
+ $return[ 'cookie-error' ] = array( 'icon' => 'warning', 'message' => __( 'Error: Cookie data cannot be loaded.', 'varnish-http-purge' ) );
330
+ }
331
+
332
+ return $return; // Bail if the data was empty for some reason
333
+ }
334
+
335
+ foreach ( $cookies as $cookie => $info ) {
336
+ $has_cookie = false;
337
+
338
  // If cookies are an array, scan the whole thing. Otherwise, we can use strpos.
339
  if ( is_array( $headers['Set-Cookie'] ) ) {
340
+ if ( in_array( $info->cookie, $headers['Set-Cookie'], true ) ) $has_cookie = true;
 
 
 
 
 
 
 
341
  } else {
342
+ $strpos = strpos( $headers['Set-Cookie'], $info->cookie );
343
+ if ( $strpos !== false ) $has_cookie = true;
 
 
 
 
 
 
344
  }
345
 
346
+ if ( $has_cookie ) {
347
+ $return[ 'Cookie: ' . $cookie ] = array( 'icon' => $info->type, 'message' => $info->message );
 
 
348
  }
349
  }
350
 
 
 
 
351
  return $return;
352
  }
353
 
 
354
  /**
355
  * Cache
356
  *
365
  // Cache Control
366
  if ( isset( $headers['Cache-Control'] ) ) {
367
 
368
+ if ( is_array( $headers['Cache-Control'] ) ) {
369
+ $no_cache = array_search( 'no-cache', $headers['Cache-Control'] );
370
+ $max_age = array_search( 'max-age=0', $headers['Cache-Control'] );
371
+ } else {
372
+ $no_cache = strpos( $headers['Cache-Control'], 'no-cache' );
373
+ $max_age = strpos( $headers['Cache-Control'], 'max-age=0' );
374
+ }
375
+
376
  // No-Cache Set
377
+ if ( $no_cache !== false ) {
378
  $return['no_cache'] = array(
379
  'icon' => 'bad',
380
+ 'message' => __( 'The header Cache-Control is returning "no-cache", which means visitors will never get cached pages.', 'varnish-http-purge' ),
381
  );
382
  }
383
 
384
  // Max-Age is 0
385
+ if ( $max_age !== false ) {
386
  $return['max_age'] = array(
387
  'icon' => 'bad',
388
+ 'message' => __( 'The header Cache-Control is returning "max-age=0", which means a page can be no older than 0 seconds before it needs to regenerate the cache.', 'varnish-http-purge' ),
389
  );
390
  }
391
  }
392
 
393
  // Age Headers
394
  if ( !isset( $headers['Age'] ) ) {
395
+ $return['Age Headers'] = array(
396
  'icon' => 'bad',
397
  'message' => __( 'Your domain does not report an "Age" header, which means we can\'t tell if the page is actually serving from cache.', 'varnish-http-purge' ),
398
  );
399
+ } elseif( ( $headers['Age'] <= 0 || $headers['Age'] == 0 ) && (bool)strtotime( $headers['Age'] ) == false ) {
400
+ $age_header = (int)$headers['Age'];
401
+ $return['Age Headers'] = array(
402
  'icon' => 'warning',
403
+ 'message' => __( 'The "Age" header is set to less than 1 second which means the page was generated without caching. This can occur when a page is visited for the first time, or if caching was just emptied. Please check again; if the header remains 0 then either the URL is intentionally excluded from caching, or a theme or plugin is sending cache headers or cookies that instruct your server not to cache.', 'varnish-http-purge' ),
404
+ );
405
+ } elseif ( (bool)strtotime( $headers['Age'] ) && time() <= strtotime( $headers['Age'] ) ) {
406
+ $return['Age Headers'] = array(
407
+ 'icon' => 'bad',
408
+ 'message' => __( 'The "Age" header is set to an invalid time. Either you checked right when the cache was clearned for that url or your server is not serving cached content for that url. Please check again, and if it happens again then a theme or plugin is requesting the URL not be cached.', 'varnish-http-purge' ),
409
  );
410
  } else {
411
+ $return['Age Headers'] = array(
412
  'icon' => 'good',
413
  'message' => __( 'Your site is returning proper "Age" headers.', 'varnish-http-purge' ),
414
  );
416
 
417
  // Pragma
418
  if ( isset( $headers['Pragma'] ) && strpos( $headers['Pragma'] ,'no-cache') !== false ) {
419
+ $return['Pragma Headers'] = array(
420
  'icon' => 'bad',
421
+ 'message' => __( 'A plugin or theme is setting the header Pragma to "no-cache" which means visitors will never get cached pages.', 'varnish-http-purge' ),
422
  );
423
  }
424
 
425
  // X-Cache
426
  if ( isset( $headers['X-Cache-Status'] ) && strpos( $headers['X-Cache-Status'] ,'MISS') !== false ) {
427
+ $return['X-Cache Satus'] = array(
428
  'icon' => 'bad',
429
+ 'message' => __( 'X-Cache missed, which means it was not able to serve this page as cached. This may be resolved by re-running the scan. If not, then a plugin or theme is forcing this setting.', 'varnish-http-purge' ),
430
  );
431
  }
432
 
433
  // Mod-PageSpeed
434
  if ( isset( $headers['X-Mod-Pagespeed'] ) ) {
435
  if ( strpos( $headers['X-Cacheable'] , 'YES:Forced') !== false ) {
436
+ $return['Mod Pagespeed'] = array(
437
  'icon' => 'good',
438
+ 'message' => __( 'Mod Pagespeed is active and configured to work properly with caching services.', 'varnish-http-purge' ),
439
  );
440
  } else {
441
+ $return['Mod Pagespeed'] = array(
442
  'icon' => 'bad',
443
+ 'message' => __( 'Mod Pagespeed is active but it looks like your caching headers may not be right. This may be a false negative if other parts of your site are overwriting headers. Fix all other errors listed, then come back to this. If you are still having errors, you will need to look into using .htaccess or Nginx to override the Pagespeed headers.', 'varnish-http-purge' ),
444
  );
445
  }
446
  }
449
  }
450
 
451
  /**
452
+ * Bad Themes
453
  *
454
+ * Themes known to be problematic
455
  *
456
+ * @since 4.5.0
457
  */
458
+ static function bad_themes_results() {
459
 
460
+ $return = array();
461
+ $request = wp_remote_get( 'https://varnish-http-purge.objects-us-east-1.dream.io/themes.json' );
462
 
463
+ if( is_wp_error( $request ) ) {
464
+ return $return; // Bail early
465
+ }
 
 
466
 
467
+ $body = wp_remote_retrieve_body( $request );
468
+ $themes = json_decode( $body );
469
+
470
+ if( empty( $themes ) ) {
471
+ if ( WP_DEBUG ) {
472
+ $return[ 'Theme Error' ] = array( 'icon' => 'warning', 'message' => __( 'Error: Theme data cannot be loaded.', 'varnish-http-purge' ) );
473
+ }
474
+
475
+ return $return; // Bail early
476
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477
 
478
  // Check all the themes. If one of the questionable ones are active, warn
479
+ foreach ( $themes as $theme => $info ) {
480
  $my_theme = wp_get_theme( $theme );
481
+ $message = __( 'Active Theme ', 'varnish-http-purge') . ucfirst( $theme ) . ': ' . $info->message;
482
+ $warning = $info->type;
483
  if ( $my_theme->exists() ) {
484
+ $return[ 'Theme: ' . ucfirst( $theme ) ] = array( 'icon' => $warning, 'message' => $message );
485
  }
486
  }
487
 
488
+ return $return;
489
+ }
490
+
491
+ /**
492
+ * Bad Plugins
493
+ *
494
+ * Plugins known to be problematic
495
+ *
496
+ * @since 4.5.0
497
+ */
498
+ static function bad_plugins_results() {
499
+
500
+ $return = array();
501
+ $messages = array(
502
+ 'incompatible' => __( 'This plugin has unexpected results with caching, making not function properly.', 'varnish-http-purge' ),
503
+ 'translation' => __( 'Translation plugins that use cookies and/or sessions prevent most server side caching from running properly.', 'varnish-http-purge' ),
504
+ 'sessions' => __( 'This plugin uses sessions, which conflicts with server side caching.', 'varnish-http-purge' ),
505
+ 'cookies' => __( 'This plugin uses cookies, which prevents server side caching.', 'varnish-http-purge' ),
506
+ 'cache' => __( 'This type of caching plugin does not work well with server side caching.', 'varnish-http-purge' ),
507
+ 'ancient' => __( 'This plugin is not up to date with WordPress best practices and breaks caching.', 'varnish-http-purge' ),
508
+ );
509
+ $request = wp_remote_get( 'https://varnish-http-purge.objects-us-east-1.dream.io/plugins.json' );
510
+
511
+ if( is_wp_error( $request ) ) {
512
+ if ( WP_DEBUG ) {
513
+ $return[ 'Plugin Error' ] = array( 'icon' => 'warning', 'message' => __( 'Error: Plugin data cannot be loaded.', 'varnish-http-purge' ) );
514
+ }
515
+ return $return; // Bail early
516
+ }
517
+
518
+ $body = wp_remote_retrieve_body( $request );
519
+ $plugins = json_decode( $body );
520
+
521
+ if( empty( $plugins ) ) {
522
+ return $return; // Bail early
523
+ }
524
+
525
+ // Check all the plugins. If one of the questionable ones are active, warn
526
+ foreach ( $plugins as $plugin => $info ) {
527
+ if ( is_plugin_active( $info->path ) ) {
528
+ $message = $messages[ $info->reason ];
529
+ $warning = $info->type;
530
+ $return[ 'Plugin: ' . ucfirst( $plugin ) ] = array( 'icon' => $warning, 'message' => $message );
531
  }
532
  }
533
 
543
  */
544
  static function get_all_the_results( $headers, $remote_ip, $varniship ) {
545
  $output = array();
546
+ $output['Cache Service'] = self::varnish_results( $headers );
547
+ $output['Remote IP'] = self::remote_ip_results( $remote_ip, $varniship );
548
 
549
  // Server Results
550
+ $server_results = self::server_results( $headers, $remote_ip, $varniship );
551
+ $output = array_merge( $output, $server_results );
552
 
553
  // Cache Results
554
  $cache_results = self::cache_results( $headers );
558
  $cookie_results = self::cookie_results( $headers );
559
  $output = array_merge( $output, $cookie_results );
560
 
561
+ // Themes that don't play nicely with Varnish)
562
+ $bad_themes_results = self::bad_themes_results();
563
+ $output = array_merge( $output, $bad_themes_results );
564
+
565
+ // Plugins that don't play nicely with Varnish)
566
+ $bad_plugins_results = self::bad_plugins_results();
567
+ $output = array_merge( $output, $bad_plugins_results );
568
+
569
  return $output;
570
  }
571
 
572
  }
573
 
574
+ $varnish_debug = new VarnishDebug();
readme.txt CHANGED
@@ -3,17 +3,19 @@ Contributors: Ipstenu, mikeschroder, techpriester
3
  Tags: varnish, purge, cache
4
  Requires at least: 4.7
5
  Tested up to: 4.9
6
- Stable tag: 4.4.0
7
  Requires PHP: 5.6
8
 
9
  Automatically empty Varnish Cache when content on your site is modified.
10
 
11
  == Description ==
12
 
13
- Varnish HTTP Purge sends a request to delete (aka flush) the cached data of a page or post every time it it modified. This happens when updating, publishing, commenting on, or deleting an post, and when changing themes.
14
-
15
  <a href="https://www.varnish-cache.org/">Varnish</a> is a web application accelerator also known as a caching HTTP reverse proxy. You install it in front of any server that speaks HTTP and configure it to cache the contents. This plugin <em>does not</em> install Varnish for you, nor will it configure Varnish for WordPress.
16
 
 
 
 
 
17
  Not all page caches are deleted every time, depending on your Varnish configuration. For example, when a post, page, or custom post type is edited, or a new comment is added, <em>only</em> the following pages will purge:
18
 
19
  * The front page
@@ -25,125 +27,137 @@ Not all page caches are deleted every time, depending on your Varnish configurat
25
  In addition, your <em>entire</em> cache will be deleted on the following actions:
26
 
27
  * Changing themes
28
- * Press the 'Purge Varnish Cache' button on the dashboard or toolbar
29
 
30
  Plugins can hook into the purge actions as well, to filter their own events to trigger a purge.
31
 
32
- On a multisite network using subfolders, only <strong>network admins</strong> can purge the main site. This is a security decision.
33
 
34
- = WP CLI =
35
 
36
  * `wp varnish purge` - Flush the entire cache
37
  * `wp varnish debug` - Help for debugging how well Varnish is (or isn't) working
38
 
39
- = Requirements =
 
 
 
 
 
 
40
 
41
  * Pretty Permalinks enabled
42
  * Varnish 3.x or higher
43
 
 
 
 
 
 
 
44
  == Frequently Asked Questions ==
45
 
46
  **Please report all issues in the [support forums](https://wordpress.org/support/plugin/varnish-http-purge)**
47
 
48
  If you have code patches, [pull requests are welcome](https://github.com/Ipstenu/varnish-http-purge).
49
 
50
- = How can I tell if everything's working? =
51
 
52
- From your WordPress Dashboard, go to Tools -> Varnish Status. There a page will auto-scan your front page and report back any issues found. This includes any known problematic plugins. You can use it to scan any URL on your domain (but ONLY on your own domain).
53
 
54
- = Does every WordPress plugin and theme work with Varnish? =
55
-
56
- No. Some of them have behaviour that causes Varnish not to cache, either by accident or design.
57
 
58
- = How can I debug my site? =
59
 
60
- Use the Varnish Status page. It will try and help you figure out what's wrong.
61
 
62
- = Will you fix my site? =
63
 
64
- I don't have that much availability. I will try to point you towards solving it on your own. Bear in mind, that may mean you have to decide if using a specific plugin or theme is worth an imperfect cache.
65
 
66
- = What version of Varnish is supported? =
67
 
68
- This was built and tested on Varnish 3.x. While it is reported to work on 2.x and 4.x, it is only supported on v3 at this time.
69
 
70
- = Why doesn't every page cache get deleted when I make a new post? =
71
 
72
- Philosophy. There are many other plugins out there which will allow you to granularly select what pages should and should not be deleted on updates. With that in mind, the choice was made for decisions instead of options, and simplicity was the driving principle. The plugin decides what's best to delete on updates, and provides hooks for developers to use as needed.
73
 
74
- = Why doesn't my cache get deleted when I edit my theme? =
75
 
76
- WordPress can only flush the cache automatically when you use the internal file editors. If you edit files manually then you will need to empty the cache manually.
77
 
78
- = How do I manually delete the whole cache? =
79
 
80
- Click the 'Empty Varnish Cache' button on the "Right Now" Dashboard (see the screenshot if you can't find it). There's also an "Empty Cache" button on the admin toolbar, and you can use `wp varnish purge` from the command line.
81
 
82
- = I don't see a button! =
83
 
84
- That means your account doesn't have the appropriate permissions. Only administrators can empty the entire cache. In the case of a subfolder multisite network, only the <em>network</em> admins can empty the cache for the primary site.
85
 
86
- = Why is nothing caching when I use PageSpeed? =
87
 
88
- PageSpeed likes to put in Caching headers to say <em>not</em> to cache. To fix this, you need to put this in your `.htaccess` section for PageSpeed: `ModPagespeedModifyCachingHeaders off`
89
 
90
- If you're using nginx, it's `pagespeed ModifyCachingHeaders off;`
91
 
92
- = Why aren't my changes showing when I use CloudFlare or another proxy? =
93
 
94
- When you use CloudFlare or any other similar service, you've got a proxy in front of the Varnish proxy. In general this isn't a bad thing, though it can introduce some network latency (that means your site may run slower because it has to go through multiple layers to get to the content). The problem arises when the DNS shenanigans send the purge request to your domain name. When you've got an additional proxy like CloudFlare, you don't want the request to go to the proxy, you want it to go to Varnish server.
95
 
96
- On single-site, you can edit this via the Tools -> Varnish Status page. On Multisite, you'll need to add the following to your wp-config.php file:
97
 
98
- `define('VHP_VARNISH_IP','123.45.67.89');`
99
 
100
- Replace "123.45.67.89" with the IP of your <em>Varnish Server</em> (not CloudFlare, Varnish). <em>DO NOT</em> put in http in this define.
101
 
102
- If you want to use WP-CLI, you can set an option in the database. This will NOT take precedence over the define, it's just there to let hosts who are using something like wp-cli do this for you in an automated fashion:
103
 
104
- `wp option add vhp_varnish_ip 123.45.67.89`
105
 
106
- and
107
 
108
- `wp option update vhp_varnish_ip 123.45.67.890`
109
 
110
- = How do I find my Varnish IP? =
111
 
112
  Your Varnish IP must be one of the IPs that Varnish is listening on. If you use multiple IPs, or if you've customized your ACLs, you'll need to pick on that doesn't conflict with your other settings. For example, if you have Varnish listening on a public and private IP, you'll want to pick the private. On the other hand, if you told Varnish to listen on 0.0.0.0 (i.e. "listen on every interface you can") you would need to check what IP you set your purge ACL to allow (commonly 127.0.0.1 aka localhost), and use that (i.e. 127.0.0.1).
113
 
114
  If your webhost set up Varnish, you may need to ask them for the specifics if they don't have it documented. I've listed the ones I know about here, however you should still check with them if you're not sure.
115
 
116
  <ul>
117
- <li><strong>DreamHost</strong> - If you're using DreamPress and Cloudflare, go into the Panel and click on the DNS settings for the domain. The entry for <em>resolve-to.domain</em> is your varnish server: `resolve-to.www A 208.97.157.172` -- If you're <em>NOT</em> using Cloudflare, you don't need it; it's just your normal IP.</li>
118
  </ul>
119
 
120
- = What if I have multiple varnish IPs? =
121
 
122
  Multiple IPs are not supported at this time.
123
 
124
- = Why isn't the whole cache deletion working? =
125
 
126
- The plugin sends a PURGE command of <code>/.*</code> and `X-Purge-Method` in the header with a value of regex. If your Varnish server doesn't doesn't understand the wildcard, you can configure it to check for the header.
127
 
128
- = How can I see what the plugin is sending to Varnish? =
129
 
130
- Danger! Here be dragons! If you're command line savvy, you can monitor the interactions between the plugin and Varnish. This can help you understand what's not working quite right, but it can very confusing.
131
 
132
- [Detailed directions can be found on the debugging section](https://github.com/Ipstenu/varnish-http-purge/wiki#debugging).
133
 
134
- = How do I configure my VCL? =
135
 
136
- This is a question beyond the support of plugin. I don't offer any Varnish Config help due to resources. I will say this, you absolutely must have PURGE set up in your VCL. This is still supported in Varnish v3, though may not be set up by default. Also, here are some links to other people who use this plugin and have made public their VCLs:
137
 
138
- * <a href="https://github.com/dreamhost/varnish-vcl-collection">DreamHost's Varnish VCL Collection</a>
139
 
140
- All of those VCLs work with this plugin.
 
 
141
 
142
- = Can I filter things to add special URLs? =
143
 
144
- Yes! [Full documentation can be found on Custom Filters in the wiki](https://github.com/Ipstenu/varnish-http-purge/wiki/Custom-Filters).
145
 
146
- = Hey, don't you work at DreamHost? Is this Official or DreamHost only? =
147
 
148
  * Yes, I do work for DreamHost.
149
  * No, this plugin is not really official nor DreamHost Only
@@ -152,16 +166,22 @@ This plugin is installed by default for _all_ DreamPress installs on DreamHost,
152
 
153
  == Changelog ==
154
 
155
- = 4.4.0 =
156
- * March 2018
157
- * Improve translations
158
- * Massive improvements to the debugging tools
159
- * Allow for port to be added to host headers (props @davidbarratt)
160
- * WP-CLI for debugging
161
 
162
  == Screenshots ==
163
 
164
  1. Purge button on Right Now (Dashboard Admin)
165
  2. Purge button on Toolbar
166
  3. Scanner results
167
- 4. Change Varnish IP address
 
 
 
 
 
 
3
  Tags: varnish, purge, cache
4
  Requires at least: 4.7
5
  Tested up to: 4.9
6
+ Stable tag: 4.5.0
7
  Requires PHP: 5.6
8
 
9
  Automatically empty Varnish Cache when content on your site is modified.
10
 
11
  == Description ==
12
 
 
 
13
  <a href="https://www.varnish-cache.org/">Varnish</a> is a web application accelerator also known as a caching HTTP reverse proxy. You install it in front of any server that speaks HTTP and configure it to cache the contents. This plugin <em>does not</em> install Varnish for you, nor will it configure Varnish for WordPress.
14
 
15
+ The Varnish HTTP Purge plugin sends a request to delete (aka flush) the cached data of a page or post every time it it modified. This happens when updating, publishing, commenting on, or deleting an post, and when changing themes.
16
+
17
+ In addition, it provides debugging tools to help you determine how effective your site setup is with Varnish. In order to provide the most up to date compatibility information, this tool contacts a service hosted on DreamObjects. [Public information about this service is available on DreamObjects](https://varnish-http-purge.objects-us-east-1.dream.io/readme.txt). The service is <em>ONLY</em> accessed when using the Varnish Debugging tool.
18
+
19
  Not all page caches are deleted every time, depending on your Varnish configuration. For example, when a post, page, or custom post type is edited, or a new comment is added, <em>only</em> the following pages will purge:
20
 
21
  * The front page
27
  In addition, your <em>entire</em> cache will be deleted on the following actions:
28
 
29
  * Changing themes
30
+ * Pressing the <strong>Empty Cache</strong> button on the dashboard or toolbar
31
 
32
  Plugins can hook into the purge actions as well, to filter their own events to trigger a purge.
33
 
34
+ On a multisite network using subfolders, only <strong>network admins</strong> can purge the main site. This is a security decision, as emptying the cache too often can be computationally expensive and cause server outages for a network.
35
 
36
+ === WP CLI ===
37
 
38
  * `wp varnish purge` - Flush the entire cache
39
  * `wp varnish debug` - Help for debugging how well Varnish is (or isn't) working
40
 
41
+ === Debugging ===
42
+
43
+ If you're working on a site and need to turn off caching, add this to your wp-config file: `define( 'VHP_DEBUG', true );`
44
+
45
+ That will break cache on page loads. It is _not_ recommended for production!
46
+
47
+ === Requirements ===
48
 
49
  * Pretty Permalinks enabled
50
  * Varnish 3.x or higher
51
 
52
+ === Privacy Policy ===
53
+
54
+ By default, no data is tracked. If you use the site scanner/debugging tool, your domain and IP address will access [a remote service hosted on DreamObjects](https://varnish-http-purge.objects-us-east-1.dream.io/readme.txt). No personally identifying transaction data is recorded or stored, only overall usage. IP addresses of the website making the request may be recorded by the service, but there is no way to access them and use it to correspond with individuals or processes.
55
+
56
+ Use of this service is required for the debugging tool, in order to provide up to date compatibility checks on plugins and themes that may conflict with running a server based cache (such as Varnish or Nginx) without needing to update the plugin every day.
57
+
58
  == Frequently Asked Questions ==
59
 
60
  **Please report all issues in the [support forums](https://wordpress.org/support/plugin/varnish-http-purge)**
61
 
62
  If you have code patches, [pull requests are welcome](https://github.com/Ipstenu/varnish-http-purge).
63
 
64
+ === Is this plugin caching my data? ===
65
 
66
+ No. This plugin tells your cache system when content is updated, and to delete the cached data at that time.
67
 
68
+ === How does this plugin know what to delete? ===
 
 
69
 
70
+ When you update content on your site, like making a post or editing one, or someone leaving a comment, WordPress triggers a command on your server to purge (aka empty) the cache for any related pages, including the REST API.
71
 
72
+ === Why doesn't the plugin automatically delete the whole cache? ===
73
 
74
+ Philosophy. There are many other plugins out there which will allow you to granularly select what pages should and should not be deleted on updates. With that in mind, the choice was made for decisions instead of options, and simplicity was the driving principle. The plugin decides what's best to delete on updates, and provides hooks for developers to use as needed.
75
 
76
+ === Can I delete the entire cache? ===
77
 
78
+ Yes! Click the 'Empty Cache' button on the "Right Now" Dashboard (see the screenshot if you can't find it). There's also an "Empty Cache" button on the admin toolbar.
79
 
80
+ If you don't see a button, then your account doesn't have the appropriate permissions. Only administrators can empty the entire cache. In the case of a subfolder multisite network, only the <em>network</em> admins can empty the cache for the primary site.
81
 
82
+ === Will the plugin delete my cache when I edit my theme or plugins? ===
83
 
84
+ No. WordPress can't detect file changes like that, and you really don't want it to. That would empty the cache every time you edited any file, which would cause your site to become unstable. You will need to use the Empty Cache buttons when you're done editing your code.
85
 
86
+ === Does every WordPress plugin and theme work with Varnish? ===
87
 
88
+ No. Some of them have behaviour that causes Varnish not to cache, either by accident or design.
89
 
90
+ === I'm a developer, can I tell your cache to empty in my plugin/theme? ===
91
 
92
+ Yes! [Full documentation can be found on Custom Filters in the wiki](https://github.com/Ipstenu/varnish-http-purge/wiki/Custom-Filters).
93
 
94
+ === Can I turn off caching? ===
95
 
96
+ Yes and no. Remember, the plugin isn't doing the caching so it really depends on your server setup. You can set the following define in your `wp-config.php` file to attempt and disable caching, however this may not work on all setups: `define( 'VHP_DEBUG', true );`
97
 
98
+ === How can I tell if everything's caching? ===
99
 
100
+ From your WordPress Dashboard, go to <em>Tools</em> -> <em>Varnish Debugging</em>. There a page will auto-scan your front page and report back any issues found. This includes any known problematic plugins. You can use it to scan any URL on your domain (but ONLY on your own domain).
101
 
102
+ === Why doesn't the debug page autoload anymore? ===
103
 
104
+ The scan files were off-loaded to a service to allow for more frequent updates without having to require people to update the plugin. In order to ensure no one is scanned without consent, the auto-scanning was disabled.
105
 
106
+ === Why is nothing caching when I use PageSpeed? ===
107
 
108
+ PageSpeed likes to put in Caching headers to say <em>not</em> to cache. To fix this, you need to put this in your `.htaccess` section for PageSpeed: `ModPagespeedModifyCachingHeaders off`
109
 
110
+ If you're using nginx, it's `pagespeed ModifyCachingHeaders off;`
111
 
112
+ === Why aren't my changes showing when I use CloudFlare or another proxy? ===
113
 
114
+ When you use CloudFlare or any other similar service, you've put a proxy in front of the Varnish proxy. In general this isn't a bad thing, though it can introduce some network latency (that means your site may run slower because it has to go through multiple layers to get to the content). The problem arises when WordPress tries to send the purge request to your domain name and, with a proxy, that means the proxy service and not your website.
115
 
116
+ On single-site, you can edit this via the Tools -> Varnish Status page. On Multisite, you'll need to add the following to your wp-config.php file: `define('VHP_VARNISH_IP','123.45.67.89');`
117
 
118
+ Replace "123.45.67.89" with the IP of your <em>Varnish Server</em> (not CloudFlare, Varnish). <em>DO NOT</em> put in http in this define.
119
 
120
+ If you want to use WP-CLI, you can set an option in the database. This will NOT take precedence over the define, it's just there to let hosts who are using something like wp-cli do this for you in an automated fashion: `wp option update vhp_varnish_ip 123.45.67.890`
121
 
122
+ === How do I find my Varnish IP? ===
123
 
124
  Your Varnish IP must be one of the IPs that Varnish is listening on. If you use multiple IPs, or if you've customized your ACLs, you'll need to pick on that doesn't conflict with your other settings. For example, if you have Varnish listening on a public and private IP, you'll want to pick the private. On the other hand, if you told Varnish to listen on 0.0.0.0 (i.e. "listen on every interface you can") you would need to check what IP you set your purge ACL to allow (commonly 127.0.0.1 aka localhost), and use that (i.e. 127.0.0.1).
125
 
126
  If your webhost set up Varnish, you may need to ask them for the specifics if they don't have it documented. I've listed the ones I know about here, however you should still check with them if you're not sure.
127
 
128
  <ul>
129
+ <li><strong>DreamHost</strong> - If you're using DreamPress and Cloudflare, go into the Panel and click on the DNS settings for the domain. The entry for <em>resolve-to.domain</em> is your varnish server: `resolve-to.www A 208.97.157.172` -- If you're <em>NOT</em> using Cloudflare, you don't need it; it's just your normal IP.</li>
130
  </ul>
131
 
132
+ === What if I have multiple varnish IPs? ===
133
 
134
  Multiple IPs are not supported at this time.
135
 
136
+ === Will you fix my site? ===
137
 
138
+ No. I will try to point you towards solving it on your own. This may mean you have to decide if using a specific plugin or theme is worth an imperfect cache.
139
 
140
+ === What version of Varnish is supported? ===
141
 
142
+ This was built and tested on Varnish 3.x. While it is reported to work on 2.x and 4.x, it is only supported on v3 at this time.
143
 
144
+ === Does this work with Nginx caching? ===
145
 
146
+ It can, if you configured nginx caching to respect the curl PURGE request.
147
 
148
+ === Will you write my cache rules for me? ===
149
 
150
+ This is a question beyond the support of plugin. I do not have the resources available to offer any configuration help. Here are some basic gotchas to be aware of:
151
 
152
+ * To empty any cached data, the service will need to respect the PURGE command
153
+ * Not all cache services set up PURGE by default
154
+ * When flushing the whole cache, the plugin sends a PURGE command of <code>/.*</code> and sets the `X-Purge-Method` header to `regex`.
155
 
156
+ === How can I see what the plugin is sending to Varnish? ===
157
 
158
+ Danger! Here be dragons! If you're command line savvy, you can monitor the interactions between the plugin and Varnish. This can help you understand what's not working quite right, but it can very confusing. [Detailed directions can be found on the debugging section on GitHub](https://github.com/Ipstenu/varnish-http-purge/wiki#debugging).
159
 
160
+ === Hey, don't you work at DreamHost? Is this Official or DreamHost only? ===
161
 
162
  * Yes, I do work for DreamHost.
163
  * No, this plugin is not really official nor DreamHost Only
166
 
167
  == Changelog ==
168
 
169
+ = 4.5.0 =
170
+ * May 2018
171
+ * Remote storage of problem plugins/themes
172
+ * Prevent auto-loading of scan for improved disclosure and compliance
173
+ * Changed colour of the purge button for improved visibility
174
+ * Support for nginx proxy headers
175
 
176
  == Screenshots ==
177
 
178
  1. Purge button on Right Now (Dashboard Admin)
179
  2. Purge button on Toolbar
180
  3. Scanner results
181
+ 4. Change Varnish IP address
182
+
183
+ == Upgrade Notice ==
184
+
185
+ = 4.5.0 =
186
+
187
+ As of this release, the Varnish debugger uses remote data to collect a list of cookies, plugins, and themes known to conflict with Varnish. This will reduce the need to update the plugin for informational changes only. [Public information about this service is available on DreamObjects](https://varnish-http-purge.objects-us-east-1.dream.io/readme.txt).
status.php CHANGED
@@ -51,7 +51,7 @@ class VarnishStatus {
51
  * @since 4.0
52
  */
53
  function admin_menu() {
54
- add_management_page( __( 'Is Varnish Working?', 'varnish-http-purge' ), __( 'Varnish Status', 'varnish-http-purge' ), 'manage_options', 'varnish-status', array( &$this, 'settings_page' ) );
55
  }
56
 
57
  /**
@@ -61,7 +61,7 @@ class VarnishStatus {
61
  */
62
  function register_settings_url() {
63
  register_setting( 'varnish-http-purge-url', 'vhp_varnish_url', array( &$this, 'varnish_url_sanitize' ) );
64
- add_settings_section( 'varnish-url-settings-section', __( 'Check Varnish Status', 'varnish-http-purge' ), array( &$this, 'options_callback_url'), 'varnish-url-settings' );
65
  add_settings_field( 'varnish_url', __( 'Check A URL On Your Site:', 'varnish-http-purge' ), array( &$this, 'varnish_url_callback' ), 'varnish-url-settings', 'varnish-url-settings-section' );
66
  }
67
 
@@ -72,8 +72,8 @@ class VarnishStatus {
72
  */
73
  function register_settings_ip() {
74
  register_setting( 'varnish-http-purge-ip', 'vhp_varnish_ip', array( &$this, 'varnish_ip_sanitize' ) );
75
- add_settings_section( 'varnish-ip-settings-section', __('Configure Custom Varnish IP', 'varnish-http-purge'), array( &$this, 'options_callback_ip'), 'varnish-ip-settings' );
76
- add_settings_field( 'varnish_ip', __('Set Varnish IP', 'varnish-http-purge'), array( &$this, 'varnish_ip_callback'), 'varnish-ip-settings', 'varnish-ip-settings-section' );
77
  }
78
 
79
  /**
@@ -84,12 +84,12 @@ class VarnishStatus {
84
  function options_callback_ip() {
85
  ?>
86
  <p><a name="#configure"></a><?php _e( 'The majority of users will never need to look down here. However there are cases when a custom Varnish IP Address will need to be set, in order to tell the plugin to empty the cache in a specific location. If you\'re using a CDN like Cloudflare or a Firewall Proxy like Sucuri, you will want to set this.', 'varnish-http-purge' ); ?></p>
87
- <p><?php _e( 'Your Varnish IP the IP address of the server where Varnish is installed. Your Varnish IP must be one of the IPs that Varnish is listening. If you use multiple IPs, or if you\'ve customized your ACLs, you\'ll need to pick one that doesn\'t conflict with your other settings. For example, if you have Varnish listening on a public and private IP, pick the private. On the other hand, if you told Varnish to listen on 0.0.0.0 (i.e. "listen on every interface you can") you would need to check what IP you set your purge ACL to allow (commonly 127.0.0.1 aka localhost), and use that (i.e. 127.0.0.1).', 'varnish-http-purge' ); ?></p>
88
- <p><?php _e( 'If your webhost set up Varnish for you, as is the case with DreamPress or WP Engine, ask them for the specifics if they don\'t have it documented. I\'ve listed the ones I know about here, however you should still check with them if you\'re not sure.', 'varnish-http-purge' ); ?></p>
89
  <p><strong><?php _e( 'If you aren\'t sure what to do, contact your webhost or server admin before making any changes.', 'varnish-http-purge' ); ?></strong></p>
90
 
91
  <ul>
92
- <li><?php _e( 'DreamHost - Go into the Panel and click on the DNS settings for the domain. The entry for <em>resolve-to.domain</em> (if set) will be your varnish server. If it\'s not set, then you don\'t need to worry about this at all. Example:', 'varnish-http-purge' ); ?> <code>resolve-to.www A 208.97.157.172</code></li>
93
  </ul>
94
  <?php
95
  }
@@ -131,14 +131,15 @@ class VarnishStatus {
131
  */
132
  function options_callback_url() {
133
 
134
- // Include the debug code
135
- include( 'debug.php' );
136
-
137
- ?><p><?php _e( 'While it is impossible to detect all possible conflicts, this status page performs a check of the most common issues that prevent Varnish from caching your site properly.', 'varnish-http-purge' ); ?></p>
138
 
139
- <p><?php _e( 'This feature is provided to help you in debugging any conflicts on your own. When filing an issue with your web-host, we recommend you include the output in your ticket.', 'varnish-http-purge' ); ?></p>
140
 
141
  <?php
 
 
 
 
142
  // Set icons
143
  $icons = array (
144
  'awesome' => '<span class="dashicons dashicons-heart" style="color:#008000;"></span>',
@@ -148,6 +149,9 @@ class VarnishStatus {
148
  'bad' => '<span class="dashicons dashicons-thumbs-down" style="color:#990000;"></span>',
149
  );
150
 
 
 
 
151
  // Get the base URL to start
152
  $url = esc_url( VarnishPurger::the_home_url() );
153
  $varnishurl = get_option( 'vhp_varnish_url', $url );
@@ -244,7 +248,7 @@ class VarnishStatus {
244
  ?>
245
  <div class="wrap">
246
 
247
- <h1><?php _e( 'Is Varnish Working?', 'varnish-http-purge' ); ?></h1>
248
 
249
  <?php settings_errors(); ?>
250
 
@@ -319,12 +323,12 @@ class VarnishStatus {
319
  } elseif ( parse_url( $output, PHP_URL_HOST ) !== parse_url( $input, PHP_URL_HOST ) ) {
320
  $set_message = __( 'You cannot scan URLs on other domains.', 'varnish-http-purge' );
321
  } else {
322
- $output = filter_var( $input, FILTER_VALIDATE_URL);
323
- $set_message = __( 'Scanning New URL...', 'varnish-http-purge' );
324
- $set_type = 'updated';
325
  }
326
 
327
- add_settings_error( 'vhp_varnish_url', 'varnish-url', $set_message, $set_type );
328
  return $output;
329
  }
330
 
51
  * @since 4.0
52
  */
53
  function admin_menu() {
54
+ add_management_page( __( 'Is Caching Working?', 'varnish-http-purge' ), __( 'Varnish Debugging', 'varnish-http-purge' ), 'manage_options', 'varnish-status', array( &$this, 'settings_page' ) );
55
  }
56
 
57
  /**
61
  */
62
  function register_settings_url() {
63
  register_setting( 'varnish-http-purge-url', 'vhp_varnish_url', array( &$this, 'varnish_url_sanitize' ) );
64
+ add_settings_section( 'varnish-url-settings-section', __( 'Check Caching Status', 'varnish-http-purge' ), array( &$this, 'options_callback_url'), 'varnish-url-settings' );
65
  add_settings_field( 'varnish_url', __( 'Check A URL On Your Site:', 'varnish-http-purge' ), array( &$this, 'varnish_url_callback' ), 'varnish-url-settings', 'varnish-url-settings-section' );
66
  }
67
 
72
  */
73
  function register_settings_ip() {
74
  register_setting( 'varnish-http-purge-ip', 'vhp_varnish_ip', array( &$this, 'varnish_ip_sanitize' ) );
75
+ add_settings_section( 'varnish-ip-settings-section', __( 'Configure Custom Varnish IP', 'varnish-http-purge' ), array( &$this, 'options_callback_ip'), 'varnish-ip-settings' );
76
+ add_settings_field( 'varnish_ip', __( 'Set Varnish IP', 'varnish-http-purge' ), array( &$this, 'varnish_ip_callback' ), 'varnish-ip-settings', 'varnish-ip-settings-section' );
77
  }
78
 
79
  /**
84
  function options_callback_ip() {
85
  ?>
86
  <p><a name="#configure"></a><?php _e( 'The majority of users will never need to look down here. However there are cases when a custom Varnish IP Address will need to be set, in order to tell the plugin to empty the cache in a specific location. If you\'re using a CDN like Cloudflare or a Firewall Proxy like Sucuri, you will want to set this.', 'varnish-http-purge' ); ?></p>
87
+ <p><?php _e( 'Your Varnish IP the IP address of the server where your caching service (i.e. Varnish or Nginx) is installed. Your Varnish IP must be one of the IPs used by your cache service. If you use multiple IPs, or if you\'ve customized your ACLs, you\'ll need to pick one that doesn\'t conflict with your other settings. For example, if you have Varnish listening on a public and private IP, pick the private. On the other hand, if you told Varnish to listen on 0.0.0.0 (i.e. "listen on every interface you can") you would need to check what IP you set your purge ACL to allow (commonly 127.0.0.1 aka localhost), and use that (i.e. 127.0.0.1).', 'varnish-http-purge' ); ?></p>
88
+ <p><?php _e( 'If your webhost set the service up for you, as is the case with DreamPress or WP Engine, ask them for the specifics if they don\'t have it documented. I\'ve listed the ones I know about here, however you should still check with them if you\'re not sure.', 'varnish-http-purge' ); ?></p>
89
  <p><strong><?php _e( 'If you aren\'t sure what to do, contact your webhost or server admin before making any changes.', 'varnish-http-purge' ); ?></strong></p>
90
 
91
  <ul>
92
+ <li><?php _e( 'DreamHost - Go into the Panel and click on the DNS settings for the domain. The entry for <em>resolve-to.domain</em> (if set) will be your cache server. If it\'s not set, then you don\'t need to worry about this at all. Example:', 'varnish-http-purge' ); ?> <code>resolve-to.www A 208.97.157.172</code></li>
93
  </ul>
94
  <?php
95
  }
131
  */
132
  function options_callback_url() {
133
 
134
+ ?><p><?php _e( 'While it is impossible to detect all possible conflicts, this status page performs a check of the most common issues that prevents your site from caching properly. This feature is provided to help you in debugging any conflicts on your own. When filing an issue with your web-host, we recommend you include the output in your ticket.', 'varnish-http-purge' ); ?></p>
 
 
 
135
 
136
+ <p><?php printf ( __( '<strong>This check uses <a href="%s">a remote service hosted on DreamObjects</a></strong>. The service used only for providing up to date compatibility checks on plugins and themes that may conflict with running a server based cache (such as Varnish or Nginx). No personally identifying information regarding persons running this check, nor the plugins and themes in use on this site will be transmitted. The bare minimum of usage information is collected, concerning only IPs and domains making requests of the service. If you do not wish to use this service, please do not use this debugging tool.', 'varnish-http-purge' ), 'https://varnish-http-purge.objects-us-east-1.dream.io/readme.txt' ); ?></p>
137
 
138
  <?php
139
+
140
+ // If there's no post made, let's not...
141
+ if ( !isset( $_REQUEST['settings-updated'] ) || !$_REQUEST['settings-updated'] ) return;
142
+
143
  // Set icons
144
  $icons = array (
145
  'awesome' => '<span class="dashicons dashicons-heart" style="color:#008000;"></span>',
149
  'bad' => '<span class="dashicons dashicons-thumbs-down" style="color:#990000;"></span>',
150
  );
151
 
152
+ // Include the debug code
153
+ include( 'debug.php' );
154
+
155
  // Get the base URL to start
156
  $url = esc_url( VarnishPurger::the_home_url() );
157
  $varnishurl = get_option( 'vhp_varnish_url', $url );
248
  ?>
249
  <div class="wrap">
250
 
251
+ <h1><?php _e( 'Is Caching Working?', 'varnish-http-purge' ); ?></h1>
252
 
253
  <?php settings_errors(); ?>
254
 
323
  } elseif ( parse_url( $output, PHP_URL_HOST ) !== parse_url( $input, PHP_URL_HOST ) ) {
324
  $set_message = __( 'You cannot scan URLs on other domains.', 'varnish-http-purge' );
325
  } else {
326
+ $set_type = 'updated';
327
+ $set_message = __( 'URL Scanned.', 'varnish-http-purge' );
328
+ $output = filter_var( $input, FILTER_VALIDATE_URL);
329
  }
330
 
331
+ if ( isset( $set_message ) ) add_settings_error( 'vhp_varnish_url', 'varnish-url', $set_message, $set_type );
332
  return $output;
333
  }
334
 
style.css ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ li#wp-admin-bar-purge-varnish-cache.varnish-http-purge {
2
+ background: #46B450;
3
+ }
varnish-http-purge.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Varnish HTTP Purge
4
  Plugin URI: https://halfelf.org/plugins/varnish-http-purge/
5
  Description: Automatically empty pages cached by Varnish when content on your site is modified.
6
- Version: 4.4.0
7
  Author: Mika Epstein
8
  Author URI: https://halfelf.org/
9
  License: http://www.apache.org/licenses/LICENSE-2.0
@@ -83,17 +83,19 @@ class VarnishPurger {
83
 
84
  // Cheap Dev Mode
85
  // If VHP_DEBUG is true, throw down a session to 'break' caching
86
- if ( VHP_DEBUG ) @session_start();
 
 
87
 
88
  // get my events
89
- $events = $this->getRegisterEvents();
90
  $noIDevents = $this->getNoIDEvents();
91
 
92
  // make sure we have events and they're in an array
93
  if ( !empty( $events ) && !empty( $noIDevents ) ) {
94
 
95
  // Force it to be an array, in case someone's stupid
96
- $events = (array) $events;
97
  $noIDevents = (array) $noIDevents;
98
 
99
  // Add the action for each event
@@ -118,6 +120,8 @@ class VarnishPurger {
118
 
119
  // Add Admin Bar
120
  add_action( 'admin_bar_menu', array( $this, 'varnish_rightnow_adminbar' ), 100 );
 
 
121
  }
122
 
123
  /**
@@ -163,6 +167,17 @@ class VarnishPurger {
163
  return $home_url;
164
  }
165
 
 
 
 
 
 
 
 
 
 
 
 
166
  /**
167
  * Varnish Purge Button in the Admin Bar
168
  *
@@ -176,6 +191,9 @@ class VarnishPurger {
176
  array(
177
  'id' => 'purge-varnish-cache',
178
  'title' => __( 'Empty Cache', 'varnish-http-purge' ),
 
 
 
179
  ),
180
  );
181
 
@@ -197,14 +215,25 @@ class VarnishPurger {
197
  'title' => __( 'Entire Cache (All Pages)', 'varnish-http-purge' ),
198
  ),
199
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  }
201
 
202
  // If we're on a front end page and the current user can edit published posts, then they can do this:
203
  if ( ! is_admin() && get_post() !== false && current_user_can( 'edit_published_posts' ) ) {
204
-
205
  $page_url = esc_url( home_url( $wp->request ) );
206
-
207
- $args[] = array(
208
  'parent' => 'purge-varnish-cache',
209
  'id' => 'purge-varnish-cache-this',
210
  'title' => __( 'This Page\'s Cache', 'varnish-http-purge' ),
@@ -228,12 +257,12 @@ class VarnishPurger {
228
  */
229
  function varnish_rightnow() {
230
  global $blog_id;
231
- $url = wp_nonce_url( add_query_arg( 'vhp_flush_do', 'all' ), 'vhp-flush-do' );
232
- $intro = sprintf( __( '<a href="%1$s">Varnish HTTP Purge</a> automatically deletes your cached posts when published or updated. When making major site changes, such as with a new theme, plugins, or widgets, you may need to manually empty the cache.', 'varnish-http-purge' ), 'http://wordpress.org/plugins/varnish-http-purge/' );
233
- $button = __( 'Press the button below to force it to empty your entire Varnish cache.', 'varnish-http-purge' );
234
- $button .= '</p><p><span class="button"><a href="'.$url.'"><strong>';
235
- $button .= __( 'Empty Cache', 'varnish-http-purge' );
236
- $button .= '</strong></a></span>';
237
  $nobutton = __( 'You do not have permission to empty the Varnish cache for the whole site. Please contact your administrator.', 'varnish-http-purge' );
238
 
239
  if (
@@ -262,13 +291,13 @@ class VarnishPurger {
262
 
263
  // Define registered purge events
264
  $actions = array(
265
- 'switch_theme', // After a theme is changed
266
- 'autoptimize_action_cachepurged', // Compat with https://wordpress.org/plugins/autoptimize/
267
- 'save_post', // Save a post
268
- 'deleted_post', // Delete a post
269
- 'trashed_post', // Empty Trashed post
270
- 'edit_post', // Edit a post - includes leaving comments
271
- 'delete_attachment', // Delete an attachment - includes re-uploading
272
  );
273
 
274
  // send back the actions array, filtered
@@ -287,8 +316,8 @@ class VarnishPurger {
287
 
288
  // Define registered purge events
289
  $actions = array(
290
- 'switch_theme', // After a theme is changed
291
- 'autoptimize_action_cachepurged,' // Compat with https://wordpress.org/plugins/autoptimize/
292
  );
293
 
294
  // send back the actions array, filtered
@@ -309,12 +338,18 @@ class VarnishPurger {
309
  $purgeUrls = array_unique( $this->purgeUrls );
310
 
311
  if ( empty( $purgeUrls ) ) {
312
- if ( isset( $_GET['vhp_flush_all'] ) && check_admin_referer( 'vhp-flush-all' ) ) {
 
 
 
 
313
  $this->purgeUrl( $this->the_home_url() . '/?vhp-regex' );
314
  } elseif ( isset( $_GET['vhp_flush_do'] ) && check_admin_referer( 'vhp-flush-do' ) ) {
315
  if ( $_GET['vhp_flush_do'] == 'all' ) {
 
316
  $this->purgeUrl( $this->the_home_url() . '/?vhp-regex' );
317
  } else {
 
318
  $p = parse_url( $_GET['vhp_flush_do'] );
319
  if ( !isset( $p['host'] ) ) return;
320
  $this->purgeUrl( $_GET['vhp_flush_do'] );
@@ -342,11 +377,11 @@ class VarnishPurger {
342
  if ( !isset( $p['host'] ) ) return;
343
 
344
  // Determine if we're using regex to flush all pages or not
345
- $pregex = '';
346
  $x_purge_method = 'default';
347
 
348
  if ( isset( $p['query'] ) && ( $p['query'] == 'vhp-regex' ) ) {
349
- $pregex = '.*';
350
  $x_purge_method = 'regex';
351
  }
352
 
@@ -496,7 +531,7 @@ class VarnishPurger {
496
  } elseif ( $this_post_type == 'page' ) {
497
  $rest_permalink = get_rest_url() . $rest_api_route . '/pages/' . $postId . '/';
498
  }
499
-
500
  if ( $rest_permalink !== false ) array_push( $listofurls, $rest_permalink );
501
 
502
  // Add in AMP permalink if Automattic's AMP is installed
3
  Plugin Name: Varnish HTTP Purge
4
  Plugin URI: https://halfelf.org/plugins/varnish-http-purge/
5
  Description: Automatically empty pages cached by Varnish when content on your site is modified.
6
+ Version: 4.5.0
7
  Author: Mika Epstein
8
  Author URI: https://halfelf.org/
9
  License: http://www.apache.org/licenses/LICENSE-2.0
83
 
84
  // Cheap Dev Mode
85
  // If VHP_DEBUG is true, throw down a session to 'break' caching
86
+ if ( VHP_DEBUG ) {
87
+ @session_start();
88
+ }
89
 
90
  // get my events
91
+ $events = $this->getRegisterEvents();
92
  $noIDevents = $this->getNoIDEvents();
93
 
94
  // make sure we have events and they're in an array
95
  if ( !empty( $events ) && !empty( $noIDevents ) ) {
96
 
97
  // Force it to be an array, in case someone's stupid
98
+ $events = (array) $events;
99
  $noIDevents = (array) $noIDevents;
100
 
101
  // Add the action for each event
120
 
121
  // Add Admin Bar
122
  add_action( 'admin_bar_menu', array( $this, 'varnish_rightnow_adminbar' ), 100 );
123
+ add_action( 'admin_enqueue_scripts', array( $this, 'custom_css' ) );
124
+ add_action( 'wp_enqueue_style', array( $this, 'custom_css' ) );
125
  }
126
 
127
  /**
167
  return $home_url;
168
  }
169
 
170
+
171
+ /**
172
+ * Custom CSS to allow for coloring.
173
+ *
174
+ * @since 4.5.0
175
+ */
176
+ function custom_css() {
177
+ wp_register_style( 'varnish_http_purge', plugins_url( 'style.css', __FILE__ ), false, '1.0.0' );
178
+ wp_enqueue_style( 'varnish_http_purge' );
179
+ }
180
+
181
  /**
182
  * Varnish Purge Button in the Admin Bar
183
  *
191
  array(
192
  'id' => 'purge-varnish-cache',
193
  'title' => __( 'Empty Cache', 'varnish-http-purge' ),
194
+ 'meta' => array(
195
+ 'class' => 'varnish-http-purge'
196
+ ),
197
  ),
198
  );
199
 
215
  'title' => __( 'Entire Cache (All Pages)', 'varnish-http-purge' ),
216
  ),
217
  );
218
+ // If a memcached file is found, we can do this too:
219
+ if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
220
+ $args[] = array(
221
+ 'parent' => 'purge-varnish-cache',
222
+ 'id' => 'purge-varnish-cache-db',
223
+ 'title' => __( 'Database Cache', 'varnish-http-purge' ),
224
+ 'href' => wp_nonce_url( add_query_arg( 'vhp_flush_object', 'all' ), 'vhp_flush_object' ),
225
+ 'meta' => array(
226
+ 'title' => __( 'Database Cache', 'varnish-http-purge' ),
227
+ ),
228
+ );
229
+ }
230
+
231
  }
232
 
233
  // If we're on a front end page and the current user can edit published posts, then they can do this:
234
  if ( ! is_admin() && get_post() !== false && current_user_can( 'edit_published_posts' ) ) {
 
235
  $page_url = esc_url( home_url( $wp->request ) );
236
+ $args[] = array(
 
237
  'parent' => 'purge-varnish-cache',
238
  'id' => 'purge-varnish-cache-this',
239
  'title' => __( 'This Page\'s Cache', 'varnish-http-purge' ),
257
  */
258
  function varnish_rightnow() {
259
  global $blog_id;
260
+ $url = wp_nonce_url( add_query_arg( 'vhp_flush_do', 'all' ), 'vhp-flush-do' );
261
+ $intro = sprintf( __( '<a href="%1$s">Varnish HTTP Purge</a> automatically deletes your cached posts when published or updated. When making major site changes, such as with a new theme, plugins, or widgets, you may need to manually empty the cache.', 'varnish-http-purge' ), 'http://wordpress.org/plugins/varnish-http-purge/' );
262
+ $button = __( 'Press the button below to force it to empty your entire Varnish cache.', 'varnish-http-purge' );
263
+ $button .= '</p><p><span class="button"><a href="'.$url.'"><strong>';
264
+ $button .= __( 'Empty Cache', 'varnish-http-purge' );
265
+ $button .= '</strong></a></span>';
266
  $nobutton = __( 'You do not have permission to empty the Varnish cache for the whole site. Please contact your administrator.', 'varnish-http-purge' );
267
 
268
  if (
291
 
292
  // Define registered purge events
293
  $actions = array(
294
+ 'switch_theme', // After a theme is changed
295
+ 'autoptimize_action_cachepurged', // Compat with https://wordpress.org/plugins/autoptimize/
296
+ 'save_post', // Save a post
297
+ 'deleted_post', // Delete a post
298
+ 'trashed_post', // Empty Trashed post
299
+ 'edit_post', // Edit a post - includes leaving comments
300
+ 'delete_attachment', // Delete an attachment - includes re-uploading
301
  );
302
 
303
  // send back the actions array, filtered
316
 
317
  // Define registered purge events
318
  $actions = array(
319
+ 'switch_theme', // After a theme is changed
320
+ 'autoptimize_action_cachepurged,' // Compat with https://wordpress.org/plugins/autoptimize/
321
  );
322
 
323
  // send back the actions array, filtered
338
  $purgeUrls = array_unique( $this->purgeUrls );
339
 
340
  if ( empty( $purgeUrls ) ) {
341
+ if ( isset( $_GET['vhp_flush_object'] ) && check_admin_referer( 'vhp_flush_object' ) ) {
342
+ // Flush DB Cache
343
+ wp_cache_flush();
344
+ } elseif ( isset( $_GET['vhp_flush_all'] ) && check_admin_referer( 'vhp-flush-all' ) ) {
345
+ // Flush Varnish Cache recursize
346
  $this->purgeUrl( $this->the_home_url() . '/?vhp-regex' );
347
  } elseif ( isset( $_GET['vhp_flush_do'] ) && check_admin_referer( 'vhp-flush-do' ) ) {
348
  if ( $_GET['vhp_flush_do'] == 'all' ) {
349
+ // Flush Varnish Cache recursize
350
  $this->purgeUrl( $this->the_home_url() . '/?vhp-regex' );
351
  } else {
352
+ // Flush the URL we're on
353
  $p = parse_url( $_GET['vhp_flush_do'] );
354
  if ( !isset( $p['host'] ) ) return;
355
  $this->purgeUrl( $_GET['vhp_flush_do'] );
377
  if ( !isset( $p['host'] ) ) return;
378
 
379
  // Determine if we're using regex to flush all pages or not
380
+ $pregex = '';
381
  $x_purge_method = 'default';
382
 
383
  if ( isset( $p['query'] ) && ( $p['query'] == 'vhp-regex' ) ) {
384
+ $pregex = '.*';
385
  $x_purge_method = 'regex';
386
  }
387
 
531
  } elseif ( $this_post_type == 'page' ) {
532
  $rest_permalink = get_rest_url() . $rest_api_route . '/pages/' . $postId . '/';
533
  }
534
+
535
  if ( $rest_permalink !== false ) array_push( $listofurls, $rest_permalink );
536
 
537
  // Add in AMP permalink if Automattic's AMP is installed
wp-cli.php CHANGED
@@ -127,27 +127,27 @@ if ( !class_exists( 'WP_CLI_Varnish_Command' ) ) {
127
  } else {
128
 
129
  // Include the debug code
130
- include( 'debug.php' );
131
 
132
  $varnishurl = get_option( 'vhp_varnish_url', $url );
133
 
134
  // Get the response and headers
135
  $remote_get = VarnishDebug::remote_get( $varnishurl );
136
  $headers = wp_remote_retrieve_headers( $remote_get );
137
-
138
  // Preflight checklist
139
  $preflight = VarnishDebug::preflight( $remote_get );
140
 
141
  // Check for Remote IP
142
  $remote_ip = VarnishDebug::remote_ip( $headers );
143
-
144
  // Get the Varnish IP
145
  if ( VHP_VARNISH_IP != false ) {
146
  $varniship = VHP_VARNISH_IP;
147
  } else {
148
  $varniship = get_option('vhp_varnish_ip');
149
  }
150
-
151
  if ( $preflight['preflight'] == false ) {
152
  WP_CLI::error( $preflight['message'] );
153
  } else {
127
  } else {
128
 
129
  // Include the debug code
130
+ if ( !class_exists( 'VarnishDebug' ) ) include( 'debug.php' );
131
 
132
  $varnishurl = get_option( 'vhp_varnish_url', $url );
133
 
134
  // Get the response and headers
135
  $remote_get = VarnishDebug::remote_get( $varnishurl );
136
  $headers = wp_remote_retrieve_headers( $remote_get );
137
+
138
  // Preflight checklist
139
  $preflight = VarnishDebug::preflight( $remote_get );
140
 
141
  // Check for Remote IP
142
  $remote_ip = VarnishDebug::remote_ip( $headers );
143
+
144
  // Get the Varnish IP
145
  if ( VHP_VARNISH_IP != false ) {
146
  $varniship = VHP_VARNISH_IP;
147
  } else {
148
  $varniship = get_option('vhp_varnish_ip');
149
  }
150
+
151
  if ( $preflight['preflight'] == false ) {
152
  WP_CLI::error( $preflight['message'] );
153
  } else {