Opened 7 weeks ago
Last modified 2 weeks ago
#65345 new defect (bug)
Site Icon subsizes use wrong array key 'width ' instead of 'width'
| Reported by: | tomatillo | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.1 |
| Component: | Media | Version: | 4.3 |
| Severity: | normal | Keywords: | has-patch needs-testing has-unit-tests |
| Cc: | Focuses: |
Description (last modified by )
In WP_Site_Icon::additional_sizes(), site icon subsize definitions use the array key 'width ' (with a trailing space) instead of 'width'.
File: wp-admin/includes/class-wp-site-icon.php
Method: WP_Site_Icon::additional_sizes()
The image editor reads $size_data['width']. Because the key is wrong, width is null and subsizes are not generated as intended square crops.
Steps to reproduce:
- Set
site_iconto a non-square attachment without going through the Customizer crop UI (e.g. assign an existing landscape photo). - Regenerate or create
site_icon-*subsizes. - Inspect attachment metadata sizes
site_icon-192,site_icon-32, etc.
Expected: 192x192, 32x32 square crops.
Actual: non-square dimensions (e.g. 256x192, 43x32).
Impact: get_site_icon_url() may fall back to the full scaled image for head meta tags.
Fix: change 'width ' to 'width' on the site_icon subsize definition line.
Attachments (3)
Change History (15)
#1
@
7 weeks ago
- Keywords has-patch needs-testing added
Patch attached.
Fixes a trailing space in the site icon subsize definition array key ('width ' → 'width').
Without this, WP_Image_Editor receives a null width and generates non-square site_icon-* crops,
which can cause get_site_icon_url() to fall back to the full scaled image.
Test plan:
- Apply patch to trunk.
- Assign a non-square attachment as site_icon without the Customizer crop UI.
- Regenerate site_icon-* subsizes.
- Confirm site_icon-32, site_icon-180, site_icon-192, and site_icon-270 are square.
- Confirm get_site_icon_url(192) returns the cropped file, not the full image.
@
7 weeks ago
Supersedes the earlier patch attachment. Please use the latest 65345.patch (Co-authored-by line removed; diff unchanged).
This ticket was mentioned in PR #11973 on WordPress/wordpress-develop by @wprashed.
7 weeks ago
#2
- Keywords has-unit-tests added
Fixes a typo in WP_Site_Icon::additional_sizes() where the subsize array used 'width ' (with a trailing space) instead of 'width'.
With the incorrect key, width can be treated as missing during subsize generation, which may produce non-square site_icon-* dimensions in some flows (for example, when assigning a non-square attachment as the site icon outside the Customizer crop UI).
This change restores expected square crops for site icon sizes such as site_icon-32, site_icon-180, site_icon-192, and site_icon-270.
#3
@
7 weeks ago
- Description modified (diff)
- Version 7.0 → 4.3
The array key has been 'width ' since r32994.
@swissspidy commented on PR #11973:
7 weeks ago
#4
Please note this PR incorrectly includes changes from a bunch of different tickets. A PR should be self-contained and here should only include the site icon change, nothing else.
Also note that the ticket already had a patch, so the extra PR is a bit redundant.
This ticket was mentioned in PR #11975 on WordPress/wordpress-develop by @mohamedahamed.
7 weeks ago
#6
- Keywords has-unit-tests added
## Summary
Fixes an issue where site icon subsizes (site_icon-192, site_icon-32, etc.) are generated with incorrect, non-square dimensions instead of the expected square crops (e.g. 192×192, 32×32).
### Root Cause
In `src/wp-admin/includes/class-wp-site-icon.php`, the WP_Site_Icon::additional_sizes() method defines subsize entries with the array key 'width ' (containing a trailing space) instead of 'width':
$only_crop_sizes[ 'site_icon-' . $size ] = array( 'width ' => $size, // ← trailing space in key 'height' => $size, 'crop' => true, );
The downstream consumer in `src/wp-includes/media.php` (wp_get_registered_image_subsizes()) reads the width using the correct key 'width' (no space):
if ( isset( $additional_sizes[ $size_name ]['width'] ) ) { $size_data['width'] = (int) $additional_sizes[ $size_name ]['width']; }
Because the keys don't match, the isset() check fails, width remains 0, and the image editor never receives a width constraint. This results in non-square, aspect-ratio-preserved thumbnails instead of the intended square crops.
This typo has existed since the WP_Site_Icon class was introduced in WordPress 4.3.
### Solution
- Changed
'width 'to'width'in the subsize definition array insideWP_Site_Icon::additional_sizes(). - Updated the corresponding test expectations in
tests/phpunit/tests/image/siteIcon.phpwhich mirrored the same typo.
## Testing
- Set up a local WordPress dev environment (e.g. using
wp-env, Local, or Docker). - Upload a non-square image (e.g. a 1200×800 landscape photo) via Media → Add New.
- Set it as the site icon without cropping:
wp option update site_icon <attachment_id>
- Regenerate the attachment metadata with the site icon filters enabled (this is necessary because by default WP-CLI does not load admin/customizer classes containing site icon filters):
wp eval ' require_once ABSPATH . "wp-admin/includes/class-wp-site-icon.php"; $wp_site_icon = new WP_Site_Icon(); add_filter( "intermediate_image_sizes_advanced", array( $wp_site_icon, "additional_sizes" ) ); $metadata = wp_generate_attachment_metadata( <attachment_id>, get_attached_file( <attachment_id> ) ); wp_update_attachment_metadata( <attachment_id>, $metadata ); '
- Inspect the generated subsizes:
wp post meta get <attachment_id> _wp_attachment_metadata
- Verify that
site_icon-270,site_icon-192,site_icon-180, andsite_icon-32are now square crops (e.g.192×192,32×32). Before the fix, they will be non-square dimensions matching the source image's aspect ratio.
---
Trac Ticket: https://core.trac.wordpress.org/ticket/65345
---
| Test Case | Expected / Result | Status |
|---|---|---|
test_additional_sizes — subsizes use 'width' key | Array keys match 'width' (no trailing space) | ✅ Passed |
test_additional_sizes_with_filter — custom sizes use 'width' key | Array keys match 'width' (no trailing space) | ✅ Passed |
| Site icon subsizes are square crops after regeneration | site_icon-192 = 192×192, site_icon-32 = 32×32, etc. | ✅ Passed |
get_site_icon_url() returns correct subsize URL | Returns subsize URL instead of falling back to full image | ✅ Passed |
## Use of AI Tools
AI assistance: No
#7
@
6 weeks ago
Test Report
Patch tested: https://github.com/WordPress/wordpress-develop/pull/11975
Environment
- WordPress: 7.1-alpha-62161-src
- Subdirectory: No
- PHP: 8.3.31
- Server: nginx/1.31.1
- Database: mysqli (Server: 9.7.0 / Client: mysqlnd 8.3.31)
- Browser: Firefox 151.0
- OS: Ubuntu
- Theme: Twenty Twenty-Five 1.5
- MU Plugins: None activated
- Plugins:
- Test Reports 1.3.0
Steps taken
Followed the testing steps from the PR
✅ Patch is solving the problem
Expected result
- I expected site_icon-270, site_icon-192, site_icon-180, and site_icon-32 to be square crops of the original image.
Screenshots/Screencast with results
'site_icon-270' =>
array (
'file' => '383074-New_Zealand-landscape-scaled-270x270.jpg',
'width' => 270,
'height' => 270,
'mime-type' => 'image/jpeg',
'filesize' => 18642,
),
'site_icon-192' =>
array (
'file' => '383074-New_Zealand-landscape-scaled-192x192.jpg',
'width' => 192,
'height' => 192,
'mime-type' => 'image/jpeg',
'filesize' => 11437,
),
'site_icon-180' =>
array (
'file' => '383074-New_Zealand-landscape-scaled-180x180.jpg',
'width' => 180,
'height' => 180,
'mime-type' => 'image/jpeg',
'filesize' => 10988,
),
'site_icon-32' =>
array (
'file' => '383074-New_Zealand-landscape-scaled-32x32.jpg',
'width' => 32,
'height' => 32,
'mime-type' => 'image/jpeg',
'filesize' => 4025,
),
#8
@
6 weeks ago
Test Report
Patch tested: https://github.com/WordPress/wordpress-develop/pull/11975
Environment
- WordPress: 7.1-alpha-62161-src
- Subdirectory: No
- PHP: 8.3.31
- Server: nginx/1.31.1
- Database: mysqli (Server: 9.7.0 / Client: mysqlnd 8.3.31)
- Browser: Chrome 148.0.0.0
- OS: macOS
- Theme: Twenty Twenty-Five 1.5
- MU Plugins: None activated
- Plugins:
- Test Reports 1.3.0
Steps taken
Followed the testing steps from the PR
- Installed WordPress using wp-env
- Uploaded the landscape photo 1200x800
- Set up as icon using wp option update site_icon
- Regenerated the attachment metadata - using the eval
- Verified that icons are square crops:
eg:
'site_icon-192' =>
array (
'file' => '0I7A9276-192x192.webp',
'width' => 192,
'height' => 192,
'mime-type' => 'image/webp',
'filesize' => 8276,
),
'site_icon-180' =>
array (
'file' => '0I7A9276-180x180.webp',
'width' => 180,
'height' => 180,
'mime-type' => 'image/webp',
'filesize' => 7622,
),
'site_icon-32' =>
array (
'file' => '0I7A9276-32x32.webp',
'width' => 32,
'height' => 32,
'mime-type' => 'image/webp',
'filesize' => 502,
),
),
- ✅ Patch is solving the problem
Expected result
- The images are cropped to square dimensions.
#9
@
6 weeks ago
Tested PR 11975 locally.
Environment:
- WordPress 7.1-alpha-62161-src
- Local wp-env/Docker environment
- PHP 8.5.6
Steps tested:
- Uploaded a non-square image.
- Set the uploaded image as the Site Icon from General Settings.
- Cropped and saved the Site Icon.
- Confirmed the site_icon option was set to the generated cropped attachment.
- Inspected the generated attachment metadata.
Result:
The generated site icon sizes are square as expected:
site_icon-270: 270x270
site_icon-192: 192x192
site_icon-180: 180x180
site_icon-32: 32x32
The patch tests successfully for me.
@yusufmudagal commented on PR #11975:
5 weeks ago
#10
Tested the patch locally against current origin/trunk in a disposable worktree.
Results:
php -l src/wp-admin/includes/class-wp-site-icon.phppassed.vendor/bin/phpunit --filter Tests_WP_Site_Iconpassed: 7 tests, 11 assertions.
The change looks focused to the incorrect width key and the updated Site Icon expectations pass for me.
#11
@
4 weeks ago
Test Report
Patch tested: https://github.com/WordPress/wordpress-develop/pull/11975
Environment
- WordPress: 7.1-alpha-62161-src
- Subdirectory: No
- PHP: 8.3.31
- Server: nginx
- Database: mysql
- Browser: Chrome
- OS: Windows 11
- Theme: Twenty Twenty-Five
- MU Plugins: None activated
- Plugins:
- Test Reports 1.3.0
Steps taken
- Applied the patch from the PR.
- Followed the testing instructions provided in the PR.
- Installed WordPress using wp-env.
- Uploaded a landscape image (1200x800).
- Set the image as the site icon using
wp option update site_icon. - Regenerated the attachment metadata using eval.
- Verified the generated site icon sizes are square crops.
Example verified output:
'site_icon-192' =>
array (
'file' => 'test-landscape-icon-192x192.webp',
'width' => 192,
'height' => 192,
'mime-type' => 'image/webp',
'filesize' => 9134,
),
'site_icon-180' =>
array (
'file' => 'test-landscape-icon-180x180.webp',
'width' => 180,
'height' => 180,
'mime-type' => 'image/webp',
'filesize' => 8461,
),
'site_icon-32' =>
array (
'file' => 'test-landscape-icon-32x32.webp',
'width' => 32,
'height' => 32,
'mime-type' => 'image/webp',
'filesize' => 621,
),
Result
- Patch successfully resolves the reported issue.
- Generated site icon images are correctly created with square dimensions.
Expected result
Site icon images should be generated as square crops while preserving the expected icon sizes.
#12
in reply to: ↑ description
@
2 weeks ago
$only_crop_sizes[ 'site_icon-' . $size ] = array(
'width' => $size,
'height' => $size,
'crop' => true,
);
Fixed the issue in the $only_crop_sizes array where the key 'width ' contained an unintended trailing space. This was causing an invalid array key definition.
Updated the code to use the correct key 'width' to ensure proper image size configuration. No functional changes were made beyond this correction.
Thanks
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Fix 'width ' → 'width' in WP_Site_Icon::additional_sizes() so site icon subsizes crop square.