Skip to content

Commit 2519bd1

Browse files
committed
#65082 Fix wp_embed_defaults() usage in WP_oEmbed()->fetch()
1 parent 6aca60d commit 2519bd1

2 files changed

Lines changed: 68 additions & 1 deletion

File tree

src/wp-includes/class-wp-oembed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ public function discover( $url ) {
515515
* @return object|false The result in the form of an object on success, false on failure.
516516
*/
517517
public function fetch( $provider, $url, $args = '' ) {
518-
$args = wp_parse_args( $args, wp_embed_defaults( $url ) );
518+
$args = wp_parse_args( $args, array_combine( array( 'width', 'height' ), wp_embed_defaults( $url ) ) );
519519

520520
$provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider );
521521
$provider = add_query_arg( 'maxheight', (int) $args['height'], $provider );

tests/phpunit/tests/media.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,64 @@ function test_autoembed( $content, $result = null ) {
366366
$this->assertSame( $wp_embed->autoembed( $content ), $result ? $result : $content );
367367
}
368368

369+
function data_oembed() {
370+
$default_embed = wp_embed_defaults();
371+
372+
return array(
373+
array(
374+
'https://example.org/oembed',
375+
'https://youtube.com/?v=xyz',
376+
'',
377+
add_query_arg(
378+
array(
379+
'maxwidth' => (int) $default_embed[0],
380+
'maxheight' => (int) $default_embed[1],
381+
'url' => urlencode( 'https://youtube.com/?v=xyz' ),
382+
'dnt' => 1,
383+
),
384+
'https://example.org/oembed',
385+
),
386+
),
387+
array(
388+
'https://example.org/oembed',
389+
'https://youtube.com/?v=xyz',
390+
'width=1280',
391+
add_query_arg(
392+
array(
393+
'maxwidth' => 1280,
394+
'maxheight' => (int) $default_embed[1],
395+
'url' => urlencode( 'https://youtube.com/?v=xyz' ),
396+
'dnt' => 1,
397+
),
398+
'https://example.org/oembed',
399+
),
400+
),
401+
array(
402+
'https://example.org/oembed',
403+
'https://youtube.com/?v=xyz',
404+
array( 'width' => 1280 ),
405+
add_query_arg(
406+
array(
407+
'maxwidth' => 1280,
408+
'maxheight' => (int) $default_embed[1],
409+
'url' => urlencode( 'https://youtube.com/?v=xyz' ),
410+
'dnt' => 1,
411+
),
412+
'https://example.org/oembed',
413+
),
414+
),
415+
);
416+
}
417+
418+
/**
419+
* @dataProvider data_oembed
420+
*/
421+
function test_oembed_fetch_url( $provider, $url, $args, $result ) {
422+
$wp_oembed = new Test_oEmbed;
423+
424+
$this->assertSame( $wp_oembed->fetch( $provider, $url, $args ), $result );
425+
}
426+
369427
function test_wp_prepare_attachment_for_js() {
370428
// Attachment without media.
371429
$id = wp_insert_attachment(
@@ -3169,3 +3227,12 @@ public function shortcode( $attr, $url = '' ) {
31693227
return '[embed]';
31703228
}
31713229
}
3230+
3231+
/**
3232+
* Helper class for `test_oembed`.
3233+
*/
3234+
class Test_oEmbed extends WP_oEmbed {
3235+
private function _fetch_with_format( $provider_url_with_args, $format ) {
3236+
return $provider_url_with_args;
3237+
}
3238+
}

0 commit comments

Comments
 (0)