bbp_get_user_role

Return a user's forums role.

Description

(string) bbp_get_user_role( (int) $user_id = 0 ); 

Returns (string)

Parameters (1)

0. $user_id — Optional. (int)
The user id.

Usage

  1. if ( !function_exists( 'bbp_get_user_role' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/users/capabilities.php'; 
  3.  
  4. // The user id. 
  5. $user_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_get_user_role($user_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/users/capabilities.php  
  1. function bbp_get_user_role( $user_id = 0 ) { 
  2.  
  3. // Validate user id 
  4. $user_id = bbp_get_user_id( $user_id ); 
  5. $user = get_userdata( $user_id ); 
  6. $role = false; 
  7.  
  8. // User has roles so look for a bbPress one 
  9. if ( ! empty( $user->roles ) ) { 
  10.  
  11. // Look for a bbPress role 
  12. $roles = array_intersect( 
  13. array_values( $user->roles ),  
  14. array_keys( bbp_get_dynamic_roles() ) 
  15. ); 
  16.  
  17. // If there's a role in the array, use the first one. This isn't very 
  18. // smart, but since roles aren't exactly hierarchical, and bbPress 
  19. // does not yet have a UI for multiple user roles, it's fine for now. 
  20. if ( !empty( $roles ) ) { 
  21. $role = array_shift( $roles ); 
  22.  
  23. return apply_filters( 'bbp_get_user_role', $role, $user_id, $user );