diff --git a/src/wp-admin/includes/template.php b/src/wp-admin/includes/template.php
index ad87a89521..e7dfb3bd83 100644
a
|
b
|
function get_post_states( $post ) { |
2234 | 2234 | * Outputs the attachment media states as HTML. |
2235 | 2235 | * |
2236 | 2236 | * @since 3.2.0 |
| 2237 | * @since 5.6.0 Added the `$echo` parameter. |
2237 | 2238 | * |
2238 | 2239 | * @param WP_Post $post The attachment post to retrieve states for. |
| 2240 | * @param bool $echo Optional. Whether to echo the post states as an HTML string. Default true. |
| 2241 | * @return string Media states string. |
2239 | 2242 | */ |
2240 | | function _media_states( $post ) { |
| 2243 | function _media_states( $post, $echo = true ) { |
| 2244 | $media_states = get_media_states( $post ); |
| 2245 | $media_states_string = ''; |
| 2246 | |
| 2247 | if ( ! empty( $media_states ) ) { |
| 2248 | $state_count = count( $media_states ); |
| 2249 | $i = 0; |
| 2250 | |
| 2251 | $media_states_string .= ' — '; |
| 2252 | |
| 2253 | foreach ( $media_states as $state ) { |
| 2254 | $sep = ( ++$i === $state_count ) ? '' : ', '; |
| 2255 | |
| 2256 | $media_states_string .= "<span class='post-state'>$state$sep</span>"; |
| 2257 | } |
| 2258 | } |
| 2259 | |
| 2260 | if ( $echo ) { |
| 2261 | echo $media_states_string; |
| 2262 | } |
| 2263 | |
| 2264 | return $media_states_string; |
| 2265 | } |
| 2266 | |
| 2267 | /** |
| 2268 | * Retrieves an array of media states from an attachment. |
| 2269 | * |
| 2270 | * @since 5.6.0 |
| 2271 | * |
| 2272 | * @param WP_Post $post The attachment to retrieve states for. |
| 2273 | * @return string[] Array of media state labels keyed by their state. |
| 2274 | */ |
| 2275 | function get_media_states( $post ) { |
2241 | 2276 | static $header_images; |
2242 | 2277 | |
2243 | 2278 | $media_states = array(); |
… |
… |
function _media_states( $post ) { |
2300 | 2335 | * 'Background Image', 'Site Icon', 'Logo'. |
2301 | 2336 | * @param WP_Post $post The current attachment object. |
2302 | 2337 | */ |
2303 | | $media_states = apply_filters( 'display_media_states', $media_states, $post ); |
2304 | | |
2305 | | if ( ! empty( $media_states ) ) { |
2306 | | $state_count = count( $media_states ); |
2307 | | $i = 0; |
2308 | | |
2309 | | echo ' — '; |
2310 | | |
2311 | | foreach ( $media_states as $state ) { |
2312 | | $sep = ( ++$i === $state_count ) ? '' : ', '; |
2313 | | |
2314 | | echo "<span class='post-state'>$state$sep</span>"; |
2315 | | } |
2316 | | } |
| 2338 | return apply_filters( 'display_media_states', $media_states, $post ); |
2317 | 2339 | } |
2318 | 2340 | |
2319 | 2341 | /** |
diff --git a/src/wp-includes/media-template.php b/src/wp-includes/media-template.php
index 0a07b5619f..adeecc1de6 100644
a
|
b
|
function wp_print_media_templates() { |
442 | 442 | </div> |
443 | 443 | <# } #> |
444 | 444 | |
| 445 | <# if ( data.mediaStates ) { #> |
| 446 | <div class="media-states"><strong><?php _e( 'Current state:' ); ?></strong> {{ data.mediaStates }}</div> |
| 447 | <# } #> |
| 448 | |
445 | 449 | <div class="compat-meta"> |
446 | 450 | <# if ( data.compat && data.compat.meta ) { #> |
447 | 451 | {{{ data.compat.meta }}} |
… |
… |
function wp_print_media_templates() { |
636 | 640 | </div> |
637 | 641 | <# } #> |
638 | 642 | |
| 643 | <# if ( data.mediaStates ) { #> |
| 644 | <div class="media-states"><strong><?php _e( 'Current state:' ); ?></strong> {{ data.mediaStates }}</div> |
| 645 | <# } #> |
| 646 | |
639 | 647 | <# if ( ! data.uploading && data.can.remove ) { #> |
640 | 648 | <?php if ( MEDIA_TRASH ) : ?> |
641 | 649 | <# if ( 'trash' === data.status ) { #> |
diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
index e1091b9d8e..01785da47f 100644
a
|
b
|
function wp_prepare_attachment_for_js( $attachment ) { |
3982 | 3982 | $response['compat'] = get_compat_media_markup( $attachment->ID, array( 'in_modal' => true ) ); |
3983 | 3983 | } |
3984 | 3984 | |
| 3985 | $media_states = get_media_states( $attachment ); |
| 3986 | if ( ! empty( $media_states ) ) { |
| 3987 | $response['mediaStates'] = implode( ', ', $media_states ); |
| 3988 | } |
| 3989 | |
3985 | 3990 | /** |
3986 | 3991 | * Filters the attachment data prepared for JavaScript. |
3987 | 3992 | * |