Version Description
- March 2021
- Now purges draft and pending posts (to account for people who un-publish) - props @jerlarke
- Localhost the debugger json. They aren't updated that often, and the remote load is unnecessary.
- More support for Health Check
- Remove strtotime check on Age header - props Matt Fields
- Support for multiple IPs (based on P.Brisson's work)
=
Download this release
Release Info
Developer | Ipstenu |
Plugin | Varnish HTTP Purge |
Version | 5.0 |
Comparing to | |
See all releases |
Code changes from version 4.8.1 to 5.0
- changelog.txt +12 -0
- debug.php +24 -44
- debugger/cookies.json +82 -0
- debugger/plugins.json +176 -0
- debugger/themes.json +18 -0
- health-check.php +94 -0
- readme.txt +40 -24
- settings.php +23 -14
- varnish-http-purge.php +103 -65
changelog.txt
CHANGED
@@ -1,5 +1,17 @@
|
|
1 |
## CHANGELOG
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
= 4.7.3 =
|
4 |
* December 2018
|
5 |
* Bugfix for Jetpack (Props @jherve)
|
1 |
## CHANGELOG
|
2 |
|
3 |
+
= 4.8.1 =
|
4 |
+
* May 2019
|
5 |
+
* Compat with WP 5.2
|
6 |
+
* Correct changes with DB cache flushing (props @mathieuhays)
|
7 |
+
* Simplified logic for edge case debugging
|
8 |
+
|
9 |
+
= 4.8 =
|
10 |
+
* March 2019
|
11 |
+
* Improve debugger
|
12 |
+
* Clean code per standards
|
13 |
+
* Improve callback on WP-CLI
|
14 |
+
|
15 |
= 4.7.3 =
|
16 |
* December 2018
|
17 |
* Bugfix for Jetpack (Props @jherve)
|
debug.php
CHANGED
@@ -342,10 +342,10 @@ class VarnishDebug {
|
|
342 |
} elseif ( false === $remote_ip && ! empty( $varniship ) ) {
|
343 |
$return = array(
|
344 |
// translators: %s is an IP address.
|
345 |
-
'message' => sprintf( __( 'Your
|
346 |
'icon' => 'warning',
|
347 |
);
|
348 |
-
} elseif ( false !== $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' ),
|
@@ -397,7 +397,7 @@ class VarnishDebug {
|
|
397 |
if ( strpos( $headers['Server'], 'cloudflare' ) !== false ) {
|
398 |
$return['CloudFlare'] = array(
|
399 |
'icon' => 'warning',
|
400 |
-
'message' => __( 'CloudFlare has been detected. Make sure you configure WordPress properly by adding your
|
401 |
);
|
402 |
}
|
403 |
|
@@ -405,7 +405,7 @@ class VarnishDebug {
|
|
405 |
if ( isset( $headers['X-Powered-By'] ) && strpos( $headers['X-Powered-By'], 'HHVM' ) !== false ) {
|
406 |
$return['HHVM'] = array(
|
407 |
'icon' => 'notice',
|
408 |
-
'message' => __( 'You are running HHVM instead of PHP. While that is compatible with Varnish, you should consider PHP 7. WordPress
|
409 |
);
|
410 |
}
|
411 |
|
@@ -417,6 +417,13 @@ class VarnishDebug {
|
|
417 |
}
|
418 |
}
|
419 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
420 |
if ( isset( $headers['X-hacker'] ) ) {
|
421 |
$return['WordPress.com'] = array(
|
422 |
'icon' => 'bad',
|
@@ -496,14 +503,8 @@ class VarnishDebug {
|
|
496 |
);
|
497 |
|
498 |
// Let's check our known bad cookies.
|
499 |
-
$
|
500 |
-
|
501 |
-
if ( is_wp_error( $request ) ) {
|
502 |
-
return $return; // Bail if we can't hit the server.
|
503 |
-
}
|
504 |
-
|
505 |
-
$body = wp_remote_retrieve_body( $request );
|
506 |
-
$cookies = json_decode( $body );
|
507 |
|
508 |
if ( empty( $cookies ) ) {
|
509 |
if ( WP_DEBUG ) {
|
@@ -599,11 +600,6 @@ class VarnishDebug {
|
|
599 |
'message' => sprintf( __( 'The "Age" header is returning %s, which means it is not properly caching. Either this URL is intentionally excluded from caching, or a theme or plugin is instructing WordPress not to cache.', 'varnish-http-purge' ), $age_header ),
|
600 |
'icon' => 'warning',
|
601 |
);
|
602 |
-
} elseif ( (bool) strtotime( $headers['Age'] ) && time() <= strtotime( $headers['Age'] ) ) {
|
603 |
-
$return['Age Headers'] = array(
|
604 |
-
'icon' => 'bad',
|
605 |
-
'message' => __( 'The "Age" header is set to an invalid time, which will result in incorrect caching.', 'varnish-http-purge' ),
|
606 |
-
);
|
607 |
} else {
|
608 |
$return['Age Headers'] = array(
|
609 |
'icon' => 'awesome',
|
@@ -659,20 +655,9 @@ class VarnishDebug {
|
|
659 |
public static function bad_themes_results() {
|
660 |
|
661 |
$return = array();
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
if ( WP_DEBUG ) {
|
666 |
-
$return['Theme Check'] = array(
|
667 |
-
'icon' => 'warning',
|
668 |
-
'message' => __( 'Error: Theme data cannot be loaded.', 'varnish-http-purge' ),
|
669 |
-
);
|
670 |
-
}
|
671 |
-
return $return; // Bail early.
|
672 |
-
}
|
673 |
-
|
674 |
-
$body = wp_remote_retrieve_body( $request );
|
675 |
-
$themes = json_decode( $body );
|
676 |
|
677 |
if ( empty( $themes ) ) {
|
678 |
if ( WP_DEBUG ) {
|
@@ -733,6 +718,7 @@ class VarnishDebug {
|
|
733 |
|
734 |
$return = array();
|
735 |
$messages = array(
|
|
|
736 |
'incompatible' => __( 'This plugin has unexpected results with caching, making not function properly.', 'varnish-http-purge' ),
|
737 |
'translation' => __( 'Translation plugins that use cookies and/or sessions prevent most server side caching from running properly.', 'varnish-http-purge' ),
|
738 |
'sessions' => __( 'This plugin uses sessions, which conflicts with server side caching.', 'varnish-http-purge' ),
|
@@ -743,19 +729,8 @@ class VarnishDebug {
|
|
743 |
'maybe' => __( 'This plugin is usually fine, but may be configured in a way that breaks caching. Please resolve all other errors. If this is the only one left, and caching is running, you may safely ignore this message.', 'varnish-http-purge' ),
|
744 |
);
|
745 |
|
746 |
-
$
|
747 |
-
|
748 |
-
if ( WP_DEBUG ) {
|
749 |
-
$return['Plugin Check'] = array(
|
750 |
-
'icon' => 'warning',
|
751 |
-
'message' => __( 'Error: Plugin data cannot be loaded.', 'varnish-http-purge' ),
|
752 |
-
);
|
753 |
-
}
|
754 |
-
return $return; // Bail early.
|
755 |
-
}
|
756 |
-
|
757 |
-
$body = wp_remote_retrieve_body( $request );
|
758 |
-
$plugins = json_decode( $body );
|
759 |
|
760 |
if ( empty( $plugins ) ) {
|
761 |
if ( WP_DEBUG ) {
|
@@ -847,6 +822,11 @@ class VarnishDebug {
|
|
847 |
$bad_themes_results = self::bad_themes_results();
|
848 |
$output = array_merge( $output, $bad_themes_results );
|
849 |
|
|
|
|
|
|
|
|
|
|
|
850 |
return $output;
|
851 |
}
|
852 |
}
|
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' => 'warning',
|
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' ),
|
397 |
if ( strpos( $headers['Server'], 'cloudflare' ) !== false ) {
|
398 |
$return['CloudFlare'] = array(
|
399 |
'icon' => 'warning',
|
400 |
+
'message' => __( 'CloudFlare has been detected. Make sure you configure WordPress properly by adding your Cache IP and to flush the CloudFlare cache if you see inconsistencies.', 'varnish-http-purge' ),
|
401 |
);
|
402 |
}
|
403 |
|
405 |
if ( isset( $headers['X-Powered-By'] ) && strpos( $headers['X-Powered-By'], 'HHVM' ) !== false ) {
|
406 |
$return['HHVM'] = array(
|
407 |
'icon' => 'notice',
|
408 |
+
'message' => __( 'You are running HHVM instead of PHP. While that is compatible with Varnish and Nginx, you should consider PHP 7. WordPress no longer supports HHVM.', 'varnish-http-purge' ),
|
409 |
);
|
410 |
}
|
411 |
|
417 |
}
|
418 |
}
|
419 |
|
420 |
+
if ( isset( $headers['X-Powered-By'] ) && strpos( $headers['X-Powered-By'], 'DreamPress' ) !== false ) {
|
421 |
+
$return['DreamHost'] = array(
|
422 |
+
'icon' => 'awesome',
|
423 |
+
'message' => __( 'This site is hosted on DreamHost (as DreamPress). The results of this scan will be accurate.', 'varnish-http-purge' ),
|
424 |
+
);
|
425 |
+
}
|
426 |
+
|
427 |
if ( isset( $headers['X-hacker'] ) ) {
|
428 |
$return['WordPress.com'] = array(
|
429 |
'icon' => 'bad',
|
503 |
);
|
504 |
|
505 |
// Let's check our known bad cookies.
|
506 |
+
$json_data = file_get_contents( plugin_dir_path( __FILE__ ) . 'debugger/cookies.json' );
|
507 |
+
$cookies = json_decode( $json_data );
|
|
|
|
|
|
|
|
|
|
|
|
|
508 |
|
509 |
if ( empty( $cookies ) ) {
|
510 |
if ( WP_DEBUG ) {
|
600 |
'message' => sprintf( __( 'The "Age" header is returning %s, which means it is not properly caching. Either this URL is intentionally excluded from caching, or a theme or plugin is instructing WordPress not to cache.', 'varnish-http-purge' ), $age_header ),
|
601 |
'icon' => 'warning',
|
602 |
);
|
|
|
|
|
|
|
|
|
|
|
603 |
} else {
|
604 |
$return['Age Headers'] = array(
|
605 |
'icon' => 'awesome',
|
655 |
public static function bad_themes_results() {
|
656 |
|
657 |
$return = array();
|
658 |
+
// Let's check our known bad themes.
|
659 |
+
$json_data = file_get_contents( plugin_dir_path( __FILE__ ) . 'debugger/themes.json' );
|
660 |
+
$themes = json_decode( $json_data );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
661 |
|
662 |
if ( empty( $themes ) ) {
|
663 |
if ( WP_DEBUG ) {
|
718 |
|
719 |
$return = array();
|
720 |
$messages = array(
|
721 |
+
'addon' => __( 'This plugin may require add-ons to ensure full compatibility. Please check their documentation.', 'varnish-http-purge' ),
|
722 |
'incompatible' => __( 'This plugin has unexpected results with caching, making not function properly.', 'varnish-http-purge' ),
|
723 |
'translation' => __( 'Translation plugins that use cookies and/or sessions prevent most server side caching from running properly.', 'varnish-http-purge' ),
|
724 |
'sessions' => __( 'This plugin uses sessions, which conflicts with server side caching.', 'varnish-http-purge' ),
|
729 |
'maybe' => __( 'This plugin is usually fine, but may be configured in a way that breaks caching. Please resolve all other errors. If this is the only one left, and caching is running, you may safely ignore this message.', 'varnish-http-purge' ),
|
730 |
);
|
731 |
|
732 |
+
$json_data = file_get_contents( plugin_dir_path( __FILE__ ) . 'debugger/plugins.json' );
|
733 |
+
$plugins = json_decode( $json_data );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
734 |
|
735 |
if ( empty( $plugins ) ) {
|
736 |
if ( WP_DEBUG ) {
|
822 |
$bad_themes_results = self::bad_themes_results();
|
823 |
$output = array_merge( $output, $bad_themes_results );
|
824 |
|
825 |
+
// Update site option data
|
826 |
+
$debug_log = get_site_option( 'vhp_varnish_debug' );
|
827 |
+
$debug_log[ VarnishPurger::the_home_url() ] = $output;
|
828 |
+
update_site_option( 'vhp_varnish_debug', $debug_log );
|
829 |
+
|
830 |
return $output;
|
831 |
}
|
832 |
}
|
debugger/cookies.json
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"JS Sessions":{
|
3 |
+
"type": "bad",
|
4 |
+
"cookie": "JSESSIONID",
|
5 |
+
"message": "A plugin or theme is setting a Javascript session cookie on every pageload, which prevents caching."
|
6 |
+
},
|
7 |
+
"PHP Sessions":{
|
8 |
+
"type": "bad",
|
9 |
+
"cookie": "PHPSESSID",
|
10 |
+
"message": "A plugin or theme is setting a PHP session cookie on every pageload, which prevents caching."
|
11 |
+
},
|
12 |
+
"Chartitable":{
|
13 |
+
"type": "bad",
|
14 |
+
"cookie": "charitable_sessions",
|
15 |
+
"message": "The plugin Charitable is putting down cookies on every page load. This has been fixed as of version 1.5.0; please upgrade to the latest version."
|
16 |
+
},
|
17 |
+
"EDD Sessions":{
|
18 |
+
"type": "warning",
|
19 |
+
"cookie": "edd_wp_session",
|
20 |
+
"message": "The plugin Easy Digital Downloads is being used with cookie sessions. This may cause your cache to misbehave. If you have issues, please set <code>define( 'EDD_USE_PHP_SESSIONS', true );</code> in your <code>wp-config.php</code> file."
|
21 |
+
},
|
22 |
+
"EDD Cart":{
|
23 |
+
"type": "warning",
|
24 |
+
"cookie": "edd_items_in_cart",
|
25 |
+
"message": "The plugin Easy Digital Downloads is putting down a shopping cart cookie on every page load. Make sure your cache is set up to ignore that when it's empty."
|
26 |
+
},
|
27 |
+
"Give Sessions":{
|
28 |
+
"type": "warning",
|
29 |
+
"cookie": "give_wp_session",
|
30 |
+
"message": "The plugin Give is putting down a session cookie on all page loads. Please make sure to add <code>define( 'GIVE_USE_PHP_SESSIONS' , false);</code> to your <code>wp-config.php</code> file."
|
31 |
+
},
|
32 |
+
"HubSpot":{
|
33 |
+
"type": "bad",
|
34 |
+
"cookie": "hubspotutk",
|
35 |
+
"message": "The plugin HubSpot is putting down cookies on every page load."
|
36 |
+
},
|
37 |
+
"Invite Anyone":{
|
38 |
+
"type": "bad",
|
39 |
+
"cookie": "invite-anyone",
|
40 |
+
"message": "The plugin Invite Anyone is putting down cookies on every page load."
|
41 |
+
},
|
42 |
+
"Marketo Forms and Tracking":{
|
43 |
+
"type": "bad",
|
44 |
+
"cookie": "trwv.uid",
|
45 |
+
"message": "The plugin Marketo Forms and Tracking is putting down cookies on every page load."
|
46 |
+
},
|
47 |
+
"Optimizely Classic":{
|
48 |
+
"type": "bad",
|
49 |
+
"cookie": "optimizelyBuckets",
|
50 |
+
"message": "The plugin Optimizely Classic is putting down cookies on every page load in order to give people unique experiences to perform it's experiments."
|
51 |
+
},
|
52 |
+
" Optimizely X or Classic":{
|
53 |
+
"type": "bad",
|
54 |
+
"cookie": "optimizelyEndUserId",
|
55 |
+
"message": "Either the plugin Optimizely X or Optimizely Classic is putting down cookies on every page load in order to track users for it's experiments."
|
56 |
+
},
|
57 |
+
"Optimizely X Web":{
|
58 |
+
"type": "bad",
|
59 |
+
"cookie": "optimizelyRedirectData",
|
60 |
+
"message": "The plugin Optimizely X is putting down cookies on every page load in order to run web experiments."
|
61 |
+
},
|
62 |
+
"Simple Membership":{
|
63 |
+
"type": "bad",
|
64 |
+
"cookie": "swpm_session",
|
65 |
+
"message": "The plugin Simple Membership is putting down cookies on every page load."
|
66 |
+
},
|
67 |
+
"WP Math Captcha":{
|
68 |
+
"type": "bad",
|
69 |
+
"cookie": "mc_session_ids",
|
70 |
+
"message": "The plugin WP Math Captcha uses session cookies on every page load."
|
71 |
+
},
|
72 |
+
"WordFence":{
|
73 |
+
"type": "warning",
|
74 |
+
"cookie": "wfvt_",
|
75 |
+
"message": "The plugin WordFence is putting down cookies on every page load. Please check 'Disable WordFence Cookies' under General Wordfence Options to resolve."
|
76 |
+
},
|
77 |
+
"WordFence Verified Human":{
|
78 |
+
"type": "bad",
|
79 |
+
"cookie": "wordfence_verifiedHuman",
|
80 |
+
"message": "The plugin WordFence is putting down Verified Homan cookies on every page load. This should not be possible. Please open a support ticket with WordFence for assistance."
|
81 |
+
}
|
82 |
+
}
|
debugger/plugins.json
ADDED
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bad-behavior":{
|
3 |
+
"type": "bad",
|
4 |
+
"path": "bad-behavior/bad-behavior.php",
|
5 |
+
"reason": "incompatible",
|
6 |
+
"always": true
|
7 |
+
},
|
8 |
+
"captainform":{
|
9 |
+
"type": "bad",
|
10 |
+
"path": "captainform/captainform.php",
|
11 |
+
"reason": "incompatible",
|
12 |
+
"always": true
|
13 |
+
},
|
14 |
+
"cleantalk":{
|
15 |
+
"type": "warning",
|
16 |
+
"path": "cleantalk/cleantalk.php",
|
17 |
+
"reason": "translation",
|
18 |
+
"always": true
|
19 |
+
},
|
20 |
+
"divi-protect":{
|
21 |
+
"type": "bad",
|
22 |
+
"path": "divi-protect/divi-protect.php",
|
23 |
+
"reason": "sessions",
|
24 |
+
"always": true
|
25 |
+
},
|
26 |
+
"download-manager":{
|
27 |
+
"type": "bad",
|
28 |
+
"path": "download-manager/download-manager.php",
|
29 |
+
"reason": "sessions",
|
30 |
+
"always": true
|
31 |
+
},
|
32 |
+
"forms-contact":{
|
33 |
+
"type": "bad",
|
34 |
+
"path": "forms-contact/forms-contact.php",
|
35 |
+
"reason": "incompatible",
|
36 |
+
"always": false
|
37 |
+
},
|
38 |
+
"give":{
|
39 |
+
"type": "warning",
|
40 |
+
"path": "give/give.php",
|
41 |
+
"reason": "sessions",
|
42 |
+
"always": false
|
43 |
+
},
|
44 |
+
"google-authenticator":{
|
45 |
+
"type": "warning",
|
46 |
+
"path": "google-authenticator/google-authenticator.php",
|
47 |
+
"reason": "sessions",
|
48 |
+
"always": false
|
49 |
+
},
|
50 |
+
"gtranslate":{
|
51 |
+
"type": "warning",
|
52 |
+
"path": "gtranslate/gtranslate.php",
|
53 |
+
"reason": "translation",
|
54 |
+
"always": true
|
55 |
+
},
|
56 |
+
"pie-register":{
|
57 |
+
"type": "warning",
|
58 |
+
"path": "pie-register/pie-register.php",
|
59 |
+
"reason": "sessions",
|
60 |
+
"always": false
|
61 |
+
},
|
62 |
+
"pods":{
|
63 |
+
"type": "warning",
|
64 |
+
"path": "pods/init.php",
|
65 |
+
"reason": "sessions",
|
66 |
+
"always": false
|
67 |
+
},
|
68 |
+
"polylang":{
|
69 |
+
"type": "warning",
|
70 |
+
"path": "polylang/polylang.php",
|
71 |
+
"reason": "translation",
|
72 |
+
"always": true
|
73 |
+
},
|
74 |
+
"quick-cache":{
|
75 |
+
"type": "bad",
|
76 |
+
"path": "quick-cache/quick-cache.php",
|
77 |
+
"reason": "cache",
|
78 |
+
"always": true
|
79 |
+
},
|
80 |
+
"qtranslate":{
|
81 |
+
"type": "warning",
|
82 |
+
"path": "qtranslate/qtranslate.php",
|
83 |
+
"reason": "translation",
|
84 |
+
"always": true
|
85 |
+
},
|
86 |
+
"qtranslate-x":{
|
87 |
+
"type": "warning",
|
88 |
+
"path": "qtranslate-x/qtranslate.php",
|
89 |
+
"reason": "translation",
|
90 |
+
"always": true
|
91 |
+
},
|
92 |
+
"simplemodal-login":{
|
93 |
+
"type": "bad",
|
94 |
+
"path": "simplemodal-login/simplemodal-login.php",
|
95 |
+
"reason": "incompatible",
|
96 |
+
"always": true
|
97 |
+
},
|
98 |
+
"simple-session-support":{
|
99 |
+
"type": "bad",
|
100 |
+
"path": "simple-session-support/simple-session-support.php",
|
101 |
+
"reason": "sessions",
|
102 |
+
"always": true
|
103 |
+
},
|
104 |
+
"tweet-blender":{
|
105 |
+
"type": "bad",
|
106 |
+
"path": "tweet-blender/tweet-blender.php",
|
107 |
+
"reason": "incompatible",
|
108 |
+
"always": true
|
109 |
+
},
|
110 |
+
"wglot":{
|
111 |
+
"type": "warning",
|
112 |
+
"path": "wglot/wglot.php",
|
113 |
+
"reason": "translation",
|
114 |
+
"always": true
|
115 |
+
},
|
116 |
+
"w3-total-cache":{
|
117 |
+
"type": "warning",
|
118 |
+
"path": "w3-total-cache/w3-total-cache.php",
|
119 |
+
"reason": "cache",
|
120 |
+
"always": true
|
121 |
+
},
|
122 |
+
"woo-advanced-discounts":{
|
123 |
+
"type": "bad",
|
124 |
+
"path": "woo-advanced-discounts/wad.php",
|
125 |
+
"reason": "sessions",
|
126 |
+
"always": true
|
127 |
+
},
|
128 |
+
"woocommerce-all-discounts":{
|
129 |
+
"type": "bad",
|
130 |
+
"path": "woocommerce-all-discounts/wad.php",
|
131 |
+
"reason": "sessions",
|
132 |
+
"always": true
|
133 |
+
},
|
134 |
+
"wordfence":{
|
135 |
+
"type": "warning",
|
136 |
+
"path": "wordfence/wordfence.php",
|
137 |
+
"reason": "cookies",
|
138 |
+
"always": false
|
139 |
+
},
|
140 |
+
"wp-cache":{
|
141 |
+
"type": "bad",
|
142 |
+
"path": "wp-cache/wp-cache.php",
|
143 |
+
"reason": "cache",
|
144 |
+
"always": true
|
145 |
+
},
|
146 |
+
"wp-file-cache":{
|
147 |
+
"type": "bad",
|
148 |
+
"path": "wp-file-cache/file-cache.php",
|
149 |
+
"reason": "cache",
|
150 |
+
"always": true
|
151 |
+
},
|
152 |
+
"wp-floating-menu-pro":{
|
153 |
+
"type": "bad",
|
154 |
+
"path": "wp-floating-menu-pro/wp-floating-menu-pro.php",
|
155 |
+
"reason": "sessions",
|
156 |
+
"always": true
|
157 |
+
},
|
158 |
+
"wp-super-cache":{
|
159 |
+
"type": "warning",
|
160 |
+
"path": "wp-super-cache/wp-cache.php",
|
161 |
+
"reason": "cache",
|
162 |
+
"always": false
|
163 |
+
},
|
164 |
+
"xtranslate":{
|
165 |
+
"type": "warning",
|
166 |
+
"path": "xtranslate/xtranslate.php",
|
167 |
+
"reason": "translation",
|
168 |
+
"always": true
|
169 |
+
},
|
170 |
+
"wp-rocket":{
|
171 |
+
"type": "warning",
|
172 |
+
"path": "wp-rocket/wp-rocket.php",
|
173 |
+
"reason": "addon",
|
174 |
+
"always": false
|
175 |
+
}
|
176 |
+
}
|
debugger/themes.json
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"Avada":{
|
3 |
+
"type": "warning",
|
4 |
+
"message": "Avada can cause data to be saved improperly, due to how older versions indiscriminately empty caches on every page-save. This primarily impacts transaction plugins like eCommerce."
|
5 |
+
},
|
6 |
+
"divi":{
|
7 |
+
"type": "warning",
|
8 |
+
"message": "Older Divi themes use sessions in their headers for many of their themes. Please make sure to upgrade your theme regularly."
|
9 |
+
},
|
10 |
+
"enfold":{
|
11 |
+
"type": "warning",
|
12 |
+
"message": "The Enfold theme uses sessions for every call of shortcodes in certain situations."
|
13 |
+
},
|
14 |
+
"prophoto6":{
|
15 |
+
"type": "warning",
|
16 |
+
"message": "Prophoto version 6 requires you to be on version 6.21.8 or higher to work properly with caching services. Please make sure your theme is up to date."
|
17 |
+
}
|
18 |
+
}
|
health-check.php
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Health Check Code
|
4 |
+
* @package varnish-http-purge
|
5 |
+
*/
|
6 |
+
|
7 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
8 |
+
die();
|
9 |
+
}
|
10 |
+
|
11 |
+
// Health Check Test
|
12 |
+
add_filter( 'site_status_tests', 'vhp_add_site_status_tests' );
|
13 |
+
|
14 |
+
function vhp_add_site_status_tests( $tests ) {
|
15 |
+
$tests['direct']['proxy_cache_purge_caching'] = array(
|
16 |
+
'label' => __( 'Proxy Cache Purge Status', 'varnish-http-purge' ),
|
17 |
+
'test' => 'vhp_site_status_caching_test',
|
18 |
+
);
|
19 |
+
return $tests;
|
20 |
+
}
|
21 |
+
|
22 |
+
function vhp_site_status_caching_test() {
|
23 |
+
|
24 |
+
// Check the debug log
|
25 |
+
$debug_log = get_site_option( 'vhp_varnish_debug' );
|
26 |
+
$debug_results = array();
|
27 |
+
foreach ( $debug_log as $site => $results ) {
|
28 |
+
foreach ( $results as $item => $content ) {
|
29 |
+
$sitename = ( VarnishPurger::the_home_url() !== $site ) ? 'Site: ' . $site . '<br />' : '';
|
30 |
+
// Log cache not working
|
31 |
+
if ( 'Cache Service' === $item && 'notice' === $content['icon'] ) {
|
32 |
+
$debug_results[ $item ] = $sitename . $content['message'];
|
33 |
+
}
|
34 |
+
// Log all Criticals
|
35 |
+
if ( isset( $content['icon'] ) && 'bad' === $content['icon'] ) {
|
36 |
+
$debug_results[ $item ] = $sitename . $content['message'];
|
37 |
+
}
|
38 |
+
}
|
39 |
+
}
|
40 |
+
|
41 |
+
// Defaults, all is good:
|
42 |
+
$result = array(
|
43 |
+
'label' => __( 'Proxy Cache Purge is working', 'varnish-http-purge' ),
|
44 |
+
'status' => 'good',
|
45 |
+
'badge' => array(
|
46 |
+
'label' => __( 'Performance', 'varnish-http-purge' ),
|
47 |
+
'color' => 'blue',
|
48 |
+
),
|
49 |
+
'description' => sprintf(
|
50 |
+
'<p>%s</p>',
|
51 |
+
__( 'Caching can help load your site more quickly for visitors. You\'re doing great!', 'varnish-http-purge' )
|
52 |
+
),
|
53 |
+
'actions' => sprintf(
|
54 |
+
'<p><a href="%s">%s</a></p>',
|
55 |
+
esc_url( admin_url( 'admin.php?page=varnish-check-caching' ) ),
|
56 |
+
__( 'Check Caching Status', 'varnish-http-purge' )
|
57 |
+
),
|
58 |
+
'test' => 'caching_plugin',
|
59 |
+
);
|
60 |
+
|
61 |
+
// If we're in dev mode....
|
62 |
+
if ( VarnishDebug::devmode_check() ) {
|
63 |
+
$result['status'] = 'recommended';
|
64 |
+
$result['label'] = __( 'Proxy Cache Purge is in development mode', 'varnish-http-purge' );
|
65 |
+
$result['description'] = sprintf(
|
66 |
+
'<p>%s</p>',
|
67 |
+
__( 'Proxy Cache Purge is active but in dev mode, which means it will not serve cached content to your users. If this is intentional, carry on. Otherwise you should re-enable caching.', 'varnish-http-purge' )
|
68 |
+
);
|
69 |
+
$result['actions'] = sprintf(
|
70 |
+
'<p><a href="%s">%s</a></p>',
|
71 |
+
esc_url( admin_url( 'admin.php?page=varnish-page' ) ),
|
72 |
+
__( 'Enable Caching' )
|
73 |
+
);
|
74 |
+
} elseif ( ! empty( $debug_results ) && '' !== $debug_results ) {
|
75 |
+
$count = count( $debug_results );
|
76 |
+
// Translators: %d is the number of issues reported
|
77 |
+
$desc = sprintf( _n( 'The most recent cache status check reported %d issue.', 'The most recent cache status check reported %d issues.', $count, 'varnish-http-purge' ), $count );
|
78 |
+
|
79 |
+
$result['status'] = 'critical';
|
80 |
+
// Translators: %d is the number of issues reported
|
81 |
+
$result['label'] = sprintf( __( 'Proxy Cache Purge has reported caching errors (%s)', 'varnish-http-purge' ), $count );
|
82 |
+
$result['description'] = sprintf(
|
83 |
+
'<p>%s</p>',
|
84 |
+
$desc
|
85 |
+
);
|
86 |
+
$result['description'] .= '<ul>';
|
87 |
+
foreach ( $debug_results as $key => $value ) {
|
88 |
+
$result['description'] .= '<li><strong>' . $key . '</strong>: ' . $value . '</li>';
|
89 |
+
}
|
90 |
+
$result['description'] .= '</ul>';
|
91 |
+
}
|
92 |
+
|
93 |
+
return $result;
|
94 |
+
}
|
readme.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
= Proxy Cache Purge =
|
2 |
Contributors: Ipstenu, mikeschroder, techpriester, danielbachhuber
|
3 |
Tags: proxy, purge, cache, varnish, nginx
|
4 |
-
Requires at least:
|
5 |
-
Tested up to: 5.
|
6 |
-
Stable tag:
|
7 |
Requires PHP: 5.6
|
8 |
|
9 |
Automatically empty proxy cached content when your site is modified.
|
@@ -50,17 +50,37 @@ That will break cache on page loads. It is _not_ recommended for production!
|
|
50 |
|
51 |
= WP CLI =
|
52 |
|
53 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
|
60 |
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
-
|
64 |
|
65 |
== Installation ==
|
66 |
|
@@ -171,15 +191,15 @@ If your web host set up your service, check their documentation.
|
|
171 |
|
172 |
= What if I have multiple proxy cache IPs? =
|
173 |
|
174 |
-
|
175 |
|
176 |
= What version of Varnish is supported? =
|
177 |
|
178 |
-
|
179 |
|
180 |
= Does this work with Nginx caching? =
|
181 |
|
182 |
-
It can, if you've configured Nginx caching to respect the curl PURGE request. If this doesn't work,
|
183 |
|
184 |
= What should my cache rules be? =
|
185 |
|
@@ -203,17 +223,13 @@ This plugin is installed by default for _all_ DreamPress installs on DreamHost,
|
|
203 |
|
204 |
== Changelog ==
|
205 |
|
206 |
-
=
|
207 |
-
*
|
208 |
-
*
|
209 |
-
*
|
210 |
-
*
|
211 |
-
|
212 |
-
|
213 |
-
* March 2019
|
214 |
-
* Improve debugger
|
215 |
-
* Clean code per standards
|
216 |
-
* Improve callback on WP-CLI
|
217 |
|
218 |
== Screenshots ==
|
219 |
|
1 |
= Proxy Cache Purge =
|
2 |
Contributors: Ipstenu, mikeschroder, techpriester, danielbachhuber
|
3 |
Tags: proxy, purge, cache, varnish, nginx
|
4 |
+
Requires at least: 5.0
|
5 |
+
Tested up to: 5.7
|
6 |
+
Stable tag: 5.0
|
7 |
Requires PHP: 5.6
|
8 |
|
9 |
Automatically empty proxy cached content when your site is modified.
|
50 |
|
51 |
= WP CLI =
|
52 |
|
53 |
+
<strong>Purge</strong>
|
|
|
|
|
54 |
|
55 |
+
Purge commands let you empty the cache.
|
56 |
+
|
57 |
+
* `wp varnish purge` - Flush the cache for your front page
|
58 |
+
* `wp varnish purge [<url>]` - Flush the cache for one URL
|
59 |
+
|
60 |
+
You can use the parameter `--wildcard` to empty everything from that URL down. So if you wanted to empty cache for all themes, you would do this:
|
61 |
+
|
62 |
+
* `wp varnish purge https://example.com/wp-content/themes --wildcard`
|
63 |
+
|
64 |
+
<strong>Debug</strong>
|
65 |
+
|
66 |
+
Debugging can help you figure out why your cache isn't working as well as it could. The default is for your home page, but you can pass any URL on your domain.
|
67 |
|
68 |
+
* `wp varnish debug [<url>]`
|
69 |
|
70 |
+
Available parameters:
|
71 |
+
|
72 |
+
* `[--include-headers]` -- Include headers in debug check output
|
73 |
+
* `[--include-grep]` -- Grep active theme and plugin directories for common issues
|
74 |
+
|
75 |
+
<strong>DevMode</strong>
|
76 |
+
|
77 |
+
Development mode allows you to disable the cache, temporarily.
|
78 |
+
|
79 |
+
* `wp varnish devmode [<activate|deactivate|toggle>]` - Change development mode state
|
80 |
+
|
81 |
+
= Privacy Policy =
|
82 |
|
83 |
+
As of version 5, this plugin no longer uses any remote data.
|
84 |
|
85 |
== Installation ==
|
86 |
|
191 |
|
192 |
= What if I have multiple proxy cache IPs? =
|
193 |
|
194 |
+
You may enter them, separated by a comma, on the settings page.
|
195 |
|
196 |
= What version of Varnish is supported? =
|
197 |
|
198 |
+
So far this plugin has been reported to successfully function on Varnish v2 through v6.
|
199 |
|
200 |
= Does this work with Nginx caching? =
|
201 |
|
202 |
+
It can, if you've configured Nginx caching to respect the curl PURGE request. If this doesn't work, try setting your Varnish IP to `localhost` as Nginx requires a service control installed for the IP address to work.
|
203 |
|
204 |
= What should my cache rules be? =
|
205 |
|
223 |
|
224 |
== Changelog ==
|
225 |
|
226 |
+
= 5.0 =
|
227 |
+
* March 2021
|
228 |
+
* Now purges draft and pending posts (to account for people who un-publish) - props @jerlarke
|
229 |
+
* Localhost the debugger json. They aren't updated that often, and the remote load is unnecessary.
|
230 |
+
* More support for Health Check
|
231 |
+
* Remove strtotime check on Age header - props Matt Fields
|
232 |
+
* Support for multiple IPs (based on P.Brisson's work)
|
|
|
|
|
|
|
|
|
233 |
|
234 |
== Screenshots ==
|
235 |
|
settings.php
CHANGED
@@ -145,7 +145,8 @@ class VarnishStatus {
|
|
145 |
public function options_settings_ip() {
|
146 |
?>
|
147 |
<p><a name="#configureip"></a><?php esc_html_e( 'There are cases when a custom IP Address is needed to for the plugin to properly communicate with the cache service. If you\'re using a CDN like Cloudflare or a Firewall Proxy like Sucuri, or your cache is Nginx based, you may need to customize this setting.', 'varnish-http-purge' ); ?></p>
|
148 |
-
<p><?php esc_html_e( 'Normally your Proxy Cache IP is the IP address of the server where your caching service (i.e. Varnish or Nginx) is installed. It must an address used by your cache service. If you use multiple IPs, or have customized your ACLs, you\'ll need to pick one that doesn\'t conflict with your other settings. For example, if you have
|
|
|
149 |
<p><?php esc_html_e( 'If your webhost set the service up for you, as is the case with DreamPress or WP Engine, ask them for the specifics.', 'varnish-http-purge' ); ?></p>
|
150 |
<p><strong><?php esc_html_e( 'If you aren\'t sure what to do, contact your webhost or server admin before making any changes.', 'varnish-http-purge' ); ?></strong></p>
|
151 |
<?php
|
@@ -167,13 +168,13 @@ class VarnishStatus {
|
|
167 |
}
|
168 |
|
169 |
echo '<input type="text" id="vhp_varnish_ip" name="vhp_varnish_ip" value="' . esc_attr( $varniship ) . '" size="25" ' . disabled( $disabled, true ) . '/>';
|
170 |
-
echo '<label for="vhp_varnish_ip"
|
171 |
|
172 |
if ( $disabled ) {
|
173 |
esc_html_e( 'A Proxy Cache IP has been defined in your wp-config file, so it is not editable in settings.', 'varnish-http-purge' );
|
174 |
} else {
|
175 |
-
esc_html_e( '
|
176 |
-
echo '<code>123.45.67.89</code> or <code>localhost</code>';
|
177 |
}
|
178 |
|
179 |
echo '</label>';
|
@@ -193,10 +194,26 @@ class VarnishStatus {
|
|
193 |
|
194 |
if ( empty( $input ) ) {
|
195 |
return; // do nothing.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
} elseif ( 'localhost' === $input || filter_var( $input, FILTER_VALIDATE_IP ) ) {
|
197 |
-
$set_message = 'Proxy Cache IP Updated
|
198 |
$set_type = 'updated';
|
199 |
-
$output =
|
200 |
}
|
201 |
|
202 |
add_settings_error( 'vhp_varnish_ip', 'varnish-ip', $set_message, $set_type );
|
@@ -222,14 +239,6 @@ class VarnishStatus {
|
|
222 |
public function options_check_caching_scan() {
|
223 |
?>
|
224 |
<p><?php esc_html_e( 'This feature performs a check of the most common issues that prevents your site from caching properly. This feature is provided to help you in resolve potential conflicts on your own. When filing an issue with your web-host, we recommend you include the output in your ticket.', 'varnish-http-purge' ); ?></p>
|
225 |
-
<h4><?php esc_html_e( 'Privacy Note', 'varnish-http-purge' ); ?></h4>
|
226 |
-
<p>
|
227 |
-
<?php
|
228 |
-
// translators: %s is a link to the readme for the detection service.
|
229 |
-
printf( wp_kses_post( __( '<strong>This check uses <a href="%s">a remote service hosted on DreamObjects</a></strong>.', 'varnish-http-purge' ) ), 'https://varnish-http-purge.objects-us-east-1.dream.io/readme.txt' );
|
230 |
-
?>
|
231 |
-
</p>
|
232 |
-
<p><?php esc_html_e( 'The service used only for providing up to date compatibility checks on plugins and themes that may conflict with running a server based cache. No personally identifying information regarding persons running this check, nor the plugins and themes in use on this site will be transmitted. The bare minimum of usage information is collected, concerning only IPs and domains making requests of the service. If you do not wish to use this service, please do not use this feature.', 'varnish-http-purge' ); ?></p>
|
233 |
<?php
|
234 |
|
235 |
// If there's no post made, let's not...
|
145 |
public function options_settings_ip() {
|
146 |
?>
|
147 |
<p><a name="#configureip"></a><?php esc_html_e( 'There are cases when a custom IP Address is needed to for the plugin to properly communicate with the cache service. If you\'re using a CDN like Cloudflare or a Firewall Proxy like Sucuri, or your cache is Nginx based, you may need to customize this setting.', 'varnish-http-purge' ); ?></p>
|
148 |
+
<p><?php esc_html_e( 'Normally your Proxy Cache IP is the IP address of the server where your caching service (i.e. Varnish or Nginx) is installed. It must an address used by your cache service. If you use multiple IPs, or have customized your ACLs, you\'ll need to pick one that doesn\'t conflict with your other settings. For example, if you have your proxy cache 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 or localhost).', 'varnish-http-purge' ); ?></p>
|
149 |
+
<p><?php esc_html_e( 'You may use multiple IPs by separating them with a comma (,). If you do so, all IPs will be sent purge requests. This can be useful if you\'re using round robin DNS entries or hosting multiple proxy cache solutions (i.e. Nginx and Varnish).', 'varnish-http-purge' ); ?></p>
|
150 |
<p><?php esc_html_e( 'If your webhost set the service up for you, as is the case with DreamPress or WP Engine, ask them for the specifics.', 'varnish-http-purge' ); ?></p>
|
151 |
<p><strong><?php esc_html_e( 'If you aren\'t sure what to do, contact your webhost or server admin before making any changes.', 'varnish-http-purge' ); ?></strong></p>
|
152 |
<?php
|
168 |
}
|
169 |
|
170 |
echo '<input type="text" id="vhp_varnish_ip" name="vhp_varnish_ip" value="' . esc_attr( $varniship ) . '" size="25" ' . disabled( $disabled, true ) . '/>';
|
171 |
+
echo '<label for="vhp_varnish_ip"> ';
|
172 |
|
173 |
if ( $disabled ) {
|
174 |
esc_html_e( 'A Proxy Cache IP has been defined in your wp-config file, so it is not editable in settings.', 'varnish-http-purge' );
|
175 |
} else {
|
176 |
+
esc_html_e( 'Examples: ', 'varnish-http-purge' );
|
177 |
+
echo '<code>123.45.67.89</code> or <code>localhost</code> or <code>12.34.56.78, 23.45.67.89</code>';
|
178 |
}
|
179 |
|
180 |
echo '</label>';
|
194 |
|
195 |
if ( empty( $input ) ) {
|
196 |
return; // do nothing.
|
197 |
+
} elseif ( strpos( $input, ',' ) ) {
|
198 |
+
// Turn IPs into an array
|
199 |
+
$ips = explode( ',', $input );
|
200 |
+
$valid_ips = array();
|
201 |
+
|
202 |
+
foreach ( $ips as $ip ) {
|
203 |
+
if ( 'localhost' === $input || filter_var( trim( $ip ), FILTER_VALIDATE_IP ) ) {
|
204 |
+
$valid_ips[] = trim( $ip );
|
205 |
+
}
|
206 |
+
}
|
207 |
+
// If all the IPs are valid, then we can carry on.
|
208 |
+
if ( ! empty( $valid_ips ) ) {
|
209 |
+
$set_message = __( 'Proxy Cache IPs Updated', 'varnish-http-purge' );
|
210 |
+
$set_type = 'updated';
|
211 |
+
$output = implode( ', ', $valid_ips );
|
212 |
+
}
|
213 |
} elseif ( 'localhost' === $input || filter_var( $input, FILTER_VALIDATE_IP ) ) {
|
214 |
+
$set_message = __( 'Proxy Cache IP Updated', 'varnish-http-purge' );
|
215 |
$set_type = 'updated';
|
216 |
+
$output = $input;
|
217 |
}
|
218 |
|
219 |
add_settings_error( 'vhp_varnish_ip', 'varnish-ip', $set_message, $set_type );
|
239 |
public function options_check_caching_scan() {
|
240 |
?>
|
241 |
<p><?php esc_html_e( 'This feature performs a check of the most common issues that prevents your site from caching properly. This feature is provided to help you in resolve potential conflicts on your own. When filing an issue with your web-host, we recommend you include the output in your ticket.', 'varnish-http-purge' ); ?></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
<?php
|
243 |
|
244 |
// If there's no post made, let's not...
|
varnish-http-purge.php
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin Name: Proxy Cache Purge
|
4 |
-
* Plugin URI: https://
|
5 |
* Description: Automatically empty cached pages when content on your site is modified.
|
6 |
-
* Version:
|
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 |
*
|
@@ -35,7 +35,7 @@ class VarnishPurger {
|
|
35 |
* Version Number
|
36 |
* @var string
|
37 |
*/
|
38 |
-
public static $version = '
|
39 |
|
40 |
/**
|
41 |
* List of URLs to be purged
|
@@ -87,6 +87,11 @@ class VarnishPurger {
|
|
87 |
update_site_option( 'vhp_varnish_ip', '' );
|
88 |
}
|
89 |
|
|
|
|
|
|
|
|
|
|
|
90 |
// Release the hounds!
|
91 |
add_action( 'init', array( &$this, 'init' ) );
|
92 |
add_action( 'admin_init', array( &$this, 'admin_init' ) );
|
@@ -95,7 +100,6 @@ class VarnishPurger {
|
|
95 |
|
96 |
// Check if there's an upgrade
|
97 |
add_action( 'upgrader_process_complete', array( &$this, 'check_upgrades' ), 10, 2 );
|
98 |
-
|
99 |
}
|
100 |
|
101 |
/**
|
@@ -105,6 +109,7 @@ class VarnishPurger {
|
|
105 |
* @access public
|
106 |
*/
|
107 |
public function admin_init() {
|
|
|
108 |
|
109 |
// If WordPress.com Master Bar is active, show the activity box.
|
110 |
if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'masterbar' ) ) {
|
@@ -119,7 +124,7 @@ class VarnishPurger {
|
|
119 |
}
|
120 |
|
121 |
// Admin notices.
|
122 |
-
if ( current_user_can( 'manage_options' ) ) {
|
123 |
|
124 |
// Warning: Debug is active.
|
125 |
if ( VarnishDebug::devmode_check() ) {
|
@@ -244,7 +249,7 @@ class VarnishPurger {
|
|
244 |
* @since 4.6
|
245 |
*/
|
246 |
public function admin_message_purge() {
|
247 |
-
echo '<div id="message" class="notice notice-success fade is-dismissible"><p><strong>' . esc_html__( '
|
248 |
}
|
249 |
|
250 |
/**
|
@@ -490,7 +495,7 @@ class VarnishPurger {
|
|
490 |
// translators: %1$s links to the plugin's page on WordPress.org.
|
491 |
$intro = sprintf( __( '<a href="%1$s">Proxy Cache 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/' );
|
492 |
$url = wp_nonce_url( add_query_arg( 'vhp_flush_do', 'all' ), 'vhp-flush-do' );
|
493 |
-
$button = __( 'Press the button below to force it to empty your entire
|
494 |
$button .= '</p><p><span class="button"><strong><a href="' . $url . '">';
|
495 |
$button .= __( 'Empty Cache', 'varnish-http-purge' );
|
496 |
$button .= '</a></strong></span>';
|
@@ -533,6 +538,7 @@ class VarnishPurger {
|
|
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 |
|
@@ -556,6 +562,7 @@ class VarnishPurger {
|
|
556 |
'import_start', // When importer starts
|
557 |
'import_end', // When importer ends
|
558 |
'switch_theme', // After a theme is changed.
|
|
|
559 |
);
|
560 |
|
561 |
/**
|
@@ -633,20 +640,27 @@ class VarnishPurger {
|
|
633 |
$x_purge_method = 'regex';
|
634 |
}
|
635 |
|
636 |
-
// Build a varniship.
|
637 |
if ( VHP_VARNISH_IP !== false ) {
|
638 |
$varniship = VHP_VARNISH_IP;
|
639 |
} else {
|
640 |
$varniship = get_site_option( 'vhp_varnish_ip' );
|
641 |
}
|
642 |
-
$varniship = apply_filters( 'vhp_varnish_ip', $varniship );
|
643 |
|
644 |
-
//
|
645 |
-
$
|
646 |
-
|
647 |
-
$
|
|
|
|
|
|
|
|
|
|
|
648 |
}
|
649 |
|
|
|
|
|
|
|
650 |
/**
|
651 |
* Schema filter
|
652 |
*
|
@@ -655,65 +669,88 @@ class VarnishPurger {
|
|
655 |
*
|
656 |
* @since 3.7.3
|
657 |
*/
|
658 |
-
$schema = apply_filters( 'varnish_http_purge_schema', 'http://' );
|
659 |
|
660 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
661 |
if ( isset( $varniship ) && ! empty( $varniship ) ) {
|
662 |
-
$
|
663 |
} else {
|
664 |
-
|
|
|
665 |
}
|
666 |
|
667 |
-
|
668 |
-
|
669 |
-
* Credit: davidbarratt - https://github.com/Ipstenu/varnish-http-purge/pull/38/
|
670 |
-
*
|
671 |
-
* (default value: $p['host'])
|
672 |
-
*
|
673 |
-
* @var string
|
674 |
-
* @access public
|
675 |
-
* @since 4.4.0
|
676 |
-
*/
|
677 |
-
$host_headers = $p['host'];
|
678 |
-
if ( isset( $p['port'] ) ) {
|
679 |
-
$host_headers .= ':' . $p['port'];
|
680 |
-
}
|
681 |
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
687 |
|
688 |
-
|
689 |
-
$purgeme = $schema . $host . $path . $pregex;
|
690 |
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
717 |
}
|
718 |
|
719 |
/**
|
@@ -773,7 +810,7 @@ class VarnishPurger {
|
|
773 |
* If this is a valid post we want to purge the post,
|
774 |
* the home page and any associated tags and categories
|
775 |
*/
|
776 |
-
$valid_post_status = array( 'publish', 'private', 'trash' );
|
777 |
$this_post_status = get_post_status( $post_id );
|
778 |
|
779 |
// Not all post types are created equal.
|
@@ -783,7 +820,7 @@ class VarnishPurger {
|
|
783 |
|
784 |
/**
|
785 |
* Determine the route for the rest API
|
786 |
-
* This will need to be
|
787 |
* Future me: Consider an array? 4.7-?? use v2, and then adapt from there?
|
788 |
*/
|
789 |
if ( version_compare( get_bloginfo( 'version' ), '4.7', '>=' ) ) {
|
@@ -1004,5 +1041,6 @@ if ( ! is_network_admin() ) {
|
|
1004 |
require_once 'settings.php';
|
1005 |
}
|
1006 |
require_once 'debug.php';
|
|
|
1007 |
|
1008 |
$purger = new VarnishPurger();
|
1 |
<?php
|
2 |
/**
|
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 |
*
|
13 |
* @package varnish-http-purge
|
14 |
*
|
15 |
+
* Copyright 2016-2021 Mika Epstein (email: ipstenu@halfelf.org)
|
16 |
*
|
17 |
* This file is part of Proxy Cache Purge, a plugin for WordPress.
|
18 |
*
|
35 |
* Version Number
|
36 |
* @var string
|
37 |
*/
|
38 |
+
public static $version = '5.0';
|
39 |
|
40 |
/**
|
41 |
* List of URLs to be purged
|
87 |
update_site_option( 'vhp_varnish_ip', '' );
|
88 |
}
|
89 |
|
90 |
+
// Default Debug is the home.
|
91 |
+
if ( ! get_site_option( 'vhp_varnish_debug' ) ) {
|
92 |
+
update_site_option( 'vhp_varnish_debug', array( $this->the_home_url() => array() ) );
|
93 |
+
}
|
94 |
+
|
95 |
// Release the hounds!
|
96 |
add_action( 'init', array( &$this, 'init' ) );
|
97 |
add_action( 'admin_init', array( &$this, 'admin_init' ) );
|
100 |
|
101 |
// Check if there's an upgrade
|
102 |
add_action( 'upgrader_process_complete', array( &$this, 'check_upgrades' ), 10, 2 );
|
|
|
103 |
}
|
104 |
|
105 |
/**
|
109 |
* @access public
|
110 |
*/
|
111 |
public function admin_init() {
|
112 |
+
global $pagenow;
|
113 |
|
114 |
// If WordPress.com Master Bar is active, show the activity box.
|
115 |
if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'masterbar' ) ) {
|
124 |
}
|
125 |
|
126 |
// Admin notices.
|
127 |
+
if ( current_user_can( 'manage_options' ) && 'site-health.php' !== $pagenow ) {
|
128 |
|
129 |
// Warning: Debug is active.
|
130 |
if ( VarnishDebug::devmode_check() ) {
|
249 |
* @since 4.6
|
250 |
*/
|
251 |
public function admin_message_purge() {
|
252 |
+
echo '<div id="message" class="notice notice-success fade is-dismissible"><p><strong>' . esc_html__( 'Cache emptied!', 'varnish-http-purge' ) . '</strong></p></div>';
|
253 |
}
|
254 |
|
255 |
/**
|
495 |
// translators: %1$s links to the plugin's page on WordPress.org.
|
496 |
$intro = sprintf( __( '<a href="%1$s">Proxy Cache 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/' );
|
497 |
$url = wp_nonce_url( add_query_arg( 'vhp_flush_do', 'all' ), 'vhp-flush-do' );
|
498 |
+
$button = __( 'Press the button below to force it to empty your entire cache.', 'varnish-http-purge' );
|
499 |
$button .= '</p><p><span class="button"><strong><a href="' . $url . '">';
|
500 |
$button .= __( 'Empty Cache', 'varnish-http-purge' );
|
501 |
$button .= '</a></strong></span>';
|
538 |
'import_end', // When importer ends
|
539 |
'save_post', // Save a post.
|
540 |
'switch_theme', // After a theme is changed.
|
541 |
+
'customize_save_after', // After Customizer is updated.
|
542 |
'trashed_post', // Empty Trashed post.
|
543 |
);
|
544 |
|
562 |
'import_start', // When importer starts
|
563 |
'import_end', // When importer ends
|
564 |
'switch_theme', // After a theme is changed.
|
565 |
+
'customize_save_after', // After Customizer is updated.
|
566 |
);
|
567 |
|
568 |
/**
|
640 |
$x_purge_method = 'regex';
|
641 |
}
|
642 |
|
643 |
+
// Build a varniship to sail.
|
644 |
if ( VHP_VARNISH_IP !== false ) {
|
645 |
$varniship = VHP_VARNISH_IP;
|
646 |
} else {
|
647 |
$varniship = get_site_option( 'vhp_varnish_ip' );
|
648 |
}
|
|
|
649 |
|
650 |
+
// Apply filters:
|
651 |
+
if ( is_array( $varniship ) ) {
|
652 |
+
// To each ship:
|
653 |
+
for ( $i = 0; $i++; $i < count( $varniship ) ) {
|
654 |
+
$varniship[ $i ] = apply_filters( 'vhp_varnish_ip', $varniship[ $i ] );
|
655 |
+
}
|
656 |
+
} else {
|
657 |
+
// To the only ship:
|
658 |
+
$varniship = apply_filters( 'vhp_varnish_ip', $varniship );
|
659 |
}
|
660 |
|
661 |
+
// Determine the path.
|
662 |
+
$path = ( isset( $p['path'] ) ) ? $p['path'] : '';
|
663 |
+
|
664 |
/**
|
665 |
* Schema filter
|
666 |
*
|
669 |
*
|
670 |
* @since 3.7.3
|
671 |
*/
|
|
|
672 |
|
673 |
+
// This is a very annoying check for DreamHost who needs to default to HTTPS without breaking
|
674 |
+
// people who've been around before
|
675 |
+
$server_hostname = gethostname();
|
676 |
+
switch ( substr( $server_hostname, 0, 3 ) ) {
|
677 |
+
case 'dp-':
|
678 |
+
$schema_type = 'https://';
|
679 |
+
break;
|
680 |
+
default:
|
681 |
+
$schema_type = 'http://';
|
682 |
+
break;
|
683 |
+
}
|
684 |
+
$schema = apply_filters( 'varnish_http_purge_schema', $schema_type );
|
685 |
+
|
686 |
+
// When we have Varnish IPs, we use them in lieu of hosts.
|
687 |
if ( isset( $varniship ) && ! empty( $varniship ) ) {
|
688 |
+
$all_hosts = ( ! is_array( $varniship ) ) ? array( $varniship ) : $varniship;
|
689 |
} else {
|
690 |
+
// default is the main host, made into an array
|
691 |
+
$all_hosts = array( $p['host'] );
|
692 |
}
|
693 |
|
694 |
+
// Since the ship is always an array now, let's loop.
|
695 |
+
foreach ( $all_hosts as $one_host ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
696 |
|
697 |
+
/**
|
698 |
+
* Allow setting of ports in host name
|
699 |
+
* Credit: davidbarratt - https://github.com/Ipstenu/varnish-http-purge/pull/38/
|
700 |
+
*
|
701 |
+
* (default value: $p['host'])
|
702 |
+
*
|
703 |
+
* @var string
|
704 |
+
* @access public
|
705 |
+
* @since 4.4.0
|
706 |
+
*/
|
707 |
+
$host_headers = $p['host'];
|
708 |
+
|
709 |
+
// If the URL to be purged has a port, we're going to re-use it.
|
710 |
+
if ( isset( $p['port'] ) ) {
|
711 |
+
$host_headers .= ':' . $p['port'];
|
712 |
+
}
|
713 |
|
714 |
+
$parsed_url = $url;
|
|
|
715 |
|
716 |
+
// Filter URL based on the Proxy IP for nginx compatibility
|
717 |
+
if ( 'localhost' === $one_host ) {
|
718 |
+
$parsed_url = str_replace( $p['host'], 'localhost', $parsed_url );
|
719 |
+
}
|
720 |
|
721 |
+
// Create path to purge.
|
722 |
+
$purgeme = $schema . $one_host . $path . $pregex;
|
723 |
+
|
724 |
+
// Check the queries...
|
725 |
+
if ( ! empty( $p['query'] ) && 'vhp-regex' !== $p['query'] ) {
|
726 |
+
$purgeme .= '?' . $p['query'];
|
727 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
728 |
|
729 |
+
/**
|
730 |
+
* Filters the HTTP headers to send with a PURGE request.
|
731 |
+
*
|
732 |
+
* @since 4.1
|
733 |
+
*/
|
734 |
+
$headers = apply_filters(
|
735 |
+
'varnish_http_purge_headers',
|
736 |
+
array(
|
737 |
+
'host' => $host_headers,
|
738 |
+
'X-Purge-Method' => $x_purge_method,
|
739 |
+
)
|
740 |
+
);
|
741 |
+
|
742 |
+
// Send response.
|
743 |
+
$response = wp_remote_request(
|
744 |
+
$purgeme,
|
745 |
+
array(
|
746 |
+
'sslverify' => false,
|
747 |
+
'method' => 'PURGE',
|
748 |
+
'headers' => $headers,
|
749 |
+
)
|
750 |
+
);
|
751 |
+
|
752 |
+
do_action( 'after_purge_url', $parsed_url, $purgeme, $response, $headers );
|
753 |
+
}
|
754 |
}
|
755 |
|
756 |
/**
|
810 |
* If this is a valid post we want to purge the post,
|
811 |
* the home page and any associated tags and categories
|
812 |
*/
|
813 |
+
$valid_post_status = array( 'publish', 'private', 'trash', 'pending', 'draft' );
|
814 |
$this_post_status = get_post_status( $post_id );
|
815 |
|
816 |
// Not all post types are created equal.
|
820 |
|
821 |
/**
|
822 |
* Determine the route for the rest API
|
823 |
+
* This will need to be revisited if WP updates the version.
|
824 |
* Future me: Consider an array? 4.7-?? use v2, and then adapt from there?
|
825 |
*/
|
826 |
if ( version_compare( get_bloginfo( 'version' ), '4.7', '>=' ) ) {
|
1041 |
require_once 'settings.php';
|
1042 |
}
|
1043 |
require_once 'debug.php';
|
1044 |
+
require_once 'health-check.php';
|
1045 |
|
1046 |
$purger = new VarnishPurger();
|