WP_REST_Templates_Controller::prepare_item_for_response( WP_Block_Template $template, WP_REST_Request $request )
Prepare a single template output for response
Parameters
- $template
-
(WP_Block_Template) (Required) Template instance.
- $request
-
(WP_REST_Request) (Required) Request object.
Return
(WP_REST_Response) $data
Source
File: wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
public function prepare_item_for_response( $template, $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable $result = array( 'id' => $template->id, 'theme' => $template->theme, 'content' => array( 'raw' => $template->content ), 'slug' => $template->slug, 'source' => $template->source, 'type' => $template->type, 'description' => $template->description, 'title' => array( 'raw' => $template->title, 'rendered' => $template->title, ), 'status' => $template->status, 'wp_id' => $template->wp_id, 'has_theme_file' => $template->has_theme_file, ); if ( 'wp_template_part' === $template->type ) { $result['area'] = $template->area; } $result = $this->add_additional_fields_to_object( $result, $request ); $response = rest_ensure_response( $result ); $links = $this->prepare_links( $template->id ); $response->add_links( $links ); if ( ! empty( $links['self']['href'] ) ) { $actions = $this->get_available_actions(); $self = $links['self']['href']; foreach ( $actions as $rel ) { $response->add_link( $rel, $self ); } } return $response; }
Changelog
Version | Description |
---|---|
5.8.0 | Introduced. |
© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_templates_controller/prepare_item_for_response