diff --git src/wp-includes/class-wp-oembed-controller.php src/wp-includes/class-wp-oembed-controller.php
index e6dae0670d..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(); |
… |
… |
final class WP_oEmbed_Controller { |
169 | 169 | $url = $request['url']; |
170 | 170 | unset( $args['url'] ); |
171 | 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 | |
172 | 180 | $data = _wp_oembed_get_object()->get_data( $url, $args ); |
173 | 181 | |
174 | 182 | if ( false === $data ) { |
diff --git tests/phpunit/tests/oembed/controller.php tests/phpunit/tests/oembed/controller.php
index ef6b42edd0..529811ceb8 100644
|
|
class Test_oEmbed_Controller extends WP_UnitTestCase { |
49 | 49 | public function tearDown() { |
50 | 50 | parent::tearDown(); |
51 | 51 | |
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 ); |
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
… |
… |
class Test_oEmbed_Controller extends WP_UnitTestCase { |
70 | 70 | public function mock_embed_request( $preempt, $r, $url ) { |
71 | 71 | unset( $preempt, $r ); |
72 | 72 | |
| 73 | $parsed_url = wp_parse_url( $url ); |
| 74 | parse_str( $parsed_url['query'], $query_params ); |
73 | 75 | $this->request_count += 1; |
74 | 76 | |
75 | 77 | // 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 ) ) { |
77 | 79 | return array( |
78 | 80 | 'response' => array( |
79 | 81 | 'code' => 200, |
… |
… |
class Test_oEmbed_Controller extends WP_UnitTestCase { |
84 | 86 | 'type' => 'video', |
85 | 87 | 'provider_name' => 'YouTube', |
86 | 88 | '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>', |
91 | 94 | 'author_name' => 'Yosemitebear62', |
92 | 95 | 'thumbnail_url' => 'https://i.ytimg.com/vi/' . self::YOUTUBE_VIDEO_ID . '/hqdefault.jpg', |
93 | 96 | 'title' => 'Yosemitebear Mountain Double Rainbow 1-8-10', |
94 | | 'height' => 375, |
95 | 97 | ) |
96 | 98 | ), |
97 | 99 | ); |
… |
… |
class Test_oEmbed_Controller extends WP_UnitTestCase { |
477 | 479 | $response = $this->server->dispatch( $request ); |
478 | 480 | |
479 | 481 | $this->assertEquals( 400, $response->get_status() ); |
480 | | $data = $response->get_data(); |
481 | 482 | } |
482 | 483 | |
483 | 484 | public function test_proxy_with_valid_oembed_provider() { |
484 | 485 | wp_set_current_user( self::$editor ); |
485 | 486 | $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); |
486 | 487 | $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 ); |
487 | 490 | $request->set_param( '_wpnonce', wp_create_nonce( 'wp_rest' ) ); |
488 | 491 | $response = $this->server->dispatch( $request ); |
489 | 492 | $this->assertEquals( 200, $response->get_status() ); |
… |
… |
class Test_oEmbed_Controller extends WP_UnitTestCase { |
498 | 501 | $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); |
499 | 502 | $request->set_param( 'url', 'https://www.youtube.com/watch?v=' . self::YOUTUBE_VIDEO_ID ); |
500 | 503 | $request->set_param( '_wpnonce', wp_create_nonce( 'wp_rest' ) ); |
| 504 | $request->set_param( 'maxwidth', 456 ); |
| 505 | $request->set_param( 'maxheight', 789 ); |
501 | 506 | $response = $this->server->dispatch( $request ); |
502 | 507 | $this->assertEquals( 1, $this->request_count ); |
503 | 508 | |
… |
… |
class Test_oEmbed_Controller extends WP_UnitTestCase { |
508 | 513 | $this->assertTrue( is_object( $data ) ); |
509 | 514 | $this->assertEquals( 'YouTube', $data->provider_name ); |
510 | 515 | $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'] ); |
511 | 518 | } |
512 | 519 | |
513 | 520 | public function test_proxy_with_invalid_oembed_provider_no_discovery() { |