Skip to content

Commit

Permalink
Embeds: ensure correct thumbnail height.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
swissspidy committed Dec 5, 2024
1 parent 29ec312 commit 9c7d008
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/wp-includes/embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ function get_oembed_response_data_rich( $data, $post, $width, $height ) {
}

if ( $thumbnail_id ) {
list( $thumbnail_url, $thumbnail_width, $thumbnail_height ) = wp_get_attachment_image_src( $thumbnail_id, array( $width, 99999 ) );
list( $thumbnail_url, $thumbnail_width, $thumbnail_height ) = wp_get_attachment_image_src( $thumbnail_id, array( $width, 0 ) );
$data['thumbnail_url'] = $thumbnail_url;
$data['thumbnail_width'] = $thumbnail_width;
$data['thumbnail_height'] = $thumbnail_height;
Expand Down
20 changes: 20 additions & 0 deletions tests/phpunit/tests/oembed/getResponseData.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,26 @@ public function test_get_oembed_response_data_with_thumbnail() {
$this->assertLessThanOrEqual( 400, $data['thumbnail_width'] );
}

/**
* @ticket 62094
*/
public function test_get_oembed_response_data_has_correct_thumbnail_size() {
$post = self::factory()->post->create_and_get();

/* Use a large image as post thumbnail */
$attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/33772.jpg' );
set_post_thumbnail( $post, $attachment_id );

/* Get the image, sized for 400x??? pixels display */
$image = wp_get_attachment_image_src( $attachment_id, array( 400, 0 ) );

/* Get the oembed data array for a 400 pixels wide embed */
$data = get_oembed_response_data( $post, 400 );

/* Make sure the embed references the small image, not the full-size one. */
$this->assertSame( $image[0], $data['thumbnail_url'] );
}

public function test_get_oembed_response_data_for_attachment() {
$parent = self::factory()->post->create();
$file = DIR_TESTDATA . '/images/canola.jpg';
Expand Down

0 comments on commit 9c7d008

Please sign in to comment.