diff --git src/wp-includes/class-wp-oembed-controller.php src/wp-includes/class-wp-oembed-controller.php
index d825c415d2..63cc1842ed 100644
|
|
final class WP_oEmbed_Controller { |
153 | 153 | * |
154 | 154 | * @see WP_oEmbed::get_html() |
155 | 155 | * @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. |
157 | 157 | */ |
158 | 158 | public function get_proxy_item( $request ) { |
159 | 159 | $args = $request->get_params(); |
160 | 160 | |
161 | 161 | // Serve oEmbed data from cache if set. |
| 162 | unset( $args['_wpnonce'] ); |
162 | 163 | $cache_key = 'oembed_' . md5( serialize( $args ) ); |
163 | 164 | $data = get_transient( $cache_key ); |
164 | 165 | if ( ! empty( $data ) ) { |
… |
… |
final class WP_oEmbed_Controller { |
168 | 169 | $url = $request['url']; |
169 | 170 | unset( $args['url'] ); |
170 | 171 | |
| 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 | |
171 | 180 | $data = _wp_oembed_get_object()->get_data( $url, $args ); |
172 | 181 | |
173 | 182 | if ( false === $data ) { |
diff --git tests/phpunit/tests/oembed/controller.php tests/phpunit/tests/oembed/controller.php
index a23c799e41..dc4bc8a4ce 100644
|
|
class Test_oEmbed_Controller extends WP_UnitTestCase { |
44 | 44 | public function tearDown() { |
45 | 45 | parent::tearDown(); |
46 | 46 | |
47 | | remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10, 3 ); |
| 47 | remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10 ); |
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
… |
… |
class Test_oEmbed_Controller extends WP_UnitTestCase { |
65 | 65 | public function mock_embed_request( $preempt, $r, $url ) { |
66 | 66 | unset( $preempt, $r ); |
67 | 67 | |
| 68 | $parsed_url = wp_parse_url( $url ); |
| 69 | parse_str( $parsed_url['query'], $query_params ); |
68 | 70 | $this->request_count += 1; |
69 | 71 | |
70 | 72 | // Mock request to YouTube Embed. |
71 | | if ( false !== strpos( $url, self::YOUTUBE_VIDEO_ID ) ) { |
| 73 | if ( ! empty( $query_params['url'] ) && false !== strpos( $query_params['url'], self::YOUTUBE_VIDEO_ID ) ) { |
72 | 74 | return array( |
73 | 75 | 'response' => array( |
74 | 76 | 'code' => 200, |
… |
… |
class Test_oEmbed_Controller extends WP_UnitTestCase { |
79 | 81 | 'type' => 'video', |
80 | 82 | 'provider_name' => 'YouTube', |
81 | 83 | 'provider_url' => 'https://www.youtube.com', |
82 | | 'thumbnail_width' => 480, |
83 | | 'width' => 500, |
84 | | 'thumbnail_height' => 360, |
85 | | 'html' => '<iframe width="500" height="375" src="https://www.youtube.com/embed/' . self::YOUTUBE_VIDEO_ID . '?feature=oembed" frameborder="0" allowfullscreen></iframe>', |
| 84 | 'thumbnail_width' => $query_params['maxwidth'], |
| 85 | 'width' => $query_params['maxwidth'], |
| 86 | 'thumbnail_height' => $query_params['maxheight'], |
| 87 | 'height' => $query_params['maxheight'], |
| 88 | '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>', |
86 | 89 | 'author_name' => 'Yosemitebear62', |
87 | 90 | 'thumbnail_url' => 'https://i.ytimg.com/vi/' . self::YOUTUBE_VIDEO_ID . '/hqdefault.jpg', |
88 | 91 | 'title' => 'Yosemitebear Mountain Double Rainbow 1-8-10', |
89 | | 'height' => 375, |
90 | 92 | ) |
91 | 93 | ), |
92 | 94 | ); |
… |
… |
class Test_oEmbed_Controller extends WP_UnitTestCase { |
472 | 474 | $response = $this->server->dispatch( $request ); |
473 | 475 | |
474 | 476 | $this->assertEquals( 400, $response->get_status() ); |
475 | | $data = $response->get_data(); |
476 | 477 | } |
477 | 478 | |
478 | 479 | public function test_proxy_with_valid_oembed_provider() { |
… |
… |
class Test_oEmbed_Controller extends WP_UnitTestCase { |
480 | 481 | |
481 | 482 | $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); |
482 | 483 | $request->set_param( 'url', 'https://www.youtube.com/watch?v=' . self::YOUTUBE_VIDEO_ID ); |
| 484 | $request->set_param( 'maxwidth', 456 ); |
| 485 | $request->set_param( 'maxheight', 789 ); |
483 | 486 | $response = $this->server->dispatch( $request ); |
484 | 487 | $this->assertEquals( 200, $response->get_status() ); |
485 | 488 | $this->assertEquals( 1, $this->request_count ); |
… |
… |
class Test_oEmbed_Controller extends WP_UnitTestCase { |
495 | 498 | $this->assertTrue( is_object( $data ) ); |
496 | 499 | $this->assertEquals( 'YouTube', $data->provider_name ); |
497 | 500 | $this->assertEquals( 'https://i.ytimg.com/vi/' . self::YOUTUBE_VIDEO_ID . '/hqdefault.jpg', $data->thumbnail_url ); |
| 501 | $this->assertEquals( $data->width, $request['maxwidth'] ); |
| 502 | $this->assertEquals( $data->height, $request['maxheight'] ); |
498 | 503 | } |
499 | 504 | |
500 | 505 | public function test_proxy_with_invalid_oembed_provider_no_discovery() { |