BP_Groups_Group_Members_Template::__construct( array $args = array() )
Constructor.
Description
Parameters
- $args
-
(Optional) An array of optional arguments.
- 'group_id'
(int) ID of the group whose members are being queried. Default: current group ID. - '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_admin_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. Search terms to match.
Default value: array()
- 'group_id'
Source
File: bp-groups/classes/class-bp-groups-group-members-template.php
public function __construct( $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 => 'max',
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(),
'page' => 1,
'per_page' => 20,
'page_arg' => 'mlpage',
'max' => false,
'exclude' => false,
'exclude_admins_mods' => 1,
'exclude_banned' => 1,
'group_role' => false,
'search_terms' => false,
'type' => 'last_joined',
), 'group_members_template' );
$this->pag_arg = sanitize_key( $r['page_arg'] );
$this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page'] );
$this->pag_num = bp_sanitize_pagination_arg( 'num', $r['per_page'] );
/**
* Check the current group is the same as the supplied group ID.
* It can differ when using {@link bp_group_has_members()} outside the Groups screens.
*/
$current_group = groups_get_current_group();
if ( empty( $current_group ) || ( $current_group && $current_group->id !== bp_get_current_group_id() ) ) {
$current_group = groups_get_group( $r['group_id'] );
}
// Assemble the base URL for pagination.
$base_url = trailingslashit( bp_get_group_permalink( $current_group ) . bp_current_action() );
if ( bp_action_variable() ) {
$base_url = trailingslashit( $base_url . bp_action_variable() );
}
$members_args = $r;
$members_args['page'] = $this->pag_page;
$members_args['per_page'] = $this->pag_num;
// Get group members for this loop.
$this->members = groups_get_group_members( $members_args );
if ( empty( $r['max'] ) || ( $r['max'] >= (int) $this->members['count'] ) ) {
$this->total_member_count = (int) $this->members['count'];
} else {
$this->total_member_count = (int) $r['max'];
}
// Reset members array for subsequent looping.
$this->members = $this->members['members'];
if ( empty( $r['max'] ) || ( $r['max'] >= count( $this->members ) ) ) {
$this->member_count = (int) count( $this->members );
} else {
$this->member_count = (int) $r['max'];
}
$this->pag_links = paginate_links( array(
'base' => add_query_arg( array( $this->pag_arg => '%#%' ), $base_url ),
'format' => '',
'total' => ! empty( $this->pag_num ) ? ceil( $this->total_member_count / $this->pag_num ) : $this->total_member_count,
'current' => $this->pag_page,
'prev_text' => '←',
'next_text' => '→',
'mid_size' => 1,
'add_args' => array(),
) );
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 1.5.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.