LLMS_REST_API_Keys_Controller::prepare_item_for_response( LLMS_REST_API_Key $item, WP_REST_Request $request )

Prepare an API Key for a REST response.


Parameters Parameters

$item

(LLMS_REST_API_Key) (Required) API Key object.

$request

(WP_REST_Request) (Required) Request object.


Top ↑

Return Return

(WP_REST_Response)


Top ↑

Source Source

File: libraries/lifterlms-rest/includes/server/class-llms-rest-api-keys-controller.php

	public function prepare_item_for_response( $item, $request ) {

		$data = array(
			'id' => $item->get( 'id' ),
		);

		// Add all readable properties.
		foreach ( $this->get_fields_for_response( $request ) as $field ) {
			$data[ $field ] = $item->get( $field );
		}

		// Is a creation request, return consumer key & secret.
		if ( 'POST' === $request->get_method() && sprintf( '/%1$s/%2$s', $this->namespace, $this->rest_base ) === $request->get_route() ) {
			$data['consumer_key']    = $item->get( 'consumer_key_one_time' );
			$data['consumer_secret'] = $item->get( 'consumer_secret' );
		}

		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
		$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( $item, $request ) );

		return $response;

	}


Top ↑

Changelog Changelog

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