Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this questionDescribe 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
- 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)); }
- Create a new Gutenberg post and publish it
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this questionDescribe 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
- 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)); }
- 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
1 Answer
Reset to default 4But 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...