0

Describe the bug

When placing a hook on transition_post_status I can see it fired but no POST data is available, to get that post data I have to use the save_post hook which is inconvenient since I don't get the $new_status and $old_status infos.

To Reproduce

  1. Hook into transition_post_status. Something like the following code in functions.php will do the job:
add_action( 'transition_post_status', 'log_data', 10, 3 );

    function log_data( $new_status, $old_status, $post ) {
        error_log(json_encode($_POST));
    }
  1. Create a new Gutenberg post and publish it

https://github.com/WordPress/gutenberg/issues/12897

closed as unclear what you're asking by Pat J, Nathan Johnson, rudtek, Christine Cooper, TheDeadMedic Mar 13 at 10:30

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • This is something to take up with the Gutenberg developers, as you and others have done at the linked Github issue. I'm not sure what you want to accomplish by posting it here. – Pat J Feb 21 at 17:47
  • Not all aware of this Github post, I want to ask developers here about this issue and if the issue will solve in Github people will know by follow the link. – Gnanasekaran Feb 21 at 20:32
2

But you shouldn't use $_POST inside that hook.

transition_post_status fires when a post is transitioned from one status to another.

It can be caused by anything (not only by sending POST request from editor).

For example here's the function that is responsible for publishing future posts: check_and_publish_future_post. It's called only by cron, without sending any POST data at all...

transition_post_status hook takes 3 params:

$new_status (string) New post status.

$old_status (string) Old post status.

$post (WP_Post) Post object.

and you should use mainly these values in your action - you can be certain that they will be passed and will be correct.

You can't assume anything about the contents of POST request...

  • publish_future_post hook not trigger when post publish – Gnanasekaran Feb 25 at 16:57
  • Yes it is - just take a look at the second link in my answer - this is the function that is used as callback for publish_future_post schedule event, and you can clearly see that it uses status transitions inside of it. – Krzysiek Dróżdż Feb 25 at 16:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.