WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/10/2017 04:31:28 AM (2 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.