BP_REST_Invites_Endpoint::prepare_item_for_response( WP_Post $item, WP_REST_Request $request )

Prepares Invite data for return as an object.

Description

Parameters

$item

(Required) bp-invite post object.

$request

(Required) Full details about the request.

Return

(WP_REST_Response)

Source

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

	public function prepare_item_for_response( $item, $request ) {
		$data = array(
			'id'             => $item->ID,
			'name'           => get_post_meta( $item->ID, '_bp_invitee_name', true ),
			'email'          => get_post_meta( $item->ID, '_bp_invitee_email', true ),
			'date'           => $this->prepare_date_response( $item->post_date_gmt, $item->post_date ),
			'date_gmt'       => $this->prepare_date_response( $item->post_date_gmt ),
			'status'         => '',
			'invitee-status' => (bool) get_post_meta( $item->ID, '_bp_invitee_status', true ),
			'revoke-invite'  => false,
		);

		if (
			function_exists( 'bp_allow_custom_registration' )
			&& function_exists( 'bp_custom_register_page_url' )
			&& bp_allow_custom_registration()
			&& '' !== bp_custom_register_page_url()
		) {
			$data['status'] = ( '1' === get_post_meta( $item->ID, '_bp_invitee_status', true ) ) ? __( 'Registered', 'buddyboss' ) : __( 'Invited', 'buddyboss' );
		} else {
			$data['status']        = ( '1' === get_post_meta( $item->ID, '_bp_invitee_status', true ) ) ? __( 'Registered', 'buddyboss' ) : __( 'Revoke Invite', 'buddyboss' );
			$data['revoke-invite'] = ( '1' === get_post_meta( $item->ID, '_bp_invitee_status', true ) ) ? false : true;
		}

		$context  = ! empty( $request['context'] ) ? $request['context'] : 'view';
		$data     = $this->add_additional_fields_to_object( $data, $request );
		$data     = $this->filter_response_by_context( $data, $context );
		$response = rest_ensure_response( $data );

		/**
		 * Filter a invite value returned from the API.
		 *
		 * @param WP_REST_Response $response The response data.
		 * @param WP_REST_Request  $request  Request used to generate the response.
		 * @param WP_Post          $item     bp-invite post object.
		 *
		 * @since 0.1.0
		 */
		return apply_filters( 'bp_rest_invites_prepare_value', $response, $request, $item );
	}

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.