Version Description
Download this release
Release Info
Developer | Ipstenu |
Plugin | Varnish HTTP Purge |
Version | 5.1.0 |
Comparing to | |
See all releases |
Code changes from version 5.0.3 to 5.1.0
- debug.php +17 -17
- readme.txt +30 -27
- settings.php +84 -6
- uninstall.php +1 -0
- varnish-http-purge.php +33 -8
debug.php
CHANGED
@@ -107,11 +107,8 @@ class VarnishDebug {
|
|
107 |
if ( ! empty( $input ) ) {
|
108 |
$parsed_input = wp_parse_url( $input );
|
109 |
if ( empty( $parsed_input['scheme'] ) ) {
|
110 |
-
$schema_input = 'http://';
|
111 |
-
|
112 |
-
$schema_input = 'https://';
|
113 |
-
}
|
114 |
-
$input = $schema_input . ltrim( $input, '/' );
|
115 |
}
|
116 |
}
|
117 |
|
@@ -139,7 +136,7 @@ class VarnishDebug {
|
|
139 |
*/
|
140 |
public static function remote_get( $url = '' ) {
|
141 |
|
142 |
-
// Make sure it's not a
|
143 |
$url = esc_url( $url );
|
144 |
|
145 |
$args = array(
|
@@ -157,8 +154,9 @@ class VarnishDebug {
|
|
157 |
return 'fail';
|
158 |
}
|
159 |
|
160 |
-
// Because the 'Age' header is an important check, wait
|
161 |
-
|
|
|
162 |
|
163 |
$response2 = wp_remote_get( $url, $args );
|
164 |
|
@@ -192,7 +190,7 @@ class VarnishDebug {
|
|
192 |
$message .= $response->get_error_message();
|
193 |
} elseif ( '404' === wp_remote_retrieve_response_code( $response ) ) {
|
194 |
$preflight = false;
|
195 |
-
$message = __( 'This URL does not resolve properly. Either it
|
196 |
}
|
197 |
|
198 |
$return = array(
|
@@ -297,7 +295,7 @@ class VarnishDebug {
|
|
297 |
}
|
298 |
}
|
299 |
|
300 |
-
if ( ! $cache_service ) {
|
301 |
$return['icon'] = 'bad';
|
302 |
$return['message'] = __( 'No known cache service has been detected on your site.', 'varnish-http-purge' );
|
303 |
} elseif ( ! $kronk ) {
|
@@ -305,12 +303,12 @@ class VarnishDebug {
|
|
305 |
$return['message'] = __( 'Your site is not responding. If this happens again, please contact your webhost.', 'varnish-http-purge' );
|
306 |
} elseif ( ! $cacheheaders_set ) {
|
307 |
$return['icon'] = 'notice';
|
308 |
-
$return['message'] = __( 'We were unable find a caching service active for this domain. This may occur if you use a proxy service (such as CloudFlare or Sucuri) or if you\'re in the middle of a DNS move.', 'varnish-http-purge' );
|
309 |
} elseif ( $is_cachable && $still_cachable ) {
|
310 |
$return['icon'] = 'awesome';
|
311 |
} else {
|
312 |
// translators: %1 is the type of caching service detected (i.e. nginx or varnish).
|
313 |
-
$return['message'] = sprintf( __( '%1s caching service is running but
|
314 |
$return['icon'] = 'warning';
|
315 |
}
|
316 |
|
@@ -335,25 +333,27 @@ class VarnishDebug {
|
|
335 |
$x_nginx = ( isset( $headers['server'] ) && ( strpos( $headers['server'], 'nginx' ) !== false || strpos( $headers['server'], 'openresty' ) !== false ) ) ? true : false;
|
336 |
|
337 |
if ( $x_nginx && 'localhost' === $varniship ) {
|
|
|
|
|
338 |
$return = array(
|
339 |
-
'icon' => 'awesome',
|
340 |
'message' => __( 'Your Nginx Proxy is set up correctly.', 'varnish-http-purge' ),
|
|
|
341 |
);
|
342 |
} elseif ( false === $remote_ip && ! empty( $varniship ) ) {
|
343 |
$return = array(
|
344 |
// translators: %s is an IP address.
|
345 |
'message' => sprintf( __( 'Your Proxy IP address is set to %s 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 the IP. Please check with your webhost or server admin before doing so.', 'varnish-http-purge' ), $varniship ),
|
346 |
-
'icon' => '
|
347 |
);
|
348 |
} elseif ( false !== $remote_ip && 'cloudflare' !== $remote_ip && $remote_ip !== $varniship ) {
|
349 |
$return = array(
|
350 |
-
'icon' => 'warning',
|
351 |
'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' ),
|
|
|
352 |
);
|
353 |
} else {
|
354 |
$return = array(
|
355 |
-
'icon' => 'awesome',
|
356 |
'message' => __( 'Your server IP setup looks good.', 'varnish-http-purge' ),
|
|
|
357 |
);
|
358 |
}
|
359 |
|
@@ -633,7 +633,7 @@ class VarnishDebug {
|
|
633 |
} else {
|
634 |
$return['Mod Pagespeed'] = array(
|
635 |
'icon' => 'bad',
|
636 |
-
'message' => __( 'Mod Pagespeed is active but your caching headers may not be
|
637 |
);
|
638 |
}
|
639 |
}
|
107 |
if ( ! empty( $input ) ) {
|
108 |
$parsed_input = wp_parse_url( $input );
|
109 |
if ( empty( $parsed_input['scheme'] ) ) {
|
110 |
+
$schema_input = ( is_ssl() ) ? 'https://' : 'http://';
|
111 |
+
$input = $schema_input . ltrim( $input, '/' );
|
|
|
|
|
|
|
112 |
}
|
113 |
}
|
114 |
|
136 |
*/
|
137 |
public static function remote_get( $url = '' ) {
|
138 |
|
139 |
+
// Make sure it's not a bad entry.
|
140 |
$url = esc_url( $url );
|
141 |
|
142 |
$args = array(
|
154 |
return 'fail';
|
155 |
}
|
156 |
|
157 |
+
// Because the 'Age' header is an important check, wait two seconds before
|
158 |
+
// fetching again.
|
159 |
+
sleep( 2 );
|
160 |
|
161 |
$response2 = wp_remote_get( $url, $args );
|
162 |
|
190 |
$message .= $response->get_error_message();
|
191 |
} elseif ( '404' === wp_remote_retrieve_response_code( $response ) ) {
|
192 |
$preflight = false;
|
193 |
+
$message = __( 'This URL does not resolve properly. Either it was not found or it redirects incorrectly.', 'varnish-http-purge' );
|
194 |
}
|
195 |
|
196 |
$return = array(
|
295 |
}
|
296 |
}
|
297 |
|
298 |
+
if ( ! isset( $cache_service ) || ! $cache_service ) {
|
299 |
$return['icon'] = 'bad';
|
300 |
$return['message'] = __( 'No known cache service has been detected on your site.', 'varnish-http-purge' );
|
301 |
} elseif ( ! $kronk ) {
|
303 |
$return['message'] = __( 'Your site is not responding. If this happens again, please contact your webhost.', 'varnish-http-purge' );
|
304 |
} elseif ( ! $cacheheaders_set ) {
|
305 |
$return['icon'] = 'notice';
|
306 |
+
$return['message'] = __( 'We were unable find a caching service active for this domain. This may occur if you use a proxy service (such as CloudFlare or Sucuri), your host removed the X-Cacheable tag, or if you\'re in the middle of a DNS move.', 'varnish-http-purge' );
|
307 |
} elseif ( $is_cachable && $still_cachable ) {
|
308 |
$return['icon'] = 'awesome';
|
309 |
} else {
|
310 |
// translators: %1 is the type of caching service detected (i.e. nginx or varnish).
|
311 |
+
$return['message'] = sprintf( __( 'We detected that the %1s caching service is running, but we are unable to determine that it\'s working.', 'varnish-http-purge' ), $cache_service );
|
312 |
$return['icon'] = 'warning';
|
313 |
}
|
314 |
|
333 |
$x_nginx = ( isset( $headers['server'] ) && ( strpos( $headers['server'], 'nginx' ) !== false || strpos( $headers['server'], 'openresty' ) !== false ) ) ? true : false;
|
334 |
|
335 |
if ( $x_nginx && 'localhost' === $varniship ) {
|
336 |
+
// This is a pretty DreamHost specific check. If other hosts want to use it,
|
337 |
+
// or extend it, please let me know.
|
338 |
$return = array(
|
|
|
339 |
'message' => __( 'Your Nginx Proxy is set up correctly.', 'varnish-http-purge' ),
|
340 |
+
'icon' => 'awesome',
|
341 |
);
|
342 |
} elseif ( false === $remote_ip && ! empty( $varniship ) ) {
|
343 |
$return = array(
|
344 |
// translators: %s is an IP address.
|
345 |
'message' => sprintf( __( 'Your Proxy IP address is set to %s 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 the IP. Please check with your webhost or server admin before doing so.', 'varnish-http-purge' ), $varniship ),
|
346 |
+
'icon' => 'notice',
|
347 |
);
|
348 |
} elseif ( false !== $remote_ip && 'cloudflare' !== $remote_ip && $remote_ip !== $varniship ) {
|
349 |
$return = array(
|
|
|
350 |
'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' ),
|
351 |
+
'icon' => 'notice',
|
352 |
);
|
353 |
} else {
|
354 |
$return = array(
|
|
|
355 |
'message' => __( 'Your server IP setup looks good.', 'varnish-http-purge' ),
|
356 |
+
'icon' => 'awesome',
|
357 |
);
|
358 |
}
|
359 |
|
633 |
} else {
|
634 |
$return['Mod Pagespeed'] = array(
|
635 |
'icon' => 'bad',
|
636 |
+
'message' => __( 'Mod Pagespeed is active but your caching headers may not be correct. 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' ),
|
637 |
);
|
638 |
}
|
639 |
}
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: Ipstenu, mikeschroder, techpriester, danielbachhuber
|
3 |
Tags: proxy, purge, cache, varnish, nginx
|
4 |
Requires at least: 5.0
|
5 |
-
Tested up to: 5.
|
6 |
-
Stable tag: 5.0
|
7 |
Requires PHP: 5.6
|
8 |
|
9 |
Automatically empty proxy cached content when your site is modified.
|
@@ -109,6 +109,24 @@ No. This plugin tells your cache system when content is updated, and to delete t
|
|
109 |
|
110 |
Speed and stability. Emptying too much of a cache on every change can slow a server down. This plugin does it's best to determine what needs to be deleted and when, while providing hooks for developers to use as necessary.
|
111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
= Can I delete the entire cache? =
|
113 |
|
114 |
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.
|
@@ -129,7 +147,9 @@ Yes. [Full documentation can be found on Custom Filters in the wiki](https://git
|
|
129 |
|
130 |
= Can I turn off caching? =
|
131 |
|
132 |
-
|
|
|
|
|
133 |
|
134 |
There are three ways to do this:
|
135 |
|
@@ -227,30 +247,13 @@ This plugin is installed by default for _all_ DreamPress installs on DreamHost,
|
|
227 |
|
228 |
== Changelog ==
|
229 |
|
230 |
-
= 5.
|
231 |
-
*
|
232 |
-
*
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
= 5.0.1 =
|
239 |
-
* April 2021
|
240 |
-
* Updating incompatibility lists
|
241 |
-
* HHVM deprecation
|
242 |
-
* Allow saving Proxy IP with ports
|
243 |
-
* Add check for CloudFlare APO
|
244 |
-
* Improve purge execution fails
|
245 |
-
* Double check multiple varnish IPs
|
246 |
-
|
247 |
-
= 5.0 =
|
248 |
-
* March 2021
|
249 |
-
* Now purges draft and pending posts (to account for people who un-publish) - props @jerlarke
|
250 |
-
* Localhost the debugger json. They aren't updated that often, and the remote load is unnecessary.
|
251 |
-
* More support for Health Check
|
252 |
-
* Remove strtotime check on Age header - props Matt Fields
|
253 |
-
* Support for multiple IPs (based on P.Brisson's work)
|
254 |
|
255 |
== Screenshots ==
|
256 |
|
2 |
Contributors: Ipstenu, mikeschroder, techpriester, danielbachhuber
|
3 |
Tags: proxy, purge, cache, varnish, nginx
|
4 |
Requires at least: 5.0
|
5 |
+
Tested up to: 5.9
|
6 |
+
Stable tag: 5.1.0
|
7 |
Requires PHP: 5.6
|
8 |
|
9 |
Automatically empty proxy cached content when your site is modified.
|
109 |
|
110 |
Speed and stability. Emptying too much of a cache on every change can slow a server down. This plugin does it's best to determine what needs to be deleted and when, while providing hooks for developers to use as necessary.
|
111 |
|
112 |
+
= How many cached files are deleted when a post is updated? =
|
113 |
+
|
114 |
+
It depends on the post, but in general the tool will delete cached content for:
|
115 |
+
|
116 |
+
1. The post name
|
117 |
+
2. The front page of the site
|
118 |
+
3. All first pages of related tags/categories
|
119 |
+
4. The JSON API pages
|
120 |
+
5. All related RSS feeds
|
121 |
+
|
122 |
+
= Is there a limit to how many pages I can purge at once? =
|
123 |
+
|
124 |
+
Not really, but in order to prevent your site from crashing by running the same checks over and over, if you try to purge more than 50 URLs at once, the plugin will do a full purge. Normally this never happens, but there are some plugins that hook into the options to add more pages to purge on an update.
|
125 |
+
|
126 |
+
You can change this value in your settings, or via the define VHP_VARNISH_MAXPOSTS in your `wp-config.php` file.
|
127 |
+
|
128 |
+
Keep in mind, the count of 50 <em>does not</em> include category/tags, API, or RSS pages. It's just the sheer number of individual posts/pages you're trying to purge at once.
|
129 |
+
|
130 |
= Can I delete the entire cache? =
|
131 |
|
132 |
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.
|
147 |
|
148 |
= Can I turn off caching? =
|
149 |
|
150 |
+
Not permanently, and remember that this plugin is not actually caching your content.
|
151 |
+
|
152 |
+
You can use development mode to have WordPress attempt to tell your proxy service not to serve cached content, but the content will still be cached by the service.
|
153 |
|
154 |
There are three ways to do this:
|
155 |
|
247 |
|
248 |
== Changelog ==
|
249 |
|
250 |
+
= 5.1 =
|
251 |
+
* February 2022
|
252 |
+
* WP 5.9 Compat
|
253 |
+
* Rate limiting to prevent abuse - if you try to purge more than the max number of posts in a go (default 50), a purge ALL is triggered
|
254 |
+
* Allows customizing the purge URL to support: (credit mickaelperrin)
|
255 |
+
- Nginx cache purge mechanism that doesn't support regex directives
|
256 |
+
- Custom purge location
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
|
258 |
== Screenshots ==
|
259 |
|
settings.php
CHANGED
@@ -58,6 +58,11 @@ class VarnishStatus {
|
|
58 |
add_settings_section( 'vhp-settings-devmode-section', __( 'Development Mode Settings', 'varnish-http-purge' ), array( &$this, 'options_settings_devmode' ), 'varnish-devmode-settings' );
|
59 |
add_settings_field( 'varnish_devmode', __( 'Development Mode', 'varnish-http-purge' ), array( &$this, 'settings_devmode_callback' ), 'varnish-devmode-settings', 'vhp-settings-devmode-section' );
|
60 |
|
|
|
|
|
|
|
|
|
|
|
61 |
// IP Settings.
|
62 |
register_setting( 'vhp-settings-ip', 'vhp_varnish_ip', array( &$this, 'settings_ip_sanitize' ) );
|
63 |
add_settings_section( 'vhp-settings-ip-section', __( 'Configure Custom IP', 'varnish-http-purge' ), array( &$this, 'options_settings_ip' ), 'varnish-ip-settings' );
|
@@ -86,7 +91,7 @@ class VarnishStatus {
|
|
86 |
$devmode = get_site_option( 'vhp_varnish_devmode', VarnishPurger::$devmode );
|
87 |
$active = ( isset( $devmode['active'] ) ) ? $devmode['active'] : false;
|
88 |
$active = ( VHP_DEVMODE ) ? true : $active;
|
89 |
-
$expire =
|
90 |
?>
|
91 |
<input type="hidden" name="vhp_varnish_devmode[expire]" value="<?php $expire; ?>" />
|
92 |
<input type="checkbox" name="vhp_varnish_devmode[active]" value="true" <?php disabled( VHP_DEVMODE ); ?> <?php checked( $active, true ); ?> />
|
@@ -115,7 +120,7 @@ class VarnishStatus {
|
|
115 |
public function settings_devmode_sanitize( $input ) {
|
116 |
|
117 |
$output = array();
|
118 |
-
$expire =
|
119 |
$set_message = __( 'Something has gone wrong!', 'varnish-http-purge' );
|
120 |
$set_type = 'error';
|
121 |
|
@@ -137,6 +142,71 @@ class VarnishStatus {
|
|
137 |
return $output;
|
138 |
}
|
139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
/**
|
141 |
* Options Settings - IP Address
|
142 |
*
|
@@ -160,7 +230,7 @@ class VarnishStatus {
|
|
160 |
public function settings_ip_callback() {
|
161 |
|
162 |
$disabled = false;
|
163 |
-
if ( false !== VHP_VARNISH_IP ) {
|
164 |
$disabled = true;
|
165 |
$varniship = VHP_VARNISH_IP;
|
166 |
} else {
|
@@ -281,7 +351,7 @@ class VarnishStatus {
|
|
281 |
$remote_ip = VarnishDebug::remote_ip( $headers );
|
282 |
|
283 |
// Get the IP.
|
284 |
-
if ( false !== VHP_VARNISH_IP ) {
|
285 |
$varniship = VHP_VARNISH_IP;
|
286 |
} else {
|
287 |
$varniship = get_site_option( 'vhp_varnish_ip' );
|
@@ -425,7 +495,15 @@ class VarnishStatus {
|
|
425 |
<?php
|
426 |
settings_fields( 'vhp-settings-devmode' );
|
427 |
do_settings_sections( 'varnish-devmode-settings' );
|
428 |
-
submit_button( __( 'Save Settings', 'varnish-http-purge' ), 'primary' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
429 |
?>
|
430 |
</form>
|
431 |
|
@@ -433,7 +511,7 @@ class VarnishStatus {
|
|
433 |
<?php
|
434 |
settings_fields( 'vhp-settings-ip' );
|
435 |
do_settings_sections( 'varnish-ip-settings' );
|
436 |
-
submit_button( __( 'Save IP', 'varnish-http-purge' ), 'secondary' );
|
437 |
?>
|
438 |
</form>
|
439 |
<?php
|
58 |
add_settings_section( 'vhp-settings-devmode-section', __( 'Development Mode Settings', 'varnish-http-purge' ), array( &$this, 'options_settings_devmode' ), 'varnish-devmode-settings' );
|
59 |
add_settings_field( 'varnish_devmode', __( 'Development Mode', 'varnish-http-purge' ), array( &$this, 'settings_devmode_callback' ), 'varnish-devmode-settings', 'vhp-settings-devmode-section' );
|
60 |
|
61 |
+
// Purge All settings
|
62 |
+
register_setting( 'vhp-settings-maxposts', 'vhp_varnish_max_posts_before_all', array( &$this, 'settings_maxposts_sanitize' ) );
|
63 |
+
add_settings_section( 'vhp-settings-maxposts-section', __( 'Maximum Individual URLs before Full Purge', 'varnish-http-purge' ), array( &$this, 'options_settings_maxposts' ), 'varnish-maxposts-settings' );
|
64 |
+
add_settings_field( 'varnish_maxposts', __( 'Set Max URLs', 'varnish-http-purge' ), array( &$this, 'settings_maxposts_callback' ), 'varnish-maxposts-settings', 'vhp-settings-maxposts-section' );
|
65 |
+
|
66 |
// IP Settings.
|
67 |
register_setting( 'vhp-settings-ip', 'vhp_varnish_ip', array( &$this, 'settings_ip_sanitize' ) );
|
68 |
add_settings_section( 'vhp-settings-ip-section', __( 'Configure Custom IP', 'varnish-http-purge' ), array( &$this, 'options_settings_ip' ), 'varnish-ip-settings' );
|
91 |
$devmode = get_site_option( 'vhp_varnish_devmode', VarnishPurger::$devmode );
|
92 |
$active = ( isset( $devmode['active'] ) ) ? $devmode['active'] : false;
|
93 |
$active = ( VHP_DEVMODE ) ? true : $active;
|
94 |
+
$expire = time() + DAY_IN_SECONDS;
|
95 |
?>
|
96 |
<input type="hidden" name="vhp_varnish_devmode[expire]" value="<?php $expire; ?>" />
|
97 |
<input type="checkbox" name="vhp_varnish_devmode[active]" value="true" <?php disabled( VHP_DEVMODE ); ?> <?php checked( $active, true ); ?> />
|
120 |
public function settings_devmode_sanitize( $input ) {
|
121 |
|
122 |
$output = array();
|
123 |
+
$expire = time() + DAY_IN_SECONDS;
|
124 |
$set_message = __( 'Something has gone wrong!', 'varnish-http-purge' );
|
125 |
$set_type = 'error';
|
126 |
|
142 |
return $output;
|
143 |
}
|
144 |
|
145 |
+
/**
|
146 |
+
* Options Settings - Max Posts before Purge All
|
147 |
+
*
|
148 |
+
* @since 4.0
|
149 |
+
*/
|
150 |
+
public function options_settings_maxposts() {
|
151 |
+
?>
|
152 |
+
<p><a name="#configuremaxposts"></a><?php esc_html_e( 'Since it\'s possible to purge multiple URLs in sequence, there can be cases where too many URLs are queued at a time. In order to minimize disruption, the plugin has a limit of how many URLs can be queued before it runs a "purge all" instead. You can customize that here.', 'varnish-http-purge' ); ?></strong></p>
|
153 |
+
<?php
|
154 |
+
}
|
155 |
+
|
156 |
+
/**
|
157 |
+
* Settings - Max Posts before purge All
|
158 |
+
*
|
159 |
+
* @since 4.0
|
160 |
+
*/
|
161 |
+
public function settings_maxposts_callback() {
|
162 |
+
|
163 |
+
$disabled = false;
|
164 |
+
if ( defined( 'VHP_VARNISH_MAXPOSTS' ) && false !== VHP_VARNISH_MAXPOSTS ) {
|
165 |
+
$disabled = true;
|
166 |
+
$max_posts = VHP_VARNISH_MAXPOSTS;
|
167 |
+
} else {
|
168 |
+
$max_posts = get_site_option( 'vhp_varnish_max_posts_before_all' );
|
169 |
+
}
|
170 |
+
|
171 |
+
?>
|
172 |
+
<input type="number" id="vhp_varnish_max_posts_before_all" name="vhp_varnish_max_posts_before_all" value="<?php echo esc_attr( $max_posts ); ?>" size="5" <?php disabled( $disabled, true ); ?> />
|
173 |
+
<label for="vhp_varnish_max_posts_before_all">
|
174 |
+
<?php
|
175 |
+
if ( $disabled ) {
|
176 |
+
esc_html_e( 'A maximum value has been defined in your wp-config file, so it is not editable in settings.', 'varnish-http-purge' );
|
177 |
+
} else {
|
178 |
+
esc_html_e( 'The default value is "50" URLs. It is not recommended to set this above 75.', 'varnish-http-purge' );
|
179 |
+
}
|
180 |
+
echo '</label>';
|
181 |
+
}
|
182 |
+
|
183 |
+
/**
|
184 |
+
* Sanitization and validation for Max Posts before purge All
|
185 |
+
*
|
186 |
+
* @param mixed $input - the input to be sanitized.
|
187 |
+
* @since 4.0
|
188 |
+
*/
|
189 |
+
public function settings_maxposts_sanitize( $input ) {
|
190 |
+
|
191 |
+
// default settings.
|
192 |
+
$output = get_site_option( 'vhp_varnish_max_posts_before_all' );
|
193 |
+
$set_message = __( 'You have entered an invalid number.', 'varnish-http-purge' );
|
194 |
+
$set_type = 'error';
|
195 |
+
|
196 |
+
if ( empty( $input ) ) {
|
197 |
+
// No input, do nothing.
|
198 |
+
return;
|
199 |
+
} elseif ( is_numeric( $input ) ) {
|
200 |
+
// If it's numeric, update.
|
201 |
+
$set_message = __( 'Number of Maximum URLs before a purge have been updated.', 'varnish-http-purge' );
|
202 |
+
$set_type = 'updated';
|
203 |
+
$output = (int) $input;
|
204 |
+
}
|
205 |
+
|
206 |
+
add_settings_error( 'vhp_varnish_max_posts_before_all', 'varnish-maxposts', $set_message, $set_type );
|
207 |
+
return $output;
|
208 |
+
}
|
209 |
+
|
210 |
/**
|
211 |
* Options Settings - IP Address
|
212 |
*
|
230 |
public function settings_ip_callback() {
|
231 |
|
232 |
$disabled = false;
|
233 |
+
if ( defined( 'VHP_VARNISH_IP' ) && false !== VHP_VARNISH_IP ) {
|
234 |
$disabled = true;
|
235 |
$varniship = VHP_VARNISH_IP;
|
236 |
} else {
|
351 |
$remote_ip = VarnishDebug::remote_ip( $headers );
|
352 |
|
353 |
// Get the IP.
|
354 |
+
if ( defined( 'VHP_VARNISH_IP' ) && false !== VHP_VARNISH_IP ) {
|
355 |
$varniship = VHP_VARNISH_IP;
|
356 |
} else {
|
357 |
$varniship = get_site_option( 'vhp_varnish_ip' );
|
495 |
<?php
|
496 |
settings_fields( 'vhp-settings-devmode' );
|
497 |
do_settings_sections( 'varnish-devmode-settings' );
|
498 |
+
submit_button( __( 'Save Devmode Settings', 'varnish-http-purge' ), 'primary' );
|
499 |
+
?>
|
500 |
+
</form>
|
501 |
+
|
502 |
+
<form action="options.php" method="POST" >
|
503 |
+
<?php
|
504 |
+
settings_fields( 'vhp-settings-maxposts' );
|
505 |
+
do_settings_sections( 'varnish-maxposts-settings' );
|
506 |
+
submit_button( __( 'Save Maxposts Settings', 'varnish-http-purge' ), 'primary' );
|
507 |
?>
|
508 |
</form>
|
509 |
|
511 |
<?php
|
512 |
settings_fields( 'vhp-settings-ip' );
|
513 |
do_settings_sections( 'varnish-ip-settings' );
|
514 |
+
submit_button( __( 'Save IP Settings', 'varnish-http-purge' ), 'secondary' );
|
515 |
?>
|
516 |
</form>
|
517 |
<?php
|
uninstall.php
CHANGED
@@ -11,3 +11,4 @@ if ( ! defined( 'ABSPATH' ) && ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
|
11 |
delete_site_option( 'vhp_varnish_url' );
|
12 |
delete_site_option( 'vhp_varnish_ip' );
|
13 |
delete_site_option( 'vhp_varnish_devmode' );
|
|
11 |
delete_site_option( 'vhp_varnish_url' );
|
12 |
delete_site_option( 'vhp_varnish_ip' );
|
13 |
delete_site_option( 'vhp_varnish_devmode' );
|
14 |
+
delete_site_option( 'vhp_varnish_max_posts_before_all' );
|
varnish-http-purge.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Proxy Cache Purge
|
4 |
* Plugin URI: https://github.com/ipstenu/varnish-http-purge/
|
5 |
* Description: Automatically empty cached pages when content on your site is modified.
|
6 |
-
* Version: 5.0
|
7 |
* Author: Mika Epstein
|
8 |
* Author URI: https://halfelf.org/
|
9 |
* License: http://www.apache.org/licenses/LICENSE-2.0
|
@@ -12,7 +12,7 @@
|
|
12 |
*
|
13 |
* @package varnish-http-purge
|
14 |
*
|
15 |
-
* Copyright 2016-
|
16 |
*
|
17 |
* This file is part of Proxy Cache Purge, a plugin for WordPress.
|
18 |
*
|
@@ -72,7 +72,7 @@ class VarnishPurger {
|
|
72 |
// Development mode defaults to off.
|
73 |
self::$devmode = array(
|
74 |
'active' => false,
|
75 |
-
'expire' =>
|
76 |
);
|
77 |
if ( ! get_site_option( 'vhp_varnish_devmode' ) ) {
|
78 |
update_site_option( 'vhp_varnish_devmode', self::$devmode );
|
@@ -93,6 +93,11 @@ class VarnishPurger {
|
|
93 |
update_site_option( 'vhp_varnish_debug', array( $this->the_home_url() => array() ) );
|
94 |
}
|
95 |
|
|
|
|
|
|
|
|
|
|
|
96 |
// Release the hounds!
|
97 |
add_action( 'init', array( &$this, 'init' ) );
|
98 |
add_action( 'admin_init', array( &$this, 'admin_init' ) );
|
@@ -297,7 +302,7 @@ class VarnishPurger {
|
|
297 |
$message = __( 'Proxy Cache Purge Development Mode has been activated via wp-config.', 'varnish-http-purge' );
|
298 |
} else {
|
299 |
$devmode = get_site_option( 'vhp_varnish_devmode', self::$devmode );
|
300 |
-
$time = human_time_diff(
|
301 |
|
302 |
if ( ! $devmode['active'] ) {
|
303 |
if ( ! is_multisite() ) {
|
@@ -588,9 +593,29 @@ class VarnishPurger {
|
|
588 |
$purge_urls = array_unique( $this->purge_urls );
|
589 |
|
590 |
if ( ! empty( $purge_urls ) && is_array( $purge_urls ) ) {
|
591 |
-
|
592 |
-
|
593 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
594 |
}
|
595 |
} elseif ( isset( $_GET ) ) {
|
596 |
// Otherwise, if we've passed a GET call...
|
@@ -742,7 +767,7 @@ class VarnishPurger {
|
|
742 |
*
|
743 |
* @since 4.1
|
744 |
*/
|
745 |
-
$headers
|
746 |
'varnish_http_purge_headers',
|
747 |
array(
|
748 |
'host' => $host_headers,
|
3 |
* Plugin Name: Proxy Cache Purge
|
4 |
* Plugin URI: https://github.com/ipstenu/varnish-http-purge/
|
5 |
* Description: Automatically empty cached pages when content on your site is modified.
|
6 |
+
* Version: 5.1.0
|
7 |
* Author: Mika Epstein
|
8 |
* Author URI: https://halfelf.org/
|
9 |
* License: http://www.apache.org/licenses/LICENSE-2.0
|
12 |
*
|
13 |
* @package varnish-http-purge
|
14 |
*
|
15 |
+
* Copyright 2016-2022 Mika Epstein (email: ipstenu@halfelf.org)
|
16 |
*
|
17 |
* This file is part of Proxy Cache Purge, a plugin for WordPress.
|
18 |
*
|
72 |
// Development mode defaults to off.
|
73 |
self::$devmode = array(
|
74 |
'active' => false,
|
75 |
+
'expire' => time(),
|
76 |
);
|
77 |
if ( ! get_site_option( 'vhp_varnish_devmode' ) ) {
|
78 |
update_site_option( 'vhp_varnish_devmode', self::$devmode );
|
93 |
update_site_option( 'vhp_varnish_debug', array( $this->the_home_url() => array() ) );
|
94 |
}
|
95 |
|
96 |
+
// Default Max posts to purge before purge all happens instead.
|
97 |
+
if ( ! get_site_option( 'vhp_varnish_max_posts_before_all' ) ) {
|
98 |
+
update_site_option( 'vhp_varnish_max_posts_before_all', 50 );
|
99 |
+
}
|
100 |
+
|
101 |
// Release the hounds!
|
102 |
add_action( 'init', array( &$this, 'init' ) );
|
103 |
add_action( 'admin_init', array( &$this, 'admin_init' ) );
|
302 |
$message = __( 'Proxy Cache Purge Development Mode has been activated via wp-config.', 'varnish-http-purge' );
|
303 |
} else {
|
304 |
$devmode = get_site_option( 'vhp_varnish_devmode', self::$devmode );
|
305 |
+
$time = human_time_diff( time(), $devmode['expire'] );
|
306 |
|
307 |
if ( ! $devmode['active'] ) {
|
308 |
if ( ! is_multisite() ) {
|
593 |
$purge_urls = array_unique( $this->purge_urls );
|
594 |
|
595 |
if ( ! empty( $purge_urls ) && is_array( $purge_urls ) ) {
|
596 |
+
|
597 |
+
// If there are URLs to purge and it's an array, we'll likely purge.
|
598 |
+
|
599 |
+
// Number of URLs to purge.
|
600 |
+
$count = count( $purge_urls );
|
601 |
+
|
602 |
+
// Max posts
|
603 |
+
if ( defined( 'VHP_VARNISH_MAXPOSTS' ) && false !== VHP_VARNISH_MAXPOSTS ) {
|
604 |
+
$max_posts = VHP_VARNISH_MAXPOSTS;
|
605 |
+
} else {
|
606 |
+
$max_posts = get_option( 'vhp_varnish_max_posts_before_all' );
|
607 |
+
}
|
608 |
+
|
609 |
+
// If there are more than vhp_varnish_max_posts_before_all URLs to purge (default 50),
|
610 |
+
// do a purge ALL instead. Else, do the normal.
|
611 |
+
if ( $max_posts <= $count ) {
|
612 |
+
// Too many URLs, purge all instead.
|
613 |
+
$this->purge_url( $this->the_home_url() . '/?vhp-regex' );
|
614 |
+
} else {
|
615 |
+
// Purge each URL.
|
616 |
+
foreach ( $purge_urls as $url ) {
|
617 |
+
$this->purge_url( $url );
|
618 |
+
}
|
619 |
}
|
620 |
} elseif ( isset( $_GET ) ) {
|
621 |
// Otherwise, if we've passed a GET call...
|
767 |
*
|
768 |
* @since 4.1
|
769 |
*/
|
770 |
+
$headers = apply_filters(
|
771 |
'varnish_http_purge_headers',
|
772 |
array(
|
773 |
'host' => $host_headers,
|