Commit e8ba97d5762 for woocommerce
commit e8ba97d576229a96ae6de72c85af15c4d9bc2e75
Author: Lucio Giannotta <lucio.giannotta@a8c.com>
Date: Tue Aug 4 23:18:52 2026 +0200
Skip image regeneration for files without a supporting image editor (#67347)
diff --git a/plugins/woocommerce/changelog/33729-skip-non-resizable-image-regeneration b/plugins/woocommerce/changelog/33729-skip-non-resizable-image-regeneration
new file mode 100644
index 00000000000..401eca0cacd
--- /dev/null
+++ b/plugins/woocommerce/changelog/33729-skip-non-resizable-image-regeneration
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Skip on-the-fly and background thumbnail regeneration for attachments no image editor supports (e.g. SVGs), preventing PHP notices and repeated doomed resize attempts.
diff --git a/plugins/woocommerce/includes/class-wc-regenerate-images-request.php b/plugins/woocommerce/includes/class-wc-regenerate-images-request.php
index 340c743dae8..c53b784a3c4 100644
--- a/plugins/woocommerce/includes/class-wc-regenerate-images-request.php
+++ b/plugins/woocommerce/includes/class-wc-regenerate-images-request.php
@@ -125,6 +125,29 @@ class WC_Regenerate_Images_Request extends WC_Background_Process {
return false;
}
+ // Files without a supporting image editor (e.g. SVGs) can never be regenerated, so remove them from the queue.
+ // The file-derived mime type is checked first, since the editor loads the file and the recorded type can be stale.
+ $mime_type = wp_check_filetype( $fullsizepath )['type'];
+
+ if ( ! $mime_type ) {
+ $mime_type = $attachment->post_mime_type;
+ }
+
+ if ( ! $mime_type || ! wp_image_editor_supports( array( 'mime_type' => $mime_type ) ) ) {
+ $log->info(
+ sprintf(
+ // translators: 1: ID of the attachment, 2: file mime type.
+ __( 'Skipping image regeneration for attachment ID: %1$s. No image editor supports its file type (%2$s).', 'woocommerce' ),
+ $this->attachment_id,
+ $mime_type ? $mime_type : 'unknown'
+ ),
+ array(
+ 'source' => 'wc-image-regeneration',
+ )
+ );
+ return false;
+ }
+
$old_metadata = wp_get_attachment_metadata( $this->attachment_id );
// We only want to regen WC images.
diff --git a/plugins/woocommerce/includes/class-wc-regenerate-images.php b/plugins/woocommerce/includes/class-wc-regenerate-images.php
index d6d8f325a1b..56999d57d09 100644
--- a/plugins/woocommerce/includes/class-wc-regenerate-images.php
+++ b/plugins/woocommerce/includes/class-wc-regenerate-images.php
@@ -333,7 +333,13 @@ class WC_Regenerate_Images {
* @return array|false An array of the filename, thumbnail width, and thumbnail height, or false on failure to resize such as the thumbnail being larger than the fullsize image.
*/
private static function get_image( $fullsizepath, $thumbnail_width, $thumbnail_height, $crop ) {
- list( $fullsize_width, $fullsize_height ) = getimagesize( $fullsizepath );
+ $imagesize = wp_getimagesize( $fullsizepath );
+
+ if ( false === $imagesize ) {
+ return false;
+ }
+
+ list( $fullsize_width, $fullsize_height ) = $imagesize;
$dimensions = image_resize_dimensions( $fullsize_width, $fullsize_height, $thumbnail_width, $thumbnail_height, $crop );
$editor = wp_get_image_editor( $fullsizepath );
@@ -364,7 +370,7 @@ class WC_Regenerate_Images {
* @param array $image Original Image.
* @param string $size Size to return for new URL.
* @param bool $icon If icon or not.
- * @return string
+ * @return array
*/
private static function resize_and_return_image( $attachment_id, $image, $size, $icon ) {
if ( ! self::is_regeneratable( $attachment_id ) ) {
@@ -377,6 +383,18 @@ class WC_Regenerate_Images {
return $image;
}
+ // Files without a supporting image editor (e.g. SVGs) can never be resized, so don't attempt it on every request.
+ // The file-derived mime type is checked first, since the editor loads the file and the recorded type can be stale.
+ $mime_type = wp_check_filetype( $fullsizepath )['type'];
+
+ if ( ! $mime_type ) {
+ $mime_type = get_post_mime_type( $attachment_id );
+ }
+
+ if ( ! $mime_type || ! wp_image_editor_supports( array( 'mime_type' => $mime_type ) ) ) {
+ return $image;
+ }
+
if ( ! function_exists( 'wp_crop_image' ) ) {
include ABSPATH . 'wp-admin/includes/image.php';
}
@@ -442,7 +460,7 @@ class WC_Regenerate_Images {
*
* @param int $attachment_id Attachment ID.
* @param string $size Size to downsize to.
- * @return string New image URL.
+ * @return array|false Image data array as returned by image_downsize(), or false on failure.
*/
private static function unfiltered_image_downsize( $attachment_id, $size ) {
remove_action( 'image_get_intermediate_size', array( __CLASS__, 'filter_image_get_intermediate_size' ), 10, 3 );
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 247bbfa9d31..2b490c83f76 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -14154,12 +14154,6 @@ parameters:
count: 2
path: includes/class-wc-regenerate-images.php
- -
- message: '#^Cannot use array destructuring on array\<int\|string, int\|string\>\|false\.$#'
- identifier: offsetAccess.nonArray
- count: 1
- path: includes/class-wc-regenerate-images.php
-
-
message: '#^Function remove_action invoked with 4 parameters, 2\-3 required\.$#'
identifier: arguments.count
@@ -14190,36 +14184,6 @@ parameters:
count: 1
path: includes/class-wc-regenerate-images.php
- -
- message: '#^Method WC_Regenerate_Images\:\:maybe_resize_image\(\) should return array but returns string\.$#'
- identifier: return.type
- count: 1
- path: includes/class-wc-regenerate-images.php
-
- -
- message: '#^Method WC_Regenerate_Images\:\:resize_and_return_image\(\) should return string but returns array\.$#'
- identifier: return.type
- count: 3
- path: includes/class-wc-regenerate-images.php
-
- -
- message: '#^Method WC_Regenerate_Images\:\:resize_and_return_image\(\) should return string but returns array\<int, mixed\>\.$#'
- identifier: return.type
- count: 1
- path: includes/class-wc-regenerate-images.php
-
- -
- message: '#^Method WC_Regenerate_Images\:\:resize_and_return_image\(\) should return string but returns array\|string\.$#'
- identifier: return.type
- count: 1
- path: includes/class-wc-regenerate-images.php
-
- -
- message: '#^Method WC_Regenerate_Images\:\:unfiltered_image_downsize\(\) should return string but returns list\<bool\|int\|string\>\|false\.$#'
- identifier: return.type
- count: 1
- path: includes/class-wc-regenerate-images.php
-
-
message: '#^Parameter \#1 \$str of function md5 expects string, string\|false given\.$#'
identifier: argument.type