Version Description
- March 2019
- Improve debugger
- Clean code per standards
- Improve callback on WP-CLI
=
Download this release
Release Info
Developer | Ipstenu |
Plugin | Varnish HTTP Purge |
Version | 4.8 |
Comparing to | |
See all releases |
Code changes from version 4.7.3 to 4.8
- changelog.txt +21 -0
- debug.php +25 -11
- readme.txt +18 -25
- settings.php +1 -0
- todo.txt +1 -3
- varnish-http-purge.php +134 -52
- wp-cli.php +8 -1
changelog.txt
CHANGED
@@ -1,5 +1,26 @@
|
|
1 |
## CHANGELOG
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
= 4.6.6 =
|
4 |
* September 2018
|
5 |
* Bugfix to allow Nginx proxy to flush individual pages.
|
1 |
## CHANGELOG
|
2 |
|
3 |
+
= 4.7.3 =
|
4 |
+
* December 2018
|
5 |
+
* Bugfix for Jetpack (Props @jherve)
|
6 |
+
|
7 |
+
= 4.7.2 =
|
8 |
+
* October 2018
|
9 |
+
* Fix regression with IP function name
|
10 |
+
* Restore "Right Now" activity box _only_ for people who use WP.com toolbar
|
11 |
+
|
12 |
+
= 4.7.1 =
|
13 |
+
* October 2018
|
14 |
+
* Documentation: Cleaning up language and spelling
|
15 |
+
|
16 |
+
= 4.7.0 =
|
17 |
+
* October 2018
|
18 |
+
* WP-CLI: documentation
|
19 |
+
* Bugfix: Nginx compatibility
|
20 |
+
* Bugfix: Only enqueue CSS on front0end if the admin bar is used (props @mathieuhays)
|
21 |
+
* Feature: Rebranding
|
22 |
+
* Deprecation: "Right Now" button (not needed anymore)
|
23 |
+
|
24 |
= 4.6.6 =
|
25 |
* September 2018
|
26 |
* Bugfix to allow Nginx proxy to flush individual pages.
|
debug.php
CHANGED
@@ -17,7 +17,7 @@ class VarnishDebug {
|
|
17 |
|
18 |
/**
|
19 |
* Devmode Check
|
20 |
-
* See if Dev Mode is active
|
21 |
*
|
22 |
* @since 4.6.0
|
23 |
* @returns true|false
|
@@ -27,16 +27,17 @@ class VarnishDebug {
|
|
27 |
$newmode = get_site_option( 'vhp_varnish_devmode', VarnishPurger::$devmode );
|
28 |
|
29 |
if ( VHP_DEVMODE ) {
|
|
|
|
|
|
|
30 |
$return = true;
|
31 |
-
} elseif ( isset( $newmode['active'] ) && $newmode['active'] ) {
|
32 |
-
// if expire is less that NOW, it's over.
|
33 |
if ( $newmode['expire'] <= current_time( 'timestamp' ) ) {
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
$return = true;
|
38 |
}
|
39 |
}
|
|
|
40 |
return $return;
|
41 |
}
|
42 |
|
@@ -49,9 +50,7 @@ class VarnishDebug {
|
|
49 |
* @return true|false
|
50 |
*/
|
51 |
public static function devmode_toggle( $state = 'deactivate' ) {
|
52 |
-
$newmode
|
53 |
-
|
54 |
-
// Weirdly this doesn't actually matter.
|
55 |
$newmode['expire'] = current_time( 'timestamp' ) + DAY_IN_SECONDS;
|
56 |
|
57 |
switch ( sanitize_text_field( $state ) ) {
|
@@ -67,6 +66,11 @@ class VarnishDebug {
|
|
67 |
break;
|
68 |
}
|
69 |
|
|
|
|
|
|
|
|
|
|
|
70 |
update_site_option( 'vhp_varnish_devmode', $newmode );
|
71 |
|
72 |
return $newmode['active'];
|
@@ -148,11 +152,21 @@ class VarnishDebug {
|
|
148 |
// Lazy run twice to make sure we get a primed cache page.
|
149 |
$response1 = wp_remote_get( $url, $args );
|
150 |
|
|
|
|
|
|
|
|
|
|
|
151 |
// Because the 'Age' header is an important check, wait a second before fetching again.
|
152 |
sleep( 1 );
|
153 |
|
154 |
$response2 = wp_remote_get( $url, $args );
|
155 |
|
|
|
|
|
|
|
|
|
|
|
156 |
return $response2;
|
157 |
}
|
158 |
|
@@ -267,7 +281,7 @@ class VarnishDebug {
|
|
267 |
|
268 |
// Which service are we?
|
269 |
$cache_service = false;
|
270 |
-
if ( $
|
271 |
$cache_service = __( 'Nginx', 'varnish-http-purge' );
|
272 |
$still_cachable = ( $is_cachable && $x_age_nginx && $x_varn_hit && $x_pragma ) ? true : false;
|
273 |
} elseif ( $x_varnish && ! $x_nginx ) {
|
17 |
|
18 |
/**
|
19 |
* Devmode Check
|
20 |
+
* See if Dev Mode is active.
|
21 |
*
|
22 |
* @since 4.6.0
|
23 |
* @returns true|false
|
27 |
$newmode = get_site_option( 'vhp_varnish_devmode', VarnishPurger::$devmode );
|
28 |
|
29 |
if ( VHP_DEVMODE ) {
|
30 |
+
// If the define is set, we're true.
|
31 |
+
$return = true;
|
32 |
+
} elseif ( $newmode['active'] ) {
|
33 |
$return = true;
|
|
|
|
|
34 |
if ( $newmode['expire'] <= current_time( 'timestamp' ) ) {
|
35 |
+
// if expire is less that NOW, it's over.
|
36 |
+
self::devmode_toggle( 'deactivate' );
|
37 |
+
$return = false;
|
|
|
38 |
}
|
39 |
}
|
40 |
+
|
41 |
return $return;
|
42 |
}
|
43 |
|
50 |
* @return true|false
|
51 |
*/
|
52 |
public static function devmode_toggle( $state = 'deactivate' ) {
|
53 |
+
$newmode = get_site_option( 'vhp_varnish_devmode', VarnishPurger::$devmode );
|
|
|
|
|
54 |
$newmode['expire'] = current_time( 'timestamp' ) + DAY_IN_SECONDS;
|
55 |
|
56 |
switch ( sanitize_text_field( $state ) ) {
|
66 |
break;
|
67 |
}
|
68 |
|
69 |
+
// No matter what, when we mess with this, flush the DB caches.
|
70 |
+
if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
|
71 |
+
wp_cache_flush();
|
72 |
+
}
|
73 |
+
|
74 |
update_site_option( 'vhp_varnish_devmode', $newmode );
|
75 |
|
76 |
return $newmode['active'];
|
152 |
// Lazy run twice to make sure we get a primed cache page.
|
153 |
$response1 = wp_remote_get( $url, $args );
|
154 |
|
155 |
+
// If this fails, we're going to assume bad things...
|
156 |
+
if ( is_wp_error( $response1 ) ) {
|
157 |
+
return 'fail';
|
158 |
+
}
|
159 |
+
|
160 |
// Because the 'Age' header is an important check, wait a second before fetching again.
|
161 |
sleep( 1 );
|
162 |
|
163 |
$response2 = wp_remote_get( $url, $args );
|
164 |
|
165 |
+
// And if this fails, we again assume badly.
|
166 |
+
if ( is_wp_error( $response2 ) ) {
|
167 |
+
return 'fail';
|
168 |
+
}
|
169 |
+
|
170 |
return $response2;
|
171 |
}
|
172 |
|
281 |
|
282 |
// Which service are we?
|
283 |
$cache_service = false;
|
284 |
+
if ( $x_nginx ) {
|
285 |
$cache_service = __( 'Nginx', 'varnish-http-purge' );
|
286 |
$still_cachable = ( $is_cachable && $x_age_nginx && $x_varn_hit && $x_pragma ) ? true : false;
|
287 |
} elseif ( $x_varnish && ! $x_nginx ) {
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: Ipstenu, mikeschroder, techpriester, danielbachhuber
|
3 |
Tags: proxy, purge, cache, varnish, nginx
|
4 |
Requires at least: 4.7
|
5 |
-
Tested up to: 5.
|
6 |
-
Stable tag: 4.
|
7 |
Requires PHP: 5.6
|
8 |
|
9 |
Automatically empty proxy cached content when your site is modified.
|
@@ -16,7 +16,7 @@ One common method of caching content for websites is via the use of reverse prox
|
|
16 |
|
17 |
A reverse proxy cache is installed in front of a server and reviews requests. If the page being requested is already cached, it delivers the cached content. Otherwise it generates the page and the cache on demand.
|
18 |
|
19 |
-
The Proxy Cache Purge plugin sends a request to delete (aka flush) the cached data of a page or post every time it
|
20 |
|
21 |
= How It Works =
|
22 |
|
@@ -52,7 +52,7 @@ That will break cache on page loads. It is _not_ recommended for production!
|
|
52 |
|
53 |
* `wp varnish purge` - Flush the entire cache
|
54 |
* `wp varnish debug [<url>]` - Help for debugging how well your cache is (or isn't) working
|
55 |
-
* `wp varnish devmode [<activate|deactivate|toggle
|
56 |
|
57 |
= Privacy Policy =
|
58 |
|
@@ -115,12 +115,16 @@ There are three ways to do this:
|
|
115 |
|
116 |
1. Chose 'Pause Cache (24hrs)' from the Cache dropdown menu in your toolbar
|
117 |
2. Go to Proxy Cache -> Settings and enable development mode
|
118 |
-
3. Add `define( 'VHP_DEVMODE', true );` to your `wp-config.php` file
|
119 |
|
120 |
The first two options will enable development mode for 24 hours. If you're working on long term development, you can should use the define.
|
121 |
|
122 |
It is _not_ recommended you use development mode on production sites for extended periods of time, as it _will_ will slow your site down and lose all the benefits of caching in the first place.
|
123 |
|
|
|
|
|
|
|
|
|
124 |
= Why don't I have access to development mode? =
|
125 |
|
126 |
Due to the damage this can cause a site, access is limited to admins only. In the case of a multisite network, only <em>Network Admins</em> can disable caching and they must do so via `wp-config.php` for security.
|
@@ -129,6 +133,10 @@ Due to the damage this can cause a site, access is limited to admins only. In th
|
|
129 |
|
130 |
While development mode is on, your server will continue to cache content but the plugin will tell WordPress not to use the cached content. That means files that exist outside of WordPress (like CSS or images) _may_ serve cached content. The plugin does its best to add a No Cache parameter to javascript and CSS, however if a theme or plugin _doesn't_ use proper WordPress enqueues, then their cached content will be shown.
|
131 |
|
|
|
|
|
|
|
|
|
132 |
= How can I tell if everything's caching? =
|
133 |
|
134 |
From your WordPress Dashboard, go to <em>Proxy Cache > Check Caching</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.
|
@@ -195,26 +203,11 @@ This plugin is installed by default for _all_ DreamPress installs on DreamHost,
|
|
195 |
|
196 |
== Changelog ==
|
197 |
|
198 |
-
= 4.
|
199 |
-
*
|
200 |
-
*
|
201 |
-
|
202 |
-
|
203 |
-
* October 2018
|
204 |
-
* Fix regression with IP function name
|
205 |
-
* Restore "Right Now" activity box _only_ for people who use WP.com toolbar
|
206 |
-
|
207 |
-
= 4.7.1 =
|
208 |
-
* October 2018
|
209 |
-
* Documentation: Cleaning up language and spelling
|
210 |
-
|
211 |
-
= 4.7.0 =
|
212 |
-
* October 2018
|
213 |
-
* WP-CLI: documentation
|
214 |
-
* Bugfix: Nginx compatibility
|
215 |
-
* Bugfix: Only enqueue CSS on front0end if the admin bar is used (props @mathieuhays)
|
216 |
-
* Feature: Rebranding
|
217 |
-
* Deprecation: "Right Now" button (not needed anymore)
|
218 |
|
219 |
== Screenshots ==
|
220 |
|
2 |
Contributors: Ipstenu, mikeschroder, techpriester, danielbachhuber
|
3 |
Tags: proxy, purge, cache, varnish, nginx
|
4 |
Requires at least: 4.7
|
5 |
+
Tested up to: 5.1
|
6 |
+
Stable tag: 4.8
|
7 |
Requires PHP: 5.6
|
8 |
|
9 |
Automatically empty proxy cached content when your site is modified.
|
16 |
|
17 |
A reverse proxy cache is installed in front of a server and reviews requests. If the page being requested is already cached, it delivers the cached content. Otherwise it generates the page and the cache on demand.
|
18 |
|
19 |
+
The Proxy Cache Purge plugin sends a request to delete (aka flush) the cached data of a page or post every time it's modified.
|
20 |
|
21 |
= How It Works =
|
22 |
|
52 |
|
53 |
* `wp varnish purge` - Flush the entire cache
|
54 |
* `wp varnish debug [<url>]` - Help for debugging how well your cache is (or isn't) working
|
55 |
+
* `wp varnish devmode [<activate|deactivate|toggle>]` - Change development mode state
|
56 |
|
57 |
= Privacy Policy =
|
58 |
|
115 |
|
116 |
1. Chose 'Pause Cache (24hrs)' from the Cache dropdown menu in your toolbar
|
117 |
2. Go to Proxy Cache -> Settings and enable development mode
|
118 |
+
3. Add `define( 'VHP_DEVMODE', true );` to your `wp-config.php` file.
|
119 |
|
120 |
The first two options will enable development mode for 24 hours. If you're working on long term development, you can should use the define.
|
121 |
|
122 |
It is _not_ recommended you use development mode on production sites for extended periods of time, as it _will_ will slow your site down and lose all the benefits of caching in the first place.
|
123 |
|
124 |
+
= Why is the restart cache button missing? =
|
125 |
+
|
126 |
+
If you've disabled caching via the define, then you cannot restart cache via the plugin. You would need to change `define( 'VHP_DEVMODE', true );` to `define( 'VHP_DEVMODE', false );` in your `wp-config.php` file.
|
127 |
+
|
128 |
= Why don't I have access to development mode? =
|
129 |
|
130 |
Due to the damage this can cause a site, access is limited to admins only. In the case of a multisite network, only <em>Network Admins</em> can disable caching and they must do so via `wp-config.php` for security.
|
133 |
|
134 |
While development mode is on, your server will continue to cache content but the plugin will tell WordPress not to use the cached content. That means files that exist outside of WordPress (like CSS or images) _may_ serve cached content. The plugin does its best to add a No Cache parameter to javascript and CSS, however if a theme or plugin _doesn't_ use proper WordPress enqueues, then their cached content will be shown.
|
135 |
|
136 |
+
= Why can I still flush cache while in development mode? =
|
137 |
+
|
138 |
+
Because the server is still caching content. The plugin provides a way to flush the cache for those pages, as well as anything not included in WordPress, for your convenience.
|
139 |
+
|
140 |
= How can I tell if everything's caching? =
|
141 |
|
142 |
From your WordPress Dashboard, go to <em>Proxy Cache > Check Caching</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.
|
203 |
|
204 |
== Changelog ==
|
205 |
|
206 |
+
= 4.8 =
|
207 |
+
* March 2019
|
208 |
+
* Improve debugger
|
209 |
+
* Clean code per standards
|
210 |
+
* Improve callback on WP-CLI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
|
212 |
== Screenshots ==
|
213 |
|
settings.php
CHANGED
@@ -322,6 +322,7 @@ class VarnishStatus {
|
|
322 |
foreach ( $headers as $header => $key ) {
|
323 |
if ( '0' !== $header ) {
|
324 |
if ( is_array( $key ) ) {
|
|
|
325 |
$content = print_r( $key, true );
|
326 |
} else {
|
327 |
$content = wp_kses_post( $key );
|
322 |
foreach ( $headers as $header => $key ) {
|
323 |
if ( '0' !== $header ) {
|
324 |
if ( is_array( $key ) ) {
|
325 |
+
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
|
326 |
$content = print_r( $key, true );
|
327 |
} else {
|
328 |
$content = wp_kses_post( $key );
|
todo.txt
CHANGED
@@ -2,7 +2,5 @@
|
|
2 |
|
3 |
We're going to sit down and look into how the plugin is structured to make it even faster and more organized. Please send coffee. Here's the wish list:
|
4 |
|
5 |
-
* Only purge all automatically once an hour (manual button click will continue to work)
|
6 |
* Refactor automated purge all to be kinder
|
7 |
-
*
|
8 |
-
* Get rid of the need to parse_url()
|
2 |
|
3 |
We're going to sit down and look into how the plugin is structured to make it even faster and more organized. Please send coffee. Here's the wish list:
|
4 |
|
|
|
5 |
* Refactor automated purge all to be kinder
|
6 |
+
* Get rid of the need to parse_url()
|
|
varnish-http-purge.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Proxy Cache Purge
|
4 |
* Plugin URI: https://halfelf.org/plugins/varnish-http-purge/
|
5 |
* Description: Automatically empty cached pages when content on your site is modified.
|
6 |
-
* Version: 4.
|
7 |
* Author: Mika Epstein
|
8 |
* Author URI: https://halfelf.org/
|
9 |
* License: http://www.apache.org/licenses/LICENSE-2.0
|
@@ -90,6 +90,11 @@ class VarnishPurger {
|
|
90 |
// Release the hounds!
|
91 |
add_action( 'init', array( &$this, 'init' ) );
|
92 |
add_action( 'admin_init', array( &$this, 'admin_init' ) );
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
}
|
95 |
|
@@ -135,17 +140,24 @@ class VarnishPurger {
|
|
135 |
* @access public
|
136 |
*/
|
137 |
public function init() {
|
138 |
-
global $blog_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
|
140 |
// If Dev Mode is true, kill caching.
|
141 |
if ( VarnishDebug::devmode_check() ) {
|
142 |
if ( ! is_admin() ) {
|
143 |
-
// Sessions to break PHP caching.
|
144 |
-
|
145 |
-
|
146 |
@session_start();
|
147 |
-
// @codingStandardsIgnoreEnd
|
148 |
}
|
|
|
149 |
|
150 |
// Add nocacche to CSS and JS.
|
151 |
add_filter( 'style_loader_src', array( 'VarnishDebug', 'nocache_cssjs' ), 10, 2 );
|
@@ -180,9 +192,8 @@ class VarnishPurger {
|
|
180 |
// Success: Admin notice when purging.
|
181 |
if ( ( isset( $_GET['vhp_flush_all'] ) && check_admin_referer( 'vhp-flush-all' ) ) ||
|
182 |
( isset( $_GET['vhp_flush_do'] ) && check_admin_referer( 'vhp-flush-do' ) ) ) {
|
183 |
-
if ( 'devmode' === $_GET['vhp_flush_do'] ) {
|
184 |
-
|
185 |
-
VarnishDebug::devmode_toggle( $toggle );
|
186 |
add_action( 'admin_notices', array( $this, 'admin_message_devmode' ) );
|
187 |
} else {
|
188 |
add_action( 'admin_notices', array( $this, 'admin_message_purge' ) );
|
@@ -195,6 +206,37 @@ class VarnishPurger {
|
|
195 |
add_action( 'wp_enqueue_scripts', array( $this, 'custom_css' ) );
|
196 |
}
|
197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
/**
|
199 |
* Purge Message
|
200 |
* Informs of a succcessful purge
|
@@ -250,16 +292,23 @@ class VarnishPurger {
|
|
250 |
} else {
|
251 |
$devmode = get_site_option( 'vhp_varnish_devmode', self::$devmode );
|
252 |
$time = human_time_diff( current_time( 'timestamp' ), $devmode['expire'] );
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
|
|
|
|
|
|
260 |
}
|
261 |
}
|
262 |
-
|
|
|
|
|
|
|
|
|
263 |
}
|
264 |
|
265 |
/**
|
@@ -363,17 +412,33 @@ class VarnishPurger {
|
|
363 |
);
|
364 |
}
|
365 |
|
366 |
-
//
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
377 |
}
|
378 |
|
379 |
if ( $can_purge ) {
|
@@ -460,13 +525,15 @@ class VarnishPurger {
|
|
460 |
|
461 |
// Define registered purge events.
|
462 |
$actions = array(
|
463 |
-
'
|
464 |
-
'
|
465 |
-
'
|
466 |
-
'
|
467 |
-
'
|
468 |
-
'
|
469 |
-
'
|
|
|
|
|
470 |
);
|
471 |
|
472 |
// send back the actions array, filtered.
|
@@ -485,8 +552,10 @@ class VarnishPurger {
|
|
485 |
|
486 |
// Define registered purge events.
|
487 |
$actions = array(
|
488 |
-
'
|
489 |
-
'
|
|
|
|
|
490 |
);
|
491 |
|
492 |
/**
|
@@ -629,14 +698,20 @@ class VarnishPurger {
|
|
629 |
*
|
630 |
* @since 4.1
|
631 |
*/
|
632 |
-
$headers = apply_filters(
|
633 |
-
'
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
640 |
|
641 |
do_action( 'after_purge_url', $parsed_url, $purgeme, $response, $headers );
|
642 |
}
|
@@ -768,7 +843,8 @@ class VarnishPurger {
|
|
768 |
$categories = get_the_category( $post_id );
|
769 |
if ( $categories ) {
|
770 |
foreach ( $categories as $cat ) {
|
771 |
-
array_push(
|
|
|
772 |
get_category_link( $cat->term_id ),
|
773 |
get_rest_url() . $rest_api_route . '/categories/' . $cat->term_id . '/'
|
774 |
);
|
@@ -783,7 +859,8 @@ class VarnishPurger {
|
|
783 |
$tag_base = '/tag/';
|
784 |
}
|
785 |
foreach ( $tags as $tag ) {
|
786 |
-
array_push(
|
|
|
787 |
get_tag_link( $tag->term_id ),
|
788 |
get_rest_url() . $rest_api_route . $tag_base . $tag->term_id . '/'
|
789 |
);
|
@@ -797,7 +874,8 @@ class VarnishPurger {
|
|
797 |
if ( $features['public'] ) {
|
798 |
$terms = wp_get_post_terms( $post_id, $taxonomy );
|
799 |
foreach ( $terms as $term ) {
|
800 |
-
array_push(
|
|
|
801 |
get_term_link( $term ),
|
802 |
get_rest_url() . $rest_api_route . '/' . $term->taxonomy . '/' . $term->slug . '/'
|
803 |
);
|
@@ -811,14 +889,16 @@ class VarnishPurger {
|
|
811 |
if ( $this_post_type && 'post' === $this_post_type ) {
|
812 |
// Author URLs:
|
813 |
$author_id = get_post_field( 'post_author', $post_id );
|
814 |
-
array_push(
|
|
|
815 |
get_author_posts_url( $author_id ),
|
816 |
get_author_feed_link( $author_id ),
|
817 |
get_rest_url() . $rest_api_route . '/users/' . $author_id . '/'
|
818 |
);
|
819 |
|
820 |
// Feeds:
|
821 |
-
array_push(
|
|
|
822 |
get_bloginfo_rss( 'rdf_url' ),
|
823 |
get_bloginfo_rss( 'rss_url' ),
|
824 |
get_bloginfo_rss( 'rss2_url' ),
|
@@ -830,7 +910,8 @@ class VarnishPurger {
|
|
830 |
|
831 |
// Archives and their feeds.
|
832 |
if ( $this_post_type && ! in_array( $this_post_type, $noarchive_post_type, true ) ) {
|
833 |
-
array_push(
|
|
|
834 |
get_post_type_archive_link( get_post_type( $post_id ) ),
|
835 |
get_post_type_archive_feed_link( get_post_type( $post_id ) )
|
836 |
// Need to add in JSON?
|
@@ -838,7 +919,8 @@ class VarnishPurger {
|
|
838 |
}
|
839 |
|
840 |
// Home Pages and (if used) posts page.
|
841 |
-
array_push(
|
|
|
842 |
get_rest_url(),
|
843 |
$this->the_home_url() . '/'
|
844 |
);
|
3 |
* Plugin Name: Proxy Cache Purge
|
4 |
* Plugin URI: https://halfelf.org/plugins/varnish-http-purge/
|
5 |
* Description: Automatically empty cached pages when content on your site is modified.
|
6 |
+
* Version: 4.8
|
7 |
* Author: Mika Epstein
|
8 |
* Author URI: https://halfelf.org/
|
9 |
* License: http://www.apache.org/licenses/LICENSE-2.0
|
90 |
// Release the hounds!
|
91 |
add_action( 'init', array( &$this, 'init' ) );
|
92 |
add_action( 'admin_init', array( &$this, 'admin_init' ) );
|
93 |
+
add_action( 'import_start', array( &$this, 'import_start' ) );
|
94 |
+
add_action( 'import_end', array( &$this, 'import_end' ) );
|
95 |
+
|
96 |
+
// Check if there's an upgrade
|
97 |
+
add_action( 'upgrader_process_complete', array( &$this, 'check_upgrades' ), 10, 2 );
|
98 |
|
99 |
}
|
100 |
|
140 |
* @access public
|
141 |
*/
|
142 |
public function init() {
|
143 |
+
global $blog_id, $wp_db_version;
|
144 |
+
|
145 |
+
// If the DB version we detect isn't the same as the version core thinks
|
146 |
+
// we will fush DB cache. This may cause double dumping in some cases but
|
147 |
+
// should not be harmful.
|
148 |
+
if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) && get_option( 'db_version' ) !== $wp_db_version ) {
|
149 |
+
wp_cache_flush();
|
150 |
+
}
|
151 |
|
152 |
// If Dev Mode is true, kill caching.
|
153 |
if ( VarnishDebug::devmode_check() ) {
|
154 |
if ( ! is_admin() ) {
|
155 |
+
// Sessions used to break PHP caching.
|
156 |
+
// @codingStandardsIgnoreStart
|
157 |
+
if ( ! is_user_logged_in() && session_status() != PHP_SESSION_ACTIVE ) {
|
158 |
@session_start();
|
|
|
159 |
}
|
160 |
+
// @codingStandardsIgnoreEnd
|
161 |
|
162 |
// Add nocacche to CSS and JS.
|
163 |
add_filter( 'style_loader_src', array( 'VarnishDebug', 'nocache_cssjs' ), 10, 2 );
|
192 |
// Success: Admin notice when purging.
|
193 |
if ( ( isset( $_GET['vhp_flush_all'] ) && check_admin_referer( 'vhp-flush-all' ) ) ||
|
194 |
( isset( $_GET['vhp_flush_do'] ) && check_admin_referer( 'vhp-flush-do' ) ) ) {
|
195 |
+
if ( 'devmode' === $_GET['vhp_flush_do'] && isset( $_GET['vhp_set_devmode'] ) ) {
|
196 |
+
VarnishDebug::devmode_toggle( esc_attr( $_GET['vhp_set_devmode'] ) );
|
|
|
197 |
add_action( 'admin_notices', array( $this, 'admin_message_devmode' ) );
|
198 |
} else {
|
199 |
add_action( 'admin_notices', array( $this, 'admin_message_purge' ) );
|
206 |
add_action( 'wp_enqueue_scripts', array( $this, 'custom_css' ) );
|
207 |
}
|
208 |
|
209 |
+
/**
|
210 |
+
* Check if something has upgraded and try to flush the DB cache.
|
211 |
+
* This runs for ALL upgrades (theme, plugin, and core) to account for
|
212 |
+
* the complex nature that are upgrades.
|
213 |
+
*
|
214 |
+
* @param array $object of upgrade data
|
215 |
+
* @param array $options picked for upgrade
|
216 |
+
* @since 4.8
|
217 |
+
*/
|
218 |
+
public function check_upgrades( $object, $options ) {
|
219 |
+
if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
|
220 |
+
wp_cache_flush();
|
221 |
+
}
|
222 |
+
}
|
223 |
+
|
224 |
+
/**
|
225 |
+
* Pause caching if Importer was started
|
226 |
+
* @since 4.8
|
227 |
+
*/
|
228 |
+
public function import_start() {
|
229 |
+
VarnishDebug::devmode_toggle( 'activate' );
|
230 |
+
}
|
231 |
+
|
232 |
+
/**
|
233 |
+
* Resume caching if Importer has ended
|
234 |
+
* @since 4.8
|
235 |
+
*/
|
236 |
+
public function import_end() {
|
237 |
+
VarnishDebug::devmode_toggle( 'deactivate' );
|
238 |
+
}
|
239 |
+
|
240 |
/**
|
241 |
* Purge Message
|
242 |
* Informs of a succcessful purge
|
292 |
} else {
|
293 |
$devmode = get_site_option( 'vhp_varnish_devmode', self::$devmode );
|
294 |
$time = human_time_diff( current_time( 'timestamp' ), $devmode['expire'] );
|
295 |
+
|
296 |
+
if ( ! $devmode['active'] ) {
|
297 |
+
if ( ! is_multisite() ) {
|
298 |
+
// translators: %1$s is the time until dev mode expires.
|
299 |
+
// translators: %2$s is a link to the settings pages.
|
300 |
+
$message = sprintf( __( 'Proxy Cache Purge Development Mode is active for the next %1$s. You can disable this at the <a href="%2$s">Proxy Settings Page</a>.', 'varnish-http-purge' ), $time, esc_url( admin_url( 'admin.php?page=varnish-page' ) ) );
|
301 |
+
} else {
|
302 |
+
// translators: %1$s is the time until dev mode expires.
|
303 |
+
$message = sprintf( __( 'Proxy Cache Purge Development Mode is active for the next %1$s.', 'varnish-http-purge' ), $time );
|
304 |
+
}
|
305 |
}
|
306 |
}
|
307 |
+
|
308 |
+
// Only echo if there's actually a message
|
309 |
+
if ( isset( $message ) ) {
|
310 |
+
echo '<div class="notice notice-warning"><p>' . wp_kses_post( $message ) . '</p></div>';
|
311 |
+
}
|
312 |
}
|
313 |
|
314 |
/**
|
412 |
);
|
413 |
}
|
414 |
|
415 |
+
// If Devmode is in the config, don't allow it to be disabled.
|
416 |
+
if ( ! VHP_DEVMODE ) {
|
417 |
+
// Populate enable/disable cache button.
|
418 |
+
if ( VarnishDebug::devmode_check() ) {
|
419 |
+
$purge_devmode_title = __( 'Restart Cache', 'varnish-http-purge' );
|
420 |
+
$vhp_add_query_arg = array(
|
421 |
+
'vhp_flush_do' => 'devmode',
|
422 |
+
'vhp_set_devmode' => 'dectivate',
|
423 |
+
);
|
424 |
+
} else {
|
425 |
+
$purge_devmode_title = __( 'Pause Cache (24h)', 'varnish-http-purge' );
|
426 |
+
$vhp_add_query_arg = array(
|
427 |
+
'vhp_flush_do' => 'devmode',
|
428 |
+
'vhp_set_devmode' => 'activate',
|
429 |
+
);
|
430 |
+
}
|
431 |
+
|
432 |
+
$args[] = array(
|
433 |
+
'parent' => 'purge-varnish-cache',
|
434 |
+
'id' => 'purge-varnish-cache-devmode',
|
435 |
+
'title' => $purge_devmode_title,
|
436 |
+
'href' => wp_nonce_url( add_query_arg( $vhp_add_query_arg ), 'vhp-flush-do' ),
|
437 |
+
'meta' => array(
|
438 |
+
'title' => $purge_devmode_title,
|
439 |
+
),
|
440 |
+
);
|
441 |
+
}
|
442 |
}
|
443 |
|
444 |
if ( $can_purge ) {
|
525 |
|
526 |
// Define registered purge events.
|
527 |
$actions = array(
|
528 |
+
'autoptimize_action_cachepurged', // Compat with https://wordpress.org/plugins/autoptimize/ plugin.
|
529 |
+
'delete_attachment', // Delete an attachment - includes re-uploading.
|
530 |
+
'deleted_post', // Delete a post.
|
531 |
+
'edit_post', // Edit a post - includes leaving comments.
|
532 |
+
'import_start', // When importer starts
|
533 |
+
'import_end', // When importer ends
|
534 |
+
'save_post', // Save a post.
|
535 |
+
'switch_theme', // After a theme is changed.
|
536 |
+
'trashed_post', // Empty Trashed post.
|
537 |
);
|
538 |
|
539 |
// send back the actions array, filtered.
|
552 |
|
553 |
// Define registered purge events.
|
554 |
$actions = array(
|
555 |
+
'autoptimize_action_cachepurged', // Compat with https://wordpress.org/plugins/autoptimize/ plugin.
|
556 |
+
'import_start', // When importer starts
|
557 |
+
'import_end', // When importer ends
|
558 |
+
'switch_theme', // After a theme is changed.
|
559 |
);
|
560 |
|
561 |
/**
|
698 |
*
|
699 |
* @since 4.1
|
700 |
*/
|
701 |
+
$headers = apply_filters(
|
702 |
+
'varnish_http_purge_headers',
|
703 |
+
array(
|
704 |
+
'host' => $host_headers,
|
705 |
+
'X-Purge-Method' => $x_purge_method,
|
706 |
+
)
|
707 |
+
);
|
708 |
+
$response = wp_remote_request(
|
709 |
+
$purgeme,
|
710 |
+
array(
|
711 |
+
'method' => 'PURGE',
|
712 |
+
'headers' => $headers,
|
713 |
+
)
|
714 |
+
);
|
715 |
|
716 |
do_action( 'after_purge_url', $parsed_url, $purgeme, $response, $headers );
|
717 |
}
|
843 |
$categories = get_the_category( $post_id );
|
844 |
if ( $categories ) {
|
845 |
foreach ( $categories as $cat ) {
|
846 |
+
array_push(
|
847 |
+
$listofurls,
|
848 |
get_category_link( $cat->term_id ),
|
849 |
get_rest_url() . $rest_api_route . '/categories/' . $cat->term_id . '/'
|
850 |
);
|
859 |
$tag_base = '/tag/';
|
860 |
}
|
861 |
foreach ( $tags as $tag ) {
|
862 |
+
array_push(
|
863 |
+
$listofurls,
|
864 |
get_tag_link( $tag->term_id ),
|
865 |
get_rest_url() . $rest_api_route . $tag_base . $tag->term_id . '/'
|
866 |
);
|
874 |
if ( $features['public'] ) {
|
875 |
$terms = wp_get_post_terms( $post_id, $taxonomy );
|
876 |
foreach ( $terms as $term ) {
|
877 |
+
array_push(
|
878 |
+
$listofurls,
|
879 |
get_term_link( $term ),
|
880 |
get_rest_url() . $rest_api_route . '/' . $term->taxonomy . '/' . $term->slug . '/'
|
881 |
);
|
889 |
if ( $this_post_type && 'post' === $this_post_type ) {
|
890 |
// Author URLs:
|
891 |
$author_id = get_post_field( 'post_author', $post_id );
|
892 |
+
array_push(
|
893 |
+
$listofurls,
|
894 |
get_author_posts_url( $author_id ),
|
895 |
get_author_feed_link( $author_id ),
|
896 |
get_rest_url() . $rest_api_route . '/users/' . $author_id . '/'
|
897 |
);
|
898 |
|
899 |
// Feeds:
|
900 |
+
array_push(
|
901 |
+
$listofurls,
|
902 |
get_bloginfo_rss( 'rdf_url' ),
|
903 |
get_bloginfo_rss( 'rss_url' ),
|
904 |
get_bloginfo_rss( 'rss2_url' ),
|
910 |
|
911 |
// Archives and their feeds.
|
912 |
if ( $this_post_type && ! in_array( $this_post_type, $noarchive_post_type, true ) ) {
|
913 |
+
array_push(
|
914 |
+
$listofurls,
|
915 |
get_post_type_archive_link( get_post_type( $post_id ) ),
|
916 |
get_post_type_archive_feed_link( get_post_type( $post_id ) )
|
917 |
// Need to add in JSON?
|
919 |
}
|
920 |
|
921 |
// Home Pages and (if used) posts page.
|
922 |
+
array_push(
|
923 |
+
$listofurls,
|
924 |
get_rest_url(),
|
925 |
$this->the_home_url() . '/'
|
926 |
);
|
wp-cli.php
CHANGED
@@ -226,7 +226,9 @@ if ( ! class_exists( 'WP_CLI_Varnish_Command' ) ) {
|
|
226 |
escapeshellarg( $path ),
|
227 |
substr_count( ABSPATH, '/' ) + 1
|
228 |
);
|
|
|
229 |
system( $cmd );
|
|
|
230 |
}
|
231 |
WP_CLI::log( '' );
|
232 |
WP_CLI::log( __( 'Grep complete. If no data was output, you\'re good!', 'varnish-http-purge' ) );
|
@@ -258,7 +260,12 @@ if ( ! class_exists( 'WP_CLI_Varnish_Command' ) ) {
|
|
258 |
|
259 |
// Get the response and headers.
|
260 |
$remote_get = VarnishDebug::remote_get( $varnishurl );
|
261 |
-
|
|
|
|
|
|
|
|
|
|
|
262 |
|
263 |
if ( WP_CLI\Utils\get_flag_value( $assoc_args, 'include-headers' ) ) {
|
264 |
WP_CLI::log( 'Headers:' );
|
226 |
escapeshellarg( $path ),
|
227 |
substr_count( ABSPATH, '/' ) + 1
|
228 |
);
|
229 |
+
// @codingStandardsIgnoreStart
|
230 |
system( $cmd );
|
231 |
+
// @codingStandardsIgnoreEnd
|
232 |
}
|
233 |
WP_CLI::log( '' );
|
234 |
WP_CLI::log( __( 'Grep complete. If no data was output, you\'re good!', 'varnish-http-purge' ) );
|
260 |
|
261 |
// Get the response and headers.
|
262 |
$remote_get = VarnishDebug::remote_get( $varnishurl );
|
263 |
+
|
264 |
+
if ( is_wp_error( $remote_get ) || 'fail' === $remote_get ) {
|
265 |
+
WP_CLI::error( __( 'Unable to retrieve data. Debug cannot be run at this time. Please run "curl -I [URL]" manually on your personal computer.', 'varnish-http-purge' ) );
|
266 |
+
}
|
267 |
+
|
268 |
+
$headers = wp_remote_retrieve_headers( $remote_get );
|
269 |
|
270 |
if ( WP_CLI\Utils\get_flag_value( $assoc_args, 'include-headers' ) ) {
|
271 |
WP_CLI::log( 'Headers:' );
|