Skip to content

Commit

Permalink
Ensure we only update images in the classic editor if they match the …
Browse files Browse the repository at this point in the history
…old image ID
  • Loading branch information
dkotter committed Oct 11, 2024
1 parent 3e39ff2 commit 49d66e6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion includes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down

0 comments on commit 49d66e6

Please sign in to comment.