bp_groups_get_profile_stats( array|string $args = '' )

Return the number of groups in user’s profile.

Description

Parameters

$args

(Optional) before|after|user_id

Default value: ''

Return

(string) HTML for stats output.

Source

File: bp-groups/bp-groups-template.php

7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
function bp_groups_get_profile_stats( $args = '' ) {
 
    // Parse the args
    $r = bp_parse_args( $args, array(
        'before'  => '<li class="bp-groups-profile-stats">',
        'after'   => '</li>',
        'user_id' => bp_displayed_user_id(),
        'groups'  => 0,
        'output'  => ''
    ), 'groups_get_profile_stats' );
 
    // Allow completely overloaded output
    if ( empty( $r['output'] ) ) {
 
        // Only proceed if a user ID was passed
        if ( ! empty( $r['user_id'] ) ) {
 
            // Get the user groups
            if ( empty( $r['groups'] ) ) {
                $r['groups'] = absint( bp_get_total_group_count_for_user( $r['user_id'] ) );
            }
 
            // If groups exist, show some formatted output
            $r['output'] = $r['before'] . sprintf( _n( '%s group', '%s groups', $r['groups'], 'buddyboss' ), '<strong>' . $r['groups'] . '</strong>' ) . $r['after'];
        }
    }
 
    /**
     * Filters the number of groups in user's profile.
     *
     * @since BuddyPress 2.0.0
     *
     * @param string $value HTML for stats output.
     * @param array  $r     Array of parsed arguments for query.
     */
    return apply_filters( 'bp_groups_get_profile_stats', $r['output'], $r );
}

Changelog

Changelog
Version Description
BuddyPress 2.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.