Update cache clearing for post actions that was originally added in PR #129 and revised in PR #142. While those PRs laid the structure for more efficient cache clearing in version 1.5.0 around post actions, like when any post type is published, or any published post type is updated or trashed, it did not take into account the old post data that may need to be cleared (except the old author). This means pages that may have referenced the cached page beforehand were not being cleared, such as old categories, tags, or permalinks. For example, if the post was in the tutorials category but was changed to definitions, only the definitions category would have been cleared because the cache being cleared occurred after the post had been updated. Or, if the post permalink was changed, like from /post-with-mispelling/ to /post-with-misspelling/, only /post-with-misspelling/ would have been cleared as it is the new permalink.
This PR fixes that oversight by using the pre_post_update hook to clear the page and associated cache before the post is updated. Clearing the cache before the post is updated fixes the issue where if a post status was publish and changed, like to draft, the home page cache was being cleared instead of the page cache because the permalink would now return the guid (e.g. https://www.example.com?p=123) as it was no longer published. After the post has been updated the page and associated cache will still try to be cleared when the save_post hook is fired and the post status is publish. Using wp_trash_post is still required for trashed posts because by the time pre_post_update is fired the permalink contains __trashed.
Update cache clearing for post actions that was originally added in PR #129 and revised in PR #142. While those PRs laid the structure for more efficient cache clearing in version 1.5.0 around post actions, like when any post type is published, or any published post type is updated or trashed, it did not take into account the old post data that may need to be cleared (except the old author). This means pages that may have referenced the cached page beforehand were not being cleared, such as old categories, tags, or permalinks. For example, if the post was in the
tutorials
category but was changed todefinitions
, only thedefinitions
category would have been cleared because the cache being cleared occurred after the post had been updated. Or, if the post permalink was changed, like from/post-with-mispelling/
to/post-with-misspelling/
, only/post-with-misspelling/
would have been cleared as it is the new permalink.This PR fixes that oversight by using the
pre_post_update
hook to clear the page and associated cache before the post is updated. Clearing the cache before the post is updated fixes the issue where if a post status waspublish
and changed, like todraft
, the home page cache was being cleared instead of the page cache because the permalink would now return the guid (e.g.https://www.example.com?p=123
) as it was no longer published. After the post has been updated the page and associated cache will still try to be cleared when thesave_post
hook is fired and the post status ispublish
. Usingwp_trash_post
is still required for trashed posts because by the timepre_post_update
is fired the permalink contains__trashed
.