Comments (6)
Oh .. wow. That makes a lot of sense why it happens. Yeah, make a PR for that. It looks right. The only other thing I can think of is hooking into the post_status change functions themselves, but even so, it would require a large retrofit either way.
from varnish-http-purge.
@carlalexander Hi, I think you pinpointed my issue too. Noticed that posts reverted to draft do not trigger a purge request since the front page remains unchanged. Where did you implement this function? In the plugin itself of functions.php?
Thanks anyways!
update - Works for me in functions.php, hope this will be merged in the main branch. :)
from varnish-http-purge.
Yeah, it's just custom code we created to work around the issue. Will probably work on a patch tomorrow. π
from varnish-http-purge.
UPDATE: Code above stopped working!
Fatal error from running VarnishPurger->purgePost( )
Our editor discovered that we were getting fatal errors when posts were reverted to draft:
Fatal error: Uncaught Error: Call to undefined function purge_post() in /.../wp-content/plugins/varnish-http-purge/varnish-http-purge.php on lineΒ 867
..
8 | 1.0819 | 59413400 | gv_varnish_purge_non_accessible_post( ) | .../class-wp-hook.php:286
9 | 1.0819 | 59413424 | VarnishPurger->purgePost( ) | .../gv-varnish.php:133
From looking at the code, it seems obvious that purgePost
was quite logically replaced with purge_post
but that despite the efforts to add purgePost
as an alias, it didn't work, and our code caused fatal errors as a result.
@Ipstenu I figured it out, though I missed it at first (have been editing this comment):
public function purgePost( $post_id ) {
purge_post( $post_id );
}
Maybe it was due to bad automation, but clearly, we shouldn't expect that alias of the old method to work. I imagine you meant $this-purge_post()
.
It seems to apply to all of the aliases in that section, so you could fix them pretty easily if you want.
New version of working code to purge when post is moved from publish->draft
@RichardNeveri PLZ take note, if you're still running this code, you should update it.
Following is our current working code (also includes more verbose explanation of the issue and workaround):
/**
* Purges a post from Varnish when their status changes from a publicly accessible link to one without one.
*
* Affects behavior of Varnish HTTP Purge plugin, which already handles most cases where the status changes,
* but neglects publish->draft and friends for seemingly technical reasons.
*
* For us having de-published posts (publish->draft) get removed from Varnish cash is obviously a priority,
* so this ensures that happens while we wait for a fix in the main plugin.
*
* @see github issue: https://github.com/Ipstenu/varnish-http-purge/issues/39
*
* Runs VarnishPurger->purgePost when the old status is
* - publish
* - private
* - trash
* And the new status is
* - pending
* - draft
*
* This covers the blind spots of the plugin, which already handles e.g. publish->trash and publish->private
*
* This method must be called before WordPress updates the database because VarnishPurger uses functions
* that use current database values. This is why we use pre_post_update
*
* @uses get_post_status($post_id) which is old status
* @uses $post_data['post_status'] which is the new status that hasn't been saved yet
* @global VarnishPurger $purger object instantiated at the bottom of varnish-http-purge.php
* @param int $post_id
* @param array $post_data
*/
function gv_varnish_purge_non_accessible_post($post_id, $post_data) {
global $purger;
/**
* Run the purger if
* - The old status IS publish, private or trash
* - AND new status IS pending or draft
*/
if (!$purger instanceof VarnishPurger
|| empty($post_data['post_status'])
|| !in_array(get_post_status($post_id), array('publish', 'private', 'trash'))
|| !in_array($post_data['post_status'], array('pending', 'draft'))
) {
return;
}
$purger->purge_post($post_id);
}
add_action('pre_post_update', 'gv_varnish_purge_non_accessible_post', 10, 2);
from varnish-http-purge.
God it would help if I PUSHED the code, wouldn't it? Lemme fix the deprecation!
from varnish-http-purge.
So for whatever reason, the promised patch never came in. I'm planning to add this in 5.0, so please check that out when that pops up in a bit.
from varnish-http-purge.
Related Issues (20)
- Problems with varnish-6.6.2
- Request to take over HOT 1
- PURGE requests should be non-blocking & Issues with redirection/302/WP HTTP API HOT 7
- Better formatting of grep output HOT 2
- Deep Dive on what Woo does differently HOT 7
- Prevent Duplicate URLs from being flushed HOT 1
- Asynchronous PHP HOT 1
- Strip all query params from the urls
- How to purge URLs that contain language cookies? HOT 3
- WooCommerce checkout causes 6 calls to VarnishPurger->purge_post per cart item HOT 3
- Undefined variable: footer_text in varnish-http-purge/settings.php on line 507 HOT 1
- "The "Age" header is set to an invalid time, which will result in incorrect caching." HOT 3
- Purging all at customize_save_after HOT 2
- All purges happen twice with Gutenberg Editor HOT 2
- Multiple IP functionality not working. HOT 10
- Unable to find a caching service active for this domain. HOT 3
- Varnish 4 and RegExp Purge HOT 1
- VCL optimizations HOT 40
- Cache Service Varnish caching service is running but is unable to cache your site. HOT 14
- Rest API archives / partial regex purge HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from varnish-http-purge.