Make WordPress Core

Opened 14 years ago

Closed 13 years ago

Last modified 7 years ago

#15628 closed defect (bug) (fixed)

Trash_post action runs twice for each call

Reported by: b-rad's profile b-rad Owned by: ryan's profile ryan
Milestone: 3.3 Priority: normal
Severity: normal Version: 2.9
Component: General Keywords: has-patch dev-feedback
Focuses: Cc:


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)

15628.patch (474 bytes) - added by SergeyBiryukov 14 years ago.

Download all attachments as: .zip

Change History (12)

#1 @nacin
14 years ago

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?

#2 @b-rad
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.

#3 @b-rad
14 years ago

  • Version changed from 3.0.2 to 3.0.3

#4 @nacin
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.

#5 @SergeyBiryukov
14 years ago

  • Keywords has-patch added; needs-patch removed

#6 follow-up: @SergeyBiryukov
14 years ago

Shouldn't we also deprecate and rename untrash_post for consistency?

#7 @mdawaffe
13 years ago

+1 to patch.

#8 @ryan
13 years ago

  • Milestone changed from Future Release to 3.3

#9 @ryan
13 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [18974]:

In wp_trash_post(), rename the trash_post action to wp_trash_post to avoid collision with the wp_transition_post_status() trash_post state transition. Props SergeyBiryukov. fixes #15628

#10 @johnjamesjacoby
13 years ago

Cross posting from #BB1707, r18974 introduced a small bbPress 2.0 bug from being hooked onto 'trash_post' there. Will be fixed in bbPress 2.1.

#11 in reply to: ↑ 6 @mkormendy
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.

Note: See TracTickets for help on using tickets.