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

		}

		return $prepared;

	}
	/**
	 * Prepare an object for response.
	 *
	 * @since 1.0.0-beta.27
	 *
	 * @param LLMS_REST_API_Key $object  API Key object.
	 * @param WP_REST_Request   $request Request object.
	 * @return array
	 */
	protected function prepare_object_for_response( $object, $request ) {

		$data       = parent::prepare_object_for_response( $object, $request );
		$data['id'] = $object->get( 'id' );

		// 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']    = $object->get( 'consumer_key_one_time' );
			$data['consumer_secret'] = $object->get( 'consumer_secret' );
		}

		return $data;

	}



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.