WP_REST_Templates_Controller::get_item()publicWP 5.8.0

Returns the given template

{} It's a method of the class: WP_REST_Templates_Controller{}

No Hooks.

Return

WP_REST_Response|WP_Error.

Usage

$WP_REST_Templates_Controller = new WP_REST_Templates_Controller();
$WP_REST_Templates_Controller->get_item( $request );
$request(WP_REST_Request) (required)
The request instance.

Changelog

Since 5.8.0 Introduced.

Code of WP_REST_Templates_Controller::get_item() WP 6.0

public function get_item( $request ) {
	if ( isset( $request['source'] ) && 'theme' === $request['source'] ) {
		$template = get_block_file_template( $request['id'], $this->post_type );
	} else {
		$template = get_block_template( $request['id'], $this->post_type );
	}

	if ( ! $template ) {
		return new WP_Error( 'rest_template_not_found', __( 'No templates exist with that id.' ), array( 'status' => 404 ) );
	}

	return $this->prepare_item_for_response( $template, $request );
}