From 709400a2edbf8e6c1fb56673a14d865f28576ef0 Mon Sep 17 00:00:00 2001 From: Martijn Gastkemper Date: Wed, 23 Aug 2023 13:24:22 +0200 Subject: [PATCH 1/2] Update SimplyStaticDeploy.php --- includes/SimplyStaticDeploy.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/includes/SimplyStaticDeploy.php b/includes/SimplyStaticDeploy.php index d5ef3db..b26d053 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); } /** @@ -149,6 +152,7 @@ protected function remove_static_page(\WP_Post $post) return; } + var_dump('BB'); $s3client->deleteObject([ 'Bucket' => $config->aws->bucket, 'Key' => $s3Key, @@ -185,4 +189,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); + } } From 3e1a1efd8a60917079053e49aadfde5f477c4646 Mon Sep 17 00:00:00 2001 From: Martijn Gastkemper Date: Wed, 23 Aug 2023 13:25:34 +0200 Subject: [PATCH 2/2] Update SimplyStaticDeploy.php --- includes/SimplyStaticDeploy.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/SimplyStaticDeploy.php b/includes/SimplyStaticDeploy.php index b26d053..4ae1d2c 100644 --- a/includes/SimplyStaticDeploy.php +++ b/includes/SimplyStaticDeploy.php @@ -152,7 +152,6 @@ protected function remove_static_page(\WP_Post $post) return; } - var_dump('BB'); $s3client->deleteObject([ 'Bucket' => $config->aws->bucket, 'Key' => $s3Key,