_media_states

The WordPress Core media states function.

Description

_media_states( (WP_Post) $post ); 

Parameters (1)

0. $post (WP_Post)
The post.

Usage

  1. if ( !function_exists( '_media_states' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/template.php'; 
  3.  
  4. // The post. 
  5. $post = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = _media_states($post); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/template.php  
  1. function _media_states( $post ) { 
  2. $media_states = array(); 
  3. $stylesheet = get_option('stylesheet'); 
  4.  
  5. if ( current_theme_supports( 'custom-header') ) { 
  6. $meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true ); 
  7.  
  8. $header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' ); 
  9.  
  10. if ( $meta_header == $stylesheet && in_array( $post->ID, $header_images ) ) { 
  11. $media_states[] = __( 'Header Image' ); 
  12. } else { 
  13. $header_image = get_header_image(); 
  14.  
  15. // Display "Header Image" if the image was ever used as a header image 
  16. if ( ! empty( $meta_header ) && $meta_header == $stylesheet && $header_image !== wp_get_attachment_url( $post->ID ) ) { 
  17. $media_states[] = __( 'Header Image' ); 
  18.  
  19. // Display "Current Header Image" if the image is currently the header image 
  20. if ( $header_image && $header_image == wp_get_attachment_url( $post->ID ) ) { 
  21. $media_states[] = __( 'Current Header Image' ); 
  22.  
  23. if ( current_theme_supports( 'custom-background') ) { 
  24. $meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true ); 
  25.  
  26. if ( ! empty( $meta_background ) && $meta_background == $stylesheet ) { 
  27. $media_states[] = __( 'Background Image' ); 
  28.  
  29. $background_image = get_background_image(); 
  30. if ( $background_image && $background_image == wp_get_attachment_url( $post->ID ) ) { 
  31. $media_states[] = __( 'Current Background Image' ); 
  32.  
  33. if ( $post->ID == get_option( 'site_icon' ) ) { 
  34. $media_states[] = __( 'Site Icon' ); 
  35.  
  36. if ( $post->ID == get_theme_mod( 'site_logo' ) ) { 
  37. $media_states[] = __( 'Logo' ); 
  38.  
  39. /** 
  40. * Filters the default media display states for items in the Media list table. 
  41. * @since 3.2.0 
  42. * @param array $media_states An array of media states. Default 'Header Image',  
  43. * 'Background Image', 'Site Icon', 'Logo'. 
  44. */ 
  45. $media_states = apply_filters( 'display_media_states', $media_states ); 
  46.  
  47. if ( ! empty( $media_states ) ) { 
  48. $state_count = count( $media_states ); 
  49. $i = 0; 
  50. echo ' — '; 
  51. foreach ( $media_states as $state ) { 
  52. ++$i; 
  53. ( $i == $state_count ) ? $sep = '' : $sep = ', '; 
  54. echo "<span class='post-state'>$state$sep</span>";