summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--import-posts.php5
1 files changed, 3 insertions, 2 deletions
diff --git a/import-posts.php b/import-posts.php
index 9c872c0..29fe0e8 100644
--- a/import-posts.php
+++ b/import-posts.php
@@ -140,12 +140,13 @@ function migrate_images( array $meta ) : array {
foreach ( array( 'custom_teaser', 'body' ) as $section ) {
if ( isset( $meta[$section] ) ) {
$body = preg_replace_callback(
- '/<img src="([^"]*)" title="([^"]*)" alt="([^"]*)"[^>]*>/',
+ '/<img src="([^"]*)" title="([^"]*)" alt="([^"]*)"[^>]*( class="[^"]*")[^>]*>/',
function( array $matches ) use ( $post_date, &$thumb ) {
$remote_filename = get_real_image_name( $matches[1] );
$filename = basename( $remote_filename );
$title = $matches[2];
$alt = $matches[3];
+ $class = $matches[4] ?? '';
$uploads = wp_upload_dir( $post_date->format( 'Y/m' ) );
$target_file = implode( '/', array( $uploads['path'], $filename ) );
@@ -176,7 +177,7 @@ function migrate_images( array $meta ) : array {
$thumb = $attachment_id;
return '<!-- image moved to thumbnail -->';
} else {
- return "<img src=\"{$target_url}\" title=\"{$title}\" alt=\"{$alt}\">";
+ return "<img src=\"{$target_url}\" title=\"{$title}\" alt=\"{$alt}\"{$class}>";
}
},
$meta[$section],