BP_REST_Group_Membership_Endpoint::prepare_item_for_response( BP_Groups_Member $group_member, WP_REST_Request $request )

Prepares group member data for return as an object.


Parameters Parameters

$group_member

(BP_Groups_Member) (Required) Group member object.

$request

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


Top ↑

Return Return

(WP_REST_Response)


Source Source

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

	public function prepare_item_for_response( $group_member, $request ) {
		$user                   = bp_rest_get_user( $group_member->user_id );
		$context                = ! empty( $request['context'] ) ? $request['context'] : 'view';
		$member_data            = $this->members_endpoint->user_data( $user, $context, $request );
		$group_member->group_id = $request->get_param( 'group_id' );

		// Merge both info.
		$data = array_merge(
			$member_data,
			array(
				'group'         => (int) $group_member->group_id,
				'is_mod'        => (bool) $group_member->is_mod,
				'is_admin'      => (bool) $group_member->is_admin,
				'is_banned'     => (bool) $group_member->is_banned,
				'is_confirmed'  => (bool) $group_member->is_confirmed,
				'date_modified' => bp_rest_prepare_date_response( $group_member->date_modified ),
			)
		);

		$data     = $this->add_additional_fields_to_object( $data, $request );
		$data     = $this->filter_response_by_context( $data, $context );
		$response = rest_ensure_response( $data );

		$response->add_links( $this->prepare_links( $group_member ) );

		/**
		 * Filter a group member value returned from the API.
		 *
		 * @since 5.0.0
		 *
		 * @param WP_REST_Response $response      The response data.
		 * @param WP_REST_Request  $request       Request used to generate the response.
		 * @param BP_Groups_Member $group_member  Group member object.
		 */
		return apply_filters( 'bp_rest_group_members_prepare_value', $response, $request, $group_member );
	}


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.