From 90e54ef13c5d05b3c2f71a40f308acdee9d6dc30 Mon Sep 17 00:00:00 2001 From: Joaquim de Souza Date: Fri, 28 Jun 2019 15:06:33 +0100 Subject: [PATCH 1/4] add before_delete hook handling to WordpressPost --- src/PostTypeManager.php | 7 +++++++ src/PostTypes/WordpressPost.php | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/PostTypeManager.php b/src/PostTypeManager.php index 070ce27..5d6d368 100644 --- a/src/PostTypeManager.php +++ b/src/PostTypeManager.php @@ -100,6 +100,13 @@ public function registerPostTypes($classNames) } }, '99', 2); // use high priority value to ensure this happens after acf finishes saving its metadata + add_action('before_delete_post', function($postId) { + $post = WordpressPost::fetchById($postId); + if ($post) { + $post->onDelete(); + } + }, '99'); + $this->registered = true; do_action('oowp/all_post_types_registered', $this->postTypes); } diff --git a/src/PostTypes/WordpressPost.php b/src/PostTypes/WordpressPost.php index bcfeb4a..b3cc7ff 100644 --- a/src/PostTypes/WordpressPost.php +++ b/src/PostTypes/WordpressPost.php @@ -121,6 +121,13 @@ public function onSave($postData) { // do nothing } + /** + * Override this to hook into the before_delete event. + */ + public function onDelete() { + // do nothing + } + /** * Proxy magic properties to WP_Post * @param string $name From 765f540d9de62163d41040982996279775706025 Mon Sep 17 00:00:00 2001 From: Joaquim de Souza Date: Fri, 28 Jun 2019 15:36:34 +0100 Subject: [PATCH 2/4] fix before_delete_post hook --- src/PostTypeManager.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/PostTypeManager.php b/src/PostTypeManager.php index 5d6d368..9cb608a 100644 --- a/src/PostTypeManager.php +++ b/src/PostTypeManager.php @@ -101,11 +101,14 @@ public function registerPostTypes($classNames) }, '99', 2); // use high priority value to ensure this happens after acf finishes saving its metadata add_action('before_delete_post', function($postId) { - $post = WordpressPost::fetchById($postId); - if ($post) { - $post->onDelete(); + $query = (new OowpQuery([ + 'post__in' => [$postId], + 'post_status' => 'trash' + ])); + if (count($query)) { + $query->posts[0]->onDelete(); } - }, '99'); + }); $this->registered = true; do_action('oowp/all_post_types_registered', $this->postTypes); From deaf0be6f9c3288ae0cdf2b8a0a1895f81a37d6b Mon Sep 17 00:00:00 2001 From: Joaquim de Souza Date: Fri, 28 Jun 2019 18:57:29 +0100 Subject: [PATCH 3/4] spaces to tabs --- src/PostTypeManager.php | 18 +++++++++--------- src/PostTypes/WordpressPost.php | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/PostTypeManager.php b/src/PostTypeManager.php index 9cb608a..4f4b156 100644 --- a/src/PostTypeManager.php +++ b/src/PostTypeManager.php @@ -100,15 +100,15 @@ public function registerPostTypes($classNames) } }, '99', 2); // use high priority value to ensure this happens after acf finishes saving its metadata - add_action('before_delete_post', function($postId) { - $query = (new OowpQuery([ - 'post__in' => [$postId], - 'post_status' => 'trash' - ])); - if (count($query)) { - $query->posts[0]->onDelete(); - } - }); + add_action('before_delete_post', function($postId) { + $query = (new OowpQuery([ + 'post__in' => [$postId], + 'post_status' => 'trash' + ])); + if (count($query)) { + $query->posts[0]->onDelete(); + } + }); $this->registered = true; do_action('oowp/all_post_types_registered', $this->postTypes); diff --git a/src/PostTypes/WordpressPost.php b/src/PostTypes/WordpressPost.php index b3cc7ff..90b6f50 100644 --- a/src/PostTypes/WordpressPost.php +++ b/src/PostTypes/WordpressPost.php @@ -124,9 +124,9 @@ public function onSave($postData) { /** * Override this to hook into the before_delete event. */ - public function onDelete() { - // do nothing - } + public function onDelete() { + // do nothing + } /** * Proxy magic properties to WP_Post From 0024e0ff78d9e67813bff3d2e491bb040572dbd3 Mon Sep 17 00:00:00 2001 From: Joaquim de Souza Date: Fri, 28 Jun 2019 18:58:46 +0100 Subject: [PATCH 4/4] spaces to tabs --- src/PostTypes/WordpressPost.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PostTypes/WordpressPost.php b/src/PostTypes/WordpressPost.php index 90b6f50..d7282ca 100644 --- a/src/PostTypes/WordpressPost.php +++ b/src/PostTypes/WordpressPost.php @@ -121,9 +121,9 @@ public function onSave($postData) { // do nothing } - /** - * Override this to hook into the before_delete event. - */ + /** + * Override this to hook into the before_delete event. + */ public function onDelete() { // do nothing }