diff --git a/src/wp-includes/class-wp-oembed.php b/src/wp-includes/class-wp-oembed.php index 3bc5de556c49e..4f4ac7f7d7c3c 100644 --- a/src/wp-includes/class-wp-oembed.php +++ b/src/wp-includes/class-wp-oembed.php @@ -526,7 +526,7 @@ public function discover( $url ) { * @return object|false The result in the form of an object on success, false on failure. */ public function fetch( $provider, $url, $args = '' ) { - $args = wp_parse_args( $args, wp_embed_defaults( $url ) ); + $args = wp_parse_args( $args, array_combine( array( 'width', 'height' ), wp_embed_defaults( $url ) ) ); $provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider ); $provider = add_query_arg( 'maxheight', (int) $args['height'], $provider ); diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 060a7295f6bb4..b813e43f98355 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -413,6 +413,65 @@ public function test_autoembed( $content, $result = null ) { $this->assertSame( $wp_embed->autoembed( $content ), $result ? $result : $content ); } + public function data_oembed() { + $default_embed = wp_embed_defaults(); + + return array( + array( + 'https://example.org/oembed', + 'https://youtube.com/?v=xyz', + '', + add_query_arg( + array( + 'maxwidth' => (int) $default_embed[0], + 'maxheight' => (int) $default_embed[1], + 'url' => urlencode( 'https://youtube.com/?v=xyz' ), + 'dnt' => 1, + ), + 'https://example.org/oembed', + ), + ), + array( + 'https://example.org/oembed', + 'https://youtube.com/?v=xyz', + 'width=1280', + add_query_arg( + array( + 'maxwidth' => 1280, + 'maxheight' => (int) $default_embed[1], + 'url' => urlencode( 'https://youtube.com/?v=xyz' ), + 'dnt' => 1, + ), + 'https://example.org/oembed', + ), + ), + array( + 'https://example.org/oembed', + 'https://youtube.com/?v=xyz', + array( 'width' => 1280 ), + add_query_arg( + array( + 'maxwidth' => 1280, + 'maxheight' => (int) $default_embed[1], + 'url' => urlencode( 'https://youtube.com/?v=xyz' ), + 'dnt' => 1, + ), + 'https://example.org/oembed', + ), + ), + ); + } + + /** + * @ticket 65082 + * @dataProvider data_oembed + */ + public function test_oembed_fetch_url( $provider, $url, $args, $result ) { + $wp_oembed = new Test_oEmbed(); + + $this->assertSame( $wp_oembed->fetch( $provider, $url, $args ), $result ); + } + public function test_wp_prepare_attachment_for_js() { // Attachment without media. $id = wp_insert_attachment( @@ -7293,3 +7352,12 @@ public function shortcode( $attr, $url = '' ) { return '[embed]'; } } + +/** + * Helper class for `test_oembed`. + */ +class Test_oEmbed extends WP_oEmbed { + private function _fetch_with_format( $provider_url_with_args, $format ) { + return $provider_url_with_args; + } +}