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
add_action( 'transition_post_status', 'log_data', 10, 3 ); function log_data( $new_status, $old_status, $post ) { error_log(json_encode($_POST)); }
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
add_action( 'transition_post_status', 'log_data', 10, 3 ); function log_data( $new_status, $old_status, $post ) { error_log(json_encode($_POST)); }
https://github/WordPress/gutenberg/issues/12897
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...