bbp_get_user_role( int $user_id )

Return a user’s forums role

Description

Parameters

$user_id

(Required)

Return

(string)

Source

File: bp-forums/users/capabilities.php

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
function bbp_get_user_role( $user_id = 0 ) {
 
    // Validate user id
    $user_id = bbp_get_user_id( $user_id );
    $user    = get_userdata( $user_id );
    $role    = false;
 
    // User has roles so look for a Forums one
    if ( ! empty( $user->roles ) ) {
 
        // Look for a Forums role
        $roles = array_intersect(
            array_values( $user->roles ),
            array_keys( bbp_get_dynamic_roles() )
        );
 
        // If there's a role in the array, use the first one. This isn't very
        // smart, but since roles aren't exactly hierarchical, and Forums
        // does not yet have a UI for multiple user roles, it's fine for now.
        if ( !empty( $roles ) ) {
            $role = array_shift( $roles );
        }
    }
 
    return apply_filters( 'bbp_get_user_role', $role, $user_id, $user );
}

Changelog

Changelog
Version Description
bbPress (r3860) 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.