BP_REST_Group_Membership_Request_Endpoint::get_items( WP_REST_Request $request )

Fetch pending group membership requests.


Parameters Parameters

$request

(WP_REST_Request) (Required) Full data about the request.


Top ↑

Return Return

(WP_REST_Response|WP_Error)


Source Source

File: bp-groups/classes/class-bp-rest-group-membership-request-endpoint.php

	public function get_items( $request ) {
		$args = array(
			'item_id'  => $request['group_id'],
			'user_id'  => $request['user_id'],
			'per_page' => $request['per_page'],
			'page'     => $request['page'],
		);

		// If the query is not restricted by group or user, limit it to the current user, if not an admin.
		if ( ! $args['item_id'] && ! $args['user_id'] && ! bp_current_user_can( 'bp_moderate' ) ) {
			$args['user_id'] = bp_loggedin_user_id();
		}

		/**
		 * Filter the query arguments for the request.
		 *
		 * @since 5.0.0
		 *
		 * @param array           $args    Key value array of query var to query value.
		 * @param WP_REST_Request $request The request sent to the API.
		 */
		$args = apply_filters( 'bp_rest_group_membership_requests_get_items_query_args', $args, $request );

		$group_requests = groups_get_requests( $args );

		$retval = array();
		foreach ( $group_requests as $group_request ) {
			$retval[] = $this->prepare_response_for_collection(
				$this->prepare_item_for_response( $group_request, $request )
			);
		}

		$response = rest_ensure_response( $retval );
		$response = bp_rest_response_add_total_headers( $response, count( $group_requests ), $args['per_page'] );

		/**
		 * Fires after a list of group membership request is fetched via the REST API.
		 *
		 * @since 5.0.0
		 *
		 * @param array of BP_Invitations $group_requests List of membership requests.
		 * @param WP_REST_Response        $response       The response data.
		 * @param WP_REST_Request         $request        The request sent to the API.
		 */
		do_action( 'bp_rest_group_membership_requests_get_items', $group_requests, $response, $request );

		return $response;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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