block editor - transition_post_status hook doesn't have any POST data when publish with Gutenberg

admin2025-06-02  3

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 6 years ago.

Improve this question

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

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 6 years ago.

Improve this question

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/WordPress/gutenberg/issues/12897

Share Improve this question asked Feb 21, 2019 at 17:33 Gnanasekaran LoganathanGnanasekaran Loganathan 1216 bronze badges 2
  • 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 Commented Feb 21, 2019 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 Loganathan Commented Feb 21, 2019 at 20:32
Add a comment  | 

1 Answer 1

Reset to default 4

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748879063a314480.html

最新回复(0)