Varnish HTTP Purge - Version 4.3.0

Version Description

  • 26 September 2017
  • Add Varnish Flush for "this" page on front end
  • Do not flush non-public taxonomies
Download this release

Release Info

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

Code changes from version 4.2.0 to 4.3.0

Files changed (6) hide show
  1. changelog.txt +15 -0
  2. readme.txt +14 -31
  3. uninstall.php +2 -3
  4. varnish-http-purge.php +79 -37
  5. varnish-status.php +27 -28
  6. wp-cli.php +5 -5
changelog.txt CHANGED
@@ -1,3 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  = 4.0.3 =
2
  * Better explanation when Cloudflare gets in the way of DNS
3
  * Rename flush button for people who don't speak Varnish
1
+ = 4.1.1 =
2
+
3
+ * JSON - fixed overzealous json assumptions from causing errors
4
+ * WP-CLI - fixed prepending of domain on domain when using purge on a domain (props @ocean90)
5
+ * Typos. We hate them.
6
+
7
+ = 4.1 =
8
+
9
+ * JSON / REST API Support
10
+ * Fix for Varnish Status Page on MAMP (props @jeremyclarke)
11
+ * Filter for purge headers (props @ocean90)
12
+ * Disallow people from editing the Varnish IP on Multisite
13
+ * Drop support for pre 4.7 because of JSON / REST API
14
+ * Support flushing cache for private pages
15
+
16
  = 4.0.3 =
17
  * Better explanation when Cloudflare gets in the way of DNS
18
  * Rename flush button for people who don't speak Varnish
readme.txt CHANGED
@@ -3,14 +3,14 @@ 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.2.0
7
  Requires PHP: 5.6
8
 
9
- Automatically empty a Varnish Cache when content on your site is modified.
10
 
11
  == Description ==
12
 
13
- Varnish HTTP Purge sends a request to delete 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
 
@@ -20,7 +20,7 @@ Not all page caches are deleted every time, depending on your Varnish configurat
20
  * The post/page edited
21
  * Any categories, tags, and/or custom taxonomies associated with the page
22
  * Related feeds
23
- * Associated json API pages
24
 
25
  In addition, your <em>entire</em> cache will be deleted on the following actions:
26
 
@@ -50,7 +50,7 @@ From your WordPress Dashboard, go to Tools -> Varnish Status. There a page will
50
 
51
  = Does every WordPress plugin and theme work with Varnish? =
52
 
53
- No. Some of them have behavior that causes Varnish not to cache. While I can't debug that for you, there is an "Is Varnish Working?" tool (see WP Admin -> Tools -> Varnish Status) that tries to detect most of the common issues and direct you to resolutions.
54
 
55
  = How can I debug my site? =
56
 
@@ -74,7 +74,7 @@ There are many other plugins out there which will allow you to granularly select
74
 
75
  If you activate a new theme, or use the customizer to edit your theme, it will delete your cache.
76
 
77
- If you edit theme (or plugin) files directly, WordPress cannot easily detect those changes and therefor the plugin cannot delete the cache. In that situation, you will need to empty the cache manually.
78
 
79
  = How do I manually delete the whole cache? =
80
 
@@ -84,7 +84,7 @@ There's also an "Empty Cache" button on the admin toolbar.
84
 
85
  = I don't see a button! =
86
 
87
- That means your user 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.
88
 
89
  = Why is nothing caching when I use PageSpeed? =
90
 
@@ -92,10 +92,6 @@ PageSpeed likes to put in Caching headers to say <em>not</em> to cache. To fix t
92
 
93
  If you're using nginx, it's `pagespeed ModifyCachingHeaders off;`
94
 
95
- = Can I use this with a proxy service like CloudFlare? =
96
-
97
- Yes, but you'll need to make some additional changes (see "Why aren't my changes showing when I use CloudFlare or another proxy?" below).
98
-
99
  = Why aren't my changes showing when I use CloudFlare or another proxy? =
100
 
101
  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.
@@ -128,10 +124,6 @@ If your webhost set up Varnish, you may need to ask them for the specifics if th
128
 
129
  Multiple IPs are not supported at this time.
130
 
131
- = Why don't my gzip'd pages get deleted? =
132
-
133
- Make sure your Varnish VCL is configured correctly to purge all the right pages. This is normally an issue with Varnish 2, which is not supported by this plugin.
134
-
135
  = Why isn't the whole cache deletion working? =
136
 
137
  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.
@@ -148,7 +140,7 @@ This is a question beyond the support of plugin. I don't offer any Varnish Confi
148
 
149
  * <a href="https://github.com/dreamhost/varnish-vcl-collection">DreamHost's Varnish VCL Collection</a>
150
 
151
- All of these VCLs work with this plugin.
152
 
153
  = Can I filter things to add special URLs? =
154
 
@@ -163,28 +155,19 @@ This plugin is installed by default for _all_ DreamPress installs on DreamHost,
163
 
164
  == Changelog ==
165
 
 
 
 
 
 
166
  = 4.2.0 =
 
167
  * More flexible support for custom cat/tag bases
168
  * Added in support for custom taxonomies
169
  * New function to generate the URLs, so it can be called by external plugins
170
  * Move right now box to be called later, preventing double calls
171
  * Extra check for if it's a URL, because some plugins are weird (props @danielkun)
172
 
173
- = 4.1.1 =
174
-
175
- * JSON - fixed overzealous json assumptions from causing errors
176
- * WP-CLI - fixed prepending of domain on domain when using purge on a domain (props @ocean90)
177
- * Typos. We hate them.
178
-
179
- = 4.1 =
180
-
181
- * JSON / REST API Support
182
- * Fix for Varnish Status Page on MAMP (props @jeremyclarke)
183
- * Filter for purge headers (props @ocean90)
184
- * Disallow people from editing the Varnish IP on Multisite
185
- * Drop support for pre 4.7 because of JSON / REST API
186
- * Support flushing cache for private pages
187
-
188
  == Screenshots ==
189
 
190
  1. Purge button on Right Now (Dashboard Admin)
3
  Tags: varnish, purge, cache
4
  Requires at least: 4.7
5
  Tested up to: 4.9
6
+ Stable tag: 4.3.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
 
20
  * The post/page edited
21
  * Any categories, tags, and/or custom taxonomies associated with the page
22
  * Related feeds
23
+ * Associated JSON API pages
24
 
25
  In addition, your <em>entire</em> cache will be deleted on the following actions:
26
 
50
 
51
  = Does every WordPress plugin and theme work with Varnish? =
52
 
53
+ No. Some of them have behaviour that causes Varnish not to cache. While I can't debug that for you, there is an "Is Varnish Working?" tool (see WP Admin -> Tools -> Varnish Status) that tries to detect most of the common issues and direct you to resolutions.
54
 
55
  = How can I debug my site? =
56
 
74
 
75
  If you activate a new theme, or use the customizer to edit your theme, it will delete your cache.
76
 
77
+ If you edit theme (or plugin) files directly, WordPress cannot easily detect those changes, therefor the plugin will not delete the cache. In that situation, you will need to empty the cache manually.
78
 
79
  = How do I manually delete the whole cache? =
80
 
84
 
85
  = I don't see a button! =
86
 
87
+ 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.
88
 
89
  = Why is nothing caching when I use PageSpeed? =
90
 
92
 
93
  If you're using nginx, it's `pagespeed ModifyCachingHeaders off;`
94
 
 
 
 
 
95
  = Why aren't my changes showing when I use CloudFlare or another proxy? =
96
 
97
  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.
124
 
125
  Multiple IPs are not supported at this time.
126
 
 
 
 
 
127
  = Why isn't the whole cache deletion working? =
128
 
129
  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.
140
 
141
  * <a href="https://github.com/dreamhost/varnish-vcl-collection">DreamHost's Varnish VCL Collection</a>
142
 
143
+ All of those VCLs work with this plugin.
144
 
145
  = Can I filter things to add special URLs? =
146
 
155
 
156
  == Changelog ==
157
 
158
+ = 4.3.0 =
159
+ * 26 September 2017
160
+ * Add Varnish Flush for "this" page on front end
161
+ * Do not flush non-public taxonomies
162
+
163
  = 4.2.0 =
164
+ * 30 August 2017
165
  * More flexible support for custom cat/tag bases
166
  * Added in support for custom taxonomies
167
  * New function to generate the URLs, so it can be called by external plugins
168
  * Move right now box to be called later, preventing double calls
169
  * Extra check for if it's a URL, because some plugins are weird (props @danielkun)
170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  == Screenshots ==
172
 
173
  1. Purge button on Right Now (Dashboard Admin)
uninstall.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
- /*
3
-
4
- Copyright 2016 Mika Epstein (email: ipstenu@halfelf.org)
5
 
6
  This file is part of Varnish HTTP Purge, a plugin for WordPress.
7
 
1
  <?php
2
+ /**
3
+ Copyright 2016-2017 Mika Epstein (email: ipstenu@halfelf.org)
 
4
 
5
  This file is part of Varnish HTTP Purge, a plugin for WordPress.
6
 
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.2.0
7
  Author: Mika Epstein
8
  Author URI: https://halfelf.org/
9
  License: http://www.apache.org/licenses/LICENSE-2.0
@@ -105,22 +105,14 @@ class VarnishPurger {
105
  add_action( 'shutdown', array( $this, 'executePurge' ) );
106
 
107
  // Success: Admin notice when purging
108
- if ( isset( $_GET['vhp_flush_all'] ) && check_admin_referer( 'vhp-flush-all' ) ) {
109
- add_action( 'admin_notices' , array( $this, 'purgeMessage'));
 
 
110
  }
111
-
112
- // Checking user permissions for who can and cannot use the admin button
113
- if (
114
- // SingleSite - admins can always purge
115
- ( !is_multisite() && current_user_can( 'activate_plugins' ) ) ||
116
- // Multisite - Network Admin can always purge
117
- current_user_can( 'manage_network' ) ||
118
- // Multisite - Site admins can purge UNLESS it's a subfolder install and we're on site #1
119
- ( is_multisite() && current_user_can( 'activate_plugins' ) && ( SUBDOMAIN_INSTALL || ( !SUBDOMAIN_INSTALL && ( BLOG_ID_CURRENT_SITE != $blog_id ) ) ) )
120
- ) {
121
- add_action( 'admin_bar_menu', array( $this, 'varnish_rightnow_adminbar' ), 100 );
122
- }
123
-
124
  }
125
 
126
  /**
@@ -161,7 +153,7 @@ class VarnishPurger {
161
  *
162
  * @since 4.0
163
  */
164
- static public function the_home_url(){
165
  $home_url = apply_filters( 'vhp_home_url', home_url() );
166
  return $home_url;
167
  }
@@ -171,15 +163,56 @@ class VarnishPurger {
171
  *
172
  * @since 2.0
173
  */
174
- function varnish_rightnow_adminbar( $admin_bar ){
175
- $admin_bar->add_menu( array(
176
- 'id' => 'purge-varnish-cache-all',
177
- 'title' => __( 'Empty Cache', 'varnish-http-purge' ),
178
- 'href' => wp_nonce_url( add_query_arg('vhp_flush_all', 1), 'vhp-flush-all'),
179
- 'meta' => array(
180
- 'title' => __( 'Empty Cache', 'varnish-http-purge' ),
 
181
  ),
182
- ));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  }
184
 
185
  /**
@@ -190,7 +223,7 @@ class VarnishPurger {
190
  */
191
  function varnish_rightnow() {
192
  global $blog_id;
193
- $url = wp_nonce_url( add_query_arg( 'vhp_flush_all', 1 ), 'vhp-flush-all' );
194
  $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/' );
195
  $button = __( 'Press the button below to force it to empty your entire Varnish cache.', 'varnish-http-purge' );
196
  $button .= '</p><p><span class="button"><a href="'.$url.'"><strong>';
@@ -273,6 +306,14 @@ class VarnishPurger {
273
  if ( empty( $purgeUrls ) ) {
274
  if ( isset( $_GET['vhp_flush_all'] ) && check_admin_referer( 'vhp-flush-all' ) ) {
275
  $this->purgeUrl( $this->the_home_url() . '/?vhp-regex' );
 
 
 
 
 
 
 
 
276
  }
277
  } else {
278
  foreach( $purgeUrls as $url ) {
@@ -299,7 +340,7 @@ class VarnishPurger {
299
  $pregex = '';
300
  $x_purge_method = 'default';
301
 
302
- if ( isset($p['query']) && ( $p['query'] == 'vhp-regex' ) ) {
303
  $pregex = '.*';
304
  $x_purge_method = 'regex';
305
  }
@@ -346,10 +387,7 @@ class VarnishPurger {
346
  *
347
  * @since 4.1
348
  */
349
- $headers = apply_filters( 'varnish_http_purge_headers', array( 'host' => $p['host'], 'X-Purge-Method' => $x_purge_method ) );
350
-
351
- // Cleanup CURL functions to be wp_remote_request and thus better
352
- // http://wordpress.org/support/topic/incompatability-with-editorial-calendar-plugin
353
  $response = wp_remote_request( $purgeme, array( 'method' => 'PURGE', 'headers' => $headers ) );
354
 
355
  do_action( 'after_purge_url', $url, $purgeme, $response, $headers );
@@ -484,15 +522,19 @@ class VarnishPurger {
484
  }
485
  }
486
  // Custom Taxonomies
 
487
  $taxonomies = get_post_taxonomies( $postId );
488
  if ( $taxonomies ) {
489
  foreach ( $taxonomies as $taxonomy ) {
490
- $terms = wp_get_post_terms( $postId, $taxonomy );
491
- foreach ( $terms as $term ) {
492
- array_push( $listofurls,
493
- get_term_link( $term ),
494
- get_rest_url() . $rest_api_route . '/' . $term->taxonomy . '/' . $term->slug . '/'
495
- );
 
 
 
496
  }
497
  }
498
  }
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.3.0
7
  Author: Mika Epstein
8
  Author URI: https://halfelf.org/
9
  License: http://www.apache.org/licenses/LICENSE-2.0
105
  add_action( 'shutdown', array( $this, 'executePurge' ) );
106
 
107
  // Success: Admin notice when purging
108
+ if (
109
+ ( isset( $_GET['vhp_flush_all'] ) && check_admin_referer( 'vhp-flush-all' ) ) ||
110
+ ( isset( $_GET['vhp_flush_do'] ) && check_admin_referer( 'vhp-flush-do' ) ) ) {
111
+ add_action( 'admin_notices' , array( $this, 'purgeMessage') );
112
  }
113
+
114
+ // Add Admin Bar
115
+ add_action( 'admin_bar_menu', array( $this, 'varnish_rightnow_adminbar' ), 100 );
 
 
 
 
 
 
 
 
 
 
116
  }
117
 
118
  /**
153
  *
154
  * @since 4.0
155
  */
156
+ static public function the_home_url() {
157
  $home_url = apply_filters( 'vhp_home_url', home_url() );
158
  return $home_url;
159
  }
163
  *
164
  * @since 2.0
165
  */
166
+ function varnish_rightnow_adminbar( $admin_bar ) {
167
+ global $wp;
168
+
169
+ // Main Array
170
+ $args = array(
171
+ array(
172
+ 'id' => 'purge-varnish-cache',
173
+ 'title' => __( 'Varnish', 'varnish-http-purge' ),
174
  ),
175
+ );
176
+
177
+ // Checking user permissions for who can and cannot use the all flush
178
+ if (
179
+ // SingleSite - admins can always purge
180
+ ( !is_multisite() && current_user_can( 'activate_plugins' ) ) ||
181
+ // Multisite - Network Admin can always purge
182
+ current_user_can( 'manage_network' ) ||
183
+ // Multisite - Site admins can purge UNLESS it's a subfolder install and we're on site #1
184
+ ( is_multisite() && current_user_can( 'activate_plugins' ) && ( SUBDOMAIN_INSTALL || ( !SUBDOMAIN_INSTALL && ( BLOG_ID_CURRENT_SITE != $blog_id ) ) ) )
185
+ ) {
186
+ $args[] = array(
187
+ 'parent' => 'purge-varnish-cache',
188
+ 'id' => 'purge-varnish-cache-all',
189
+ 'title' => __( 'Empty Cache (All)', 'varnish-http-purge' ),
190
+ 'href' => wp_nonce_url( add_query_arg( 'vhp_flush_do', 'all' ), 'vhp-flush-do' ),
191
+ 'meta' => array(
192
+ 'title' => __( 'Empty Cache (All)', 'varnish-http-purge' ),
193
+ ),
194
+ );
195
+ }
196
+
197
+ // If we're on a front end page and the current user can edit published posts, then they can do this:
198
+ if ( ! is_admin() && get_post() !== false && current_user_can( 'edit_published_posts' ) ) {
199
+
200
+ $page_url = esc_url( home_url( $wp->request ) );
201
+
202
+ $args[] = array(
203
+ 'parent' => 'purge-varnish-cache',
204
+ 'id' => 'purge-varnish-cache-this',
205
+ 'title' => __( 'Empty Cache (This Page)', 'varnish-http-purge' ),
206
+ 'href' => wp_nonce_url( add_query_arg( 'vhp_flush_do', $page_url . '/' ), 'vhp-flush-do' ),
207
+ 'meta' => array(
208
+ 'title' => __( 'Empty Cache (This Page)', 'varnish-http-purge' ),
209
+ ),
210
+ );
211
+ }
212
+
213
+ foreach ( $args as $arg ) {
214
+ $admin_bar->add_node( $arg );
215
+ }
216
  }
217
 
218
  /**
223
  */
224
  function varnish_rightnow() {
225
  global $blog_id;
226
+ $url = wp_nonce_url( add_query_arg( 'vhp_flush_do', 'all' ), 'vhp-flush-do' );
227
  $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/' );
228
  $button = __( 'Press the button below to force it to empty your entire Varnish cache.', 'varnish-http-purge' );
229
  $button .= '</p><p><span class="button"><a href="'.$url.'"><strong>';
306
  if ( empty( $purgeUrls ) ) {
307
  if ( isset( $_GET['vhp_flush_all'] ) && check_admin_referer( 'vhp-flush-all' ) ) {
308
  $this->purgeUrl( $this->the_home_url() . '/?vhp-regex' );
309
+ } elseif ( isset( $_GET['vhp_flush_do'] ) && check_admin_referer( 'vhp-flush-do' ) ) {
310
+ if ( $_GET['vhp_flush_do'] == 'all' ) {
311
+ $this->purgeUrl( $this->the_home_url() . '/?vhp-regex' );
312
+ } else {
313
+ $p = parse_url( $_GET['vhp_flush_do'] );
314
+ if ( !isset( $p['host'] ) ) return;
315
+ $this->purgeUrl( $_GET['vhp_flush_do'] );
316
+ }
317
  }
318
  } else {
319
  foreach( $purgeUrls as $url ) {
340
  $pregex = '';
341
  $x_purge_method = 'default';
342
 
343
+ if ( isset( $p['query'] ) && ( $p['query'] == 'vhp-regex' ) ) {
344
  $pregex = '.*';
345
  $x_purge_method = 'regex';
346
  }
387
  *
388
  * @since 4.1
389
  */
390
+ $headers = apply_filters( 'varnish_http_purge_headers', array( 'host' => $p['host'], 'X-Purge-Method' => $x_purge_method ) );
 
 
 
391
  $response = wp_remote_request( $purgeme, array( 'method' => 'PURGE', 'headers' => $headers ) );
392
 
393
  do_action( 'after_purge_url', $url, $purgeme, $response, $headers );
522
  }
523
  }
524
  // Custom Taxonomies
525
+ // Only show if the taxonomy is public
526
  $taxonomies = get_post_taxonomies( $postId );
527
  if ( $taxonomies ) {
528
  foreach ( $taxonomies as $taxonomy ) {
529
+ $features = get_taxonomy( $taxonomy );
530
+ if ( $features['public'] ) {
531
+ $terms = wp_get_post_terms( $postId, $taxonomy );
532
+ foreach ( $terms as $term ) {
533
+ array_push( $listofurls,
534
+ get_term_link( $term ),
535
+ get_rest_url() . $rest_api_route . '/' . $term->taxonomy . '/' . $term->slug . '/'
536
+ );
537
+ }
538
  }
539
  }
540
  }
varnish-status.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
2
-
3
  /**
 
 
4
  This file is part of Varnish HTTP Purge, a plugin for WordPress.
5
 
6
  Varnish HTTP Purge is free software: you can redistribute it and/or modify
@@ -11,7 +12,7 @@
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
  */
13
 
14
- if ( !defined('ABSPATH') ) {
15
  die();
16
  }
17
 
@@ -52,7 +53,7 @@ class VarnishStatus {
52
  * @since 4.0
53
  */
54
  function admin_menu() {
55
- add_management_page( __('Is Varnish Working?', 'varnish-http-purge'), __('Varnish Status', 'varnish-http-purge'), 'manage_options', 'varnish-status', array( &$this, 'settings_page' ) );
56
  }
57
 
58
  /**
@@ -62,8 +63,8 @@ class VarnishStatus {
62
  */
63
  function register_settings_url() {
64
  register_setting( 'varnish-http-purge-url', 'vhp_varnish_url', array( &$this, 'varnish_url_sanitize' ) );
65
- add_settings_section( 'varnish-url-settings-section', __('Check Varnish Status', 'varnish-http-purge'), array( &$this, 'options_callback_url'), 'varnish-url-settings' );
66
- 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' );
67
  }
68
 
69
  /**
@@ -84,13 +85,13 @@ class VarnishStatus {
84
  */
85
  function options_callback_ip() {
86
  ?>
87
- <p><a name="#configure"></a><?php _e('The majority of users will never need to so much as 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>
88
- <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>
89
- <p><?php _e('If your webhost set up Varnish for you, as is the case with DreamPress or WP Engine, 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.', 'varnish-http-purge'); ?></p>
90
- <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>
91
 
92
  <ul>
93
- <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>
94
  </ul>
95
  <?php
96
  }
@@ -108,7 +109,7 @@ class VarnishStatus {
108
  $disabled = true;
109
  $varniship = VHP_VARNISH_IP;
110
  } else {
111
- $varniship = get_option('vhp_varnish_ip');
112
  }
113
 
114
  ?>
@@ -116,9 +117,9 @@ class VarnishStatus {
116
  <label for="vhp_varnish_ip">
117
  <?php
118
  if ( $disabled == true ) {
119
- _e('The Varnish IP has been defined in your wp-config, so it is not editable here.', 'varnish-http-purge');
120
  } else {
121
- _e('Example:', 'varnish-http-purge'); ?> <code>123.45.67.89</code><?php
122
  }
123
  ?>
124
  </label>
@@ -132,12 +133,11 @@ class VarnishStatus {
132
  */
133
  function options_callback_url() {
134
 
135
- ?><p><?php _e( 'While it is impossible to detect all possible conflicts, this Status Page will perform a check of the most common issues that prevent Varnish from caching your site properly.', 'varnish-http-purge' ); ?></p>
136
 
137
- <p><?php _e( 'This feature is provided to help you in debugging any conflicts. If filing an issue with your webhost, it can be useful to include the output in your ticket.', 'varnish-http-purge' ); ?></p>
138
 
139
  <?php
140
-
141
  $icon_awesome = '<span class="dashicons dashicons-heart" style="color:#008000;"></span>';
142
  $icon_good = '<span class="dashicons dashicons-thumbs-up" style="color:#008000;"></span>';
143
  $icon_warning = '<span class="dashicons dashicons-warning" style="color:#FF9933"></span>';
@@ -161,12 +161,12 @@ class VarnishStatus {
161
  // Basic checks that should stop a scan
162
  if( is_wp_error($response) ) {
163
  $preflight = false;
164
- $failure_to_launch = __('This request cannot be performed: ', 'varnish-http-purge');
165
  $failure_to_launch .= $response->get_error_message();
166
  }
167
  if( wp_remote_retrieve_response_code($response) == '404' ) {
168
  $preflight = false;
169
- $failure_to_launch = __('This URL is a 404. Please check your typing and try again.', 'varnish-http-purge');
170
  }
171
 
172
  // Get the IP address so we can check things later
@@ -187,7 +187,6 @@ class VarnishStatus {
187
  } else {
188
  $varniship = get_option('vhp_varnish_ip');
189
  }
190
-
191
  ?>
192
 
193
  <h4><?php printf( __( 'Results for %s', 'varnish-http-purge' ), $varnishurl ); ?></h4>
@@ -212,12 +211,12 @@ class VarnishStatus {
212
  } elseif (isset( $headers['x-cacheable'] ) && strpos( $headers['x-cacheable'] ,'NO') !== false ) {
213
  ?><tr>
214
  <td width="40px"><?php echo $icon_bad; ?></td>
215
- <td><?php _e( 'Varnish is running but cannot cache.', 'varnish-http-purge' ); ?></td>
216
  </tr><?php
217
  } else {
218
  ?><tr>
219
  <td width="40px"><?php echo $icon_warning; ?></td>
220
- <td><?php _e( 'We did not find Varnish active for this domain.', 'varnish-http-purge' ); ?></td>
221
  </tr><?php
222
  }
223
 
@@ -226,7 +225,7 @@ class VarnishStatus {
226
  if ( $remote_ip == false && !empty( $varniship) ) {
227
  ?>
228
  <td width="40px"><?php echo $icon_warning; ?></td>
229
- <td><?php printf( __( 'You have a Varnish IP set but a proxy like Cloudflare or Sucuri has not been detected. This is usually fine, 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' ); ?></td>
230
  <?php
231
  } elseif ( $remote_ip !== false && $remote_ip !== $varniship ) {
232
  ?>
@@ -245,16 +244,16 @@ class VarnishStatus {
245
  if ( isset( $headers['Server'] ) && strpos( $headers['Server'] ,'cloudflare') !== false ) {
246
  ?><tr>
247
  <td><?php echo $icon_warning; ?></td>
248
- <td><?php printf( __( 'Because CloudFlare is running, you may experience some cache oddities. Make sure you <a href="%s">configure WordPress for Cloudflare</a>.', 'varnish-http-purge' ), '#configure' ); ?></td>
249
  </tr><?php
250
  }
251
 
252
  // HHVM
253
  if ( isset( $headers['X-Powered-By'] ) ) {
254
- if ( strpos( $headers['X-Powered-By'] ,'HHVM') !== false ) {
255
  ?><tr>
256
  <td><?php echo $icon_good; ?></td>
257
- <td><?php _e( 'You are running HHVM instead of PHP. Hip Hop!', 'varnish-http-purge' ); ?></td>
258
  </tr><?php
259
  }
260
  }
@@ -262,7 +261,7 @@ class VarnishStatus {
262
  // GZIP
263
  if ( isset( $headers['Content-Encoding'] ) ) {
264
  // Regular gZIP
265
- if( strpos( $headers['Content-Encoding'] ,'gzip') !== false || ( isset( $headers['Vary']) && strpos( $headers['Vary'] ,'gzip') !== false ) ) {
266
  ?><tr>
267
  <td><?php echo $icon_good; ?></td>
268
  <td><?php _e( 'Your site is compressing content and making the internet faster.', 'varnish-http-purge' ); ?></td>
@@ -273,7 +272,7 @@ class VarnishStatus {
273
  if ( strpos( $headers['Content-Encoding'] ,'Fastly') !== false ) {
274
  ?><tr>
275
  <td><?php echo $icon_good; ?></td>
276
- <td><?php printf( __( '<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.', 'varnish-http-purge' ), esc_url('https://fastly.com') ); ?></td>
277
  </tr><?php
278
  }
279
  }
@@ -513,4 +512,4 @@ class VarnishStatus {
513
 
514
  }
515
 
516
- $status = new VarnishStatus();
1
  <?php
 
2
  /**
3
+ Copyright 2016-2017 Mika Epstein (email: ipstenu@halfelf.org)
4
+
5
  This file is part of Varnish HTTP Purge, a plugin for WordPress.
6
 
7
  Varnish HTTP Purge is free software: you can redistribute it and/or modify
12
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
  */
14
 
15
+ if ( !defined( 'ABSPATH' ) ) {
16
  die();
17
  }
18
 
53
  * @since 4.0
54
  */
55
  function admin_menu() {
56
+ add_management_page( __( 'Is Varnish Working?', 'varnish-http-purge' ), __( 'Varnish Status', 'varnish-http-purge' ), 'manage_options', 'varnish-status', array( &$this, 'settings_page' ) );
57
  }
58
 
59
  /**
63
  */
64
  function register_settings_url() {
65
  register_setting( 'varnish-http-purge-url', 'vhp_varnish_url', array( &$this, 'varnish_url_sanitize' ) );
66
+ add_settings_section( 'varnish-url-settings-section', __( 'Check Varnish Status', 'varnish-http-purge' ), array( &$this, 'options_callback_url'), 'varnish-url-settings' );
67
+ 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' );
68
  }
69
 
70
  /**
85
  */
86
  function options_callback_ip() {
87
  ?>
88
+ <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>
89
+ <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>
90
+ <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>
91
+ <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>
92
 
93
  <ul>
94
+ <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>
95
  </ul>
96
  <?php
97
  }
109
  $disabled = true;
110
  $varniship = VHP_VARNISH_IP;
111
  } else {
112
+ $varniship = get_option( 'vhp_varnish_ip' );
113
  }
114
 
115
  ?>
117
  <label for="vhp_varnish_ip">
118
  <?php
119
  if ( $disabled == true ) {
120
+ _e( 'A Varnish IP has been defined in your wp-config, so it is not editable here.', 'varnish-http-purge' );
121
  } else {
122
+ _e( 'Example:', 'varnish-http-purge' ); ?> <code>123.45.67.89</code><?php
123
  }
124
  ?>
125
  </label>
133
  */
134
  function options_callback_url() {
135
 
136
+ ?><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>
137
 
138
+ <p><?php _e( 'This feature is provided to help you in debugging any conflicts on your own. If filing an issue with your webhost, it can be useful to include the output in your ticket.', 'varnish-http-purge' ); ?></p>
139
 
140
  <?php
 
141
  $icon_awesome = '<span class="dashicons dashicons-heart" style="color:#008000;"></span>';
142
  $icon_good = '<span class="dashicons dashicons-thumbs-up" style="color:#008000;"></span>';
143
  $icon_warning = '<span class="dashicons dashicons-warning" style="color:#FF9933"></span>';
161
  // Basic checks that should stop a scan
162
  if( is_wp_error($response) ) {
163
  $preflight = false;
164
+ $failure_to_launch = __( 'This request cannot be performed: ', 'varnish-http-purge' );
165
  $failure_to_launch .= $response->get_error_message();
166
  }
167
  if( wp_remote_retrieve_response_code($response) == '404' ) {
168
  $preflight = false;
169
+ $failure_to_launch = __( 'This URL is a 404. Please check your typing and try again.', 'varnish-http-purge' );
170
  }
171
 
172
  // Get the IP address so we can check things later
187
  } else {
188
  $varniship = get_option('vhp_varnish_ip');
189
  }
 
190
  ?>
191
 
192
  <h4><?php printf( __( 'Results for %s', 'varnish-http-purge' ), $varnishurl ); ?></h4>
211
  } elseif (isset( $headers['x-cacheable'] ) && strpos( $headers['x-cacheable'] ,'NO') !== false ) {
212
  ?><tr>
213
  <td width="40px"><?php echo $icon_bad; ?></td>
214
+ <td><?php _e( 'Varnish is running but is unable to cache your site.', 'varnish-http-purge' ); ?></td>
215
  </tr><?php
216
  } else {
217
  ?><tr>
218
  <td width="40px"><?php echo $icon_warning; ?></td>
219
+ <td><?php _e( 'We cannot find Varnish active for this domain.', 'varnish-http-purge' ); ?></td>
220
  </tr><?php
221
  }
222
 
225
  if ( $remote_ip == false && !empty( $varniship) ) {
226
  ?>
227
  <td width="40px"><?php echo $icon_warning; ?></td>
228
+ <td><?php printf( __( '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' ); ?></td>
229
  <?php
230
  } elseif ( $remote_ip !== false && $remote_ip !== $varniship ) {
231
  ?>
244
  if ( isset( $headers['Server'] ) && strpos( $headers['Server'] ,'cloudflare') !== false ) {
245
  ?><tr>
246
  <td><?php echo $icon_warning; ?></td>
247
+ <td><?php printf( __( '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' ); ?></td>
248
  </tr><?php
249
  }
250
 
251
  // HHVM
252
  if ( isset( $headers['X-Powered-By'] ) ) {
253
+ if ( strpos( $headers['X-Powered-By'], 'HHVM' ) !== false ) {
254
  ?><tr>
255
  <td><?php echo $icon_good; ?></td>
256
+ <td><?php _e( 'You are running HHVM instead of PHP. While that works fine, you should consider PHP 7. WordPress will be ceasing support for HHVM in 2018.', 'varnish-http-purge' ); ?></td>
257
  </tr><?php
258
  }
259
  }
261
  // GZIP
262
  if ( isset( $headers['Content-Encoding'] ) ) {
263
  // Regular gZIP
264
+ if( strpos( $headers['Content-Encoding'] ,'gzip') !== false || ( isset( $headers['Vary'] ) && strpos( $headers['Vary'] ,'gzip' ) !== false ) ) {
265
  ?><tr>
266
  <td><?php echo $icon_good; ?></td>
267
  <td><?php _e( 'Your site is compressing content and making the internet faster.', 'varnish-http-purge' ); ?></td>
272
  if ( strpos( $headers['Content-Encoding'] ,'Fastly') !== false ) {
273
  ?><tr>
274
  <td><?php echo $icon_good; ?></td>
275
+ <td><?php printf( __( '<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.', 'varnish-http-purge' ), esc_url( 'https://fastly.com' ) ); ?></td>
276
  </tr><?php
277
  }
278
  }
512
 
513
  }
514
 
515
+ $status = new VarnishStatus();
wp-cli.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
2
-
3
  /**
 
 
4
  This file is part of Varnish HTTP Purge, a plugin for WordPress.
5
 
6
  Varnish HTTP Purge is free software: you can redistribute it and/or modify
@@ -9,10 +10,9 @@
9
  Varnish HTTP Purge is distributed in the hope that it will be useful,
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
-
13
  */
14
 
15
- if (!defined('ABSPATH')) {
16
  die();
17
  }
18
 
@@ -80,11 +80,11 @@ class WP_CLI_Varnish_Purge_Command extends WP_CLI_Command {
80
 
81
  WP_CLI::log( sprintf( 'This plugin does not work on WP 4.6 and up, unless WP-CLI is version 0.25.0 or greater. You\'re using WP-CLI %s and WordPress %s.', $cli_version, $wp_version ) );
82
  WP_CLI::log( 'To flush your cache, please run the following command:');
83
- WP_CLI::log( sprintf( '$ curl -X PURGE "%s"' , $url.$wild ) );
84
  WP_CLI::error( 'Varnish Cache must be purged manually.' );
85
  }
86
 
87
- $this->varnish_purge->purgeUrl( $url.$pregex );
88
 
89
  if ( WP_DEBUG == true ) {
90
  WP_CLI::log( sprintf( 'Flushing URL: %s with params: %s.', $url, $pregex ) );
1
  <?php
 
2
  /**
3
+ Copyright 2015-2017 Mika Epstein (email: ipstenu@halfelf.org)
4
+
5
  This file is part of Varnish HTTP Purge, a plugin for WordPress.
6
 
7
  Varnish HTTP Purge is free software: you can redistribute it and/or modify
10
  Varnish HTTP Purge is distributed in the hope that it will be useful,
11
  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
13
  */
14
 
15
+ if ( !defined( 'ABSPATH' ) ) {
16
  die();
17
  }
18
 
80
 
81
  WP_CLI::log( sprintf( 'This plugin does not work on WP 4.6 and up, unless WP-CLI is version 0.25.0 or greater. You\'re using WP-CLI %s and WordPress %s.', $cli_version, $wp_version ) );
82
  WP_CLI::log( 'To flush your cache, please run the following command:');
83
+ WP_CLI::log( sprintf( '$ curl -X PURGE "%s"' , $url . $wild ) );
84
  WP_CLI::error( 'Varnish Cache must be purged manually.' );
85
  }
86
 
87
+ $this->varnish_purge->purgeUrl( $url . $pregex );
88
 
89
  if ( WP_DEBUG == true ) {
90
  WP_CLI::log( sprintf( 'Flushing URL: %s with params: %s.', $url, $pregex ) );