From ff34603e8acc5c1bfe8704e4ad6a91dffd831934 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Tue, 19 Mar 2024 16:18:07 +0100 Subject: Copy class of img elements to imported posts. This is mainly to capture the image alignment. Should probably refined a bit to _only_ capture that. We'll see later. --- import-posts.php | 5 +++-- 1 file 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( - '/([^]*>/', + '/([^]*( 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 ''; } else { - return "\"{$alt}\""; + return "\"{$alt}\"{$class}"; } }, $meta[$section], -- cgit v1.2.3