[wp-trac] [WordPress Trac] #46671: wp-admin/revisions.php uses the $post global in the wrong way
WordPress Trac
noreply at wordpress.org
Sun Jul 26 21:05:43 UTC 2020
#46671: wp-admin/revisions.php uses the $post global in the wrong way
--------------------------+-----------------------------
Reporter: tofandel | Owner: SergeyBiryukov
Type: defect (bug) | Status: reviewing
Priority: normal | Milestone: 5.5
Component: Revisions | Version: 5.2
Severity: major | Resolution:
Keywords: has-patch | Focuses: administration
--------------------------+-----------------------------
Comment (by SergeyBiryukov):
Just noting [attachment:"46671.2.diff"] didn't work in my testing, as
there are some other functions in the file depending on the `$post`
global:
* `get_edit_post_link()`
* `_draft_or_post_title()`
* `wp_print_revision_templates()`
[attachment:"46671.3.diff"] seems to work, however it also appears to be a
lot of effort to move away from the global that we ultimately have to set
up again.
I don't think `setup_postdata()` is necessary here, or that
`wp_reset_postdata()` not working as expected is a concern here, because
the hooks in `wp_insert_post()` and `wp_transition_post_status()` should
have all the necessary context without relying on the `$post` global.
Since these hooks are not in the WordPress Loop, any functions hooked to
them should not expect the `$post` global to be available.
So it looks like the only thing to fix here is to make sure core doesn't
break if a plugin sets up the `$post` global for its own purposes, either
intentionally or accidentally, as in comment:4.
[attachment:"46671.4.diff"] does just that, using the approach already
applied in `wp-admin/edit-form-blocks.php`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46671#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list