Advertisement
mrwweb

Nonfunctional WordPress get_image_tag filter

Nov 14th, 2011
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. /**
  2.  * Filter to get caption and append image information to it.
  3.  *
  4.  * @returns text HTML content describing with media attribution
  5.  **/
  6.  
  7. add_filter('get_image_tag', 'append_media_credit', 10, 2);
  8.  
  9. function append_media_credit($html, $id) {
  10.    
  11.     $media_string = media_credit_string( $id );
  12.        
  13.     $html = $html . $media_string;
  14.    
  15.     return $html;
  16.    
  17. }
  18.  
  19. /**
  20.  * Function to lookup media creator fields and put them together.
  21.  *
  22.  * @returns an html string with creator name and license name links.
  23.  **/
  24.  
  25. function media_credit_string( $media_id ) {
  26.  
  27.     $name = get_post_meta( $media_id, 'creator_name', true );
  28.     $name_url = get_post_meta( $media_id, 'creator_url', true );
  29.     $license_name = get_post_meta( $media_id, 'license_name', true );
  30.     $license_url = get_post_meta( $media_id, 'license_url', true );
  31.    
  32.     $creator = null;
  33.     if( $name ) {
  34.         if( $name_url ) {
  35.             $creator = ' <a href="' . $name_url . '">' . $name . '</a>.';  
  36.         } else {
  37.             $creator = ' ' . $name;
  38.         }
  39.     }
  40.    
  41.     $license = null;
  42.     if( $license_name ) {
  43.         if( $license_url ) {
  44.             $license = ' <a href="' . $license_url . '">' . $license_name . '</a>.';   
  45.         } else {
  46.             $license = ' ' . $license_name;
  47.         }
  48.     }
  49.    
  50.     return '<span class="mrw-media-attr">Credit:' . $creator . $license . '</span>';
  51.  
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement