Make WordPress Core

Changeset 59493


Ignore:
Timestamp:
12/05/2024 09:19:37 PM (14 months ago)
Author:
swissspidy
Message:

Embeds: ensure correct thumbnail height.

Use height 0 instead of 9999 to avoid unnecessarily using the full size version.

Props colinleroy, swissspidy.
Fixes #62094.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/embed.php

    r58286 r59493  
    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;
  • trunk/tests/phpunit/tests/oembed/getResponseData.php

    r58235 r59493  
    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();
Note: See TracChangeset for help on using the changeset viewer.