_media_states( WP_Post $post )
Parameters
- $post
-
(Required)
Source
File: wp-admin/includes/template.php
function _media_states( $post ) {
$media_states = array();
$stylesheet = get_option('stylesheet');
if ( current_theme_supports( 'custom-header') ) {
$meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true );
if ( is_random_header_image() ) {
$header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' );
if ( $meta_header == $stylesheet && in_array( $post->ID, $header_images ) ) {
$media_states[] = __( 'Header Image' );
}
} else {
$header_image = get_header_image();
// Display "Header Image" if the image was ever used as a header image
if ( ! empty( $meta_header ) && $meta_header == $stylesheet && $header_image !== wp_get_attachment_url( $post->ID ) ) {
$media_states[] = __( 'Header Image' );
}
// Display "Current Header Image" if the image is currently the header image
if ( $header_image && $header_image == wp_get_attachment_url( $post->ID ) ) {
$media_states[] = __( 'Current Header Image' );
}
}
}
if ( current_theme_supports( 'custom-background') ) {
$meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true );
if ( ! empty( $meta_background ) && $meta_background == $stylesheet ) {
$media_states[] = __( 'Background Image' );
$background_image = get_background_image();
if ( $background_image && $background_image == wp_get_attachment_url( $post->ID ) ) {
$media_states[] = __( 'Current Background Image' );
}
}
}
if ( $post->ID == get_option( 'site_icon' ) ) {
$media_states[] = __( 'Site Icon' );
}
if ( $post->ID == get_theme_mod( 'custom_logo' ) ) {
$media_states[] = __( 'Logo' );
}
/**
* Filters the default media display states for items in the Media list table.
*
* @since WP-3.2.0
* @since WP-4.8.0 Added the `$post` parameter.
*
* @param array $media_states An array of media states. Default 'Header Image',
* '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 ' — ';
foreach ( $media_states as $state ) {
++$i;
( $i == $state_count ) ? $sep = '' : $sep = ', ';
echo "<span class='post-state'>$state$sep</span>";
}
}
}