Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-oembed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
68 changes: 68 additions & 0 deletions tests/phpunit/tests/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
}
Loading