Media: Fix WP_Site_Icon 'width ' typo causing non-square site icon subsizes#11975
Media: Fix WP_Site_Icon 'width ' typo causing non-square site icon subsizes#11975NoumaanAhamed wants to merge 2 commits into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
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, theWP_Site_Icon::additional_sizes()method defines subsize entries with the array key'width '(containing a trailing space) instead of'width':The downstream consumer in
src/wp-includes/media.php(wp_get_registered_image_subsizes()) reads the width using the correct key'width'(no space):Because the keys don't match, the
isset()check fails,widthremains0, 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_Iconclass was introduced in WordPress 4.3.Solution
'width 'to'width'in the subsize definition array insideWP_Site_Icon::additional_sizes().tests/phpunit/tests/image/siteIcon.phpwhich mirrored the same typo.Testing
wp-env, Local, or Docker).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_additional_sizes— subsizes use'width'key'width'(no trailing space)test_additional_sizes_with_filter— custom sizes use'width'key'width'(no trailing space)site_icon-192= 192×192,site_icon-32= 32×32, etc.get_site_icon_url()returns correct subsize URLUse of AI Tools
AI assistance: No