Skip to content

Fix media regenerate dropping site-icon-specific image sizes#223

Merged
swissspidy merged 3 commits intomainfrom
copilot/fix-site-icon-size-regeneration
Feb 25, 2026
Merged

Fix media regenerate dropping site-icon-specific image sizes#223
swissspidy merged 3 commits intomainfrom
copilot/fix-site-icon-size-regeneration

Conversation

Copy link
Contributor

Copilot AI commented Feb 25, 2026

When wp media regenerate runs on a site-icon attachment (the cropped image created via Customizer → Site Identity), it calls wp_generate_attachment_metadata() without the WP_Site_Icon filters that WordPress core applies during site icon creation — resulting in the custom sizes (32, 180, 192, 270px) being lost and replaced with only the standard registered sizes.

Changes

  • src/Media_Command.php: Added add_site_icon_filter() method that detects site-icon attachments via the _wp_attachment_context = 'site-icon' post meta and temporarily hooks WP_Site_Icon::additional_sizes onto intermediate_image_sizes_advanced — mirroring what WordPress core does in wp-admin/includes/ajax-actions.php. The filter is added before and removed after wp_generate_attachment_metadata().

  • features/media-regenerate.feature: Added @require-wp-4.3 scenario that imports an image, marks it as a site icon via post meta, regenerates, and asserts site_icon-32/180/192/270 keys are present in the attachment metadata.

Original prompt

This section details on the original issue you should resolve

<issue_title>media regenerate removes/doesn't recreate custom site-icon sizes</issue_title>
<issue_description>Summary

When regenerating all media, the special-case site-icon loses its custom sizes

Steps to Reproduce

  1. Through Customizer -> Site Identity, add a Site Icon
  2. Observe that in addition to the originally uploaded image present in the media gallery, a 2nd "cropped" variant is created with unique image sizes
  3. Run wp media regenerate --yes
  4. Observe that the cropped variant's sizes are replaced with the standard active sizes

Environment

  1. PHP 7.1.16 (cli) (built: Mar 31 2018 02:28:54) ( NTS )
  2. $wp_version = '4.9.6';
  3. WP-CLI 1.5.1
  4. twentyseventeen theme, no plugins

Severity - Low

Expected Results: The special case 'site-icon' should be handled as it is in core to generate the correct media sizes

Actual Results: The site-icon image attachment is handled the same as all other uploads, and loses its special sizes, which may cause issues with devices/services looking for/expecting to find images of a particular size. The meta tags output in the site header do link to the newly generated image sizes, but attributes on the meta tags still show the original sizes that were expected to exist.

Core is only expecting this image to ever be set via the customizer, so the case for it is handled in ajax-actions.php which calls on the WP_Site_Icon class from class-wp-site-icon.php.

File and metadata before/after regeneration: https://gist.github.com/dotsam/f31dfed2ee1b64b149883520ee901b43</issue_description>

Comments on the Issue (you are @copilot in this section)

@schlessera We should include a hardcoded check for this edge case.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix media regenerate not recreating custom site-icon sizes Fix media regenerate dropping site-icon-specific image sizes Feb 25, 2026
Copilot AI requested a review from swissspidy February 25, 2026 17:48
@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Media_Command.php 91.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

@swissspidy swissspidy requested a review from Copilot February 25, 2026 22:26
@swissspidy swissspidy added this to the 2.2.4 milestone Feb 25, 2026
@swissspidy swissspidy marked this pull request as ready for review February 25, 2026 22:26
@swissspidy swissspidy requested a review from a team as a code owner February 25, 2026 22:26

This comment was marked as resolved.

@swissspidy swissspidy merged commit e6fd286 into main Feb 25, 2026
63 checks passed
@swissspidy swissspidy deleted the copilot/fix-site-icon-size-regeneration branch February 25, 2026 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

media regenerate removes/doesn't recreate custom site-icon sizes

3 participants