bp_groupblog_get_user_role

Bp_groupblog_get_user_role( $user_id, $user_login, $blog_id ).

Description

(string) bp_groupblog_get_user_role( (int) $user_id, (bool) $user_login, (int) $blog_id ); 

Reworked function to retrieve the users current role - by Boone

Returns (string)

The user's blog role

Parameters (3)

0. $user_id (int)
The user id.
1. $user_login (bool)
Deprecated. Don't use.
2. $blog_id (int)
The blog id.

Usage

  1. if ( !function_exists( 'bp_groupblog_get_user_role' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bp-groupblog/bp-groupblog.php'; 
  3.  
  4. // The user id. 
  5. $user_id = -1; 
  6.  
  7. // Deprecated. Don't use. 
  8. $user_login = true; 
  9.  
  10. // The blog id. 
  11. $blog_id = -1; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bp_groupblog_get_user_role($user_id, $user_login, $blog_id); 
  15.  

Defined (1)

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

/bp-groupblog.php  
  1. function bp_groupblog_get_user_role( $user_id, $user_login = false, $blog_id ) { 
  2. global $wpdb; 
  3.  
  4. // determine users role, if any, on this blog 
  5. $roles = get_user_meta( $user_id, $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', true ); 
  6.  
  7. // this seems to be the only way to do this 
  8. if ( isset( $roles['subscriber'] ) ) { 
  9. $user_role = 'subscriber'; 
  10. } elseif ( isset( $roles['contributor'] ) ) { 
  11. $user_role = 'contributor'; 
  12. } elseif ( isset( $roles['author'] ) ) { 
  13. $user_role = 'author'; 
  14. } elseif ( isset( $roles['editor'] ) ) { 
  15. $user_role = 'editor'; 
  16. } elseif ( isset( $roles['administrator'] ) ) { 
  17. $user_role = 'administrator'; 
  18. } elseif ( is_super_admin( $user_id ) ) { 
  19. $user_role = 'siteadmin'; 
  20. } else { 
  21. $user_role = 'norole'; 
  22.  
  23. return $user_role;