jfb_bp_avatar

The WP-FB-AutoConnect jfb bp avatar function.

Description

jfb_bp_avatar( $avatar, (string) $params = '' ); 

Parameters (2)

0. $avatar
The avatar.
1. $params — Optional. (string) => ''
The params.

Usage

  1. if ( !function_exists( 'jfb_bp_avatar' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'wp-fb-autoconnect/Main.php'; 
  3.  
  4. // The avatar. 
  5. $avatar = null; 
  6.  
  7. // The params. 
  8. $params = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = jfb_bp_avatar($avatar, $params); 
  12.  

Defined (1)

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

/Main.php  
  1. function jfb_bp_avatar($avatar, $params='') 
  2. //First, get the userid 
  3. global $comment; 
  4. if (is_object($comment)) $user_id = $comment->user_id; 
  5. if (is_object($params)) $user_id = $params->user_id; 
  6. if (is_array($params) && $params['object']=='user') $user_id = $params['item_id']; 
  7. if (!isset($user_id)) return $avatar; 
  8.  
  9. //Now that we have a userID, let's see if we have their facebook profile pic stored in usermeta. If not, fallback on the default. 
  10. $fb_img = 0; 
  11. if( $params['type'] == 'full' ) $fb_img = get_user_meta($user_id, 'facebook_avatar_full', true); 
  12. if( !$fb_img ) $fb_img = get_user_meta($user_id, 'facebook_avatar_thumb', true); 
  13. if( !$fb_img ) return $avatar; 
  14.  
  15. //Users who didn't update to 2.3.1 when it was released may have some malformed avatar URLs in their db. Handle this. 
  16. if( is_array($fb_img) && isset($fb_img['data']['url'])) $fb_img = $fb_img['data']['url']; 
  17.  
  18. //If the usermeta doesn't contain an absolute path, prefix it with the path to the uploads dir 
  19. if( strpos($fb_img, "http") === FALSE ) 
  20. $uploads_url = wp_upload_dir(); 
  21. $uploads_url = $uploads_url['baseurl']; 
  22. $fb_img = trailingslashit($uploads_url) . $fb_img; 
  23.  
  24. //And return the Facebook avatar (rather than the default WP one) 
  25. return '<img alt="' . esc_attr($params['alt']) . '" src="' . $fb_img . '" class="avatar" />';