WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/09/2020 08:52:06 PM (7 months ago)
Author:
TimothyBlynJacobs
Message:

REST API: Introduce selective link embedding.

Previously the _embed flag would embed all embeddable links in a response even if only a subset of the links were necessary. Now, a list of link relations can be passed in the _embed parameter to restrict the list of embedded objects.

Props rheinardkorf, adamsilverstein, jnylen0, cklosows, chrisvanpatten, TimothyBlynJacobs.
Fixes #39696.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api.php

    r47122 r47224  
    907907        $this->assertEquals( 'GET', $request->get_method() );
    908908    }
     909
     910    /**
     911     * @dataProvider _dp_rest_parse_embed_param
     912     */
     913    public function test_rest_parse_embed_param( $expected, $embed ) {
     914        $this->assertEquals( $expected, rest_parse_embed_param( $embed ) );
     915    }
     916
     917    public function _dp_rest_parse_embed_param() {
     918        return array(
     919            array( true, '' ),
     920            array( true, null ),
     921            array( true, '1' ),
     922            array( true, 'true' ),
     923            array( true, array() ),
     924            array( array( 'author' ), 'author' ),
     925            array( array( 'author', 'replies' ), 'author,replies' ),
     926            array( array( 'author', 'replies' ), 'author,replies ' ),
     927            array( array( 'wp:term' ), 'wp:term' ),
     928            array( array( 'wp:term', 'wp:attachment' ), 'wp:term,wp:attachment' ),
     929            array( array( 'author' ), array( 'author' ) ),
     930            array( array( 'author', 'replies' ), array( 'author', 'replies' ) ),
     931            array( array( 'https://api.w.org/term' ), 'https://api.w.org/term' ),
     932            array( array( 'https://api.w.org/term', 'https://api.w.org/attachment' ), 'https://api.w.org/term,https://api.w.org/attachment' ),
     933            array( array( 'https://api.w.org/term', 'https://api.w.org/attachment' ), array( 'https://api.w.org/term', 'https://api.w.org/attachment' ) ),
     934        );
     935    }
    909936}
Note: See TracChangeset for help on using the changeset viewer.