mediaroot
mediaroot

Reputation: 445

get_avatar alternative for Buddypress's uploaded photo

I am using the following snippet in my theme to get the logged-in user's avatar of the default wp user's setting page.

<?php echo get_avatar($id_or_email, $size='64', $default, $alt='User name' ); ?>

However, After installing the buddypress; I wanted to display the uploaded profile's photo of the user where the above snippet only shows the default wp avatar.

Any idea on how to achieve that?

Upvotes: 0

Views: 455

Answers (2)

shanebp
shanebp

Reputation: 1956

Use the BuddyPress function bp_core_fetch_avatar

$user_id = bp_loggedin_user_id();
echo bp_core_fetch_avatar( array( 'item_id' => $user_id) );

Review the function in bp-core/bp-core-avatars.php to see the available arguments.

Upvotes: 0

c0utinh0
c0utinh0

Reputation: 179

You should enable both options:

<?php 
if ( empty ( bp_loggedin_user_id() == false ) ) {
    $user_id = bp_loggedin_user_id();
    echo bp_core_fetch_avatar( array( 'item_id' => $user_id) );
} else {
    echo get_avatar($id_or_email, $size='64', $default, $alt='User name' ); 
}
?>

Upvotes: 1

Related Questions