Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete post hook #6

Open
wants to merge 4 commits into
base: v2
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix before_delete_post hook
  • Loading branch information
joaquimds committed Jun 28, 2019
commit 765f540d9de62163d41040982996279775706025
11 changes: 7 additions & 4 deletions src/PostTypeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down