groups_get_group_members( array $args = array() )
Fetch the members of a group.
Description
Since BuddyPress 1.8, a procedural wrapper for BP_Group_Member_Query. Previously called BP_Groups_Member::get_all_for_group().
To use the legacy query, filter ‘bp_use_legacy_group_member_query’, returning true.
Parameters
- $args
-
(Optional) An array of optional arguments.
- 'group_id'
(int|array|string) ID of the group to limit results to. Also accepts multiple values either as an array or as a comma-delimited string. - 'page'
(int) Page of results to be queried. Default: 1. - 'per_page'
(int) Number of items to return per page of results. Default: 20. - 'max'
(int) Optional. Max number of items to return. - 'exclude'
(array) Optional. Array of user IDs to exclude. - 'exclude_admins_mods'
(bool|int) True (or 1) to exclude admins and mods from results. Default: 1. - 'exclude_banned'
(bool|int) True (or 1) to exclude banned users from results. Default: 1. - 'group_role'
(array) Optional. Array of group roles to include. - 'search_terms'
(string) Optional. Filter results by a search string. - 'type'
(string) Optional. Sort the order of results. 'last_joined', 'first_joined', or any of the $type params available in BP_User_Query. Default: 'last_joined'.
Default value: array()
- 'group_id'
Return
(false|array) Multi-d array of 'members' list and 'count'.
Source
File: bp-groups/bp-groups-functions.php
function groups_get_group_members( $args = array() ) { // Backward compatibility with old method of passing arguments. if ( ! is_array( $args ) || func_num_args() > 1 ) { _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddyboss' ), __METHOD__, __FILE__ ) ); $old_args_keys = array( 0 => 'group_id', 1 => 'per_page', 2 => 'page', 3 => 'exclude_admins_mods', 4 => 'exclude_banned', 5 => 'exclude', 6 => 'group_role', ); $args = bp_core_parse_args_array( $old_args_keys, func_get_args() ); } $r = bp_parse_args( $args, array( 'group_id' => bp_get_current_group_id(), 'per_page' => false, 'page' => false, 'exclude_admins_mods' => true, 'exclude_banned' => true, 'exclude' => false, 'group_role' => array(), 'search_terms' => false, 'type' => 'last_joined', ), 'groups_get_group_members' ); // For legacy users. Use of BP_Groups_Member::get_all_for_group() is deprecated. if ( apply_filters( 'bp_use_legacy_group_member_query', false, __FUNCTION__, func_get_args() ) ) { $retval = BP_Groups_Member::get_all_for_group( $r['group_id'], $r['per_page'], $r['page'], $r['exclude_admins_mods'], $r['exclude_banned'], $r['exclude'] ); } else { // Both exclude_admins_mods and exclude_banned are legacy arguments. // Convert to group_role. if ( empty( $r['group_role'] ) ) { $r['group_role'] = array( 'member' ); if ( ! $r['exclude_admins_mods'] ) { $r['group_role'][] = 'mod'; $r['group_role'][] = 'admin'; } if ( ! $r['exclude_banned'] ) { $r['group_role'][] = 'banned'; } } // Perform the group member query (extends BP_User_Query). $members = new BP_Group_Member_Query( array( 'group_id' => $r['group_id'], 'per_page' => $r['per_page'], 'page' => $r['page'], 'group_role' => $r['group_role'], 'exclude' => $r['exclude'], 'search_terms' => $r['search_terms'], 'type' => $r['type'], ) ); // Structure the return value as expected by the template functions. $retval = array( 'members' => array_values( $members->results ), 'count' => $members->total_users, ); } return $retval; }
Changelog
Version | Description |
---|---|
BuddyPress 1.0.0 | 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.