From aca737cb79868d773fdae2f8cfbaff7f73b7ecce Mon Sep 17 00:00:00 2001 From: Darshan Gada Date: Thu, 9 Apr 2026 15:03:25 +0530 Subject: [PATCH 1/2] Add reason for skipping regeneration in `wp media regenerate` When `wp media regenerate` skips a thumbnail, it now includes the specific reason in the output message (e.g., "no editor available for image/svg+xml"). This helps users understand why regeneration was skipped without needing to investigate further. Also adds `WP_CLI::debug()` output throughout the regeneration decision logic, providing detailed diagnostics when `--debug` is used (e.g., size changes detected, missing thumbnail files, all thumbnails up to date). Fixes wp-cli/media-command#95 --- features/media-regenerate.feature | 30 +++++++++++++++--------------- src/Media_Command.php | 15 +++++++++++---- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/features/media-regenerate.feature b/features/media-regenerate.feature index edec0726..22fa5732 100644 --- a/features/media-regenerate.feature +++ b/features/media-regenerate.feature @@ -1146,7 +1146,7 @@ Feature: Regenerate WordPress attachments """ And STDOUT should contain: """ - 1/1 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {ATTACHMENT_ID}) + 1/1 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {ATTACHMENT_ID}): no editor available for image/svg+xml. """ And STDOUT should not contain: """ @@ -1166,7 +1166,7 @@ Feature: Regenerate WordPress attachments """ And STDOUT should contain: """ - 1/1 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {ATTACHMENT_ID}) + 1/1 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {ATTACHMENT_ID}): no editor available for image/svg+xml. """ And STDOUT should not contain: """ @@ -1213,7 +1213,7 @@ Feature: Regenerate WordPress attachments """ And STDOUT should contain: """ - /2 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}) + /2 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}): no editor available for application/pdf. """ And STDOUT should contain: """ @@ -1237,7 +1237,7 @@ Feature: Regenerate WordPress attachments """ And STDOUT should contain: """ - /2 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}) + /2 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}): no editor available for application/pdf. """ And STDOUT should contain: """ @@ -1286,7 +1286,7 @@ Feature: Regenerate WordPress attachments """ And STDOUT should contain: """ - /1 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}) + /1 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}): no editor available for application/pdf. """ And STDOUT should not contain: """ @@ -1371,7 +1371,7 @@ Feature: Regenerate WordPress attachments """ And STDOUT should contain: """ - /1 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}) + /1 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}): no editor available for application/pdf. """ And STDOUT should not contain: """ @@ -1470,7 +1470,7 @@ Feature: Regenerate WordPress attachments """ And STDOUT should contain: """ - 1/1 Skipped thumbnail regeneration for "My imported BMP attachment" (ID {BMP_ATTACHMENT_ID}). + 1/1 Skipped thumbnail regeneration for "My imported BMP attachment" (ID {BMP_ATTACHMENT_ID}): no editor available for image/bmp. """ And STDOUT should contain: """ @@ -1529,7 +1529,7 @@ Feature: Regenerate WordPress attachments """ And STDOUT should contain: """ - 1/1 Skipped thumbnail regeneration for "My imported BMP attachment" (ID {BMP_ATTACHMENT_ID}). + 1/1 Skipped thumbnail regeneration for "My imported BMP attachment" (ID {BMP_ATTACHMENT_ID}): no editor available for image/bmp. """ And STDOUT should contain: """ @@ -1621,7 +1621,7 @@ Feature: Regenerate WordPress attachments """ And STDOUT should contain: """ - /4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}). + /4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}): no editor available for image/svg+xml. """ And STDOUT should contain: """ @@ -1653,11 +1653,11 @@ Feature: Regenerate WordPress attachments """ And STDOUT should contain: """ - /4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}). + /4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}): no editor available for image/svg+xml. """ And STDOUT should contain: """ - /4 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}). + /4 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}): no editor available for application/pdf. """ And STDOUT should contain: """ @@ -1683,11 +1683,11 @@ Feature: Regenerate WordPress attachments """ And STDOUT should contain: """ - /4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}). + /4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}): no editor available for image/svg+xml. """ And STDOUT should contain: """ - /4 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}). + /4 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}): no editor available for application/pdf. """ And STDOUT should contain: """ @@ -1716,7 +1716,7 @@ Feature: Regenerate WordPress attachments """ And STDOUT should contain: """ - /4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}). + /4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}): no editor available for image/svg+xml. """ And STDOUT should contain: """ @@ -1765,7 +1765,7 @@ Feature: Regenerate WordPress attachments """ And STDOUT should contain: """ - /4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}). + /4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}): no editor available for image/svg+xml. """ And STDOUT should contain: """ diff --git a/src/Media_Command.php b/src/Media_Command.php index f1b5a1a4..67198bfb 100644 --- a/src/Media_Command.php +++ b/src/Media_Command.php @@ -1167,7 +1167,7 @@ private function process_regeneration( $id, $skip_delete, $only_missing, $delete $needs_regeneration = $this->needs_regeneration( $id, $fullsizepath, $is_pdf, $image_sizes, $skip_delete, $skip_it ); if ( $skip_it ) { - WP_CLI::log( "$progress Skipped $thumbnail_desc regeneration for $att_desc." ); + WP_CLI::log( "$progress Skipped $thumbnail_desc regeneration for $att_desc: $skip_it." ); ++$skips; return; } @@ -1429,8 +1429,8 @@ private function remove_old_images( $metadata, $fullsizepath, $image_sizes ) { * @param bool $is_pdf * @param string[] $image_sizes * @param bool $skip_delete - * @param bool $skip_it - * @param-out bool $skip_it + * @param string|false $skip_it Reason string if skipping, false otherwise. + * @param-out string|false $skip_it * @return bool */ private function needs_regeneration( $att_id, $fullsizepath, $is_pdf, $image_sizes, $skip_delete, &$skip_it ) { @@ -1449,7 +1449,9 @@ private function needs_regeneration( $att_id, $fullsizepath, $is_pdf, $image_siz if ( ! $is_pdf && is_array( $metadata ) && ! empty( $metadata['sizes'] ) ) { WP_CLI::warning( sprintf( '%s (ID %d)', $attachment_sizes->get_error_message(), $att_id ) ); } - $skip_it = true; + $mime_type = get_post_mime_type( $att_id ); + $skip_it = sprintf( 'no editor available for %s', $mime_type ? $mime_type : 'this file type' ); + WP_CLI::debug( sprintf( 'Skipping attachment %d: %s.', $att_id, $skip_it ), 'media' ); return false; } @@ -1481,6 +1483,7 @@ private function needs_regeneration( $att_id, $fullsizepath, $is_pdf, $image_siz $filtered_sizes = array_intersect_key( $attachment_sizes, array_flip( $image_sizes ) ); if ( empty( $filtered_sizes ) ) { + WP_CLI::debug( sprintf( 'Skipping attachment %d: no requested sizes apply to this attachment.', $att_id ), 'media' ); return false; } @@ -1501,6 +1504,7 @@ private function needs_regeneration( $att_id, $fullsizepath, $is_pdf, $image_siz } if ( $this->image_sizes_differ( $attachment_sizes, $metadata['sizes'] ) ) { + WP_CLI::debug( sprintf( 'Regenerating attachment %d: image sizes have changed.', $att_id ), 'media' ); return true; } @@ -1519,9 +1523,12 @@ private function needs_regeneration( $att_id, $fullsizepath, $is_pdf, $image_siz } if ( ! file_exists( $intermediate_path ) ) { + WP_CLI::debug( sprintf( 'Regenerating attachment %d: missing thumbnail file "%s".', $att_id, $size_info['file'] ), 'media' ); return true; } } + + WP_CLI::debug( sprintf( 'Attachment %d: all thumbnails up to date.', $att_id ), 'media' ); return false; } From a3aac394984d144d17a441472153b8d0a2c17c8e Mon Sep 17 00:00:00 2001 From: Darshan Gada Date: Thu, 9 Apr 2026 16:10:51 +0530 Subject: [PATCH 2/2] Address review feedback on skip reason formatting - Remove trailing period from log format string; let the reason string itself carry punctuation to avoid doubled periods - Change debug message from "Skipping" to "Not regenerating" for the no-applicable-sizes path, since it is not counted as a skip --- src/Media_Command.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Media_Command.php b/src/Media_Command.php index 67198bfb..5a1362a5 100644 --- a/src/Media_Command.php +++ b/src/Media_Command.php @@ -1167,7 +1167,7 @@ private function process_regeneration( $id, $skip_delete, $only_missing, $delete $needs_regeneration = $this->needs_regeneration( $id, $fullsizepath, $is_pdf, $image_sizes, $skip_delete, $skip_it ); if ( $skip_it ) { - WP_CLI::log( "$progress Skipped $thumbnail_desc regeneration for $att_desc: $skip_it." ); + WP_CLI::log( "$progress Skipped $thumbnail_desc regeneration for $att_desc: $skip_it" ); ++$skips; return; } @@ -1450,7 +1450,7 @@ private function needs_regeneration( $att_id, $fullsizepath, $is_pdf, $image_siz WP_CLI::warning( sprintf( '%s (ID %d)', $attachment_sizes->get_error_message(), $att_id ) ); } $mime_type = get_post_mime_type( $att_id ); - $skip_it = sprintf( 'no editor available for %s', $mime_type ? $mime_type : 'this file type' ); + $skip_it = sprintf( 'no editor available for %s.', $mime_type ? $mime_type : 'this file type' ); WP_CLI::debug( sprintf( 'Skipping attachment %d: %s.', $att_id, $skip_it ), 'media' ); return false; } @@ -1483,7 +1483,7 @@ private function needs_regeneration( $att_id, $fullsizepath, $is_pdf, $image_siz $filtered_sizes = array_intersect_key( $attachment_sizes, array_flip( $image_sizes ) ); if ( empty( $filtered_sizes ) ) { - WP_CLI::debug( sprintf( 'Skipping attachment %d: no requested sizes apply to this attachment.', $att_id ), 'media' ); + WP_CLI::debug( sprintf( 'Not regenerating attachment %d: no requested sizes apply to this attachment.', $att_id ), 'media' ); return false; }