BP_REST_Notifications_Endpoint::prepare_item_for_response( BP_Notifications_Notification $notification, WP_REST_Request $request )

Prepares notification data to return as an object.


Description Description


Parameters Parameters

$notification

(Required) Notification data.

$request

(Required) Full details about the request.


Top ↑

Return Return

(WP_REST_Response)


Top ↑

Source Source

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

	public function prepare_item_for_response( $notification, $request ) {
		$data = array(
			'id'                => $notification->id,
			'user_id'           => $notification->user_id,
			'item_id'           => $notification->item_id,
			'secondary_item_id' => $notification->secondary_item_id,
			'component'         => $notification->component_name,
			'action'            => $notification->component_action,
			'date'              => bp_rest_prepare_date_response( $notification->date_notified ),
			'is_new'            => $notification->is_new,
		);

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

		// @todo add prepare_links
		$response = rest_ensure_response( $data );

		/**
		 * Filter a notification 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_Notifications_Notification $notification Notification object.
		 */
		return apply_filters( 'bp_rest_notifications_prepare_value', $response, $request, $notification );
	}

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.