From 7d187854978a0712652e0229e94a365afba96f17 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Wed, 8 Apr 2015 17:10:53 +0000 Subject: [PATCH] Don't allow whitespace-only image captions from the Media modal. Captions containing only whitespace trick `image_add_caption()` into thinking a caption is required, but the empty caption text confuses wpeditimage into stripping the 'align' class specified by the user. Fixes #21848. git-svn-id: https://develop.svn.wordpress.org/trunk@32079 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/ajax-actions.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 7a01af9657..2c287e1589 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -2445,7 +2445,13 @@ function wp_ajax_send_attachment_to_editor() { $align = isset( $attachment['align'] ) ? $attachment['align'] : 'none'; $size = isset( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium'; $alt = isset( $attachment['image_alt'] ) ? $attachment['image_alt'] : ''; + + // No whitespace-only captions. $caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : ''; + if ( '' === trim( $caption ) ) { + $caption = ''; + } + $title = ''; // We no longer insert title tags into tags, as they are redundant. $html = get_image_send_to_editor( $id, $caption, $title, $align, $url, (bool) $rel, $size, $alt ); } elseif ( wp_attachment_is( 'video', $post ) || wp_attachment_is( 'audio', $post ) ) {