Skip to content

Commit

Permalink
Media Credit Plugin Migrator: Fix: remove line breaks from captions
Browse files Browse the repository at this point in the history
  • Loading branch information
ronchambers committed Apr 25, 2024
1 parent f32717c commit f328cfb
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Command/General/MediaCreditPluginMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]';
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f328cfb

Please sign in to comment.