-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
transition_post_status hook always return the same status value for $old_status and $new_status arguments. #12797
Comments
I haven't been able to replicate this. I see proper transitions from |
Yes, I have. Now that's weird @TimothyBJacobs. When I put the code in functions.php and deactivate the plugins that add the classic meta boxes, everything works fine. But when I activate the plugin that hooks to The code in the theme is linked directly to |
And the error log is entirely of the same status to same status? No entries that are correct? |
The entries that are correct are those from the code in functions.php. The entries from the plugin are entirely of the same status to same status. Both codes are the same, but the code in the theme works while the code in the plugin don't. I got the following after transitioning from draft to post in the error log: [11-Dec-2018 16:11:32 UTC] THEME: From draft to pending for post 281 |
@TimothyBJacobs apparently I found the problem. The hook in the plugin is only done when is_admin(). It seems that is_admin() is not set to true in Gutenberg REST API requests, and that's why the hook was not working as expected. According to #11138, @swissspidy indicated "Since Gutenberg uses the REST API to save posts, you would have to check for that, not is_admin or wp_doing_ajax". What substitutes is_admin() in this case is not clear to me. Is there an is_rest() method? I tried checking REST_REQUEST as indicated here but didn't work. In some cases (like |
Yeah the I don't see the need for that though. |
Thanks for the comment @swissspidy. That's true, we where doing things more complicated than they should be. I've reorganized the hooks to avoid problems like this one. The issue is now closed :-) |
Hi, |
Describe the bug
The action
transition_post_status
is fired when you change the status of a post. It has three parameters according to the documentation:$new_status
(string): New post status.$old_status
(string): Old post status.$post
(WP_Post): Post object.In the classic editor, the hook worked fine. In Gutenberg (block editor) the hook fires properly but the values of
$new_status
and$old_status
are always the same. When you have a draft and save it as pending, the hook is called with both$old_status
and$new_status
to 'pending'. The same happens all the time when you change the status of a post.To Reproduce
Steps to reproduce the behavior:
transition_post_status
. Something like the following code infunctions.php
will do the job:$new_status
and$old_status
.Expected behavior
$old_status
should take the proper value instead of always returning the same value as$new_status
.The text was updated successfully, but these errors were encountered: