Cleanups for audio/video metadata, see [27862].
see #27574. Built from https://develop.svn.wordpress.org/trunk@27864 git-svn-id: http://core.svn.wordpress.org/trunk@27695 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
7eb24edf4e
commit
c95f232727
|
@ -140,7 +140,7 @@ if ( 'attachment' == $post_type ) {
|
|||
add_meta_box( 'submitdiv', __('Save'), 'attachment_submit_meta_box', null, 'side', 'core' );
|
||||
add_action( 'edit_form_after_title', 'edit_form_image_editor' );
|
||||
|
||||
if ( preg_match( '#^audio#', $post->post_mime_type ) ) {
|
||||
if ( 0 === strpos( $post->post_mime_type, 'audio/' ) ) {
|
||||
add_meta_box( 'attachment-id3', __( 'Metadata' ), 'attachment_id3_data_meta_box', null, 'normal', 'core' );
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -2662,7 +2662,7 @@ function edit_form_image_editor( $post ) {
|
|||
<div class="wp_attachment_details edit-form-section">
|
||||
<p>
|
||||
<label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong><?php
|
||||
if ( preg_match( '#^audio|video#', $post->post_mime_type ) ): ?>: <?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>
|
||||
|
@ -2688,7 +2688,7 @@ function edit_form_image_editor( $post ) {
|
|||
?>
|
||||
|
||||
<label for="content"><strong><?php _e( 'Description' ); ?></strong><?php
|
||||
if ( preg_match( '#^audio|video#', $post->post_mime_type ) ): ?>: <?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 ); ?>
|
||||
|
@ -2751,7 +2751,7 @@ function attachment_submitbox_metadata() {
|
|||
<?php
|
||||
endif;
|
||||
|
||||
if ( preg_match( '#^(audio|video)#', $post->post_mime_type ) ):
|
||||
if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ):
|
||||
|
||||
/**
|
||||
* Filter the audio and video metadata fields to be shown in the publish meta box.
|
||||
|
|
|
@ -1071,7 +1071,7 @@ function attachment_id3_data_meta_box( $post ) {
|
|||
$meta = wp_get_attachment_metadata( $post->ID );
|
||||
}
|
||||
|
||||
foreach ( wp_get_relevant_id3_keys() as $key => $label ): ?>
|
||||
foreach ( wp_get_relevant_id3_keys( $post ) 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
|
||||
|
|
|
@ -237,19 +237,15 @@ function edit_post( $post_data = null ) {
|
|||
}
|
||||
}
|
||||
|
||||
if ( 'attachment' === $post_data['post_type'] && preg_match( '#^audio|video#', $post_data['post_mime_type'] ) ) {
|
||||
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 ) {
|
||||
foreach ( wp_get_relevant_id3_keys( $post ) 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 ] ) );
|
||||
}
|
||||
$id3data[ $key ] = sanitize_post_field( wp_unslash( $post_data[ 'id3_' . $key ] ) );
|
||||
}
|
||||
}
|
||||
wp_update_attachment_metadata( $post_ID, $id3data );
|
||||
|
|
|
@ -1016,25 +1016,25 @@ function wp_underscore_playlist_templates() {
|
|||
?>
|
||||
<script type="text/html" id="tmpl-wp-playlist-current-item">
|
||||
<# if ( data.image ) { #>
|
||||
<img src="{{{ data.thumb.src }}}"/>
|
||||
<img src="{{ data.thumb.src }}"/>
|
||||
<# } #>
|
||||
<div class="wp-playlist-caption">
|
||||
<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><# } #>
|
||||
<# 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><# } #>
|
||||
</div>
|
||||
</script>
|
||||
<script type="text/html" id="tmpl-wp-playlist-item">
|
||||
<div class="wp-playlist-item">
|
||||
<div class="wp-playlist-caption">
|
||||
{{{ data.index ? ( data.index + '. ' ) : '' }}}
|
||||
{{ data.index ? ( data.index + '. ' ) : '' }}
|
||||
<# 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>
|
||||
<span class="wp-caption-artist">{{ data.meta.artist }}</span>
|
||||
<# } #>
|
||||
<# } #>
|
||||
</div>
|
||||
|
@ -1203,7 +1203,7 @@ function wp_playlist_shortcode( $attr ) {
|
|||
$meta = wp_get_attachment_metadata( $attachment->ID );
|
||||
if ( ! empty( $meta ) ) {
|
||||
|
||||
foreach ( wp_get_relevant_id3_keys() as $key => $label ) {
|
||||
foreach ( wp_get_relevant_id3_keys( $attachment ) as $key => $label ) {
|
||||
if ( ! empty( $meta[ $key ] ) ) {
|
||||
$track['meta'][ $key ] = $meta[ $key ];
|
||||
}
|
||||
|
@ -1317,9 +1317,10 @@ function wp_get_audio_extensions() {
|
|||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param WP_Post $post The post in question, provided for context.
|
||||
* @return array
|
||||
*/
|
||||
function wp_get_relevant_id3_keys() {
|
||||
function wp_get_relevant_id3_keys( $post ) {
|
||||
$fields = array(
|
||||
'artist' => __( 'Artist' ),
|
||||
'album' => __( 'Album' ),
|
||||
|
@ -1327,14 +1328,16 @@ function wp_get_relevant_id3_keys() {
|
|||
'year' => __( 'Year' ),
|
||||
'length_formatted' => __( 'Formatted Length' )
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter the editable list of keys to lookup data from an attachment's metadata
|
||||
* Filter the editable list of keys to lookup data from an attachment's metadata.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param array $fields
|
||||
* @param array $fields Key/value pairs of field keys to labels.
|
||||
* @param WP_Post $post Post object.
|
||||
*/
|
||||
return apply_filters( 'wp_get_relevant_id3_keys', $fields );
|
||||
return apply_filters( 'wp_get_relevant_id3_keys', $fields, $post );
|
||||
}
|
||||
/**
|
||||
* The Audio shortcode.
|
||||
|
@ -2331,7 +2334,7 @@ function wp_prepare_attachment_for_js( $attachment ) {
|
|||
$response['fileLength'] = $meta['length_formatted'];
|
||||
|
||||
$response['meta'] = array();
|
||||
foreach ( wp_get_relevant_id3_keys() as $key => $label ) {
|
||||
foreach ( wp_get_relevant_id3_keys( $attachment ) as $key => $label ) {
|
||||
if ( ! empty( $meta[ $key ] ) ) {
|
||||
$response['meta'][ $key ] = $meta[ $key ];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue