Skip to content

Administration: Create site icon sizes for exact-size images in General Settings. - #14280

Open
rvpatel wants to merge 2 commits into
WordPress:trunkfrom
rvpatel:66309-site-icon-exact-size-crop
Open

rvpatel wants to merge 2 commits into
WordPress:trunkfrom
rvpatel:66309-site-icon-exact-size-crop

Conversation

@rvpatel

@rvpatel rvpatel commented Oct 14, 2026 •

Copy link
Copy Markdown

In Settings > General, when the selected Site Icon image is already exactly 512×512, the crop step is skipped and the original image is saved as the site icon. The site icon sizes (32, 64, 180, 192 and 270) are only created by the crop-image request with the site-icon context, so they are never generated. Favicons and app icons then fall back to the regular thumbnail (150px) and medium (300px) sizes. Square images of other sizes also always have to go through the cropper, while the Customizer offers "Skip cropping" (#64020).

The Customizer's Site Icon control handles both cases. Exact-size images still go through a full-size "crop" request (wp.customize.SiteIconControl.onSelect()), and square images get a "Skip cropping" button that also sends the whole image through crop-image. Both were lost when the control was brought to the General Settings screen in 6.5.

This PR:

  • Sends exact-size images through the same crop-image request with the site-icon context, and reuses the existing cropped handler to update the field and previews. A failed request shows the media modal's crop error.
  • Sets hasRequiredAspectRatio and suggestedCropSize in calculateImageSelectOptions(), as the Customizer does, so the cropper shows "Skip cropping" for square images. Skipping crops the whole image to 512×512, so the site icon sizes are created.

Trac tickets: https://core.trac.wordpress.org/ticket/66309, https://core.trac.wordpress.org/ticket/64020

Testing Instructions

  1. Go to Settings > General.
  2. Under Site Icon, choose an image that is exactly 512×512 and click "Set as Site Icon". The modal closes without the crop step and the previews update.
  3. Choose a square image larger than 512×512, for example 1024×1024. The cropper shows "Skip cropping" next to "Crop image". Click "Skip cropping": the previews update with the whole image.
  4. Choose an image that is not square. The cropper shows only "Crop image", as before.
  5. Click "Save Changes". In Media > Library, a new cropped-… image is created for the site icon.
  6. Check the generated sizes, e.g. wp eval 'print_r( array_keys( wp_get_attachment_metadata( get_option( "site_icon" ) )["sizes"] ) );': it includes site_icon-32, site_icon-64, site_icon-180, site_icon-192 and site_icon-270.

Before this change, step 2 saves the original image, step 6 only lists thumbnail and medium, and get_site_icon_url( 32 ) returns the 150×150 image. Step 3 shows only "Crop image".

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Investigating the cause, writing the fix, testing it in a browser and writing this description. I reviewed the code and the results.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

…al Settings.

When an image that already has the required site icon dimensions (512x512) is selected in Settings > General, the crop step is skipped and the original image is saved as the site icon, so the site icon sizes (32, 64, 180, 192 and 270) are never generated.

Send the image through the crop-image request with the `site-icon` context, as the Customizer already does, so the site icon and its sizes are created.

See #66309.
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props ravipatel, adamsilverstein.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@adamsilverstein

Copy link
Copy Markdown
Member

Thanks for the PR @rvpatel - the code looks fine on the face of it, but I'm not sure this is the best approach. It creates an additional request and could require different capabilities than the current flow, possibly silently failing.

I chatted with Claude about this to come up with some alternate approaches. I chose a couple possibilities to consider:

  1. Create the sizes when the site_icon option is saved

Essentially silently fix the issue silently by creating the missing sizes when the option gets saved.

// hook add_option_site_icon and update_option_site_icon. If the attachment has no site_icon-* sizes, create only the missing ones:
$wp_site_icon = new WP_Site_Icon();
$new_sizes    = $wp_site_icon->additional_sizes( wp_get_registered_image_subsizes() );
$metadata     = _wp_make_subsizes( $new_sizes, get_attached_file( $id ), wp_get_attachment_metadata( $id ), $id );

The advantage here is it ensures site icons always work, no matter where the icon comes from , including REST and WP-CLI. It feels a little kludgy to me though.

  1. Match the Customizer: always show the cropper with a "Skip Cropping" button

This is what @jorbin and @joedolson asked for on https://core.trac.wordpress.org/ticket/64020. It makes the two screens behave the same.

"Skip Cropping" in the Customizer still sends the full image through crop-image, so it keeps the duplicate copy and the re-encoding.So its the current PR with an extra button. It would fix #64020 and #66309 together.

What do you think?

@adamsilverstein adamsilverstein left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is good, consider alternate approaches

In Settings > General, show the "Skip cropping" button for square images,
as the Customizer does. Skipping still sends the whole image through the
`crop-image` request with the `site-icon` context, so the site icon sizes
are created.

See #64020, #66309.
@rvpatel

rvpatel commented Nov 11, 2026 •

Copy link
Copy Markdown
Author

Thanks @adamsilverstein, and sorry for the slow reply. I went with option 4 and pushed it in 418052e: General Settings now shows the "Skip cropping" button for square images, as the Customizer does.

How it works: calculateImageSelectOptions() now sets hasRequiredAspectRatio and suggestedCropSize on the cropper, the same way wp.customize.CroppedImageControl does. The existing Cropper.createCropToolbar() then adds the button, and "Skip cropping" sends the whole image through crop-image with the site-icon context. No new request type and no change to the media library code.

On your concerns about the extra request:

  • Capabilities: wp_ajax_crop_image() checks the attachment's image_editor-{id} nonce and edit_post on the attachment. Every image that isn't exactly 512×512 already goes through that same request when "Crop image" is clicked, so no new capability is needed.
  • Silent failure: if the request fails, the modal shows its crop error (content:error:crop), as the cropper does.

I tested it in a browser (Chromium via Playwright) on trunk's General Settings:

Image Trunk With this PR
1024×1024 Cropper, "Crop image" only Cropper with "Skip cropping" and "Crop image"; skipping creates a 512×512 icon
512×512 Original saved, sizes: medium, thumbnail Crop request, new 512×512 icon
800×600 Cropper, "Crop image" only Same, no skip button

Each icon created with the PR has site_icon-32, -64, -180, -192 and -270.

This should cover #64020 as well as #66309. I'd still like your view on option 1 as a follow-up, since icons set through REST or WP-CLI also miss these sizes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants