#15628 closed defect (bug) (fixed)
Trash_post action runs twice for each call
Reported by: | b-rad | Owned by: | ryan |
---|---|---|---|
Milestone: | 3.3 | Priority: | normal |
Severity: | normal | Version: | 2.9 |
Component: | General | Keywords: | has-patch dev-feedback |
Focuses: | Cc: |
Description
Whenever I run
add_action ( 'trash_post', 'my_trash_post' );
in a plugin, the function being run (e.g. my_trash_post) always runs twice. Shouldn't it only run once?
Attachments (1)
Change History (12)
#2
@
14 years ago
I'm testing it by trashing a single, new test post. I'm the only user in the system and there's nothing special about the posts being used as test cases. When I trash one post, no other posts are being trashed or marked as trashed (i.e. only the post I'm trashing actually gets trashed as expected, yet the action runs twice). I've looked at wp-includes/post.php for a reason for this but haven't found one. But then again, I don't know exactly what the start to finish process is when Wordpress goes through a trash operation.
#4
@
14 years ago
- Keywords needs-patch dev-feedback added; trash_post removed
- Milestone changed from Awaiting Review to Future Release
- Version changed from 3.0.3 to 2.9
Ah ha. It's an action name clash.
wp_trash_post() calls 'trash_post'.
wp_transition_post_status() calls '$post_status_$post_type', which is 'trash_post'.
Clever. We'll have to kill or rename the one in wp_trash_post.
#6
follow-up:
↓ 11
@
14 years ago
Shouldn't we also deprecate and rename untrash_post
for consistency?
#9
@
13 years ago
- Owner set to ryan
- Resolution set to fixed
- Status changed from new to closed
In [18974]:
#11
in reply to:
↑ 6
@
7 years ago
Replying to SergeyBiryukov:
Shouldn't we also deprecate and rename
untrash_post
for consistency?
Yes one would think. I was working on a plugin and kept thinking that wp_untrash_post was going to fire and never did. However there is a method that is called wp_untrash_post which when called, does the untrashing of the post in the trash and is not actually a hook.
Some semantic naming could help here.
I don't see this anywhere in the code. I do know there's an issue with delete(d)?_post being fired twice, but not this.
Perhaps it's getting run on multiple posts, post types, etc?