1. <?php
  2.  
  3. function bfa_image_size() {
  4. $meta = wp_get_attachment_metadata();
  5. echo $meta['width']. '&times;' . $meta['height'];
  6. }
  7.  
  8.  
  9. function bfa_image_meta( $args = '' ) {
  10.  
  11. $defaults = array(
  12. 'keys' => '',
  13. 'before' => '',
  14. 'after' => '',
  15. 'item_before' => '',
  16. 'item_after' => '',
  17. 'item_sep' => ' &middot; ',
  18. 'key_before' => '',
  19. 'key_after' => ': ',
  20. 'value_before' => '',
  21. 'value_after' => '',
  22. 'display_empty' => FALSE
  23. );
  24.  
  25. $r = wp_parse_args( $args, $defaults );
  26. extract( $r, EXTR_SKIP );
  27.  
  28. $meta = wp_get_attachment_metadata();
  29.  
  30. $string_array = array();
  31. $image_meta = array_keys( $meta['image_meta'] );
  32.  
  33. // All keys, alphabetically sorted, as provided by wp_get_attachment_metadata()
  34. if( $keys == '' && isset( $image_meta ) ) {
  35. $array_keys = array_keys( $meta['image_meta'] );
  36. // Only keys specificed in parameter:
  37. } else {
  38. $array_keys = array_map( 'trim', explode( ',', $keys ) );
  39. }
  40.  
  41. if ( $array_keys ) {
  42. foreach( $array_keys as $key ) {
  43.  
  44. $value = $meta['image_meta'][$key];
  45.  
  46. if( $display_empty === TRUE || ( $value != '' && $value != '0' ) ) {
  47.  
  48. if( $key == 'created_timestamp' )
  49. // Transform timestamp into readable date, based on default WP date/time settings:
  50. $value = date( get_option('date_format') . ' - ' . get_option('time_format'), $value );
  51.  
  52. // Prettify key
  53. $key = ucwords( str_replace( '_', ' ', $key ) );
  54. $key = $key == 'Iso' ? 'ISO' : $key;
  55.  
  56.  
  57. $key = str_replace(
  58. array(
  59. 'Aperture',
  60. 'Credit',
  61. 'Camera',
  62. 'Caption',
  63. 'Created Timestamp',
  64. 'Copyright',
  65. 'Focal Length',
  66. 'ISO',
  67. 'Shutter Speed',
  68. 'Title'
  69. ),
  70. array(
  71. __( 'Aperture', 'montezuma' ),
  72. __( 'Credit', 'montezuma' ),
  73. __( 'Camera', 'montezuma' ),
  74. __( 'Caption', 'montezuma' ),
  75. __( 'Timestamp', 'montezuma' ),
  76. __( 'Copyright', 'montezuma' ),
  77. __( 'Focal Length', 'montezuma' ),
  78. __( 'ISO', 'montezuma' ),
  79. __( 'Shutter Speed', 'montezuma' ),
  80. __( 'Title', 'montezuma' )
  81. ),
  82. $key
  83. );
  84.  
  85.  
  86. // Glue it together
  87. $string = $item_before
  88. . $key_before
  89. . $key
  90. . $key_after
  91. . $value_before
  92. . $value
  93. . $value_after
  94. . $item_after;
  95.  
  96. $string_array[] = $string;
  97. }
  98. }
  99. }
  100.  
  101. $final_string = '';
  102.  
  103. // Glue together with item separator
  104. if( ! empty( $string_array ) )
  105. $final_string = implode( $item_sep, $string_array );
  106.  
  107. // Wrap into parent container
  108. if( $final_string != '' )
  109. $final_string = $before . $final_string . $after;
  110.  
  111. echo $final_string;
  112. }