diff --git a/wp-admin/includes/image.php b/wp-admin/includes/image.php index 9171247d2f..355a63d737 100644 --- a/wp-admin/includes/image.php +++ b/wp-admin/includes/image.php @@ -299,20 +299,17 @@ function wp_read_image_metadata( $file ) { if ( ! empty( $iptc['2#120'][0] ) ) { // description / legacy caption $caption = trim( $iptc['2#120'][0] ); - if ( empty( $meta['title'] ) ) { - mbstring_binary_safe_encoding(); - $caption_length = strlen( $caption ); - reset_mbstring_encoding(); + mbstring_binary_safe_encoding(); + $caption_length = strlen( $caption ); + reset_mbstring_encoding(); + + if ( empty( $meta['title'] ) && $caption_length < 80 ) { // Assume the title is stored in 2:120 if it's short. - if ( $caption_length < 80 ) { - $meta['title'] = $caption; - } else { - $meta['caption'] = $caption; - } - } elseif ( $caption != $meta['title'] ) { - $meta['caption'] = $caption; + $meta['title'] = $caption; } + + $meta['caption'] = $caption; } if ( ! empty( $iptc['2#110'][0] ) ) // credit @@ -346,13 +343,16 @@ function wp_read_image_metadata( $file ) { if ( empty( $meta['title'] ) && $description_length < 80 ) { // Assume the title is stored in ImageDescription $meta['title'] = trim( $exif['ImageDescription'] ); - if ( empty( $meta['caption'] ) && ! empty( $exif['COMPUTED']['UserComment'] ) && trim( $exif['COMPUTED']['UserComment'] ) != $meta['title'] ) { - $meta['caption'] = trim( $exif['COMPUTED']['UserComment'] ); - } - } elseif ( empty( $meta['caption'] ) && trim( $exif['ImageDescription'] ) != $meta['title'] ) { + } + + if ( empty( $meta['caption'] ) && ! empty( $exif['COMPUTED']['UserComment'] ) ) { + $meta['caption'] = trim( $exif['COMPUTED']['UserComment'] ); + } + + if ( empty( $meta['caption'] ) ) { $meta['caption'] = trim( $exif['ImageDescription'] ); } - } elseif ( empty( $meta['caption'] ) && ! empty( $exif['Comments'] ) && trim( $exif['Comments'] ) != $meta['title'] ) { + } elseif ( empty( $meta['caption'] ) && ! empty( $exif['Comments'] ) ) { $meta['caption'] = trim( $exif['Comments'] ); } diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 5f6d08c7ab..2b3196c008 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -280,14 +280,14 @@ function media_handle_upload($file_id, $post_id, $post_data = array(), $override $file = $file['file']; $title = $name; $content = ''; + $excerpt = ''; if ( preg_match( '#^audio#', $type ) ) { $meta = wp_read_audio_metadata( $file ); - if ( ! empty( $meta['title'] ) ) + if ( ! empty( $meta['title'] ) ) { $title = $meta['title']; - - $content = ''; + } if ( ! empty( $title ) ) { @@ -335,10 +335,13 @@ function media_handle_upload($file_id, $post_id, $post_data = array(), $override // Use image exif/iptc data for title and caption defaults if possible. } elseif ( 0 === strpos( $type, 'image/' ) && $image_meta = @wp_read_image_metadata( $file ) ) { - if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) + if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) { $title = $image_meta['title']; - if ( trim( $image_meta['caption'] ) ) - $content = $image_meta['caption']; + } + + if ( trim( $image_meta['caption'] ) ) { + $excerpt = $image_meta['caption']; + } } // Construct the attachment array @@ -348,6 +351,7 @@ function media_handle_upload($file_id, $post_id, $post_data = array(), $override 'post_parent' => $post_id, 'post_title' => $title, 'post_content' => $content, + 'post_excerpt' => $excerpt, ), $post_data ); // This should never be set as it would then overwrite an existing attachment. diff --git a/wp-includes/version.php b/wp-includes/version.php index 546c2d9d2a..fcb4e2e7ad 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31693'; +$wp_version = '4.2-alpha-31694'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.