diff --git a/includes/SimplyStaticDeploy.php b/includes/SimplyStaticDeploy.php index d5ef3db..4ae1d2c 100644 --- a/includes/SimplyStaticDeploy.php +++ b/includes/SimplyStaticDeploy.php @@ -89,10 +89,7 @@ public function remove_static_pages_for_certain_status_transitions( return; } - $publicPostTypes = get_post_types(['public' => true]); - $postTypesToObserve = f\omit(['attachment'], $publicPostTypes); - - if (!in_array($post->post_type, $postTypesToObserve)) { + if (!$this->is_post_applicable($post)) { return; } @@ -106,9 +103,15 @@ public function remove_old_static_page_when_slug_is_changed( WP_Post $post_after, WP_Post $post_before ) { - if ($post_after->post_name !== $post_before->post_name) { - $this->remove_static_page($post_before); + if ($post_after->post_name === $post_before->post_name) { + return; + } + + if (!$this->is_post_applicable($post_after)) { + return; } + + $this->remove_static_page($post_before); } /** @@ -185,4 +188,12 @@ protected function get_pretty_permalink(\WP_Post $post): string $samplePermalink[0] // https://example.com/updates/%postname%/ ); } + + private function is_post_applicable(\WP_Post $post): bool + { + $publicPostTypes = get_post_types(['public' => true]); + $postTypesToObserve = f\omit(['attachment'], $publicPostTypes); + + return in_array($post->post_type, $postTypesToObserve); + } }