diff --git a/src/PostTypeManager.php b/src/PostTypeManager.php index 070ce27..4f4b156 100644 --- a/src/PostTypeManager.php +++ b/src/PostTypeManager.php @@ -100,6 +100,16 @@ 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(); + } + }); + $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..d7282ca 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