Make WordPress Core

Changeset 63765


Ignore:
Timestamp:
09/21/2026 12:56:14 AM (8 weeks ago)
Author:
peterwilsoncc
Message:

Media: Ensure cropped site icons generate square images.

Fixes a typo in WP_Site_Icon::additional_sizes() to ensure that sub-sizes generated for site icons are square. A trailing space on the width key could cause the icon to be cropped to rectangles for the sub sizes.

Follow up to r32994.
Developed in ​https://github.com/WordPress/wordpress-develop/pull/11975

Props mohamedahamed, yusufmudagal, agnieszkablu, analogstudio, darshitrajyaguru97, davidbaumwald, jamesbregenzer, juanmaguitar, mukesh27, pedrofigueroa1989, sabernhardt, shailesh7714, swissspidy, tomatillo, ugyensupport, wildworks.
Fixes #65345.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-site-icon.php

    r63569 r63765  
    171171                        if ( $size < $this->min_size ) {
    172172                                $only_crop_sizes[ 'site_icon-' . $size ] = array(
    173                                         'width ' => $size,
     173                                        'width' => $size,
    174174                                        'height' => $size,
    175175                                        'crop'   => true,
  • trunk/tests/phpunit/tests/image/siteIcon.php

    r57755 r63765  
    6767                foreach ( $this->wp_site_icon->site_icon_sizes as $size ) {
    6868                        $sizes[ 'site_icon-' . $size ] = array(
    69                                 'width ' => $size,
     69                                'width' => $size,
    7070                                'height' => $size,
    7171                                'crop'   => true,
    … …  
    8383                foreach ( $this->wp_site_icon->site_icon_sizes as $size ) {
    8484                        $sizes[ 'site_icon-' . $size ] = array(
    85                                 'width ' => $size,
     85                                'width' => $size,
    8686                                'height' => $size,
    8787                                'crop'   => true,
    … …  
    9797                // Remove custom size.
    9898                unset( $this->wp_site_icon->site_icon_sizes[ array_search( 321, $this->wp_site_icon->site_icon_sizes, true ) ] );
     99        }
     100
     101        /**
     102         * Tests that the registered sub-sizes are generated as square crops.
     103         *
     104         * @ticket 65345
     105         *
     106         * @covers WP_Site_Icon::additional_sizes
     107         */
     108        public function test_additional_sizes_generate_square_subsizes() {
     109                // A non-square source, large enough for every site icon size.
     110                $filename = DIR_TESTDATA . '/images/waffles.jpg';
     111                $upload   = wp_upload_bits( wp_basename( $filename ), null, file_get_contents( $filename ) );
     112
     113                $attachment_id = $this->_make_attachment( $upload );
     114                $file          = get_attached_file( $attachment_id );
     115
     116                $editor = wp_get_image_editor( $file );
     117
     118                if ( is_wp_error( $editor ) ) {
     119                        $this->markTestSkipped( $editor->get_error_message() );
     120                }
     121
     122                add_filter( 'intermediate_image_sizes_advanced', array( $this->wp_site_icon, 'additional_sizes' ) );
     123                $metadata = wp_generate_attachment_metadata( $attachment_id, $file );
     124
     125                foreach ( $this->wp_site_icon->site_icon_sizes as $size ) {
     126                        $size_name = 'site_icon-' . $size;
     127
     128                        $this->assertArrayHasKey( $size_name, $metadata['sizes'], "The {$size_name} sub-size was not generated." );
     129                        $this->assertSame(
     130                                array( $size, $size ),
     131                                array( $metadata['sizes'][ $size_name ]['width'], $metadata['sizes'][ $size_name ]['height'] ),
     132                                "The {$size_name} sub-size is not a square crop."
     133                        );
     134                }
    99135        }
    100136
Note: See TracChangeset for help on using the changeset viewer.