Skip to content

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

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

rvpatel wants to merge 1 commit 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.

The Customizer's Site Icon control handles the same case by still sending a full-size "crop" request (wp.customize.SiteIconControl.onSelect()). This was 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.

Trac ticket: https://core.trac.wordpress.org/ticket/66309

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".
  3. The modal closes without the crop step and the previews update. Click "Save Changes".
  4. In Media > Library, a new cropped-… image is created for the site icon.
  5. Check the generated sizes, e.g. wp eval 'print_r( array_keys( wp_get_attachment_metadata( get_option( "site_icon" ) )["sizes"] ) );': it now includes site_icon-32, site_icon-64, site_icon-180, site_icon-192 and site_icon-270.
  6. Choosing an image of any other size still opens the cropper, as before.

Before this change, step 5 only lists thumbnail and medium, and get_site_icon_url( 32 ) returns the 150×150 image.

Props ravipatel.

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 and this description. I reproduced the issue, tested the fix locally, and take responsibility for it.


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

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