Skip to content

Commit 9c7d008

Browse files
committed
Embeds: ensure correct thumbnail height.
Use height 0 instead of 9999 to avoid unnecessarily using the full size version. Props colinleroy, swissspidy. Fixes #62094. git-svn-id: https://develop.svn.wordpress.org/trunk@59493 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 29ec312 commit 9c7d008

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/wp-includes/embed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ function get_oembed_response_data_rich( $data, $post, $width, $height ) {
721721
}
722722

723723
if ( $thumbnail_id ) {
724-
list( $thumbnail_url, $thumbnail_width, $thumbnail_height ) = wp_get_attachment_image_src( $thumbnail_id, array( $width, 99999 ) );
724+
list( $thumbnail_url, $thumbnail_width, $thumbnail_height ) = wp_get_attachment_image_src( $thumbnail_id, array( $width, 0 ) );
725725
$data['thumbnail_url'] = $thumbnail_url;
726726
$data['thumbnail_width'] = $thumbnail_width;
727727
$data['thumbnail_height'] = $thumbnail_height;

tests/phpunit/tests/oembed/getResponseData.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,26 @@ public function test_get_oembed_response_data_with_thumbnail() {
251251
$this->assertLessThanOrEqual( 400, $data['thumbnail_width'] );
252252
}
253253

254+
/**
255+
* @ticket 62094
256+
*/
257+
public function test_get_oembed_response_data_has_correct_thumbnail_size() {
258+
$post = self::factory()->post->create_and_get();
259+
260+
/* Use a large image as post thumbnail */
261+
$attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/33772.jpg' );
262+
set_post_thumbnail( $post, $attachment_id );
263+
264+
/* Get the image, sized for 400x??? pixels display */
265+
$image = wp_get_attachment_image_src( $attachment_id, array( 400, 0 ) );
266+
267+
/* Get the oembed data array for a 400 pixels wide embed */
268+
$data = get_oembed_response_data( $post, 400 );
269+
270+
/* Make sure the embed references the small image, not the full-size one. */
271+
$this->assertSame( $image[0], $data['thumbnail_url'] );
272+
}
273+
254274
public function test_get_oembed_response_data_for_attachment() {
255275
$parent = self::factory()->post->create();
256276
$file = DIR_TESTDATA . '/images/canola.jpg';

0 commit comments

Comments
 (0)