REST API: ignore empty templates.

Ignore empty templates when using the `/lookup` endpoint in the `WP_REST_Templates_Controller` class.

Props ramonopoly, jorgefilipecosta, spacedmonkey, youknowriad, mukesh27.
Fixes #58615.


Built from https://develop.svn.wordpress.org/trunk@56051


git-svn-id: http://core.svn.wordpress.org/trunk@55563 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
isabel_brison 2023-06-27 05:36:22 +00:00
parent 6619429fc3
commit 54c97ab015
2 changed files with 11 additions and 4 deletions

View File

@ -150,14 +150,21 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
* Returns the fallback template for the given slug.
*
* @since 6.1.0
* @since 6.3.0 Ignore empty templates.
*
* @param WP_REST_Request $request The request instance.
* @return WP_REST_Response|WP_Error
*/
public function get_template_fallback( $request ) {
$hierarchy = get_template_hierarchy( $request['slug'], $request['is_custom'], $request['template_prefix'] );
$fallback_template = resolve_block_template( $request['slug'], $hierarchy, '' );
$response = $this->prepare_item_for_response( $fallback_template, $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 ) );
$response = $this->prepare_item_for_response( $fallback_template, $request );
return rest_ensure_response( $response );
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.3-alpha-56050';
$wp_version = '6.3-alpha-56051';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.