Metadata for audio and video files:

* Make attachment metadata for audio files editable by providing a metabox on the Edit Media page
* Standardize on using the attachment title everywhere
* Label the Caption and Description fields for audio and video appropriately
* Make the playlist Underscore templates more straightforward

See #27574.



git-svn-id: https://develop.svn.wordpress.org/trunk@27862 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2014-03-30 19:27:31 +00:00
parent a9d54abfed
commit 149f36ed35
5 changed files with 93 additions and 23 deletions

View File

@ -139,6 +139,10 @@ if ( 'attachment' == $post_type ) {
wp_enqueue_style( 'imgareaselect' ); wp_enqueue_style( 'imgareaselect' );
add_meta_box( 'submitdiv', __('Save'), 'attachment_submit_meta_box', null, 'side', 'core' ); add_meta_box( 'submitdiv', __('Save'), 'attachment_submit_meta_box', null, 'side', 'core' );
add_action( 'edit_form_after_title', 'edit_form_image_editor' ); add_action( 'edit_form_after_title', 'edit_form_image_editor' );
if ( preg_match( '#^audio#', $post->post_mime_type ) ) {
add_meta_box( 'attachment-id3', __( 'Metadata' ), 'attachment_id3_data_meta_box', null, 'normal', 'core' );
}
} else { } else {
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core', $publish_callback_args ); add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core', $publish_callback_args );
} }

View File

@ -2661,10 +2661,14 @@ function edit_form_image_editor( $post ) {
</div> </div>
<div class="wp_attachment_details edit-form-section"> <div class="wp_attachment_details edit-form-section">
<p> <p>
<label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br /> <label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong><?php
if ( preg_match( '#^audio|video#', $post->post_mime_type ) ): ?>: <?php
_e( "Custom label for item in a playlist. If empty, the file's available data is used." );
endif ?></label><br />
<textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea> <textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea>
</p> </p>
<?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?> <?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?>
<p> <p>
<label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br /> <label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br />
@ -2683,7 +2687,10 @@ function edit_form_image_editor( $post ) {
); );
?> ?>
<label for="content"><strong><?php _e( 'Description' ); ?></strong></label> <label for="content"><strong><?php _e( 'Description' ); ?></strong><?php
if ( preg_match( '#^audio|video#', $post->post_mime_type ) ): ?>: <?php
_e( 'Displayed on attachment pages.' );
endif ?></label>
<?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?> <?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?>
</div> </div>
@ -2765,8 +2772,6 @@ function attachment_submitbox_metadata() {
*/ */
$fields = apply_filters( 'media_submitbox_misc_sections', array( $fields = apply_filters( 'media_submitbox_misc_sections', array(
'mime_type' => __( 'Mime-type:' ), 'mime_type' => __( 'Mime-type:' ),
'year' => __( 'Year:' ),
'genre' => __( 'Genre:' ),
'length_formatted' => __( 'Length:' ), 'length_formatted' => __( 'Length:' ),
) ); ) );

View File

@ -1057,3 +1057,28 @@ function post_thumbnail_meta_box( $post ) {
$thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true ); $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );
echo _wp_post_thumbnail_html( $thumbnail_id, $post->ID ); echo _wp_post_thumbnail_html( $thumbnail_id, $post->ID );
} }
/**
* Display fields for ID3 data
*
* @since 3.9.0
*
* @param WP_Post $post
*/
function attachment_id3_data_meta_box( $post ) {
$meta = array();
if ( ! empty( $post->ID ) ) {
$meta = wp_get_attachment_metadata( $post->ID );
}
foreach ( wp_get_relevant_id3_keys() as $key => $label ): ?>
<p>
<label for="title"><?php echo $label ?></label>
<input type="text" name="id3_<?php echo esc_attr( $key ) ?>" id="id3_<?php echo esc_attr( $key ) ?>" class="widefat" value="<?php
if ( ! empty( $meta[ $key ] ) ) {
echo esc_attr( $meta[ $key ] );
}
?>" />
</p>
<?php endforeach;
}

View File

@ -237,6 +237,24 @@ function edit_post( $post_data = null ) {
} }
} }
if ( 'attachment' === $post_data['post_type'] && preg_match( '#^audio|video#', $post_data['post_mime_type'] ) ) {
$id3data = wp_get_attachment_metadata( $post_ID );
if ( ! is_array( $id3data ) ) {
$id3data = array();
}
foreach ( wp_get_relevant_id3_keys() as $key => $label ) {
if ( isset( $post_data[ 'id3_' . $key ] ) ) {
if ( current_user_can( 'unfiltered_html' ) ) {
$id3data[ $key ] = wp_unslash( $post_data[ 'id3_' . $key ] );
} else {
$id3data[ $key ] = wp_unslash( wp_kses_post( $post_data[ 'id3_' . $key ] ) );
}
}
}
wp_update_attachment_metadata( $post_ID, $id3data );
}
// Meta Stuff // Meta Stuff
if ( isset($post_data['meta']) && $post_data['meta'] ) { if ( isset($post_data['meta']) && $post_data['meta'] ) {
foreach ( $post_data['meta'] as $key => $value ) { foreach ( $post_data['meta'] as $key => $value ) {

View File

@ -1018,30 +1018,26 @@ function wp_underscore_playlist_templates() {
<# if ( data.image ) { #> <# if ( data.image ) { #>
<img src="{{{ data.thumb.src }}}"/> <img src="{{{ data.thumb.src }}}"/>
<# } #> <# } #>
<# if ( data.meta.title ) { #>
<div class="wp-playlist-caption"> <div class="wp-playlist-caption">
<span class="wp-caption-meta wp-caption-title">&#8220;{{{ data.meta.title }}}&#8221;</span> <span class="wp-caption-meta wp-caption-title">&#8220;{{{ data.title }}}&#8221;</span>
<span class="wp-caption-meta wp-caption-album">{{{ data.meta.album }}}</span> <# if ( data.meta.album ) { #><span class="wp-caption-meta wp-caption-album">{{{ data.meta.album }}}</span><# } #>
<span class="wp-caption-meta wp-caption-artist">{{{ data.meta.artist }}}</span> <# if ( data.meta.artist ) { #><span class="wp-caption-meta wp-caption-artist">{{{ data.meta.artist }}}</span><# } #>
</div> </div>
<# } else { #>
<div class="wp-playlist-caption">{{{ data.caption ? data.caption : data.title }}}</div>
<# } #>
</script> </script>
<script type="text/html" id="tmpl-wp-playlist-item"> <script type="text/html" id="tmpl-wp-playlist-item">
<div class="wp-playlist-item"> <div class="wp-playlist-item">
<# if ( ( data.title || data.meta.title ) && ( ! data.artists || data.meta.artist ) ) { #>
<div class="wp-playlist-caption"> <div class="wp-playlist-caption">
{{{ data.index ? ( data.index + '.&nbsp;' ) : '' }}} {{{ data.index ? ( data.index + '.&nbsp;' ) : '' }}}
<span class="wp-caption-title">&#8220;{{{ data.title ? data.title : data.meta.title }}}&#8221;</span> <# if ( data.caption ) { #>
<# if ( data.artists ) { #> {{{ data.caption }}}
<# } else { #>
<span class="wp-caption-title">&#8220;{{{ data.title }}}&#8221;</span>
<# if ( data.artists && data.meta.artist ) { #>
<span class="wp-caption-by"><?php _e( 'by' ) ?></span> <span class="wp-caption-by"><?php _e( 'by' ) ?></span>
<span class="wp-caption-artist">{{{ data.meta.artist }}}</span> <span class="wp-caption-artist">{{{ data.meta.artist }}}</span>
<# } #> <# } #>
</div>
<# } else { #>
<div class="wp-playlist-caption">{{{ data.index ? ( data.index + '.' ) : '' }}} {{{ data.caption ? data.caption : data.title }}}</div>
<# } #> <# } #>
</div>
<# if ( data.meta.length_formatted ) { #> <# if ( data.meta.length_formatted ) { #>
<div class="wp-playlist-item-length">{{{ data.meta.length_formatted }}}</div> <div class="wp-playlist-item-length">{{{ data.meta.length_formatted }}}</div>
<# } #> <# } #>
@ -1207,8 +1203,7 @@ function wp_playlist_shortcode( $attr ) {
$meta = wp_get_attachment_metadata( $attachment->ID ); $meta = wp_get_attachment_metadata( $attachment->ID );
if ( ! empty( $meta ) ) { if ( ! empty( $meta ) ) {
$keys = array( 'title', 'artist', 'band', 'album', 'genre', 'year', 'length', 'length_formatted' ); foreach ( wp_get_relevant_id3_keys() as $key => $label ) {
foreach ( $keys as $key ) {
if ( ! empty( $meta[ $key ] ) ) { if ( ! empty( $meta[ $key ] ) ) {
$track['meta'][ $key ] = $meta[ $key ]; $track['meta'][ $key ] = $meta[ $key ];
} }
@ -1317,6 +1312,30 @@ function wp_get_audio_extensions() {
return apply_filters( 'wp_audio_extensions', array( 'mp3', 'ogg', 'wma', 'm4a', 'wav' ) ); return apply_filters( 'wp_audio_extensions', array( 'mp3', 'ogg', 'wma', 'm4a', 'wav' ) );
} }
/**
* Return useful keys to use to lookup data from an attachment's stored metadata
*
* @since 3.9.0
*
* @return array
*/
function wp_get_relevant_id3_keys() {
$fields = array(
'artist' => __( 'Artist' ),
'album' => __( 'Album' ),
'genre' => __( 'Genre' ),
'year' => __( 'Year' ),
'length_formatted' => __( 'Formatted Length' )
);
/**
* Filter the editable list of keys to lookup data from an attachment's metadata
*
* @since 3.9.0
*
* @param array $fields
*/
return apply_filters( 'wp_get_relevant_id3_keys', $fields );
}
/** /**
* The Audio shortcode. * The Audio shortcode.
* *
@ -2312,8 +2331,7 @@ function wp_prepare_attachment_for_js( $attachment ) {
$response['fileLength'] = $meta['length_formatted']; $response['fileLength'] = $meta['length_formatted'];
$response['meta'] = array(); $response['meta'] = array();
$keys = array( 'title', 'artist', 'band', 'album', 'genre', 'year', 'length', 'length_formatted' ); foreach ( wp_get_relevant_id3_keys() as $key => $label ) {
foreach ( $keys as $key ) {
if ( ! empty( $meta[ $key ] ) ) { if ( ! empty( $meta[ $key ] ) ) {
$response['meta'][ $key ] = $meta[ $key ]; $response['meta'][ $key ] = $meta[ $key ];
} }