修改get_avatar()函数

I found a great tutorial to create a custom avatar (https://www.billerickson.net/wordpress-custom-avatar/). Basically it checks:

1) If there’s a custom avatar, use that.

2) If there isn’t a custom avatar, check to see if there’s a gravatar. If there’s a gravatar, use that.

3) If there’s neither, display the default.

The issue is that I have registered users on my wordpress, so whenever they comment, it uses the custom avatar I've set for the author, for all the commentors who have an email registered.

This is the part of the code I'm struggling with:

// If provided an email and it doesn't exist as WP user, return avatar since there can't be a custom avatar
$email = is_object( $id_or_email ) ? $id_or_email->comment_author_email : $id_or_email;
if( is_email( $email ) && ! email_exists( $email ) )
    return $avatar;

$custom_avatar = get_the_author_meta('be_custom_avatar');
if ($custom_avatar) 
    $return = '<img src="'.$custom_avatar.'" width="'.$size.'" height="'.$size.'" alt="'.$alt.'" />';
elseif ($avatar) 
    $return = $avatar;
else 
    $return = '<img src="'.$default.'" width="'.$size.'" height="'.$size.'" alt="'.$alt.'" />';
return $return;

How can I make it check so that if the "be_custom_avatar" is empty in the Users Profile, and they have no gravatar set, it returns the default wordpress $avatar ?

Thank you

Add your own avatar in WordPress

add_filter( 'avatar_defaults', 'custom_avatar' );
    function custom_avatar($avatar_defaults){
    $custom_avatar = get_stylesheet_directory_uri() . '/images/default-avatar.jpg';
    $avatar_defaults[$custom_avatar] = "My Default Avatar";
    return $avatar_defaults;
 }

Try this code, you get the solution

</div>