From 49d66e6ce51998471656f1c50aa09ba1c2ac9530 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Fri, 11 Oct 2024 15:07:54 -0600 Subject: [PATCH] Ensure we only update images in the classic editor if they match the old image ID --- includes/utils.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/utils.php b/includes/utils.php index 0f826ed51..e4827912f 100644 --- a/includes/utils.php +++ b/includes/utils.php @@ -1055,9 +1055,16 @@ function update_image_tag( string $content, array $media_item, int $image_id ) { $processor = new \WP_HTML_Tag_Processor( $content ); while ( $processor->next_tag( 'img' ) ) { + $classes = explode( ' ', $processor->get_attribute( 'class' ) ?? ' ' ); + + // Only process the image that matches the old ID. + if ( ! is_array( $classes ) || ! in_array( 'wp-image-' . $media_item['id'], $classes, true ) ) { + continue; + } + // Try to determine the image size from the size class WordPress adds. $image_size = 'full'; - $classes = explode( ' ', $processor->get_attribute( 'class' ) ); + $classes = explode( ' ', $processor->get_attribute( 'class' ) ?? [] ); $size_classes = array_filter( $classes, function ( $image_class ) {