WordPress.org

Make WordPress Core

Changeset 27862


Ignore:
Timestamp:
03/30/2014 07:27:31 PM (7 years ago)
Author:
wonderboymusic
Message:

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.

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit-form-advanced.php

    r27657 r27862  
    140140    add_meta_box( 'submitdiv', __('Save'), 'attachment_submit_meta_box', null, 'side', 'core' );
    141141    add_action( 'edit_form_after_title', 'edit_form_image_editor' );
     142
     143    if ( preg_match( '#^audio#', $post->post_mime_type ) ) {
     144        add_meta_box( 'attachment-id3', __( 'Metadata' ), 'attachment_id3_data_meta_box', null, 'normal', 'core' );
     145    }
    142146} else {
    143147    add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core', $publish_callback_args );
  • trunk/src/wp-admin/includes/media.php

    r27695 r27862  
    26622662    <div class="wp_attachment_details edit-form-section">
    26632663        <p>
    2664             <label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br />
     2664            <label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong><?php
     2665            if ( preg_match( '#^audio|video#', $post->post_mime_type ) ): ?>: <?php
     2666                _e( "Custom label for item in a playlist. If empty, the file's available data is used." );
     2667            endif ?></label><br />
    26652668            <textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea>
    26662669        </p>
     2670
    26672671
    26682672    <?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?>
     
    26842688    ?>
    26852689
    2686     <label for="content"><strong><?php _e( 'Description' ); ?></strong></label>
     2690    <label for="content"><strong><?php _e( 'Description' ); ?></strong><?php
     2691    if ( preg_match( '#^audio|video#', $post->post_mime_type ) ): ?>: <?php
     2692        _e( 'Displayed on attachment pages.' );
     2693    endif ?></label>
    26872694    <?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?>
    26882695
     
    27662773        $fields = apply_filters( 'media_submitbox_misc_sections', array(
    27672774            'mime_type'        => __( 'Mime-type:' ),
    2768             'year'             => __( 'Year:' ),
    2769             'genre'            => __( 'Genre:' ),
    27702775            'length_formatted' => __( 'Length:' ),
    27712776        ) );
  • trunk/src/wp-admin/includes/meta-boxes.php

    r27747 r27862  
    10581058    echo _wp_post_thumbnail_html( $thumbnail_id, $post->ID );
    10591059}
     1060
     1061/**
     1062 * Display fields for ID3 data
     1063 *
     1064 * @since 3.9.0
     1065 *
     1066 * @param WP_Post $post
     1067 */
     1068function attachment_id3_data_meta_box( $post ) {
     1069    $meta = array();
     1070    if ( ! empty( $post->ID ) ) {
     1071        $meta = wp_get_attachment_metadata( $post->ID );
     1072    }
     1073
     1074    foreach ( wp_get_relevant_id3_keys() as $key => $label ): ?>
     1075    <p>
     1076        <label for="title"><?php echo $label ?></label>
     1077        <input type="text" name="id3_<?php echo esc_attr( $key ) ?>" id="id3_<?php echo esc_attr( $key ) ?>" class="widefat" value="<?php
     1078            if ( ! empty( $meta[ $key ] ) ) {
     1079                echo esc_attr( $meta[ $key ] );
     1080            }
     1081        ?>" />
     1082    </p>
     1083    <?php endforeach;
     1084}
  • trunk/src/wp-admin/includes/post.php

    r27690 r27862  
    236236                update_post_meta( $post_ID, $keyed, wp_filter_post_kses( $post_data[ $keyed ] ) );
    237237        }
     238    }
     239
     240    if ( 'attachment' === $post_data['post_type'] && preg_match( '#^audio|video#', $post_data['post_mime_type'] ) ) {
     241        $id3data = wp_get_attachment_metadata( $post_ID );
     242        if ( ! is_array( $id3data ) ) {
     243            $id3data = array();
     244        }
     245
     246        foreach ( wp_get_relevant_id3_keys() as $key => $label ) {
     247            if ( isset( $post_data[ 'id3_' . $key ] ) ) {
     248                if ( current_user_can( 'unfiltered_html' ) ) {
     249                    $id3data[ $key ] = wp_unslash( $post_data[ 'id3_' . $key ] );
     250                } else {
     251                    $id3data[ $key ] = wp_unslash( wp_kses_post( $post_data[ 'id3_' . $key ] ) );
     252                }
     253            }
     254        }
     255        wp_update_attachment_metadata( $post_ID, $id3data );
    238256    }
    239257
  • trunk/src/wp-includes/media.php

    r27813 r27862  
    10191019    <img src="{{{ data.thumb.src }}}"/>
    10201020    <# } #>
    1021     <# if ( data.meta.title ) { #>
    10221021    <div class="wp-playlist-caption">
    1023         <span class="wp-caption-meta wp-caption-title">&#8220;{{{ data.meta.title }}}&#8221;</span>
    1024         <span class="wp-caption-meta wp-caption-album">{{{ data.meta.album }}}</span>
    1025         <span class="wp-caption-meta wp-caption-artist">{{{ data.meta.artist }}}</span>
     1022        <span class="wp-caption-meta wp-caption-title">&#8220;{{{ data.title }}}&#8221;</span>
     1023        <# if ( data.meta.album ) { #><span class="wp-caption-meta wp-caption-album">{{{ data.meta.album }}}</span><# } #>
     1024        <# if ( data.meta.artist ) { #><span class="wp-caption-meta wp-caption-artist">{{{ data.meta.artist }}}</span><# } #>
    10261025    </div>
    1027     <# } else { #>
    1028     <div class="wp-playlist-caption">{{{ data.caption ? data.caption : data.title }}}</div>
    1029     <# } #>
    10301026</script>
    10311027<script type="text/html" id="tmpl-wp-playlist-item">
    10321028    <div class="wp-playlist-item">
    1033         <# if ( ( data.title || data.meta.title ) && ( ! data.artists || data.meta.artist ) ) { #>
    10341029        <div class="wp-playlist-caption">
    10351030            {{{ data.index ? ( data.index + '.&nbsp;' ) : '' }}}
    1036             <span class="wp-caption-title">&#8220;{{{ data.title ? data.title : data.meta.title }}}&#8221;</span>
    1037             <# if ( data.artists ) { #>
    1038             <span class="wp-caption-by"><?php _e( 'by' ) ?></span>
    1039             <span class="wp-caption-artist">{{{ data.meta.artist }}}</span>
     1031            <# if ( data.caption ) { #>
     1032                {{{ data.caption }}}
     1033            <# } else { #>
     1034                <span class="wp-caption-title">&#8220;{{{ data.title }}}&#8221;</span>
     1035                <# if ( data.artists && data.meta.artist ) { #>
     1036                <span class="wp-caption-by"><?php _e( 'by' ) ?></span>
     1037                <span class="wp-caption-artist">{{{ data.meta.artist }}}</span>
     1038                <# } #>
    10401039            <# } #>
    10411040        </div>
    1042         <# } else { #>
    1043         <div class="wp-playlist-caption">{{{ data.index ? ( data.index + '.' ) : '' }}} {{{ data.caption ? data.caption : data.title }}}</div>
    1044         <# } #>
    10451041        <# if ( data.meta.length_formatted ) { #>
    10461042        <div class="wp-playlist-item-length">{{{ data.meta.length_formatted }}}</div>
     
    12081204        if ( ! empty( $meta ) ) {
    12091205
    1210             $keys = array( 'title', 'artist', 'band', 'album', 'genre', 'year', 'length', 'length_formatted' );
    1211             foreach ( $keys as $key ) {
     1206            foreach ( wp_get_relevant_id3_keys() as $key => $label ) {
    12121207                if ( ! empty( $meta[ $key ] ) ) {
    12131208                    $track['meta'][ $key ] = $meta[ $key ];
     
    13181313}
    13191314
     1315/**
     1316 * Return useful keys to use to lookup data from an attachment's stored metadata
     1317 *
     1318 * @since 3.9.0
     1319 *
     1320 * @return array
     1321 */
     1322function wp_get_relevant_id3_keys() {
     1323    $fields = array(
     1324        'artist' => __( 'Artist' ),
     1325        'album' => __( 'Album' ),
     1326        'genre' => __( 'Genre' ),
     1327        'year' => __( 'Year' ),
     1328        'length_formatted' => __( 'Formatted Length' )
     1329    );
     1330    /**
     1331     * Filter the editable list of keys to lookup data from an attachment's metadata
     1332     *
     1333     * @since 3.9.0
     1334     *
     1335     * @param array $fields
     1336     */
     1337    return apply_filters( 'wp_get_relevant_id3_keys', $fields );
     1338}
    13201339/**
    13211340 * The Audio shortcode.
     
    23132332
    23142333        $response['meta'] = array();
    2315         $keys = array( 'title', 'artist', 'band', 'album', 'genre', 'year', 'length', 'length_formatted' );
    2316         foreach ( $keys as $key ) {
     2334        foreach ( wp_get_relevant_id3_keys() as $key => $label ) {
    23172335            if ( ! empty( $meta[ $key ] ) ) {
    23182336                $response['meta'][ $key ] = $meta[ $key ];
Note: See TracChangeset for help on using the changeset viewer.