Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds re-publish action hooks #215

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

piscis
Copy link

@piscis piscis commented Dec 1, 2021

Context

This PR introduces two action hooks dp_republish_start and dp_republish_done to the republish method. A developer can hook into the republish cycle at the beginning or end when a post gets republished.

We needed to hook into the republish cycle of the plugin to trigger cache invalidation steps after a post gets republished. unfortunately the wp save_post hook was not enough for our case because some of the meta fields still got copied over while the main article content was already finished copying over its original content. In some cases (very large posts with a couple of 100 meta field entries) this could lead to a raise condition were the cache was invalidated but did not show the complete republished update of that post.

Introduces start and done hook when a republish is triggered
@jphorn
Copy link

jphorn commented Jun 28, 2022

I could really use this PR as we're seeing the same race conditions issues as described in the PR.

@piscis
Copy link
Author

piscis commented Jun 28, 2022

@jphorn I'll updated the PR one more time with the latest changes but it's unfortunate that we never got a response from someone at yoast ( e.g. @enricobattocchi) regarding this PR. Since then we decided to maintain a forke of this plugin just for the sake of getting this functionality ;-(

@jphorn
Copy link

jphorn commented Jun 28, 2022

Thank you. Please know it's much appreciated. If nothing happens we'll might have to use your fork.
Could you please share how you currently use the filters on your site?

@piscis
Copy link
Author

piscis commented Jun 28, 2022

We did not publish our fork of this because we feel that this is something that should be supported by the plugin authors and it does not make sense in the long run to maintain it for the community.

Regarding the implementation. We're using the dp_publish_done action to clear our reverse proxy caches when ever a post is (re)published. That's why we need a hook at the end of a publish run that makes sure that the post + every meta data field got copied over before we trigger our caches to invalidate and generate a new version of the published post.

The implementation looks more or less like this:

<?php

add_action('dp_republish_done', function($post, $original_post) {

  if(!empty($original_post)) {
       // ... Logic to invalidate caches after a post is published via rewrite/republish
    }
  }
}, 10, 2);  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants