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 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.


Top ↑

Parameters Parameters

$query

(BP_Group_Member_Query) (Required) A BP_Group_Member_Query object.

$member_type

(string) (Required) member|mod|admin|banned.


Top ↑

Return Return

(string) Pagination links HTML.


Source 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 member 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 member type that is displayed in group editing admin area.
	 *
	 * @since 2.8.0
	 *
	 * @param string $member_type Member 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' => __( '&laquo;', 'buddypress' ),
		'next_text' => __( '&raquo;', 'buddypress' ),
		'total'     => ceil( $query->total_users / $per_page ),
		'current'   => $page,
	) );

	if ( 1 == $query->total_users ) {
		$viewing_text = __( 'Viewing 1 member', 'buddypress' );
	} else {
		$viewing_text = sprintf(
			/* translators: 1: group member from number. 2: group member to number. 3: total group members. */
			_nx( 'Viewing %1$s - %2$s of %3$s member', 'Viewing %1$s - %2$s of %3$s members', $query->total_users, 'Group members pagination in group admin', 'buddypress' ),
			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;
}


Top ↑

Changelog Changelog

Changelog
Version Description
1.8.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.