Commit 98cac13c69b for woocommerce
commit 98cac13c69b1c75122fdb21661b5be74b1a7ea84
Author: Tung Du <dinhtungdu@gmail.com>
Date: Tue Aug 25 21:24:28 2026 +0700
Fix: Prevent regenerating a non-existent image size (#68008)
* fix: prevent regenerate image size that doesn't exists
* fix: guard image size type before registration check
* chore: add changelog for image metadata fix
* chore: remove resolved PHPStan baseline entry
diff --git a/plugins/woocommerce/changelog/60577-featured-image-metadata-loss b/plugins/woocommerce/changelog/60577-featured-image-metadata-loss
new file mode 100644
index 00000000000..8721ecf15c9
--- /dev/null
+++ b/plugins/woocommerce/changelog/60577-featured-image-metadata-loss
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Prevent featured image metadata loss when a WooCommerce image size is not registered.
diff --git a/plugins/woocommerce/includes/class-wc-regenerate-images.php b/plugins/woocommerce/includes/class-wc-regenerate-images.php
index 56999d57d09..fdfd39b39b3 100644
--- a/plugins/woocommerce/includes/class-wc-regenerate-images.php
+++ b/plugins/woocommerce/includes/class-wc-regenerate-images.php
@@ -219,6 +219,10 @@ class WC_Regenerate_Images {
return $image;
}
+ if ( ! is_string( $size ) || ! has_image_size( $size ) ) {
+ return $image;
+ }
+
$target_size = wc_get_image_size( $size );
$image_width = $image[1];
$image_height = $image[2];
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 09a27a50971..4c23b8cd9db 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -14166,12 +14166,6 @@ parameters:
count: 1
path: includes/class-wc-regenerate-images.php
- -
- message: '#^Parameter \#3 \$size of static method WC_Regenerate_Images\:\:resize_and_return_image\(\) expects string, array\|string given\.$#'
- identifier: argument.type
- count: 1
- path: includes/class-wc-regenerate-images.php
-
-
message: '#^Access to an undefined property WC_Register_WP_Admin_Settings\:\:\$description\.$#'
identifier: property.notFound