Make WordPress Core

Changeset 60477


Ignore:
Timestamp:
07/16/2025 02:07:58 PM (5 months ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Reorder width and height for consistency in wp_get_attachment_image().

Includes correcting the placement of the filter_wp_get_attachment_image() helper function in unit tests.

Follow-up to [60415], [60476].

See #63168.

Location:
trunk
Files:
2 edited

Legend:

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

    r60476 r60477  
    10901090         * @param string $context The context. Default 'wp_get_attachment_image'.
    10911091         */
    1092         $context        = apply_filters( 'wp_get_attachment_image_context', 'wp_get_attachment_image' );
     1092        $context = apply_filters( 'wp_get_attachment_image_context', 'wp_get_attachment_image' );
     1093
    10931094        $attr           = wp_parse_args( $attr, $default_attr );
    10941095        $attr['width']  = $width;
     
    11591160         *
    11601161         * @since 2.8.0
    1161          * @since 6.8.2 The `$attr` array includes `height` and `width` attributes.
     1162         * @since 6.8.2 The `$attr` array includes `width` and `height` attributes.
    11621163         *
    11631164         * @param string[]     $attr       Array of attribute values for the image markup, keyed by attribute name.
     
    11691170        $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size );
    11701171
     1172        if ( isset( $attr['width'] ) && is_numeric( $attr['width'] ) ) {
     1173            $width = absint( $attr['width'] );
     1174        }
    11711175        if ( isset( $attr['height'] ) && is_numeric( $attr['height'] ) ) {
    11721176            $height = absint( $attr['height'] );
    11731177        }
    1174         if ( isset( $attr['width'] ) && is_numeric( $attr['width'] ) ) {
    1175             $width = absint( $attr['width'] );
    1176         }
    1177         unset( $attr['height'], $attr['width'] );
     1178        unset( $attr['width'], $attr['height'] );
     1179
    11781180        $attr     = array_map( 'esc_attr', $attr );
    11791181        $hwstring = image_hwstring( $width, $height );
  • trunk/tests/phpunit/tests/media.php

    r60415 r60477  
    15841584    }
    15851585
     1586    public function filter_wp_get_attachment_image() {
     1587        return 'Override wp_get_attachment_image';
     1588    }
     1589
    15861590    /**
    15871591     * @ticket 14110
    15881592     */
    1589     public function test_wp_get_attachment_image_filter_with_height_width() {
     1593    public function test_wp_get_attachment_image_filter_with_width_height() {
    15901594        $mock_action = new MockAction();
    15911595        add_filter( 'wp_get_attachment_image_attributes', array( $mock_action, 'filter' ) );
     
    16011605     * @ticket 14110
    16021606     */
    1603     public function test_wp_get_attachment_image_filter_change_height_width() {
     1607    public function test_wp_get_attachment_image_filter_change_width_height() {
    16041608        add_filter(
    16051609            'wp_get_attachment_image_attributes',
    16061610            static function ( $args ) {
     1611                $args['width']  = '999';
    16071612                $args['height'] = '999';
    1608                 $args['width']  = '999';
    16091613                return $args;
    16101614            }
     
    16181622     * @ticket 14110
    16191623     */
    1620     public function test_wp_get_attachment_image_filter_unset_height_width() {
     1624    public function test_wp_get_attachment_image_filter_unset_width_height() {
    16211625        add_filter(
    16221626            'wp_get_attachment_image_attributes',
    16231627            static function ( $args ) {
    1624                 unset( $args['height'], $args['width'] );
     1628                unset( $args['width'], $args['height'] );
    16251629                return $args;
    16261630            }
     
    16291633        $this->assertStringContainsString( 'width="150"', $output, 'Width should not be changed.' );
    16301634        $this->assertStringContainsString( 'height="150"', $output, 'Height should not be changed.' );
    1631     }
    1632 
    1633     public function filter_wp_get_attachment_image() {
    1634         return 'Override wp_get_attachment_image';
    16351635    }
    16361636
Note: See TracChangeset for help on using the changeset viewer.