attachment_submitbox_metadata

Displays non-editable attachment metadata in the publish meta box.

Description

attachment_submitbox_metadata(); 

Usage

  1. if ( !function_exists( 'attachment_submitbox_metadata' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/media.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = attachment_submitbox_metadata(); 
  7.  

Defined (1)

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

/wp-admin/includes/media.php  
  1. function attachment_submitbox_metadata() { 
  2. $post = get_post(); 
  3.  
  4. $file = get_attached_file( $post->ID ); 
  5. $filename = esc_html( wp_basename( $file ) ); 
  6.  
  7. $media_dims = ''; 
  8. $meta = wp_get_attachment_metadata( $post->ID ); 
  9. if ( isset( $meta['width'], $meta['height'] ) ) 
  10. $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> "; 
  11. /** This filter is documented in wp-admin/includes/media.php */ 
  12. $media_dims = apply_filters( 'media_meta', $media_dims, $post ); 
  13.  
  14. $att_url = wp_get_attachment_url( $post->ID ); 
  15. ?> 
  16. <div class="misc-pub-section misc-pub-attachment"> 
  17. <label for="attachment_url"><?php _e( 'File URL:' ); ?></label> 
  18. <input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" id="attachment_url" value="<?php echo esc_attr( $att_url ); ?>" /> 
  19. </div> 
  20. <div class="misc-pub-section misc-pub-filename"> 
  21. <?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong> 
  22. </div> 
  23. <div class="misc-pub-section misc-pub-filetype"> 
  24. <?php _e( 'File type:' ); ?> <strong><?php 
  25. if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) { 
  26. echo esc_html( strtoupper( $matches[1] ) ); 
  27. list( $mime_type ) = explode( '/', $post->post_mime_type ); 
  28. if ( $mime_type !== 'image' && ! empty( $meta['mime_type'] ) ) { 
  29. if ( $meta['mime_type'] !== "$mime_type/" . strtolower( $matches[1] ) ) { 
  30. echo ' (' . $meta['mime_type'] . ')'; 
  31. } else { 
  32. echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) ); 
  33. ?></strong> 
  34. </div> 
  35.  
  36. <?php 
  37. $file_size = false; 
  38.  
  39. if ( isset( $meta['filesize'] ) ) 
  40. $file_size = $meta['filesize']; 
  41. elseif ( file_exists( $file ) ) 
  42. $file_size = filesize( $file ); 
  43.  
  44. if ( ! empty( $file_size ) ) : ?> 
  45. <div class="misc-pub-section misc-pub-filesize"> 
  46. <?php _e( 'File size:' ); ?> <strong><?php echo size_format( $file_size ); ?></strong> 
  47. </div> 
  48. <?php 
  49. endif; 
  50.  
  51. if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) { 
  52.  
  53. /** 
  54. * Filters the audio and video metadata fields to be shown in the publish meta box. 
  55. * The key for each item in the array should correspond to an attachment 
  56. * metadata key, and the value should be the desired label. 
  57. * @since 3.7.0 
  58. * @param array $fields An array of the attachment metadata keys and labels. 
  59. */ 
  60. 'length_formatted' => __( 'Length:' ),  
  61. 'bitrate' => __( 'Bitrate:' ),  
  62. ) ); 
  63.  
  64. foreach ( $fields as $key => $label ) { 
  65. if ( empty( $meta[ $key ] ) ) { 
  66. continue; 
  67. ?> 
  68. <div class="misc-pub-section misc-pub-mime-meta misc-pub-<?php echo sanitize_html_class( $key ); ?>"> 
  69. <?php echo $label ?> <strong><?php 
  70. switch ( $key ) { 
  71. case 'bitrate' : 
  72. echo round( $meta['bitrate'] / 1000 ) . 'kb/s'; 
  73. if ( ! empty( $meta['bitrate_mode'] ) ) { 
  74. echo ' ' . strtoupper( esc_html( $meta['bitrate_mode'] ) ); 
  75. break; 
  76. default: 
  77. echo esc_html( $meta[ $key ] ); 
  78. break; 
  79. ?></strong> 
  80. </div> 
  81. <?php 
  82.  
  83. /** 
  84. * Filters the audio attachment metadata fields to be shown in the publish meta box. 
  85. * The key for each item in the array should correspond to an attachment 
  86. * metadata key, and the value should be the desired label. 
  87. * @since 3.7.0 
  88. * @param array $fields An array of the attachment metadata keys and labels. 
  89. */ 
  90. 'dataformat' => __( 'Audio Format:' ),  
  91. 'codec' => __( 'Audio Codec:' ) 
  92. ) ); 
  93.  
  94. foreach ( $audio_fields as $key => $label ) { 
  95. if ( empty( $meta['audio'][ $key ] ) ) { 
  96. continue; 
  97. ?> 
  98. <div class="misc-pub-section misc-pub-audio misc-pub-<?php echo sanitize_html_class( $key ); ?>"> 
  99. <?php echo $label; ?> <strong><?php echo esc_html( $meta['audio'][$key] ); ?></strong> 
  100. </div> 
  101. <?php 
  102.  
  103.  
  104. if ( $media_dims ) : ?> 
  105. <div class="misc-pub-section misc-pub-dimensions"> 
  106. <?php _e( 'Dimensions:' ); ?> <strong><?php echo $media_dims; ?></strong> 
  107. </div> 
  108. <?php 
  109. endif;