summaryrefslogtreecommitdiffstats
path: root/import-posts.php
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2024-03-19 16:18:07 +0100
committerHarald Eilertsen <haraldei@anduin.net>2024-03-19 16:18:07 +0100
commitff34603e8acc5c1bfe8704e4ad6a91dffd831934 (patch)
treea656ab4f8b37804e92cc855c867e5889f8c99087 /import-posts.php
parentf824ab488c07eafeaf26b763dad83779a2a7581a (diff)
downloadmigrate-ff34603e8acc5c1bfe8704e4ad6a91dffd831934.tar.gz
migrate-ff34603e8acc5c1bfe8704e4ad6a91dffd831934.tar.bz2
migrate-ff34603e8acc5c1bfe8704e4ad6a91dffd831934.zip
Copy class of img elements to imported posts.HEADdev
This is mainly to capture the image alignment. Should probably refined a bit to _only_ capture that. We'll see later.
Diffstat (limited to 'import-posts.php')
-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],