bbp_get_user_blog_role

Return a user's blog role.

Description

(string) bbp_get_user_blog_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_blog_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_blog_role($user_id); 
  9.  

Defined (1)

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

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