Advertisement
Guest User

Untitled

a guest
Dec 26th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  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.  
  32. // All keys, alphabetically sorted, as provided by wp_get_attachment_metadata()
  33. if( $keys == '' ) {
  34. $array_keys = array_keys( $meta['image_meta'] );
  35. // Only keys specificed in parameter:
  36. } else {
  37. $array_keys = array_map( 'trim', explode( ',', $keys ) );
  38. }
  39.  
  40. if ( is_array( $array_keys ) ) {
  41. foreach( $array_keys as $key ) {
  42.  
  43. $value = $meta['image_meta'][$key];
  44.  
  45. if( $display_empty === TRUE || ( $value != '' && $value != '0' ) ) {
  46.  
  47. if( $key == 'created_timestamp' )
  48. // Transform timestamp into readable date, based on default WP date/time settings:
  49. $value = date( get_option('date_format') . ' - ' . get_option('time_format'), $value );
  50.  
  51. // Prettify key
  52. $key = ucwords( str_replace( '_', ' ', $key ) );
  53. $key = $key == 'Iso' ? 'ISO' : $key;
  54.  
  55.  
  56. $key = str_replace(
  57. array(
  58. 'Aperture',
  59. 'Credit',
  60. 'Camera',
  61. 'Caption',
  62. 'Created Timestamp',
  63. 'Copyright',
  64. 'Focal Length',
  65. 'ISO',
  66. 'Shutter Speed',
  67. 'Title'
  68. ),
  69. array(
  70. __( 'Aperture', 'montezuma' ),
  71. __( 'Credit', 'montezuma' ),
  72. __( 'Camera', 'montezuma' ),
  73. __( 'Caption', 'montezuma' ),
  74. __( 'Timestamp', 'montezuma' ),
  75. __( 'Copyright', 'montezuma' ),
  76. __( 'Focal Length', 'montezuma' ),
  77. __( 'ISO', 'montezuma' ),
  78. __( 'Shutter Speed', 'montezuma' ),
  79. __( 'Title', 'montezuma' )
  80. ),
  81. $key
  82. );
  83.  
  84.  
  85. // Glue it together
  86. $string = $item_before
  87. . $key_before
  88. . $key
  89. . $key_after
  90. . $value_before
  91. . $value
  92. . $value_after
  93. . $item_after;
  94.  
  95. $string_array[] = $string;
  96. }
  97. }
  98. }
  99.  
  100. $final_string = '';
  101.  
  102. // Glue together with item separator
  103. if( ! empty( $string_array ) )
  104. $final_string = implode( $item_sep, $string_array );
  105.  
  106. // Wrap into parent container
  107. if( $final_string != '' )
  108. $final_string = $before . $final_string . $after;
  109.  
  110. echo $final_string;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement