BuddyPress changing all commenter's gravatars to the author's gravatar.

I am using a custom child theme based on sandbox on one of my blogs. Not the main one that uses a BuddyPress theme (of course).

Whenever BuddyPress is active all the Gravatars for every comment show the author’s gravatar, instead of the one belonging to the commentor.

Correct Gravatars show when BuddyPress is not active.

  • lgedeon
    • Flash Drive

    Have been chasing this all day. Findings so far:

    I echoed (in a html comment) $avatar_email right before running get_avatar( $avatar_email, $avatar_size ) and it is providing the correct email.

    I read (on a site I have now lost) that BuddyPress filters get_avatar() but requires a username instead of an email, but 98% of commenters are not registered at my site and gravatar works by using the email address so I need to send that to the function anyway.

    All gravatars are correct with BuddyPress deactivated. Gravatars on all blogs including main blog are wrong with BP active.

    Dev said this would be fixed in BuddyPress 1.2.2 but as of it is still wrong.

  • lgedeon
    • Flash Drive

    Hey! I found a solution! All it took was banging my head against a wall for a solid week. :slight_smile:

    Full text at: http://luke.gedeon.name/buddypress-wrong-avatar-fix.html

    What I found:

    In the file /wp-content/plugins/buddypress/bp-core/bp-core-avatars.php, lines 344 and following contain the following code:

    global $authordata;

    if ( is_object( $user ) )

    $id = $user->user_id;

    else if ( is_numeric( $user ) )

    $id = $user;


    $id = $authordata->ID;

    if ( empty( $id ) )

    return $avatar;

    I think that last “if statement” may be there to catch cases where the commenter does not have a BuddyPress account (which is the majority on my site at this point). However, if you look closely at the block just above the “if ( empty( $id))” you will notice $id is never going to be empty at this point.

    That suggests two possible solutions.

    Solution 1:

    I have not tested this, but it makes sense that you could move the last “if statement” above the first “if statement.” That way you can check for “empty( $id )” before it gets set to”$authordata->ID”

    Solution 2:

    I found it works quite well to add these lines just under the last “if statement.”

    if ( is_string( $user ) )

    return $avatar;

    This will catch any case where an email is sent as input, which is what all (most) non-buddypress themes send. Cases where numbers or objects are sent (the BuddyPress method) will be handled normally.

    Maybe I can get this added into the next release of BuddyPress.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.