bb_get_ids_by_role

The BuddyPress bb get ids by role function.

Description

bb_get_ids_by_role( (string) $role = 'moderator', (int) $sort = 0, (int) $page = 1, (int) $limit = 50 ); 

Parameters (4)

0. $role — Optional. (string) => 'moderator'
The role.
1. $sort — Optional. (int)
The sort.
2. $page — Optional. (int) => 1
The page.
3. $limit — Optional. (int) => 50
The limit.

Usage

  1. if ( !function_exists( 'bb_get_ids_by_role' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-admin/includes/functions.bb-admin.php'; 
  3.  
  4. // The role. 
  5. $role = 'moderator'; 
  6.  
  7. // The sort. 
  8. $sort = -1; 
  9.  
  10. // The page. 
  11. $page = 1; 
  12.  
  13. // The limit. 
  14. $limit = 50; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = bb_get_ids_by_role($role, $sort, $page, $limit); 
  18.  

Defined (1)

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

/bp-forums/bbpress/bb-admin/includes/functions.bb-admin.php  
  1. function bb_get_ids_by_role( $role = 'moderator', $sort = 0, $page = 1, $limit = 50 ) { 
  2. global $bbdb, $bb_last_countable_query; 
  3. $sort = $sort ? 'DESC' : 'ASC'; 
  4. $key = $bbdb->escape( $bbdb->prefix . 'capabilities' ); 
  5.  
  6. if ( !$page = abs( (int) $page ) ) 
  7. $page = 1; 
  8. $limit = abs( (int) $limit ); 
  9.  
  10. $limit = ($limit * ($page - 1)) . ", $limit"; 
  11.  
  12. $role = $bbdb->escape_deep($role); 
  13.  
  14. if ( is_array($role) ) 
  15. $and_where = "( meta_value LIKE '%" . join("%' OR meta_value LIKE '%", $role) . "%' )"; 
  16. else 
  17. $and_where = "meta_value LIKE '%$role%'"; 
  18. $bb_last_countable_query = "SELECT user_id FROM $bbdb->usermeta WHERE meta_key = '$key' AND $and_where ORDER BY user_id $sort LIMIT $limit"; 
  19.  
  20. $ids = false; 
  21.  
  22. $_tuple = compact( 'ids', 'role', 'sort', 'page', 'key', 'limit', 'bb_last_countable_query' ); 
  23. $_tuple = apply_filters( 'bb_get_ids_by_role', $_tuple ); 
  24. extract( $_tuple, EXTR_OVERWRITE ); 
  25.  
  26. if ( !$ids ) { 
  27. $ids = (array) $bbdb->get_col( $bb_last_countable_query ); 
  28.  
  29. if ( $ids ) { 
  30. bb_cache_users( $ids ); 
  31.  
  32. return $ids;