Varnish HTTP Purge - Version 4.2.0

Version Description

  • More flexible support for custom cat/tag bases
  • Added in support for custom taxonomies
  • New function to generate the URLs, so it can be called by external plugins
  • Move right now box to be called later, preventing double calls
  • Extra check for if it's a URL, because some plugins are weird (props @danielkun)
Download this release

Release Info

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

Code changes from version 4.1.1 to 4.2.0

Files changed (4) hide show
  1. LICENSE +202 -0
  2. readme.txt +27 -74
  3. varnish-http-purge.php +41 -3
  4. varnish-status.php +6 -2
LICENSE ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
readme.txt CHANGED
@@ -2,34 +2,36 @@
2
  Contributors: Ipstenu, mikeschroder, techpriester
3
  Tags: varnish, purge, cache
4
  Requires at least: 4.7
5
- Tested up to: 4.8
6
- Stable tag: 4.1.1
 
7
 
8
  Automatically empty a Varnish Cache when content on your site is modified.
9
 
10
  == Description ==
11
 
12
- Varnish HTTP Purge sends a PURGE request to delete the cached data of a page or post every time it it modified. This happens when updating, publishing, commenting on, or deleting an post, and when changing themes.
13
 
14
- <a href="https://www.varnish-cache.org/">Varnish</a> is a web application accelerator also known as a caching HTTP reverse proxy. You install it in front of any server that speaks HTTP and configure it to cache the contents. This plugin <em>does not</em> install Varnish for you, nor will it configure Varnish for WordPress. It's expected you already did that on your own.
15
 
16
  Not all page caches are deleted every time, depending on your Varnish configuration. For example, when a post, page, or custom post type is edited, or a new comment is added, <em>only</em> the following pages will purge:
17
 
18
  * The front page
19
  * The post/page edited
20
- * Any categories or tags associated with the page
 
 
21
 
22
  In addition, your <em>entire</em> cache will be deleted on the following actions:
23
 
24
  * Changing themes
25
- * Press the 'Purge Varnish Cache' button on the dashboard
26
- * Press the 'Purge Varnish' button on the toolbar
27
 
28
  Plugins can hook into the purge actions as well, to filter their own events to trigger a purge.
29
 
30
  And if you're into WP-CLI, you can use that too: `wp varnish purge`
31
 
32
- Please note: On a multisite network using subfolders, only <strong>network admins</strong> can purge the main site. This is a security decision.
33
 
34
  = Requirements =
35
 
@@ -52,11 +54,11 @@ No. Some of them have behavior that causes Varnish not to cache. While I can't d
52
 
53
  = How can I debug my site? =
54
 
55
- Use the Varnish Status page. It'll try and help you figure out what's wrong.
56
 
57
  = Will you fix my site if there's a conflict with a theme or plugin? =
58
 
59
- I wish I could. I don't have that much free time. What I can do is try and point you to how you can fix it yourself. Bear in mind, that may mean you have to decide if using a specific plugin or theme is worth an imperfect cache.
60
 
61
  = What version of Varnish is supported? =
62
 
@@ -64,19 +66,15 @@ This was built and tested on Varnish 3.x. While it is reported to work on 2.x an
64
 
65
  = Why doesn't every page cache get deleted when I make a new post? =
66
 
67
- The only cache pages that should be deleted are the post's page, the front page, categories, and tags. The reason why is a little philosophical.
68
 
69
- When building out this plugin, there were a couple pathways on how best to handle purging caches and they boiled down to two: Decisions (the plugin deletes what it deletes when it deems it appropriate) and Options (you decide what to delete, when and why). It's entirely possible to make this plugin delete everything in a cache, every time a 'trigger' happens, have it only delete prt of the cache, or have it be so you can pick what gets deleted.
70
-
71
- It was decided that the KISS principle was key. Since you can configure Varnish itself to always delete all pages recursively (i.e. purging `http://example.com/` would purge all pages below it), I felt it prudent to allow you to make that choice yourself in Varnish, not the plugin. There are also other plugins that allow for more granular control of Varnish and deleting caches (including W3 Total Cache).
72
-
73
- In the interest of simplicity, this plugin will not be gaining a whole bunch of options to handle that.
74
 
75
  = Why doesn't my cache get deleted when I edit my theme? =
76
 
77
- Because the plugin only deletes caches of your <em>content</em> when you edit it. That means if you edit a page/post, or someone leaves a comment, it'll delete the impacted cached content. Otherwise, you have to delete the whole cache. The plugin will do this for you if you activate a new theme, but not when you edit your current theme's files, and not when you use customizer to change your widgets etc.
78
 
79
- However... If you use the CSS editor in customizer, it will empty the whole cache for your site on publish.
80
 
81
  = How do I manually delete the whole cache? =
82
 
@@ -86,11 +84,7 @@ There's also an "Empty Cache" button on the admin toolbar.
86
 
87
  = I don't see a button! =
88
 
89
- If you're on a Multisite Network and you're on the primary site in the network, only the <em>network</em> admins can empty the cache for that site
90
-
91
- On a subfolder network if you empty the cache for `example.com`, then everything under that (like `example.com/site1` and `example.com/site99` and everything in between) would also get flushed. That means that deleting the cache on the main site deletes the cache for the entire network. Which would really suck.
92
-
93
- In order to mitigate the destructive nature of that power, only the network admins can empty the cache of the main site of a subfolder network.
94
 
95
  = Why is nothing caching when I use PageSpeed? =
96
 
@@ -124,7 +118,7 @@ and
124
 
125
  Your Varnish IP must be one of the IPs that Varnish is listening on. If you use multiple IPs, or if you've customized your ACLs, you'll need to pick on that doesn't conflict with your other settings. For example, if you have Varnish listening on a public and private IP, you'll want to pick the private. On the other hand, if you told Varnish to listen on 0.0.0.0 (i.e. "listen on every interface you can") you would need to check what IP you set your purge ACL to allow (commonly 127.0.0.1 aka localhost), and use that (i.e. 127.0.0.1).
126
 
127
- If your webhost set up Varnish for you, you may need to ask them for the specifics if they don't have it documented. I've listed the ones I know about here, however you should still check with them if you're not sure.
128
 
129
  <ul>
130
  <li><strong>DreamHost</strong> - If you're using DreamPress and Cloudflare, go into the Panel and click on the DNS settings for the domain. The entry for <em>resolve-to.domain</em> is your varnish server: `resolve-to.www A 208.97.157.172` -- If you're <em>NOT</em> using Cloudflare, you don't need it; it's just your normal IP.</li>
@@ -134,8 +128,6 @@ If your webhost set up Varnish for you, you may need to ask them for the specifi
134
 
135
  Multiple IPs are not supported at this time.
136
 
137
- I have a major issue with writing code I don't use, which means that since I'm only using one IP right now, I don't want to be on the ball for supporting multiple IPs. I don't even have a place to test it, which is just insane to attempt to code if you think about it. Yes, I could accept pull requests, but that means everyone's at some other person's discretion. So no, I won't be doing that at this time.
138
-
139
  = Why don't my gzip'd pages get deleted? =
140
 
141
  Make sure your Varnish VCL is configured correctly to purge all the right pages. This is normally an issue with Varnish 2, which is not supported by this plugin.
@@ -148,37 +140,7 @@ The plugin sends a PURGE command of <code>/.*</code> and `X-Purge-Method` in the
148
 
149
  Danger! Here be dragons! If you're command line savvy, you can monitor the interactions between the plugin and Varnish. This can help you understand what's not working quite right, but it can very confusing.
150
 
151
- To see every request made to varnish, use this:
152
- `varnishncsa -F "%m %U"`
153
-
154
- If you want to grab the last purge requests, it's this:
155
- `varnishlog -d -c -m RxRequest:PURGE`
156
-
157
- And this will show you if the WP button was used:
158
- `varnishlog -d -c -m RxURL:.*vhp_flush_all.*`
159
-
160
- In general, I leave the first command up and test the plugin.
161
-
162
- A full Varnish flush looks like this:
163
- `PURGE /.*`
164
-
165
- And a new-post (or edited post) would look like this:
166
-
167
- <pre>
168
- PURGE /category/uncategorized/
169
- PURGE /author/ipstenu/
170
- PURGE /author/ipstenu/feed/
171
- PURGE /2015/08/test-post/
172
- PURGE /feed/rdf/
173
- PURGE /feed/rss/
174
- PURGE /feed/
175
- PURGE /feed/atom/
176
- PURGE /comments/feed/
177
- PURGE /2015/08/test-post/feed/
178
- PURGE /
179
- </pre>
180
-
181
- It's just a matter of poking at things from then on.
182
 
183
  = How do I configure my VCL? =
184
 
@@ -190,23 +152,7 @@ All of these VCLs work with this plugin.
190
 
191
  = Can I filter things to add special URLs? =
192
 
193
- Yes!
194
-
195
-
196
- * `vhp_home_url` - Change the home URL (default is `home_url()`)
197
- * `vhp_purge_urls` - Add additional URLs to what will be purged
198
- * `varnish_http_purge_headers` - Allows you to change the HTTP headers to send with a PURGE request.
199
- * `varnish_http_purge_schema` - Allows you to change the schema (default is http)
200
- * `varnish_http_purge_events` - Add a specific event to trigger a page purge
201
- * `varnish_http_purge_events_full` - Add a specific event to trigger a full site purge
202
-
203
- I strongly urge you to use the last one with caution. If you trigger a full site purge too often, you'll obviate the usefulness of caching!
204
-
205
- = I added in an event to purge on and it's not working =
206
-
207
- If you're using `varnish_http_purge_events` then you have to make sure your event spits out a post ID.
208
-
209
- If you don't have a post ID and you still need this, add it to *both* `varnish_http_purge_events_full` and `varnish_http_purge_events` - but please use this with caution, otherwise you'll be purging everything all the time, and you're a terrible person.
210
 
211
  = Hey, don't you work at DreamHost? Is this Official or DreamHost only? =
212
 
@@ -217,6 +163,13 @@ This plugin is installed by default for _all_ DreamPress installs on DreamHost,
217
 
218
  == Changelog ==
219
 
 
 
 
 
 
 
 
220
  = 4.1.1 =
221
 
222
  * JSON - fixed overzealous json assumptions from causing errors
2
  Contributors: Ipstenu, mikeschroder, techpriester
3
  Tags: varnish, purge, cache
4
  Requires at least: 4.7
5
+ Tested up to: 4.9
6
+ Stable tag: 4.2.0
7
+ Requires PHP: 5.6
8
 
9
  Automatically empty a Varnish Cache when content on your site is modified.
10
 
11
  == Description ==
12
 
13
+ Varnish HTTP Purge sends a request to delete the cached data of a page or post every time it it modified. This happens when updating, publishing, commenting on, or deleting an post, and when changing themes.
14
 
15
+ <a href="https://www.varnish-cache.org/">Varnish</a> is a web application accelerator also known as a caching HTTP reverse proxy. You install it in front of any server that speaks HTTP and configure it to cache the contents. This plugin <em>does not</em> install Varnish for you, nor will it configure Varnish for WordPress.
16
 
17
  Not all page caches are deleted every time, depending on your Varnish configuration. For example, when a post, page, or custom post type is edited, or a new comment is added, <em>only</em> the following pages will purge:
18
 
19
  * The front page
20
  * The post/page edited
21
+ * Any categories, tags, and/or custom taxonomies associated with the page
22
+ * Related feeds
23
+ * Associated json API pages
24
 
25
  In addition, your <em>entire</em> cache will be deleted on the following actions:
26
 
27
  * Changing themes
28
+ * Press the 'Purge Varnish Cache' button on the dashboard or toolbar
 
29
 
30
  Plugins can hook into the purge actions as well, to filter their own events to trigger a purge.
31
 
32
  And if you're into WP-CLI, you can use that too: `wp varnish purge`
33
 
34
+ On a multisite network using subfolders, only <strong>network admins</strong> can purge the main site. This is a security decision.
35
 
36
  = Requirements =
37
 
54
 
55
  = How can I debug my site? =
56
 
57
+ Use the Varnish Status page. It will try and help you figure out what's wrong.
58
 
59
  = Will you fix my site if there's a conflict with a theme or plugin? =
60
 
61
+ I'm sorry but I can't do that, I don't have that much availability. I will try to point you towards solving it on your own. Bear in mind, that may mean you have to decide if using a specific plugin or theme is worth an imperfect cache.
62
 
63
  = What version of Varnish is supported? =
64
 
66
 
67
  = Why doesn't every page cache get deleted when I make a new post? =
68
 
69
+ Philosophy.
70
 
71
+ There are many other plugins out there which will allow you to granularly select what pages should and should not be deleted on updates. With that in mind, the choice was made for decisions instead of options, and simplicity was the driving principle. The plugin decides what's best to delete on updates, and provides hooks for developers to use as needed.
 
 
 
 
72
 
73
  = Why doesn't my cache get deleted when I edit my theme? =
74
 
75
+ If you activate a new theme, or use the customizer to edit your theme, it will delete your cache.
76
 
77
+ If you edit theme (or plugin) files directly, WordPress cannot easily detect those changes and therefor the plugin cannot delete the cache. In that situation, you will need to empty the cache manually.
78
 
79
  = How do I manually delete the whole cache? =
80
 
84
 
85
  = I don't see a button! =
86
 
87
+ That means your user doesn't have the appropriate permissions. Only administrators can empty the entire cache. In the case of a subfolder multisite network, only the <em>network</em> admins can empty the cache for the primary site.
 
 
 
 
88
 
89
  = Why is nothing caching when I use PageSpeed? =
90
 
118
 
119
  Your Varnish IP must be one of the IPs that Varnish is listening on. If you use multiple IPs, or if you've customized your ACLs, you'll need to pick on that doesn't conflict with your other settings. For example, if you have Varnish listening on a public and private IP, you'll want to pick the private. On the other hand, if you told Varnish to listen on 0.0.0.0 (i.e. "listen on every interface you can") you would need to check what IP you set your purge ACL to allow (commonly 127.0.0.1 aka localhost), and use that (i.e. 127.0.0.1).
120
 
121
+ If your webhost set up Varnish, you may need to ask them for the specifics if they don't have it documented. I've listed the ones I know about here, however you should still check with them if you're not sure.
122
 
123
  <ul>
124
  <li><strong>DreamHost</strong> - If you're using DreamPress and Cloudflare, go into the Panel and click on the DNS settings for the domain. The entry for <em>resolve-to.domain</em> is your varnish server: `resolve-to.www A 208.97.157.172` -- If you're <em>NOT</em> using Cloudflare, you don't need it; it's just your normal IP.</li>
128
 
129
  Multiple IPs are not supported at this time.
130
 
 
 
131
  = Why don't my gzip'd pages get deleted? =
132
 
133
  Make sure your Varnish VCL is configured correctly to purge all the right pages. This is normally an issue with Varnish 2, which is not supported by this plugin.
140
 
141
  Danger! Here be dragons! If you're command line savvy, you can monitor the interactions between the plugin and Varnish. This can help you understand what's not working quite right, but it can very confusing.
142
 
143
+ [Detailed directions can be found on the debugging section](https://github.com/Ipstenu/varnish-http-purge/wiki#debugging).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
 
145
  = How do I configure my VCL? =
146
 
152
 
153
  = Can I filter things to add special URLs? =
154
 
155
+ Yes! [Full documentation can be found on Custom Filters in the wiki](https://github.com/Ipstenu/varnish-http-purge/wiki/Custom-Filters).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
 
157
  = Hey, don't you work at DreamHost? Is this Official or DreamHost only? =
158
 
163
 
164
  == Changelog ==
165
 
166
+ = 4.2.0 =
167
+ * More flexible support for custom cat/tag bases
168
+ * Added in support for custom taxonomies
169
+ * New function to generate the URLs, so it can be called by external plugins
170
+ * Move right now box to be called later, preventing double calls
171
+ * Extra check for if it's a URL, because some plugins are weird (props @danielkun)
172
+
173
  = 4.1.1 =
174
 
175
  * JSON - fixed overzealous json assumptions from causing errors
varnish-http-purge.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Varnish HTTP Purge
4
  Plugin URI: https://halfelf.org/plugins/varnish-http-purge/
5
  Description: Automatically empty pages cached by Varnish when content on your site is modified.
6
- Version: 4.1.1
7
  Author: Mika Epstein
8
  Author URI: https://halfelf.org/
9
  License: http://www.apache.org/licenses/LICENSE-2.0
@@ -44,7 +44,6 @@ class VarnishPurger {
44
  defined( 'VHP_VARNISH_IP' ) || define( 'VHP_VARNISH_IP' , false );
45
  add_action( 'init', array( &$this, 'init' ) );
46
  add_action( 'admin_init', array( &$this, 'admin_init' ) );
47
- add_action( 'activity_box_end', array( $this, 'varnish_rightnow' ), 100 );
48
  }
49
 
50
  /**
@@ -54,6 +53,9 @@ class VarnishPurger {
54
  * @access public
55
  */
56
  public function admin_init() {
 
 
 
57
 
58
  // Failure: Pre WP 4.7
59
  if ( version_compare( get_bloginfo( 'version' ), '4.7', '<=' ) ) {
@@ -289,6 +291,9 @@ class VarnishPurger {
289
  */
290
  public function purgeUrl( $url ) {
291
  $p = parse_url( $url );
 
 
 
292
 
293
  // Determine if we're using regex to flush all pages or not
294
  $pregex = '';
@@ -370,6 +375,22 @@ class VarnishPurger {
370
  }
371
  }
372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
373
  /**
374
  * Purge Post
375
  * Flush the post
@@ -442,6 +463,8 @@ class VarnishPurger {
442
  $categories = get_the_category( $postId) ;
443
  if ( $categories ) {
444
  foreach ( $categories as $cat ) {
 
 
445
  array_push( $listofurls,
446
  get_category_link( $cat->term_id ),
447
  get_rest_url() . $rest_api_route . '/categories/' . $cat->term_id . '/'
@@ -451,13 +474,28 @@ class VarnishPurger {
451
  // Tag purge based on Donnacha's work in WP Super Cache
452
  $tags = get_the_tags( $postId );
453
  if ( $tags ) {
 
 
454
  foreach ( $tags as $tag ) {
455
  array_push( $listofurls,
456
  get_tag_link( $tag->term_id ),
457
- get_rest_url() . $rest_api_route . '/tags/' . $tag->term_id . '/'
458
  );
459
  }
460
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
461
 
462
  // Author URL
463
  $author_id = get_post_field( 'post_author', $postId );
3
  Plugin Name: Varnish HTTP Purge
4
  Plugin URI: https://halfelf.org/plugins/varnish-http-purge/
5
  Description: Automatically empty pages cached by Varnish when content on your site is modified.
6
+ Version: 4.2.0
7
  Author: Mika Epstein
8
  Author URI: https://halfelf.org/
9
  License: http://www.apache.org/licenses/LICENSE-2.0
44
  defined( 'VHP_VARNISH_IP' ) || define( 'VHP_VARNISH_IP' , false );
45
  add_action( 'init', array( &$this, 'init' ) );
46
  add_action( 'admin_init', array( &$this, 'admin_init' ) );
 
47
  }
48
 
49
  /**
53
  * @access public
54
  */
55
  public function admin_init() {
56
+
57
+ // Add to 'right now'
58
+ add_action( 'activity_box_end', array( $this, 'varnish_rightnow' ), 100 );
59
 
60
  // Failure: Pre WP 4.7
61
  if ( version_compare( get_bloginfo( 'version' ), '4.7', '<=' ) ) {
291
  */
292
  public function purgeUrl( $url ) {
293
  $p = parse_url( $url );
294
+
295
+ // Bail early if there's no host since some plugins are weird
296
+ if ( !isset( $p['host'] ) ) return;
297
 
298
  // Determine if we're using regex to flush all pages or not
299
  $pregex = '';
375
  }
376
  }
377
 
378
+ /**
379
+ * Generate URLs
380
+ *
381
+ * Generates a list of URLs that should be purged, based on the post ID
382
+ * passed through. Useful for when you're trying to get a post to flush
383
+ * another post.
384
+ *
385
+ * @access public
386
+ * @param mixed $postId
387
+ * @return array()
388
+ */
389
+ public function generate_urls ( $postId ) {
390
+ $this->purgePost( $postId );
391
+ return $this->purgeUrls;
392
+ }
393
+
394
  /**
395
  * Purge Post
396
  * Flush the post
463
  $categories = get_the_category( $postId) ;
464
  if ( $categories ) {
465
  foreach ( $categories as $cat ) {
466
+ $category_base = get_option( 'category_base');
467
+ if ( $category_base == '' ) $category_base = '/category/';
468
  array_push( $listofurls,
469
  get_category_link( $cat->term_id ),
470
  get_rest_url() . $rest_api_route . '/categories/' . $cat->term_id . '/'
474
  // Tag purge based on Donnacha's work in WP Super Cache
475
  $tags = get_the_tags( $postId );
476
  if ( $tags ) {
477
+ $tag_base = get_option( 'tag_base' );
478
+ if ( $tag_base == '' ) $tag_base = '/tag/';
479
  foreach ( $tags as $tag ) {
480
  array_push( $listofurls,
481
  get_tag_link( $tag->term_id ),
482
+ get_rest_url() . $rest_api_route . $tag_base . $tag->term_id . '/'
483
  );
484
  }
485
  }
486
+ // Custom Taxonomies
487
+ $taxonomies = get_post_taxonomies( $postId );
488
+ if ( $taxonomies ) {
489
+ foreach ( $taxonomies as $taxonomy ) {
490
+ $terms = wp_get_post_terms( $postId, $taxonomy );
491
+ foreach ( $terms as $term ) {
492
+ array_push( $listofurls,
493
+ get_term_link( $term ),
494
+ get_rest_url() . $rest_api_route . '/' . $term->taxonomy . '/' . $term->slug . '/'
495
+ );
496
+ }
497
+ }
498
+ }
499
 
500
  // Author URL
501
  $author_id = get_post_field( 'post_author', $postId );
varnish-status.php CHANGED
@@ -90,7 +90,7 @@ class VarnishStatus {
90
  <p><strong><?php _e('If you aren\'t sure what to do, contact your webhost or server admin before making any changes.', 'varnish-http-purge'); ?></strong></p>
91
 
92
  <ul>
93
- <li><?php _e('DreamHost - Go into the Panel and click on the DNS settings for the domain. The entry for <em>resolve-to.domain</em> (if set) will your varnish server. If it\'s not set, then you don\'t need to worry about this at all. Example:', 'varnish-http-purge'); ?> <code>resolve-to.www A 208.97.157.172</code></li>
94
  </ul>
95
  <?php
96
  }
@@ -132,7 +132,11 @@ class VarnishStatus {
132
  */
133
  function options_callback_url() {
134
 
135
- ?><p><?php _e( 'While it would be impossible to detect all possible conflicts, this Status Page will perform a check of the most common issues that prevent Varnish from caching your site properly.', 'varnish-http-purge' ); ?></p><?php
 
 
 
 
136
 
137
  $icon_awesome = '<span class="dashicons dashicons-heart" style="color:#008000;"></span>';
138
  $icon_good = '<span class="dashicons dashicons-thumbs-up" style="color:#008000;"></span>';
90
  <p><strong><?php _e('If you aren\'t sure what to do, contact your webhost or server admin before making any changes.', 'varnish-http-purge'); ?></strong></p>
91
 
92
  <ul>
93
+ <li><?php _e('DreamHost - Go into the Panel and click on the DNS settings for the domain. The entry for <em>resolve-to.domain</em> (if set) will be your varnish server. If it\'s not set, then you don\'t need to worry about this at all. Example:', 'varnish-http-purge'); ?> <code>resolve-to.www A 208.97.157.172</code></li>
94
  </ul>
95
  <?php
96
  }
132
  */
133
  function options_callback_url() {
134
 
135
+ ?><p><?php _e( 'While it is impossible to detect all possible conflicts, this Status Page will perform a check of the most common issues that prevent Varnish from caching your site properly.', 'varnish-http-purge' ); ?></p>
136
+
137
+ <p><?php _e( 'This feature is provided to help you in debugging any conflicts. If filing an issue with your webhost, it can be useful to include the output in your ticket.', 'varnish-http-purge' ); ?></p>
138
+
139
+ <?php
140
 
141
  $icon_awesome = '<span class="dashicons dashicons-heart" style="color:#008000;"></span>';
142
  $icon_good = '<span class="dashicons dashicons-thumbs-up" style="color:#008000;"></span>';