BP_REST_Invites_Endpoint::get_items( WP_REST_Request $request )

Sent Invites.

Description

Parameters

$request

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

Return

(WP_REST_Response) | WP_Error List of bp-invite post's object data.

Source

File: bp-invites/classes/class-bp-rest-invites-endpoint.php

	public function get_items( $request ) {

		$args = array(
			'post_type'      => bp_get_invite_post_type(),
			'author'         => (int) get_current_user_id(),
			'paged'          => ( ! empty( $request['page'] ) ? $request['page'] : '' ),
			'posts_per_page' => ( ! empty( $request['per_page'] ) ? $request['per_page'] : '' ),
			'orderby'        => ( ! empty( $request['orderby'] ) ? $request['orderby'] : 'date' ),
			'order'          => ( ! empty( $request['order'] ) ? $request['order'] : 'desc' ),
		);

		$invites_query = new WP_Query( $args );

		$sent_invites = ( ! empty( $invites_query->posts ) ? $invites_query->posts : array() );

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

		wp_reset_postdata();

		$response = rest_ensure_response( $retval );
		$response = bp_rest_response_add_total_headers( $response, $invites_query->found_posts, $args['posts_per_page'] );

		/**
		 * Fires after a list of sent invites is fetched via the REST API.
		 *
		 * @param array            $sent_invites Fetched Invites.
		 * @param WP_REST_Response $response     The response data.
		 * @param WP_REST_Request  $request      The request sent to the API.
		 *
		 * @since 0.1.0
		 */
		do_action( 'bp_rest_invites_get_items', $sent_invites, $response, $request );

		return $response;
	}

Changelog

Changelog
Version Description
0.1.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.