BP_Core_Members_Template::__construct( string $type, int $page_number, int $per_page, int $max, int $user_id, string $search_terms, array $include, bool $populate_extras, array $exclude, array $meta_key, array $meta_value, string $page_arg = 'upage', array|string $member_type = '', array|string $member_type__in = '', array|string $member_type__not_in = '' )
Constructor method.
Description
See also
- BP_User_Query: for an in-depth description of parameters.
Parameters
- $type
-
(Required) Sort order.
- $page_number
-
(Required) Page of results.
- $per_page
-
(Required) Number of results per page.
- $max
-
(Required) Max number of results to return.
- $user_id
-
(Required) Limit to friends of a user.
- $search_terms
-
(Required) Limit to users matching search terms.
- $include
-
(Required) Limit results by these user IDs.
- $populate_extras
-
(Required) Fetch optional extras.
- $exclude
-
(Required) Exclude these IDs from results.
- $meta_key
-
(Required) Limit to users with a meta_key.
- $meta_value
-
(Required) Limit to users with a meta_value (with meta_key).
- $page_arg
-
(Optional) The string used as a query parameter in pagination links. Default: 'upage'.
Default value: 'upage'
- $member_type
-
(Optional) Array or comma-separated string of profile types to limit results to.
Default value: ''
- $member_type__in
-
(Optional) Array or comma-separated string of profile types to limit results to.
Default value: ''
- $member_type__not_in
-
(Optional) Array or comma-separated string of profile types to exclude from results.
Default value: ''
Source
File: bp-members/classes/class-bp-core-members-template.php
function __construct( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value, $page_arg = 'upage', $member_type = '', $member_type__in = '', $member_type__not_in = '' ) {
$this->pag_arg = sanitize_key( $page_arg );
$this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $page_number );
$this->pag_num = bp_sanitize_pagination_arg( 'num', $per_page );
$this->type = $type;
if ( !empty( $_REQUEST['letter'] ) )
$this->members = BP_Core_User::get_users_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras, $exclude );
else
$this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras, 'exclude' => $exclude, 'meta_key' => $meta_key, 'meta_value' => $meta_value, 'member_type' => $member_type, 'member_type__in' => $member_type__in, 'member_type__not_in' => $member_type__not_in ) );
if ( !$max || $max >= (int) $this->members['total'] )
$this->total_member_count = (int) $this->members['total'];
else
$this->total_member_count = (int) $max;
$this->members = $this->members['users'];
if ( $max ) {
if ( $max >= count( $this->members ) ) {
$this->member_count = count( $this->members );
} else {
$this->member_count = (int) $max;
}
} else {
$this->member_count = count( $this->members );
}
if ( (int) $this->total_member_count && (int) $this->pag_num ) {
$pag_args = array(
$this->pag_arg => '%#%',
);
if ( defined( 'DOING_AJAX' ) && true === (bool) DOING_AJAX ) {
$base = remove_query_arg( 's', wp_get_referer() );
} else {
$base = '';
}
/**
* Defaults to an empty array to make sure paginate_links()
* won't add the $page_arg to the links which would break
* pagination in case JavaScript is disabled.
*/
$add_args = array();
if ( ! empty( $search_terms ) ) {
$query_arg = bp_core_get_component_search_query_arg( 'members' );
$add_args[ $query_arg ] = urlencode( $search_terms );
}
$this->pag_links = paginate_links( array(
'base' => add_query_arg( $pag_args, $base ),
'format' => '',
'total' => ceil( (int) $this->total_member_count / (int) $this->pag_num ),
'current' => (int) $this->pag_page,
'prev_text' => __( '←', 'buddyboss' ),
'next_text' => __( '→', 'buddyboss' ),
'mid_size' => 1,
'add_args' => $add_args,
) );
}
}
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.