Media: Indicate if item is or was used as a site option in the details modal.

Props Mista-Flo, melchoyce.
Fixes #42063.

Built from https://develop.svn.wordpress.org/trunk@49223


git-svn-id: http://core.svn.wordpress.org/trunk@48985 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Helen Hou-Sandí 2020-10-20 03:14:06 +00:00
parent 6b90568840
commit edb64a3d8e
4 changed files with 51 additions and 16 deletions

View File

@ -2237,10 +2237,45 @@ function get_post_states( $post ) {
* Outputs the attachment media states as HTML.
*
* @since 3.2.0
* @since 5.6.0 Added the `$echo` parameter.
*
* @param WP_Post $post The attachment post to retrieve states for.
* @param bool $echo Optional. Whether to echo the post states as an HTML string. Default true.
* @return string Media states string.
*/
function _media_states( $post ) {
function _media_states( $post, $echo = true ) {
$media_states = get_media_states( $post );
$media_states_string = '';
if ( ! empty( $media_states ) ) {
$state_count = count( $media_states );
$i = 0;
$media_states_string .= ' — ';
foreach ( $media_states as $state ) {
$sep = ( ++$i === $state_count ) ? '' : ', ';
$media_states_string .= "<span class='post-state'>$state$sep</span>";
}
}
if ( $echo ) {
echo $media_states_string;
}
return $media_states_string;
}
/**
* Retrieves an array of media states from an attachment.
*
* @since 5.6.0
*
* @param WP_Post $post The attachment to retrieve states for.
* @return string[] Array of media state labels keyed by their state.
*/
function get_media_states( $post ) {
static $header_images;
$media_states = array();
@ -2310,20 +2345,7 @@ function _media_states( $post ) {
* 'Background Image', 'Site Icon', 'Logo'.
* @param WP_Post $post The current attachment object.
*/
$media_states = apply_filters( 'display_media_states', $media_states, $post );
if ( ! empty( $media_states ) ) {
$state_count = count( $media_states );
$i = 0;
echo ' &mdash; ';
foreach ( $media_states as $state ) {
$sep = ( ++$i === $state_count ) ? '' : ', ';
echo "<span class='post-state'>$state$sep</span>";
}
}
return apply_filters( 'display_media_states', $media_states, $post );
}
/**

View File

@ -459,6 +459,10 @@ function wp_print_media_templates() {
</div>
<# } #>
<# if ( data.mediaStates ) { #>
<div class="media-states"><strong><?php _e( 'Used as:' ); ?></strong> {{ data.mediaStates }}</div>
<# } #>
<div class="compat-meta">
<# if ( data.compat && data.compat.meta ) { #>
{{{ data.compat.meta }}}
@ -673,6 +677,10 @@ function wp_print_media_templates() {
</div>
<# } #>
<# if ( data.mediaStates ) { #>
<div class="media-states"><strong><?php _e( 'Used as:' ); ?></strong> {{ data.mediaStates }}</div>
<# } #>
<# if ( ! data.uploading && data.can.remove ) { #>
<?php if ( MEDIA_TRASH ) : ?>
<# if ( 'trash' === data.status ) { #>

View File

@ -3976,6 +3976,11 @@ function wp_prepare_attachment_for_js( $attachment ) {
$response['compat'] = get_compat_media_markup( $attachment->ID, array( 'in_modal' => true ) );
}
$media_states = get_media_states( $attachment );
if ( ! empty( $media_states ) ) {
$response['mediaStates'] = implode( ', ', $media_states );
}
/**
* Filters the attachment data prepared for JavaScript.
*

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.6-alpha-49222';
$wp_version = '5.6-alpha-49223';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.