WordPress.org

Make WordPress Core

Changeset 41049


Ignore:
Timestamp:
07/14/2017 04:18:42 PM (12 months ago)
Author:
westonruter
Message:

REST API: Ensure maxwidth and maxheight params are forwarded to oEmbed provider in proxy requests.

Also correct phpdoc return tag on WP_oEmbed_Controller::get_proxy_item() and remove dead code in oEmbed controller phpunit tests.

Merges [41047] into 4.8 branch.
Amends [40628].
See #40450.
Fixes #41299 for 4.8.1.

Location:
branches/4.8
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.8

  • branches/4.8/src/wp-includes/class-wp-oembed-controller.php

    r41048 r41049  
    154154     * @see WP_oEmbed::get_html()
    155155     * @param WP_REST_Request $request Full data about the request.
    156      * @return WP_Error|array oEmbed response data or WP_Error on failure.
     156     * @return object|WP_Error oEmbed response data or WP_Error on failure.
    157157     */
    158158    public function get_proxy_item( $request ) {
     
    170170        unset( $args['url'] );
    171171
     172        // Copy maxwidth/maxheight to width/height since WP_oEmbed::fetch() uses these arg names.
     173        if ( isset( $args['maxwidth'] ) ) {
     174            $args['width'] = $args['maxwidth'];
     175        }
     176        if ( isset( $args['maxheight'] ) ) {
     177            $args['height'] = $args['maxheight'];
     178        }
     179
    172180        $data = _wp_oembed_get_object()->get_data( $url, $args );
    173181
  • branches/4.8/tests/phpunit/tests/oembed/controller.php

    r41048 r41049  
    5050        parent::tearDown();
    5151
    52         remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10, 3 );
     52        remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10 );
    5353    }
    5454
     
    7171        unset( $preempt, $r );
    7272
     73        $parsed_url = wp_parse_url( $url );
     74        parse_str( $parsed_url['query'], $query_params );
    7375        $this->request_count += 1;
    7476
    7577        // Mock request to YouTube Embed.
    76         if ( false !== strpos( $url, self::YOUTUBE_VIDEO_ID ) ) {
     78        if ( ! empty( $query_params['url'] ) && false !== strpos( $query_params['url'], self::YOUTUBE_VIDEO_ID ) ) {
    7779            return array(
    7880                'response' => array(
     
    8587                        'provider_name'    => 'YouTube',
    8688                        'provider_url'     => 'https://www.youtube.com',
    87                         'thumbnail_width'  => 480,
    88                         'width'            => 500,
    89                         'thumbnail_height' => 360,
    90                         'html'             => '<iframe width="500" height="375" src="https://www.youtube.com/embed/' . self::YOUTUBE_VIDEO_ID . '?feature=oembed" frameborder="0" allowfullscreen></iframe>',
     89                        'thumbnail_width'  => $query_params['maxwidth'],
     90                        'width'            => $query_params['maxwidth'],
     91                        'thumbnail_height' => $query_params['maxheight'],
     92                        'height'           => $query_params['maxheight'],
     93                        'html'             => '<iframe width="' . $query_params['maxwidth'] . '" height="' . $query_params['maxheight'] . '" src="https://www.youtube.com/embed/' . self::YOUTUBE_VIDEO_ID . '?feature=oembed" frameborder="0" allowfullscreen></iframe>',
    9194                        'author_name'      => 'Yosemitebear62',
    9295                        'thumbnail_url'    => 'https://i.ytimg.com/vi/' . self::YOUTUBE_VIDEO_ID . '/hqdefault.jpg',
    9396                        'title'            => 'Yosemitebear Mountain Double Rainbow 1-8-10',
    94                         'height'           => 375,
    9597                    )
    9698                ),
     
    478480
    479481        $this->assertEquals( 400, $response->get_status() );
    480         $data = $response->get_data();
    481482    }
    482483
     
    485486        $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' );
    486487        $request->set_param( 'url', 'https://www.youtube.com/watch?v=' . self::YOUTUBE_VIDEO_ID );
     488        $request->set_param( 'maxwidth', 456 );
     489        $request->set_param( 'maxheight', 789 );
    487490        $request->set_param( '_wpnonce', wp_create_nonce( 'wp_rest' ) );
    488491        $response = $this->server->dispatch( $request );
     
    499502        $request->set_param( 'url', 'https://www.youtube.com/watch?v=' . self::YOUTUBE_VIDEO_ID );
    500503        $request->set_param( '_wpnonce', wp_create_nonce( 'wp_rest' ) );
     504        $request->set_param( 'maxwidth', 456 );
     505        $request->set_param( 'maxheight', 789 );
    501506        $response = $this->server->dispatch( $request );
    502507        $this->assertEquals( 1, $this->request_count );
     
    509514        $this->assertEquals( 'YouTube', $data->provider_name );
    510515        $this->assertEquals( 'https://i.ytimg.com/vi/' . self::YOUTUBE_VIDEO_ID . '/hqdefault.jpg', $data->thumbnail_url );
     516        $this->assertEquals( $data->width, $request['maxwidth'] );
     517        $this->assertEquals( $data->height, $request['maxheight'] );
    511518    }
    512519
Note: See TracChangeset for help on using the changeset viewer.