Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#34715 closed defect (bug) (invalid)

transition_post_status does not fire when untrashing a post

Reported by: sebsz's profile SeBsZ Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.3.1
Component: Posts, Post Types Keywords:
Focuses: Cc:


transition_post_status does not fire when untrashing a published custom post.

I've got an action added as follows:

add_action('transition_post_status', 'my_transition', 10, 3);

When I trash a drafted custom post, the function is fired with old=draft and new=trash. If I then undo the trash action, the function is correctly fired with old=trash and new=draft. If we then repeat the experiment with a published post, and we trash it the function fires with old=publish and new=trash. If we now undo the action, the function does NOT fire at all, where it should have fired with old=trash and new=publish.

I've noticed this with a custom post type. This does NOT happen with the default post type.

Change History (5)

#1 @archon810
8 years ago

Definitely interested in seeing this one resolved.

#2 @nadimtuhin
8 years ago

I want to help fixing this bug

#3 @eventualo
8 years ago

I've added this log function and I've made some tests with a couple of custom post types:

add_action('transition_post_status', function( $new_status, $old_status, $post ){
        error_log( 'Post ID '. $post->ID .': '. $old_status . ' => '. $new_status );
}, 10, 3);

It seems that the action has been fired by all transitions and I can see them in log, including old=trash => new=publish.

#4 @johnbillion
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Tested with untrashing a published custom post type, and the transition_post_status hook fires as expected with publish and trash as the $new_status and $old_status parameters respectively.

The wp_transition_post_status() function is called for all post types except attachments:

I'm not sure what to suggest to aid in your debugging I'm afraid, but the hook definitely fires as expected. You may want to try posting your custom post type code on the support forums or on WordPress Stack Exchange to see if anyone can help.

Last edited 8 years ago by johnbillion (previous) (diff)

#5 @SeBsZ
8 years ago

I confirm that there is no bug. This was actually caused by a series of recursive functions firing which at one point contained a

remove_action('transition_post_status', 'my_publish_post', 1);

No wonder the action didn't fire. I apologize for any time I wasted, but thanks for looking into this!

Note: See TracTickets for help on using tickets.