<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[27862] trunk/src: Metadata for audio and video files:</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/27862">27862</a></dd>
<dt>Author</dt> <dd>wonderboymusic</dd>
<dt>Date</dt> <dd>2014-03-30 19:27:31 +0000 (Sun, 30 Mar 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>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 <a href="http://core.trac.wordpress.org/ticket/27574">#27574</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadmineditformadvancedphp">trunk/src/wp-admin/edit-form-advanced.php</a></li>
<li><a href="#trunksrcwpadminincludesmediaphp">trunk/src/wp-admin/includes/media.php</a></li>
<li><a href="#trunksrcwpadminincludesmetaboxesphp">trunk/src/wp-admin/includes/meta-boxes.php</a></li>
<li><a href="#trunksrcwpadminincludespostphp">trunk/src/wp-admin/includes/post.php</a></li>
<li><a href="#trunksrcwpincludesmediaphp">trunk/src/wp-includes/media.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadmineditformadvancedphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/edit-form-advanced.php (27861 => 27862)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/edit-form-advanced.php 2014-03-30 17:50:08 UTC (rev 27861)
+++ trunk/src/wp-admin/edit-form-advanced.php 2014-03-30 19:27:31 UTC (rev 27862)
</span><span class="lines">@@ -139,6 +139,10 @@
</span><span class="cx"> wp_enqueue_style( 'imgareaselect' );
</span><span class="cx"> add_meta_box( 'submitdiv', __('Save'), 'attachment_submit_meta_box', null, 'side', 'core' );
</span><span class="cx"> add_action( 'edit_form_after_title', 'edit_form_image_editor' );
</span><ins>+
+ if ( preg_match( '#^audio#', $post->post_mime_type ) ) {
+ add_meta_box( 'attachment-id3', __( 'Metadata' ), 'attachment_id3_data_meta_box', null, 'normal', 'core' );
+ }
</ins><span class="cx"> } else {
</span><span class="cx"> add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core', $publish_callback_args );
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunksrcwpadminincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/media.php (27861 => 27862)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/media.php 2014-03-30 17:50:08 UTC (rev 27861)
+++ trunk/src/wp-admin/includes/media.php 2014-03-30 19:27:31 UTC (rev 27862)
</span><span class="lines">@@ -2661,10 +2661,14 @@
</span><span class="cx"> </div>
</span><span class="cx"> <div class="wp_attachment_details edit-form-section">
</span><span class="cx"> <p>
</span><del>- <label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br />
</del><ins>+ <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 />
</ins><span class="cx"> <textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea>
</span><span class="cx"> </p>
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> <?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?>
</span><span class="cx"> <p>
</span><span class="cx"> <label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br />
</span><span class="lines">@@ -2683,7 +2687,10 @@
</span><span class="cx"> );
</span><span class="cx"> ?>
</span><span class="cx">
</span><del>- <label for="content"><strong><?php _e( 'Description' ); ?></strong></label>
</del><ins>+ <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>
</ins><span class="cx"> <?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?>
</span><span class="cx">
</span><span class="cx"> </div>
</span><span class="lines">@@ -2765,8 +2772,6 @@
</span><span class="cx"> */
</span><span class="cx"> $fields = apply_filters( 'media_submitbox_misc_sections', array(
</span><span class="cx"> 'mime_type' => __( 'Mime-type:' ),
</span><del>- 'year' => __( 'Year:' ),
- 'genre' => __( 'Genre:' ),
</del><span class="cx"> 'length_formatted' => __( 'Length:' ),
</span><span class="cx"> ) );
</span><span class="cx">
</span></span></pre></div>
<a id="trunksrcwpadminincludesmetaboxesphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/meta-boxes.php (27861 => 27862)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/meta-boxes.php 2014-03-30 17:50:08 UTC (rev 27861)
+++ trunk/src/wp-admin/includes/meta-boxes.php 2014-03-30 19:27:31 UTC (rev 27862)
</span><span class="lines">@@ -1057,3 +1057,28 @@
</span><span class="cx"> $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );
</span><span class="cx"> echo _wp_post_thumbnail_html( $thumbnail_id, $post->ID );
</span><span class="cx"> }
</span><ins>+
+/**
+ * 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;
+}
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunksrcwpadminincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/post.php (27861 => 27862)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/post.php 2014-03-30 17:50:08 UTC (rev 27861)
+++ trunk/src/wp-admin/includes/post.php 2014-03-30 19:27:31 UTC (rev 27862)
</span><span class="lines">@@ -237,6 +237,24 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ 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 );
+ }
+
</ins><span class="cx"> // Meta Stuff
</span><span class="cx"> if ( isset($post_data['meta']) && $post_data['meta'] ) {
</span><span class="cx"> foreach ( $post_data['meta'] as $key => $value ) {
</span></span></pre></div>
<a id="trunksrcwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/media.php (27861 => 27862)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/media.php 2014-03-30 17:50:08 UTC (rev 27861)
+++ trunk/src/wp-includes/media.php 2014-03-30 19:27:31 UTC (rev 27862)
</span><span class="lines">@@ -1018,30 +1018,26 @@
</span><span class="cx"> <# if ( data.image ) { #>
</span><span class="cx"> <img src="{{{ data.thumb.src }}}"/>
</span><span class="cx"> <# } #>
</span><del>- <# if ( data.meta.title ) { #>
</del><span class="cx"> <div class="wp-playlist-caption">
</span><del>- <span class="wp-caption-meta wp-caption-title">“{{{ data.meta.title }}}”</span>
- <span class="wp-caption-meta wp-caption-album">{{{ data.meta.album }}}</span>
- <span class="wp-caption-meta wp-caption-artist">{{{ data.meta.artist }}}</span>
</del><ins>+ <span class="wp-caption-meta wp-caption-title">“{{{ data.title }}}”</span>
+ <# if ( data.meta.album ) { #><span class="wp-caption-meta wp-caption-album">{{{ data.meta.album }}}</span><# } #>
+ <# if ( data.meta.artist ) { #><span class="wp-caption-meta wp-caption-artist">{{{ data.meta.artist }}}</span><# } #>
</ins><span class="cx"> </div>
</span><del>- <# } else { #>
- <div class="wp-playlist-caption">{{{ data.caption ? data.caption : data.title }}}</div>
- <# } #>
</del><span class="cx"> </script>
</span><span class="cx"> <script type="text/html" id="tmpl-wp-playlist-item">
</span><span class="cx"> <div class="wp-playlist-item">
</span><del>- <# if ( ( data.title || data.meta.title ) && ( ! data.artists || data.meta.artist ) ) { #>
</del><span class="cx"> <div class="wp-playlist-caption">
</span><span class="cx"> {{{ data.index ? ( data.index + '. ' ) : '' }}}
</span><del>- <span class="wp-caption-title">“{{{ data.title ? data.title : data.meta.title }}}”</span>
- <# if ( data.artists ) { #>
- <span class="wp-caption-by"><?php _e( 'by' ) ?></span>
- <span class="wp-caption-artist">{{{ data.meta.artist }}}</span>
</del><ins>+ <# if ( data.caption ) { #>
+ {{{ data.caption }}}
+ <# } else { #>
+ <span class="wp-caption-title">“{{{ data.title }}}”</span>
+ <# if ( data.artists && data.meta.artist ) { #>
+ <span class="wp-caption-by"><?php _e( 'by' ) ?></span>
+ <span class="wp-caption-artist">{{{ data.meta.artist }}}</span>
+ <# } #>
</ins><span class="cx"> <# } #>
</span><span class="cx"> </div>
</span><del>- <# } else { #>
- <div class="wp-playlist-caption">{{{ data.index ? ( data.index + '.' ) : '' }}} {{{ data.caption ? data.caption : data.title }}}</div>
- <# } #>
</del><span class="cx"> <# if ( data.meta.length_formatted ) { #>
</span><span class="cx"> <div class="wp-playlist-item-length">{{{ data.meta.length_formatted }}}</div>
</span><span class="cx"> <# } #>
</span><span class="lines">@@ -1207,8 +1203,7 @@
</span><span class="cx"> $meta = wp_get_attachment_metadata( $attachment->ID );
</span><span class="cx"> if ( ! empty( $meta ) ) {
</span><span class="cx">
</span><del>- $keys = array( 'title', 'artist', 'band', 'album', 'genre', 'year', 'length', 'length_formatted' );
- foreach ( $keys as $key ) {
</del><ins>+ foreach ( wp_get_relevant_id3_keys() as $key => $label ) {
</ins><span class="cx"> if ( ! empty( $meta[ $key ] ) ) {
</span><span class="cx"> $track['meta'][ $key ] = $meta[ $key ];
</span><span class="cx"> }
</span><span class="lines">@@ -1318,6 +1313,30 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * 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 );
+}
+/**
</ins><span class="cx"> * The Audio shortcode.
</span><span class="cx"> *
</span><span class="cx"> * This implements the functionality of the Audio Shortcode for displaying
</span><span class="lines">@@ -2312,8 +2331,7 @@
</span><span class="cx"> $response['fileLength'] = $meta['length_formatted'];
</span><span class="cx">
</span><span class="cx"> $response['meta'] = array();
</span><del>- $keys = array( 'title', 'artist', 'band', 'album', 'genre', 'year', 'length', 'length_formatted' );
- foreach ( $keys as $key ) {
</del><ins>+ foreach ( wp_get_relevant_id3_keys() as $key => $label ) {
</ins><span class="cx"> if ( ! empty( $meta[ $key ] ) ) {
</span><span class="cx"> $response['meta'][ $key ] = $meta[ $key ];
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>