8

So I have the User Id of someone in Buddypress.

What is the function to print out their Avatar?

What is the function to link to their profile?

Jordash
  • 2,926
  • 8
  • 38
  • 77

5 Answers5

14

This will display the user avatar by user ID and also make the avatar a clickable link to their profile.

<?php $member_id = bp_core_get_userid( '1' ) ?>

<a href="<?php echo bp_core_get_user_domain( $member_id ) ?>" 

title="<?php echo bp_core_get_user_displayname( $member ) ?>">

<?php echo bp_core_fetch_avatar ( array( 'item_id' => $member_id, 'type' => 'full' ) ) ?></a>

Obviously replace the number in the first line with the userID that you want.

gordyr
  • 6,078
  • 14
  • 65
  • 123
  • 2
    Thanks for this! FYI - The bp_core_get_userid() function accepts the username as the parameter and returns the user_id. Also, for those copying and pasting this code, fix the bp_core_get_user_displayname to accept $member_id as the argument, not $member. – Clint Jan 07 '12 at 20:58
1

Simply you can use bp_activity_avatar() function:

<?php bp_activity_avatar(array('user_id' => $user_id)); ?>
revo
  • 47,783
  • 14
  • 74
  • 117
  • is it safe usage? I tried to use it and i got warning: Notice: Trying to get property of non-object in "\wp-content\plugins\buddypress\bp-activity\bp-activity-template.php" — Coz the (global $activities_template) variable is not declared. – Juljan Mar 14 '16 at 08:48
1

Output the avatar of the user for specified User ID

 bp_activity_avatar( 'user_id=' . $user_id );

Returns a HTML formatted link for a user with the user's full name as the link text for specified User ID

 echo bp_core_get_userlink(  $user_id );
Paresh Radadiya
  • 185
  • 4
  • 10
0

I've managed do it with code like this (without php warnings):

$imgTagAva = apply_filters( 'bp_group_request_user_avatar_thumb', bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $user_id ) ) ) ) );
Juljan
  • 2,391
  • 1
  • 17
  • 20
-1

found it. The best solution is below:

get_avatar(get_the_author_meta('ID'), 40);
// OR
get_avatar($author_id_or_email, $size);
Juljan
  • 2,391
  • 1
  • 17
  • 20
  • Found... where? I see that code [in previous posts](http://stackoverflow.com/search?q=get_avatar%28get_the_author_meta%28%27ID%27%29%2C+is%3Aa). Be sure to [give proper attribution](http://blog.stackoverflow.com/2009/06/attribution-required/). – Mogsdad Mar 15 '16 at 14:23