Skip to content

Commit

Permalink
Remove no-longer-necessary post status inspection code
Browse files Browse the repository at this point in the history
Because we are now hooked on `transition_post_status`, which handles the logic
of determining when to purge for a post for various post status transitions (or
same-to-same "transitions"), `purgeCacheByRelevantURLs()` no longer
needs to do this work.

see #365
fixes #395
  • Loading branch information
markjaquith committed Mar 22, 2021
1 parent 2e9b9ce commit ce99b69
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
2 changes: 1 addition & 1 deletion cloudflare.loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
$cloudflarePurgeURLActions = apply_filters('cloudflare_purge_url_actions', $cloudflarePurgeURLActions);

foreach ($cloudflarePurgeURLActions as $action) {
add_action($action, array($cloudflareHooks, 'purgeCacheByRelevantURLs'), PHP_INT_MAX, 4);
add_action($action, array($cloudflareHooks, 'purgeCacheByRelevantURLs'), PHP_INT_MAX);
}

/**
Expand Down
31 changes: 4 additions & 27 deletions src/WordPress/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function purgeCacheEverything()
}
}

public function purgeCacheByRelevantURLs($postId, ...$args)
public function purgeCacheByRelevantURLs($postId)
{
if ($this->isPluginSpecificCacheEnabled() || $this->isAutomaticPlatformOptimizationEnabled()) {
$wpDomainList = $this->integrationAPI->getDomainList();
Expand All @@ -135,36 +135,13 @@ public function purgeCacheByRelevantURLs($postId, ...$args)
}
$wpDomain = $wpDomainList[0];

$validPostStatus = array('publish', 'trash', 'private');
$thisPostStatus = get_post_status($postId);

if (get_permalink($postId) != true || !in_array($thisPostStatus, $validPostStatus)) {
return;
}

// We don't need to purge for private posts, except when they were just transitioned from public.
if ('private' === $thisPostStatus) {
// The action that fires on transition of status is "post_updated", which will have the old version
// in the extra args. If that arg is not there we can bail out.
if (! isset($args[1])) {
return;
}
/**
* @var \WP_Post $before Previous version of post.
*/
list(, $before) = $args;

if ('private' === $before->post_status) {
return;
}
}

if (is_int(wp_is_post_autosave($postId)) || is_int(wp_is_post_revision($postId))) {
// Do not purge for autosaves or updates to post revisions.
if (wp_is_post_autosave($postId) || wp_is_post_revision($postId)) {
return;
}

$savedPost = get_post($postId);
if (is_a($savedPost, 'WP_Post') == false) {
if (!is_a($savedPost, 'WP_Post')) {
return;
}

Expand Down

0 comments on commit ce99b69

Please sign in to comment.