WP_REST_Templates_Controller::get_template_fallback()
Returns the fallback template for the given slug.
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_template_fallback( $request );
- $request(WP_REST_Request) (required)
- The request instance.
Changelog
Since 6.1.0 | Introduced. |
Since 6.3.0 | Ignore empty templates. |
WP_REST_Templates_Controller::get_template_fallback() WP REST Templates Controller::get template fallback code WP 6.7.1
public function get_template_fallback( $request ) { $hierarchy = get_template_hierarchy( $request['slug'], $request['is_custom'], $request['template_prefix'] ); do { $fallback_template = resolve_block_template( $request['slug'], $hierarchy, '' ); array_shift( $hierarchy ); } while ( ! empty( $hierarchy ) && empty( $fallback_template->content ) ); // To maintain original behavior, return an empty object rather than a 404 error when no template is found. $response = $fallback_template ? $this->prepare_item_for_response( $fallback_template, $request ) : new stdClass(); return rest_ensure_response( $response ); }