From f328cfbf318e685fc2ac6beac71a1111bfa4aa05 Mon Sep 17 00:00:00 2001 From: ronchambers Date: Wed, 24 Apr 2024 19:05:07 -0700 Subject: [PATCH] Media Credit Plugin Migrator: Fix: remove line breaks from captions --- src/Command/General/MediaCreditPluginMigrator.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Command/General/MediaCreditPluginMigrator.php b/src/Command/General/MediaCreditPluginMigrator.php index ddde0c21..2304aa41 100644 --- a/src/Command/General/MediaCreditPluginMigrator.php +++ b/src/Command/General/MediaCreditPluginMigrator.php @@ -280,10 +280,10 @@ private function process_post_content( $post_id, $post_content ) { $new_shortcode_string .= ']'; - $new_shortcode_string .= $shortcode_match[5]; + $new_shortcode_string .= trim( $shortcode_match[5] ); if ( ! empty( $media_credit_info[0] ) ) { - $new_shortcode_string .= esc_html( $media_credit_info[0] ); + $new_shortcode_string .= ' ' . esc_html( trim( $media_credit_info[0] ) ); } $new_shortcode_string .= '[/caption]'; @@ -351,14 +351,19 @@ private function process_caption_shortcode_match( $post_id, $shortcode_match ) { ); } + $updated_shortcode = $shortcode_match[0]; + + // Remove media credit preceeding line break if exists. + $updated_shortcode = preg_replace( '/\]\s+\[media-credit/i', '][media-credit', $updated_shortcode ); + // Remove media credit shortcode. - $updated_shortcode = str_replace( $media_credit_shortcode_matches[0][0], $media_credit_shortcode_matches[0][5], $shortcode_match[0] ); + $updated_shortcode = str_replace( $media_credit_shortcode_matches[0][0], trim( $media_credit_shortcode_matches[0][5] ), $updated_shortcode ); // Add credit into caption if needed. $media_credit_info = $this->process_media_credit_shortcode( $post_id, $media_credit_shortcode_matches[0] ); if ( ! empty( $media_credit_info ) && is_array( $media_credit_info ) && ! empty( $media_credit_info[0] ) ) { - $updated_shortcode = str_replace( '[/caption]', ' (Credit: ' . esc_html( $media_credit_info[0] ) . ')[/caption]', $updated_shortcode ); + $updated_shortcode = str_replace( '[/caption]', ' (Credit: ' . esc_html( trim( $media_credit_info[0] ) ) . ')[/caption]', $updated_shortcode ); } return $updated_shortcode;