here’s the code I’ve used successfully to fix my issue:
add_filter( 'bp_core_fetch_avatar', 'bfg_bp_core_fetch_avatar', 15, 2 );
/**
* bfg_bp_core_fetch_avatar()
*
* Modifieds the BuddyPress avatar with WP Social Login avatar if default avatar is rendered
*
*
* @param string $bp_avatar Avatar image returned by BuddyPress
* @param array $args Determine the output of this function
* @return string Formatted HTML <img> element, or raw avatar URL based on $html arg
*/
function bfg_bp_core_fetch_avatar($bp_avatar, $args = '') {
$params = wp_parse_args( $args, array(
'item_id' => false,
'object' => $def_object, // user/group/blog/custom type (if you use filters)
'type' => $def_type, // thumb or full
'avatar_dir' => false, // Specify a custom avatar directory for your object
'width' => false, // Custom width (int)
'height' => false, // Custom height (int)
'class' => $def_class, // Custom <img> class (string)
'css_id' => false, // Custom <img> ID (string)
'alt' => '', // Custom <img> alt (string)
'email' => false, // Pass the user email (for gravatar) to prevent querying the DB for it
'no_grav' => false, // If there is no avatar found, return false instead of a grav?
'html' => true, // Wrap the return img URL in <img />
'title' => '' // Custom <img> title (string)
) );
extract( $params, EXTR_SKIP );
//modify only user's avatars and
if(!empty ($bp_avatar) && $object == 'user' && get_option('wsl_settings_users_avatars')) {
if(empty($email) && !empty($item_id)) {
$email = get_userdata($item_id)->user_email;
}
if($item_id || $email) {
if(is_default_gravatar($email)) {
$user_thumbnail = get_user_meta ($item_id, 'wsl_user_image', true);
if ($user_thumbnail !== false && strlen(trim($user_thumbnail)) > 0) {
$user_thumbnail = preg_replace ('#src=([\'"])([^\\1]+)\\1#Ui', "src=\\1" . $user_thumbnail . "\\1", $bp_avatar);
if (!is_ssl()) {
$user_thumbnail = str_replace('https', 'http', $user_thumbnail);
}
return $user_thumbnail;
}
}
}
}
return $bp_avatar;
}
//given user e-mail tests if gravatar exits or a default image is rendered
//returns true if default image is going to be used, false if a valid gravatar image exists
function is_default_gravatar($email) {
// Craft a potential url and test its headers
$hash = md5(strtolower(trim($email)));
$uri = 'https://www.gravatar.com/avatar/' . $hash . '?d=404';
$headers = @get_headers($uri);
return !preg_match("|200|", $headers[0]);
}
Hope this helps.