-
Notifications
You must be signed in to change notification settings - Fork 891
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
Yoast SEO breaks restoring of revisions due to processing shortcodes #12017
Comments
Hi @smerriman, thank you for your submission. |
When a post gets retrieved from revisions, it is saved as the "new" version of the post. This invokes a Our plugin hooks into the To fix this particular instance, you can store the function custom_short(){
global $post;
$old_post = $post; // Store $post for restoration
// Do some cool stuff
$post = $old_post; // Restore the global $post
return '';
}; Because we hook into the Closing this as it's more about the code in the shortcodes than our plugin. |
I disagree that this is the responsibility of the shortcode. Using wp_reset_postdata is the correct method for shortcodes, and you're right; it's not meant to be called in the backend, because processing shortcodes is not meant to be done outside of the loop, and the plugin is doing that. Gutenberg itself had this problem as they run shortcodes for the preview, and it was determined this needed to be fixed in Gutenberg, not in every single shortcode that plugins may add: A similar fix therefore needs to be applied to Yoast SEO. |
Hi @smerriman , thanks for the reply. I contacted one of our architects about this and this is what we determined: This is indeed not a shortcode issue but rather a core bug. See: https://core.trac.wordpress.org/ticket/18408 The Gutenberg fix was intended only as a temporary workaround. See: https://core.trac.wordpress.org/ticket/18408#comment:29 However, at this time we do not consider this issue severe enough to implement a (temporary) workaround ourselves and believe the core issue should be fixed. |
Please give us a description of what happened.
When a shortcode changes the $post variable, then resets it with wp_reset_postdata, restoring a revision of anything containing that shortcode redirects you to the wrong URL (whatever the last value of $post was).
Please describe what you expected to happen and why.
It should redirect you to the page you restored.
How can we reproduce this behavior?
Add this shortcode to a post (without ID 1), and then create a couple of revisions.
Attempt to restore a revision of this post. It will restore correctly, but you will be redirected to the post with ID 1.
Without Yoast SEO active, restoring a revision does not process the shortcode at all. With Yoast SEO active, it appears the shortcode is processed, without the main query set, so wp_reset_postdata returns early and things break.
Used versions
The text was updated successfully, but these errors were encountered: