Cleanup up the display, escaping, and handling of ID3 data for media. Rename `wp_get_relevant_id3_keys()` to `wp_get_attachment_id3_keys()`.
Props nacin. See #27574. Built from https://develop.svn.wordpress.org/trunk@27869 git-svn-id: http://core.svn.wordpress.org/trunk@27700 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
98ceb17972
commit
01d2062af3
|
@ -2661,10 +2661,7 @@ 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><?php
|
<label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br />
|
||||||
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>
|
||||||
|
|
||||||
|
@ -2688,9 +2685,9 @@ function edit_form_image_editor( $post ) {
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<label for="content"><strong><?php _e( 'Description' ); ?></strong><?php
|
<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 ) ) {
|
||||||
_e( 'Displayed on attachment pages.' );
|
echo ': ' . __( 'Displayed on attachment pages.' );
|
||||||
endif ?></label>
|
} ?></label>
|
||||||
<?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?>
|
<?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -2728,10 +2725,17 @@ function attachment_submitbox_metadata() {
|
||||||
</div>
|
</div>
|
||||||
<div class="misc-pub-section misc-pub-filetype">
|
<div class="misc-pub-section misc-pub-filetype">
|
||||||
<?php _e( 'File type:' ); ?> <strong><?php
|
<?php _e( 'File type:' ); ?> <strong><?php
|
||||||
if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) )
|
if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) {
|
||||||
echo esc_html( strtoupper( $matches[1] ) );
|
echo esc_html( strtoupper( $matches[1] ) );
|
||||||
else
|
list( $mime_type ) = explode( '/', $post->post_mime_type );
|
||||||
|
if ( $mime_type !== 'image' && ! empty( $meta['mime_type'] ) ) {
|
||||||
|
if ( $meta['mime_type'] !== "$mime_type/" . strtolower( $matches[1] ) ) {
|
||||||
|
echo ' (' . $meta['mime_type'] . ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) );
|
echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) );
|
||||||
|
}
|
||||||
?></strong>
|
?></strong>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -2751,7 +2755,7 @@ function attachment_submitbox_metadata() {
|
||||||
<?php
|
<?php
|
||||||
endif;
|
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.
|
* Filter the audio and video metadata fields to be shown in the publish meta box.
|
||||||
|
@ -2761,41 +2765,35 @@ function attachment_submitbox_metadata() {
|
||||||
*
|
*
|
||||||
* @since 3.7.0
|
* @since 3.7.0
|
||||||
*
|
*
|
||||||
* @param array $fields {
|
* @param array $fields An array of the attachment metadata keys and labels.
|
||||||
* An array of the attachment metadata keys and labels.
|
|
||||||
*
|
|
||||||
* @type string $mime_type Label to be shown before the field mime_type.
|
|
||||||
* @type string $year Label to be shown before the field year.
|
|
||||||
* @type string $genre Label to be shown before the field genre.
|
|
||||||
* @type string $length_formatted Label to be shown before the field length_formatted.
|
|
||||||
* }
|
|
||||||
*/
|
*/
|
||||||
$fields = apply_filters( 'media_submitbox_misc_sections', array(
|
$fields = apply_filters( 'media_submitbox_misc_sections', array(
|
||||||
'mime_type' => __( 'Mime-type:' ),
|
|
||||||
'length_formatted' => __( 'Length:' ),
|
'length_formatted' => __( 'Length:' ),
|
||||||
|
'bitrate' => __( 'Bitrate:' ),
|
||||||
) );
|
) );
|
||||||
|
|
||||||
foreach ( $fields as $key => $label ):
|
foreach ( $fields as $key => $label ) {
|
||||||
if ( ! empty( $meta[$key] ) ) : ?>
|
if ( empty( $meta[ $key ] ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
?>
|
||||||
<div class="misc-pub-section misc-pub-mime-meta misc-pub-<?php echo sanitize_html_class( $key ); ?>">
|
<div class="misc-pub-section misc-pub-mime-meta misc-pub-<?php echo sanitize_html_class( $key ); ?>">
|
||||||
<?php echo $label ?> <strong><?php echo esc_html( $meta[$key] ); ?></strong>
|
<?php echo $label ?> <strong><?php
|
||||||
</div>
|
switch ( $key ) {
|
||||||
<?php
|
case 'bitrate' :
|
||||||
endif;
|
echo round( $meta['bitrate'] / 1000 ) . 'kb/s';
|
||||||
endforeach;
|
if ( ! empty( $meta['bitrate_mode'] ) ) {
|
||||||
|
echo ' ' . strtoupper( esc_html( $meta['bitrate_mode'] ) );
|
||||||
if ( ! empty( $meta['bitrate'] ) ) : ?>
|
}
|
||||||
<div class="misc-pub-section misc-pub-bitrate">
|
break;
|
||||||
<?php _e( 'Bitrate:' ); ?> <strong><?php
|
default:
|
||||||
echo round( $meta['bitrate'] / 1000 ), 'kb/s';
|
echo esc_html( $meta[ $key ] );
|
||||||
|
break;
|
||||||
if ( ! empty( $meta['bitrate_mode'] ) )
|
}
|
||||||
echo ' ', strtoupper( $meta['bitrate_mode'] );
|
|
||||||
|
|
||||||
?></strong>
|
?></strong>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
endif;
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the audio attachment metadata fields to be shown in the publish meta box.
|
* Filter the audio attachment metadata fields to be shown in the publish meta box.
|
||||||
|
@ -2805,28 +2803,25 @@ function attachment_submitbox_metadata() {
|
||||||
*
|
*
|
||||||
* @since 3.7.0
|
* @since 3.7.0
|
||||||
*
|
*
|
||||||
* @param array $fields {
|
* @param array $fields An array of the attachment metadata keys and labels.
|
||||||
* An array of the attachment metadata keys and labels.
|
|
||||||
*
|
|
||||||
* @type string $dataformat Label to be shown before the field dataformat.
|
|
||||||
* @type string $codec Label to be shown before the field codec.
|
|
||||||
* }
|
|
||||||
*/
|
*/
|
||||||
$audio_fields = apply_filters( 'audio_submitbox_misc_sections', array(
|
$audio_fields = apply_filters( 'audio_submitbox_misc_sections', array(
|
||||||
'dataformat' => __( 'Audio Format:' ),
|
'dataformat' => __( 'Audio Format:' ),
|
||||||
'codec' => __( 'Audio Codec:' )
|
'codec' => __( 'Audio Codec:' )
|
||||||
) );
|
) );
|
||||||
|
|
||||||
foreach ( $audio_fields as $key => $label ):
|
foreach ( $audio_fields as $key => $label ) {
|
||||||
if ( ! empty( $meta['audio'][$key] ) ) : ?>
|
if ( empty( $meta['audio'][ $key ] ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
?>
|
||||||
<div class="misc-pub-section misc-pub-audio misc-pub-<?php echo sanitize_html_class( $key ); ?>">
|
<div class="misc-pub-section misc-pub-audio misc-pub-<?php echo sanitize_html_class( $key ); ?>">
|
||||||
<?php echo $label; ?> <strong><?php echo esc_html( $meta['audio'][$key] ); ?></strong>
|
<?php echo $label; ?> <strong><?php echo esc_html( $meta['audio'][$key] ); ?></strong>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
endif;
|
}
|
||||||
endforeach;
|
|
||||||
|
|
||||||
endif;
|
}
|
||||||
|
|
||||||
if ( $media_dims ) : ?>
|
if ( $media_dims ) : ?>
|
||||||
<div class="misc-pub-section misc-pub-dimensions">
|
<div class="misc-pub-section misc-pub-dimensions">
|
||||||
|
|
|
@ -1071,14 +1071,15 @@ function attachment_id3_data_meta_box( $post ) {
|
||||||
$meta = wp_get_attachment_metadata( $post->ID );
|
$meta = wp_get_attachment_metadata( $post->ID );
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( wp_get_relevant_id3_keys( $post ) as $key => $label ): ?>
|
foreach ( wp_get_attachment_id3_keys( $post, 'edit' ) as $key => $label ) : ?>
|
||||||
<p>
|
<p>
|
||||||
<label for="title"><?php echo $label ?></label>
|
<label for="title"><?php echo $label ?></label><br />
|
||||||
<input type="text" name="id3_<?php echo esc_attr( $key ) ?>" id="id3_<?php echo esc_attr( $key ) ?>" class="widefat" value="<?php
|
<input type="text" name="id3_<?php echo esc_attr( $key ) ?>" id="id3_<?php echo esc_attr( $key ) ?>" class="large-text" value="<?php
|
||||||
if ( ! empty( $meta[ $key ] ) ) {
|
if ( ! empty( $meta[ $key ] ) ) {
|
||||||
echo esc_attr( $meta[ $key ] );
|
echo esc_attr( $meta[ $key ] );
|
||||||
}
|
}
|
||||||
?>" />
|
?>" />
|
||||||
</p>
|
</p>
|
||||||
<?php endforeach;
|
<?php
|
||||||
|
endforeach;
|
||||||
}
|
}
|
|
@ -243,7 +243,7 @@ function edit_post( $post_data = null ) {
|
||||||
$id3data = array();
|
$id3data = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( wp_get_relevant_id3_keys( $post ) as $key => $label ) {
|
foreach ( wp_get_attachment_id3_keys( $post, 'edit' ) as $key => $label ) {
|
||||||
if ( isset( $post_data[ 'id3_' . $key ] ) ) {
|
if ( isset( $post_data[ 'id3_' . $key ] ) ) {
|
||||||
$id3data[ $key ] = sanitize_text_field( wp_unslash( $post_data[ 'id3_' . $key ] ) );
|
$id3data[ $key ] = sanitize_text_field( wp_unslash( $post_data[ 'id3_' . $key ] ) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1019,7 +1019,7 @@ function wp_underscore_playlist_templates() {
|
||||||
<img src="{{ data.thumb.src }}"/>
|
<img src="{{ data.thumb.src }}"/>
|
||||||
<# } #>
|
<# } #>
|
||||||
<div class="wp-playlist-caption">
|
<div class="wp-playlist-caption">
|
||||||
<span class="wp-playlist-item-meta wp-playlist-item-title">“{{{ data.title }}}”</span>
|
<span class="wp-playlist-item-meta wp-playlist-item-title">“{{ data.title }}”</span>
|
||||||
<# if ( data.meta.album ) { #><span class="wp-playlist-item-meta wp-playlist-item-album">{{ data.meta.album }}</span><# } #>
|
<# if ( data.meta.album ) { #><span class="wp-playlist-item-meta wp-playlist-item-album">{{ data.meta.album }}</span><# } #>
|
||||||
<# if ( data.meta.artist ) { #><span class="wp-playlist-item-meta wp-playlist-item-artist">{{ data.meta.artist }}</span><# } #>
|
<# if ( data.meta.artist ) { #><span class="wp-playlist-item-meta wp-playlist-item-artist">{{ data.meta.artist }}</span><# } #>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1029,16 +1029,16 @@ function wp_underscore_playlist_templates() {
|
||||||
<div class="wp-playlist-caption">
|
<div class="wp-playlist-caption">
|
||||||
{{ data.index ? ( data.index + '. ' ) : '' }}
|
{{ data.index ? ( data.index + '. ' ) : '' }}
|
||||||
<# if ( data.caption ) { #>
|
<# if ( data.caption ) { #>
|
||||||
{{{ data.caption }}}
|
{{ data.caption }}
|
||||||
<# } else { #>
|
<# } else { #>
|
||||||
<span class="wp-playlist-item-title">“{{{ data.title }}}”</span>
|
<span class="wp-playlist-item-title">“{{ data.title }}”</span>
|
||||||
<# if ( data.artists && data.meta.artist ) { #>
|
<# if ( data.artists && data.meta.artist ) { #>
|
||||||
<span class="wp-playlist-item-artist"> — {{ data.meta.artist }}</span>
|
<span class="wp-playlist-item-artist"> — {{ data.meta.artist }}</span>
|
||||||
<# } #>
|
<# } #>
|
||||||
<# } #>
|
<# } #>
|
||||||
</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>
|
||||||
<# } #>
|
<# } #>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
@ -1202,7 +1202,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 ) ) {
|
||||||
|
|
||||||
foreach ( wp_get_relevant_id3_keys( $attachment ) as $key => $label ) {
|
foreach ( wp_get_attachment_id3_keys( $attachment ) as $key => $label ) {
|
||||||
if ( ! empty( $meta[ $key ] ) ) {
|
if ( ! empty( $meta[ $key ] ) ) {
|
||||||
$track['meta'][ $key ] = $meta[ $key ];
|
$track['meta'][ $key ] = $meta[ $key ];
|
||||||
}
|
}
|
||||||
|
@ -1312,31 +1312,35 @@ function wp_get_audio_extensions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return useful keys to use to lookup data from an attachment's stored metadata
|
* Return useful keys to use to lookup data from an attachment's stored metadata.
|
||||||
*
|
*
|
||||||
* @since 3.9.0
|
* @since 3.9.0
|
||||||
*
|
*
|
||||||
* @param WP_Post $post The post in question, provided for context.
|
* @param WP_Post $attachment The attachment in question, provided for context.
|
||||||
|
* @param string $context The context. Accepts 'edit', 'display'. Default 'display'.
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function wp_get_relevant_id3_keys( $post ) {
|
function wp_get_attachment_id3_keys( $attachment, $context = 'display' ) {
|
||||||
$fields = array(
|
$fields = array(
|
||||||
'artist' => __( 'Artist' ),
|
'artist' => __( 'Artist' ),
|
||||||
'album' => __( 'Album' ),
|
'album' => __( 'Album' ),
|
||||||
'genre' => __( 'Genre' ),
|
|
||||||
'year' => __( 'Year' ),
|
|
||||||
'length_formatted' => __( 'Formatted Length' )
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ( 'display' === $context ) {
|
||||||
|
$fields['genre'] = __( 'Genre' );
|
||||||
|
$fields['year'] = __( 'Year' );
|
||||||
|
$fields['length_formatted'] = _x( 'Length', 'video or audio' );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
* @since 3.9.0
|
||||||
*
|
*
|
||||||
* @param array $fields Key/value pairs of field keys to labels.
|
* @param array $fields Key/value pairs of field keys to labels.
|
||||||
* @param WP_Post $post Post object.
|
* @param WP_Post $attachment Attachment object.
|
||||||
*/
|
*/
|
||||||
return apply_filters( 'wp_get_relevant_id3_keys', $fields, $post );
|
return apply_filters( 'wp_get_attachment_id3_keys', $fields, $attachment, $context );
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* The Audio shortcode.
|
* The Audio shortcode.
|
||||||
|
@ -2333,7 +2337,7 @@ function wp_prepare_attachment_for_js( $attachment ) {
|
||||||
$response['fileLength'] = $meta['length_formatted'];
|
$response['fileLength'] = $meta['length_formatted'];
|
||||||
|
|
||||||
$response['meta'] = array();
|
$response['meta'] = array();
|
||||||
foreach ( wp_get_relevant_id3_keys( $attachment ) as $key => $label ) {
|
foreach ( wp_get_attachment_id3_keys( $attachment ) as $key => $label ) {
|
||||||
if ( ! empty( $meta[ $key ] ) ) {
|
if ( ! empty( $meta[ $key ] ) ) {
|
||||||
$response['meta'][ $key ] = $meta[ $key ];
|
$response['meta'][ $key ] = $meta[ $key ];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue