LLMS_REST_Controller::prepare_item_for_response( obj $object, WP_REST_Request $request )

Prepares a single object for response.


Parameters Parameters

$object

(obj) (Required) Raw object from database.

$request

(WP_REST_Request) (Required) Request object.


Top ↑

Return Return

(WP_Error|WP_REST_Response)


Top ↑

Source Source

File: libraries/lifterlms-rest/includes/abstracts/class-llms-rest-controller.php

	public function prepare_item_for_response( $object, $request ) {

		if ( is_wp_error( $object ) ) {
			return $object;
		}

		$data = $this->prepare_object_for_response( $object, $request );

		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';

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

		// Wrap the data in a response object.
		$response = rest_ensure_response( $data );

		// Add links.
		$response->add_links( $this->prepare_links( $object, $request ) );

		return $response;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0-beta.3 Return early with a WP_Error if $object is a WP_Error.
1.0.0-beta.14 Pass the $request parameter to prepare_links().
1.0.0-beta.1 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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