#40626 closed defect (bug) (fixed)
Revisions API do not initialize GLOBALS['post']
Reported by: | pdufour | Owned by: | rmccue |
---|---|---|---|
Milestone: | 4.8 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | REST API | Keywords: | has-unit-tests has-patch commit |
Focuses: | Cc: |
Description (last modified by )
Calling functions like get_post()
do not work within the Post Revisions API endpoint since they don't have a line like $GLOBALS['post'] = $post;
which the posts controller does have https://github.com/WordPress/WordPress/blob/4.7.4/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L1381-L1383.
Fix if I understand the issue would be to add those two lines to prepare_item_for_response
in the revisions controller.
Attachments (2)
Change History (13)
This ticket was mentioned in Slack in #core-restapi by pdufour. View the logs.
7 years ago
#3
@
7 years ago
- Description modified (diff)
- Keywords has-patch has-unit-tests needs-refresh added
- Milestone changed from Awaiting Review to 4.7.5
- Owner set to jnylen0
- Status changed from new to accepted
- Version set to 4.7
#5
@
7 years ago
Unless it's needed, I'm not sure _why_ we would want to add this. I believe they are there in the Posts Controller because there's some internal WP functions that require these globals to be set, so we had to make $post global. If that's not explicitly needed in the revisions endpoint, I don't think we should add it. All filters in the Revisions controller should get passed the Request or WP_Post object, so I'm not sure why you'd want to do get_post()
with not ID param.
Thanks for the report and the patch. There are two super-minor whitespace issues in 40626-add-global.patch:
$parent_post_id = wp_is_post_revision ( $post->ID );
As far as the change itself, I can't think of any unintended effects this would have. Anyone else? Otherwise let's get this committed soon.