EXIF/IPTC captions should populate Caption (post_excerpt) on upload, not Description (post_content).

Make sure the caption is always set if found. Previously, if the caption was less than 80 characters, only the Title field would be set.

props beaulebens, ericlewis, bendoh, SergeyBiryukov.
fixes #22768.

git-svn-id: https://develop.svn.wordpress.org/trunk@31694 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2015-03-10 05:06:39 +00:00
parent e0f843cd81
commit 5fe8182c7f
3 changed files with 55 additions and 22 deletions

View File

@@ -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'] );
}