Skip to:
Content
Pages
Categories
Search
Top
Bottom

Fetch user’s avatar


  • jbrandsma
    Participant

    @jbrandsma

    I am working with bbpress and I noticed that on the forums page of my site (bbpress), the avatars for user’s are from their wordpress profiles instead of the avatar used for buddypress.

    Would anyone have a fix where the avatar for users in the forum matches the avatar from buddypress?

Viewing 1 replies (of 1 total)

  • jbrandsma
    Participant

    @jbrandsma

    Welp, I couldn’t wait so I just spent hours trying to figure this out – with SUCCESS. If anyone stumbles upon this, here is the code I placed in my theme’s function.php file.

    function jb_get_bp_user_avatar($avatar, $id_or_email, $size, $default, $alt)
    {
    if (is_numeric($id_or_email)) {
    $id = (int) $id_or_email;
    $user = get_user_by(‘id’, $id);
    } elseif (is_object($id_or_email)) {
    if (!empty($id_or_email->user_id)) {
    $id = (int) $id_or_email->user_id;
    $user = get_user_by(‘id’, $id);
    }
    } else {
    $user = get_user_by(’email’, $id_or_email);
    }
    if ($user && is_object($user)) {
    $avatar = bp_core_fetch_avatar(array(‘item_id’ => $user->ID));
    }
    return $avatar;
    }
    add_filter(‘get_avatar’, ‘jb_get_bp_user_avatar’, 10000, 5);

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar