Compter le nombre de groupes associés à un membre

BuddyPress
function count_groups_a_user_is_member($type, $user_id) {
    
    $count = 0;
    
    $group_ids = groups_get_user_groups(bp_displayed_user_id($user_id));
    
    foreach ($group_ids["groups"] as $group_id) {
        
        // Afficher des infos
        //$group_info = (groups_get_group(array('group_id' => $group_id))->name . (end($group_ids["groups"]) == $group_id ? '' : ', ' ) );

        $group_type = bp_groups_get_group_type($group_id);
        //echo $group_type;
        if ($group_type === $type) {
            $count++;
        }
    }
    return $count;
}

// usage
echo count_groups_a_user_is_member('film', $user_id_parameter);

Afficher l’avatar d’un utilisateur BuddyPress

BuddyPress

Afficher dans un template l’avatar d’un user (en dehors de la loop BuddyPress) :

 

$avatar = bp_core_fetch_avatar(array('item_id' => $user_id, 'html' => true, 'object' => 'group', 'type' => thumb, 'avatar_dir' => 'group-avatars', 'alt' => $group->name, 'css_id' => $id, 'class' => $class, 'width' => 50, 'height' => 50));

Retourner le nom d’un utilisateur BuddyPress

BuddyPress

Code snippet pour retourner le nom d’un utilisateur (username ) BuddyPress basé sur son ID (user id)

$name = bp_core_get_username($user_id);

Paramètres

$user_id
// ( int ) optional – User ID to check.
$user_nicename
// ( string|bool ) optional – Optional. user_nicename of user being checked.
$user_login
//( string|bool ) optional – Optional. user_login of user being checked.

$name = bp_core_get_username($user_id);