duplicate-post icon indicating copy to clipboard operation
duplicate-post copied to clipboard

Adds re-publish action hooks

Open piscis opened this issue 4 years ago • 4 comments

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.

piscis avatar Dec 01 '21 21:12 piscis

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

jphorn avatar Jun 28 '22 13:06 jphorn

@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 ;-(

piscis avatar Jun 28 '22 16:06 piscis

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?

jphorn avatar Jun 28 '22 19:06 jphorn

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);  

piscis avatar Jun 28 '22 19:06 piscis