您好,JanoChen,
WP FP AutoConnect创建一个函数,用于获取Facebook个人资料图像并将其输出为头像。
功能是jfb_wp_avatar
并且可以将其添加到模板中。
您必须在插件设置中启用该选项。
以下是如何在插件中定义函数:
/**
* Optionally replace WORDPRESS avatars with FACEBOOK profile pictures
*/
if( get_option($opt_jfb_wp_avatars) ) add_filter(\'get_avatar\', \'jfb_wp_avatar\', 10, 5);
function jfb_wp_avatar($avatar, $id_or_email, $size, $default, $alt)
{
//First, get the userid
if (is_numeric($id_or_email))
$user_id = $id_or_email;
else if(is_object($id_or_email) && !empty($id_or_email->user_id))
$user_id = $id_or_email->user_id;
else if(is_string($id_or_email))
$user_id = get_user_by(\'email\', $id_or_email );
//If we couldn\'t get the userID, just return default behavior (email-based gravatar, etc)
if(!isset($user_id) || !$user_id) return $avatar;
//Now that we have a userID, let\'s see if we have their facebook profile pic stored in usermeta
$fb_img = get_usermeta($user_id, \'facebook_avatar_thumb\');
//If so, replace the avatar! Otherwise, fallback on what WP core already gave us.
if($fb_img) $avatar = "<img alt=\'fb_avatar\' src=\'$fb_img\' class=\'avatar avatar-{$size} photo\' height=\'{$size}\' width=\'{$size}\' />";
return $avatar;
}