WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/08/2019 04:43:10 AM (6 months ago)
Author:
kadamwhite
Message:

REST API: Permit embedding of the 'self' link relation in the /search endpoint.

Removes a special-case prohibition against embedding 'self' which prevented ?_embed from being used with the /wp/v2/search endpoint.

Props TimothyBlynJacobs, chrisvanpatten, kadamwhite.
Fixes #47684.

File:
1 edited

Legend:

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

    r45809 r46434  
    570570    /**
    571571     * @depends test_link_embedding
     572     * @ticket 47684
    572573     */
    573574    public function test_link_embedding_self() {
     
    583584        $response = new WP_REST_Response();
    584585
    585         // 'self' should be ignored.
    586         $response->add_link( 'self', rest_url( '/test/notembeddable' ), array( 'embeddable' => true ) );
     586        // 'self' should not be special-cased, and may be marked embeddable.
     587        $response->add_link( 'self', rest_url( '/test/embeddable' ), array( 'embeddable' => true ) );
     588
     589        $data = rest_get_server()->response_to_data( $response, true );
     590
     591        $this->assertArrayHasKey( '_embedded', $data );
     592    }
     593
     594    /**
     595     * @depends test_link_embedding
     596     * @ticket 47684
     597     */
     598    public function test_link_embedding_self_non_embeddable() {
     599        // Register our testing route.
     600        rest_get_server()->register_route(
     601            'test',
     602            '/test/embeddable',
     603            array(
     604                'methods'  => 'GET',
     605                'callback' => array( $this, 'embedded_response_callback' ),
     606            )
     607        );
     608        $response = new WP_REST_Response();
     609
     610        // 'self' should not be special-cased, and should be ignored if not marked embeddable.
     611        $response->add_link( 'self', rest_url( '/test/notembeddable' ) );
    587612
    588613        $data = rest_get_server()->response_to_data( $response, true );
Note: See TracChangeset for help on using the changeset viewer.