bp_groups_admin_create_pagination_links( BP_Group_Member_Query $query, string $member_type )
Create pagination links out of a BP_Group_Member_Query.
Description
This function is intended to create pagination links for use under the Manage Members section of the Groups Admin Dashboard pages. It is a stopgap measure until a more general pagination solution is in place for BuddyPress. Plugin authors should not use this function, as it is likely to be deprecated soon.
Parameters
- $query
-
(Required) A BP_Group_Member_Query object.
- $member_type
-
(Required) member|mod|admin|banned.
Return
(string) Pagination links HTML.
Source
File: bp-groups/bp-groups-admin.php
function bp_groups_admin_create_pagination_links( BP_Group_Member_Query $query, $member_type ) {
$pagination = '';
if ( ! in_array( $member_type, array( 'admin', 'mod', 'member', 'banned' ) ) ) {
return $pagination;
}
// The key used to paginate this profile type in the $_GET global.
$qs_key = $member_type . '_page';
$url_base = remove_query_arg( array( $qs_key, 'updated', 'success_modified' ), $_SERVER['REQUEST_URI'] );
$page = isset( $_GET[ $qs_key ] ) ? absint( $_GET[ $qs_key ] ) : 1;
/**
* Filters the number of members per profile type that is displayed in group editing admin area.
*
* @since BuddyPress 2.8.0
*
* @param string $member_type profile type, which is a group role (admin, mod etc).
*/
$per_page = apply_filters( 'bp_groups_admin_members_type_per_page', 10, $member_type );
// Don't show anything if there's no pagination.
if ( 1 === $page && $query->total_users <= $per_page ) {
return $pagination;
}
$current_page_start = ( ( $page - 1 ) * $per_page ) + 1;
$current_page_end = $page * $per_page > intval( $query->total_users ) ? $query->total_users : $page * $per_page;
$pag_links = paginate_links( array(
'base' => add_query_arg( $qs_key, '%#%', $url_base ),
'format' => '',
'prev_text' => __( '«', 'buddyboss' ),
'next_text' => __( '»', 'buddyboss' ),
'total' => ceil( $query->total_users / $per_page ),
'current' => $page,
) );
$viewing_text = sprintf(
_n( 'Viewing 1 member', 'Viewing %1$s - %2$s of %3$s members', $query->total_users, 'buddyboss' ),
bp_core_number_format( $current_page_start ),
bp_core_number_format( $current_page_end ),
bp_core_number_format( $query->total_users )
);
$pagination .= '<span class="bp-group-admin-pagination-viewing">' . $viewing_text . '</span>';
$pagination .= '<span class="bp-group-admin-pagination-links">' . $pag_links . '</span>';
return $pagination;
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 1.8.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.