Make WordPress Core


Ignore:
Timestamp:
08/15/2025 07:09:36 PM (12 months ago)
Author:
adamsilverstein
Message:

Media: ensure wp_get_attachment_image uses valid user-provided width and height.

Fix a bug introduced in WordPress 6.8.2 (r60415) that led to user supplied values for width and height in the $attr array passed to wp_get_attachment_image to be overwritten.

Props rainbowgeek, ocean90, rollybueno, shreya0shrivastava, heybran, mukesh27.
Fixes #63714.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r60477 r60641  
    16331633                $this->assertStringContainsString( 'width="150"', $output, 'Width should not be changed.' );
    16341634                $this->assertStringContainsString( 'height="150"', $output, 'Height should not be changed.' );
     1635        }
     1636
     1637        /**
     1638         * Test that `wp_get_attachment_image` doesn't overwrite an already valid user-provided width and height.
     1639         *
     1640         * @ticket 63714
     1641         */
     1642        public function test_wp_get_attachment_image_not_overwrite_user_provided_width_height() {
     1643                $img = wp_get_attachment_image(
     1644                        self::$large_id,
     1645                        'large',
     1646                        false,
     1647                        array(
     1648                                'width'  => 999,
     1649                                'height' => 999,
     1650                        )
     1651                );
     1652
     1653                $this->assertStringContainsString( 'width="999"', $img, 'User-provided width should not be changed.' );
     1654                $this->assertStringContainsString( 'height="999"', $img, 'User-provided height should not be changed.' );
    16351655        }
    16361656
Note: See TracChangeset for help on using the changeset viewer.