jfb_wp_avatar

The WP-FB-AutoConnect jfb wp avatar function.

Description

jfb_wp_avatar( $avatar, $id_or_email, $size, $default, $alt ); 

Parameters (5)

0. $avatar
The avatar.
1. $id_or_email
The id or email.
2. $size
The size.
3. $default
The default.
4. $alt
The alt.

Usage

  1. if ( !function_exists( 'jfb_wp_avatar' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'wp-fb-autoconnect/Main.php'; 
  3.  
  4. // The avatar. 
  5. $avatar = null; 
  6.  
  7. // The id or email. 
  8. $id_or_email = null; 
  9.  
  10. // The size. 
  11. $size = null; 
  12.  
  13. // The default. 
  14. $default = null; 
  15.  
  16. // The alt. 
  17. $alt = null; 
  18.  
  19. // NOTICE! Understand what this does before running. 
  20. $result = jfb_wp_avatar($avatar, $id_or_email, $size, $default, $alt); 
  21.  

Defined (1)

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

/Main.php  
  1. function jfb_wp_avatar($avatar, $id_or_email, $size, $default, $alt) 
  2. //First, get the userid 
  3. if (is_numeric($id_or_email))  
  4. $user_id = $id_or_email; 
  5. else if(is_object($id_or_email) && !empty($id_or_email->user_id)) 
  6. $user_id = $id_or_email->user_id; 
  7. else 
  8. return $avatar; 
  9.  
  10. //If we couldn't get the userID, just return default behavior (email-based gravatar, etc) 
  11. if(!isset($user_id) || !$user_id) return $avatar; 
  12.  
  13. //Now that we have a userID, let's see if we have their facebook profile pic stored in usermeta. 
  14. //Note: Facebook "thumbs" are 50x50; if they request that resolution or lower, return facebook_avatar_thumb; otherwise,  
  15. //return facebook_avatar_full. If neither are available, just fallback on WP's default behavior. 
  16. if(is_numeric($size) && $size > 50) $fb_img = get_user_meta($user_id, 'facebook_avatar_full', true); 
  17. else if(is_numeric($size) && $size <= 50) $fb_img = get_user_meta($user_id, 'facebook_avatar_thumb', true); 
  18. if( !$fb_img ) return $avatar; 
  19.  
  20. //Users who didn't update to 2.3.1 when it was released may have some malformed avatar URLs in their db. Handle this. 
  21. if( is_array($fb_img) && isset($fb_img['data']['url'])) $fb_img = $fb_img['data']['url']; 
  22.  
  23. //If the usermeta doesn't contain an absolute path, prefix it with the path to the uploads dir 
  24. if( strpos($fb_img, "http") === FALSE ) 
  25. if(function_exists('jfb_p_get_avatar_cache_dir')) 
  26. $ud = jfb_p_get_avatar_cache_dir(); 
  27. else 
  28. $ud = wp_upload_dir(); 
  29. $uploads_url = $ud['baseurl']; 
  30. $fb_img = trailingslashit($uploads_url) . $fb_img; 
  31.  
  32. //And return the Facebook avatar (rather than the default WP one) 
  33. return "<img alt='" . esc_attr($alt) . "' src='$fb_img' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";