Make WordPress Core

Changeset 40601


Ignore:
Timestamp:
05/10/2017 04:31:28 AM (8 years ago)
Author:
rmccue
Message:

REST API: Set global $post when preparing revisions.

For compatibility with filters on hooks on content filters (such as shortcodes), we need to set the global. This mirrors the Posts controller.

Props pdufour, jnylen0.
Fixes #40626.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php

    r40063 r40601  
    339339     */
    340340    public function prepare_item_for_response( $post, $request ) {
     341        $GLOBALS['post'] = $post;
     342
     343        setup_postdata( $post );
    341344
    342345        $schema = $this->get_item_schema();
  • trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php

    r40063 r40601  
    336336    }
    337337
     338    public function test_get_item_sets_up_postdata() {
     339        wp_set_current_user( self::$editor_id );
     340        $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
     341        $this->server->dispatch( $request );
     342
     343        $post = get_post();
     344        $parent_post_id = wp_is_post_revision( $post->ID );
     345
     346        $this->assertEquals( $post->ID, $this->revision_id1 );
     347        $this->assertEquals( $parent_post_id, self::$post_id );
     348    }
     349
    338350}
Note: See TracChangeset for help on using the changeset viewer.