From 2519bd161ac606042d683d101196ca4afb35d301 Mon Sep 17 00:00:00 2001 From: Robert O'Rourke Date: Thu, 16 Apr 2026 22:51:58 +0100 Subject: [PATCH 1/3] #65082 Fix wp_embed_defaults() usage in WP_oEmbed()->fetch() --- src/wp-includes/class-wp-oembed.php | 2 +- tests/phpunit/tests/media.php | 67 +++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-oembed.php b/src/wp-includes/class-wp-oembed.php index 4226e8163eaf4..8ebfa8b7a99b6 100644 --- a/src/wp-includes/class-wp-oembed.php +++ b/src/wp-includes/class-wp-oembed.php @@ -515,7 +515,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 b968b95a5123e..f05b3334a0652 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -366,6 +366,64 @@ function test_autoembed( $content, $result = null ) { $this->assertSame( $wp_embed->autoembed( $content ), $result ? $result : $content ); } + 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', + ), + ), + ); + } + + /** + * @dataProvider data_oembed + */ + function test_oembed_fetch_url( $provider, $url, $args, $result ) { + $wp_oembed = new Test_oEmbed; + + $this->assertSame( $wp_oembed->fetch( $provider, $url, $args ), $result ); + } + function test_wp_prepare_attachment_for_js() { // Attachment without media. $id = wp_insert_attachment( @@ -3169,3 +3227,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; + } +} From b8a44064c5b85d16d39425034bd8170b3bd6d69e Mon Sep 17 00:00:00 2001 From: Robert O'Rourke Date: Fri, 17 Apr 2026 00:20:02 +0100 Subject: [PATCH 2/3] Use brackets when instantiating a new class --- tests/phpunit/tests/media.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index f05b3334a0652..104c66cdb3457 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -419,7 +419,7 @@ function data_oembed() { * @dataProvider data_oembed */ function test_oembed_fetch_url( $provider, $url, $args, $result ) { - $wp_oembed = new Test_oEmbed; + $wp_oembed = new Test_oEmbed(); $this->assertSame( $wp_oembed->fetch( $provider, $url, $args ), $result ); } From 8ab3707374438d0aaaa8271d8acd3fb4236773fd Mon Sep 17 00:00:00 2001 From: Robert O'Rourke Date: Fri, 17 Apr 2026 00:25:25 +0100 Subject: [PATCH 3/3] Fix array arrow alignment --- tests/phpunit/tests/media.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index ac91a12f396cb..b813e43f98355 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -423,10 +423,10 @@ public function data_oembed() { '', add_query_arg( array( - 'maxwidth' => (int) $default_embed[0], + 'maxwidth' => (int) $default_embed[0], 'maxheight' => (int) $default_embed[1], - 'url' => urlencode( 'https://youtube.com/?v=xyz' ), - 'dnt' => 1, + 'url' => urlencode( 'https://youtube.com/?v=xyz' ), + 'dnt' => 1, ), 'https://example.org/oembed', ), @@ -437,10 +437,10 @@ public function data_oembed() { 'width=1280', add_query_arg( array( - 'maxwidth' => 1280, + 'maxwidth' => 1280, 'maxheight' => (int) $default_embed[1], - 'url' => urlencode( 'https://youtube.com/?v=xyz' ), - 'dnt' => 1, + 'url' => urlencode( 'https://youtube.com/?v=xyz' ), + 'dnt' => 1, ), 'https://example.org/oembed', ), @@ -451,10 +451,10 @@ public function data_oembed() { array( 'width' => 1280 ), add_query_arg( array( - 'maxwidth' => 1280, + 'maxwidth' => 1280, 'maxheight' => (int) $default_embed[1], - 'url' => urlencode( 'https://youtube.com/?v=xyz' ), - 'dnt' => 1, + 'url' => urlencode( 'https://youtube.com/?v=xyz' ), + 'dnt' => 1, ), 'https://example.org/oembed', ),