[wp-trac] [WordPress Trac] #40626: Revisions API do not initialize GLOBALS['post']

WordPress Trac noreply at wordpress.org
Mon May 1 22:52:58 UTC 2017


#40626: Revisions API do not initialize GLOBALS['post']
-------------------------------------------------+-------------------------
 Reporter:  pdufour                              |       Owner:  jnylen0
     Type:  defect (bug)                         |      Status:  accepted
 Priority:  normal                               |   Milestone:  4.7.5
Component:  REST API                             |     Version:  4.7
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests needs-      |     Focuses:
  refresh                                        |
-------------------------------------------------+-------------------------
Changes (by jnylen0):

 * status:  new => accepted
 * owner:   => jnylen0
 * version:   => 4.7
 * milestone:  Awaiting Review => 4.7.5
 * keywords:   => has-patch has-unit-tests needs-refresh


Old description:

> 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/master/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.

New description:

 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.

--

Comment:

 Thanks for the report and the patch.  There are two super-minor whitespace
 issues in [attachment:40626-add-global.patch]:

 - Blank line added to the beginning of the test file
 - Extra space in `$parent_post_id = wp_is_post_revision ( $post->ID );`

 I can't think of any unintended effects this would have.  Anyone else?
 Otherwise let's get this committed soon.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40626#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list