Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#34715 closed defect (bug) (invalid)

transition_post_status does not fire when untrashing a post

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

Description

transition_post_status does not fire when untrashing a published custom post.

I've got an action added as follows:

<?php
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
11 years ago

Definitely interested in seeing this one resolved.

#2 @nadimtuhin
11 years ago

I want to help fixing this bug

#3 @eventualo
11 years ago

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

<?php
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
11 years ago

  • Milestone Awaiting Review
  • Resolutioninvalid
  • Status newclosed

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: https://core.trac.wordpress.org/browser/tags/4.3.1/src/wp-includes/post.php#L3517

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 WordPress.org support forums or on WordPress Stack Exchange to see if anyone can help.

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

#5 @SeBsZ
11 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

<?php
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.