mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-16 19:46:21 +00:00
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. Built from https://develop.svn.wordpress.org/trunk@31694 git-svn-id: http://core.svn.wordpress.org/trunk@31675 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
be24bc3a97
commit
19f1d4f402
@ -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'] );
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user