From 3c7be41ae3be8432d56a96176fd25c80ff584e03 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Feb 2026 17:43:19 +0000 Subject: [PATCH 1/3] Initial plan From 9401b6931519c913b16ac80f13d46579852df751 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Feb 2026 17:47:46 +0000 Subject: [PATCH 2/3] Fix site-icon sizes not regenerated during media regenerate Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/media-regenerate.feature | 40 +++++++++++++++++++++++++++++++ src/Media_Command.php | 28 ++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/features/media-regenerate.feature b/features/media-regenerate.feature index 181cd9d8..02bf5d32 100644 --- a/features/media-regenerate.feature +++ b/features/media-regenerate.feature @@ -1721,3 +1721,43 @@ Feature: Regenerate WordPress attachments """ And the wp-content/uploads/large-image-125x125.jpg file should not exist And the wp-content/uploads/large-image-200x200.jpg file should not exist + + @require-wp-4.3 + Scenario: Regenerate site-icon attachment preserves site-icon-specific image sizes + Given download: + | path | url | + | {CACHE_DIR}/large-image.jpg | http://wp-cli.org/behat-data/large-image.jpg | + And I run `wp option update uploads_use_yearmonth_folders 0` + + When I run `wp media import {CACHE_DIR}/large-image.jpg --title="My site icon" --porcelain` + Then save STDOUT as {ATTACHMENT_ID} + + When I run `wp post meta update {ATTACHMENT_ID} _wp_attachment_context site-icon` + Then STDOUT should contain: + """ + Success: Updated custom field '_wp_attachment_context'. + """ + + When I run `wp media regenerate {ATTACHMENT_ID} --yes` + Then STDOUT should contain: + """ + Success: Regenerated 1 of 1 images. + """ + + When I run `wp post meta get {ATTACHMENT_ID} _wp_attachment_metadata --format=json` + Then STDOUT should contain: + """ + site_icon-32 + """ + And STDOUT should contain: + """ + site_icon-180 + """ + And STDOUT should contain: + """ + site_icon-192 + """ + And STDOUT should contain: + """ + site_icon-270 + """ diff --git a/src/Media_Command.php b/src/Media_Command.php index ef4a7d40..4e015c86 100644 --- a/src/Media_Command.php +++ b/src/Media_Command.php @@ -666,8 +666,14 @@ private function process_regeneration( $id, $skip_delete, $only_missing, $delete return; } + $site_icon_filter = $this->add_site_icon_filter( $id ); + $metadata = wp_generate_attachment_metadata( $id, $fullsizepath ); + if ( $site_icon_filter ) { + remove_filter( 'intermediate_image_sizes_advanced', $site_icon_filter ); + } + // Note it's possible for no metadata to be generated for PDFs if restricted to a specific image size. if ( empty( $metadata ) && ! ( $is_pdf && $image_size ) ) { WP_CLI::warning( sprintf( 'No metadata. (ID %d)', $id ) ); @@ -960,6 +966,28 @@ private function remove_image_size_filters( $image_size_filters ) { } } + /** + * Adds the WP_Site_Icon filter for site-icon attachments. + * + * @param int $id Attachment ID. + * @return callable|null The filter callback if added, null otherwise. + */ + private function add_site_icon_filter( $id ) { + if ( 'site-icon' !== get_post_meta( $id, '_wp_attachment_context', true ) ) { + return null; + } + + if ( ! class_exists( 'WP_Site_Icon' ) ) { + return null; + } + + $wp_site_icon = new WP_Site_Icon(); + $filter = array( $wp_site_icon, 'additional_sizes' ); + add_filter( 'intermediate_image_sizes_advanced', $filter ); + + return $filter; + } + public function filter_upload_dir( $uploads ) { if ( ! $this->destination_dir ) { return $uploads; From 5ce2e04e3b5ac6d44cf49c42e065c5bd48261444 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 25 Feb 2026 23:25:44 +0100 Subject: [PATCH 3/3] Load class if missing --- src/Media_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Media_Command.php b/src/Media_Command.php index 4e015c86..97126c78 100644 --- a/src/Media_Command.php +++ b/src/Media_Command.php @@ -978,7 +978,7 @@ private function add_site_icon_filter( $id ) { } if ( ! class_exists( 'WP_Site_Icon' ) ) { - return null; + require_once ABSPATH . 'wp-admin/includes/class-wp-site-icon.php'; } $wp_site_icon = new WP_Site_Icon();