WordPress / wordpress-importer

The WordPress Importer
https://wordpress.org/plugins/wordpress-importer/
GNU General Public License v2.0
78 stars 76 forks source link

Newly imported images have the incorrect id in the class attribute #129

Open mukeshpanchal27 opened 2 years ago

mukeshpanchal27 commented 2 years ago

Actually, this issue arises in the performance repo #339.

If we import unit test data from https://codex.wordpress.org/Theme_Unit_Test into any existing site, the actual image is different from the image tag class id wp-image-%image_ID.

For example, If we have an attachment id 10 for an image but when we import the unit test that image will get the last database insert id called 100. In this case, the image class still shows class="wp-image-10" instead of class="wp-image-100".

WP Import changes the image URL in https://github.com/WordPress/wordpress-importer/blob/master/src/class-wp-import.php#L1269-L1280 function with an update query.

$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, %s, %s)", $from_url, $to_url ) );

It should be fixed so others can use the accurate image id from the class for newly imported attachments.