Make WordPress Core

Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#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:


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 4 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 nacin4 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?

comment:2 b-rad4 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.

comment:3 b-rad4 years ago

  • Version changed from 3.0.2 to 3.0.3

comment:4 nacin4 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.

SergeyBiryukov4 years ago

comment:5 SergeyBiryukov4 years ago

  • Keywords has-patch added; needs-patch removed

comment:6 SergeyBiryukov4 years ago

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

comment:7 mdawaffe3 years ago

+1 to patch.

comment:8 ryan3 years ago

  • Milestone changed from Future Release to 3.3

comment:9 ryan3 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

comment:10 johnjamesjacoby3 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.

Note: See TracTickets for help on using tickets.