WP_REST_Templates_Controller::get_item( WP_REST_Request $request ): WP_REST_Response|WP_Error

In this article

Returns the given template

Parameters

$requestWP_REST_Requestrequired
The request instance.

Return

WP_REST_Response|WP_Error

Source

public function get_item( $request ) {
	if ( isset( $request['source'] ) && ( 'theme' === $request['source'] || 'plugin' === $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 );
}

Changelog

VersionDescription
5.8.0Introduced.

User Contributed Notes

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