diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2024-03-19 16:18:07 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2024-03-19 16:18:07 +0100 |
commit | ff34603e8acc5c1bfe8704e4ad6a91dffd831934 (patch) | |
tree | a656ab4f8b37804e92cc855c867e5889f8c99087 | |
parent | f824ab488c07eafeaf26b763dad83779a2a7581a (diff) | |
download | migrate-ff34603e8acc5c1bfe8704e4ad6a91dffd831934.tar.gz migrate-ff34603e8acc5c1bfe8704e4ad6a91dffd831934.tar.bz2 migrate-ff34603e8acc5c1bfe8704e4ad6a91dffd831934.zip |
This is mainly to capture the image alignment. Should probably refined a
bit to _only_ capture that. We'll see later.
-rw-r--r-- | import-posts.php | 5 |
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], |