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:
parent
6619429fc3
commit
54c97ab015
|
@ -150,14 +150,21 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
|
||||||
* Returns the fallback template for the given slug.
|
* Returns the fallback template for the given slug.
|
||||||
*
|
*
|
||||||
* @since 6.1.0
|
* @since 6.1.0
|
||||||
|
* @since 6.3.0 Ignore empty templates.
|
||||||
*
|
*
|
||||||
* @param WP_REST_Request $request The request instance.
|
* @param WP_REST_Request $request The request instance.
|
||||||
* @return WP_REST_Response|WP_Error
|
* @return WP_REST_Response|WP_Error
|
||||||
*/
|
*/
|
||||||
public function get_template_fallback( $request ) {
|
public function get_template_fallback( $request ) {
|
||||||
$hierarchy = get_template_hierarchy( $request['slug'], $request['is_custom'], $request['template_prefix'] );
|
$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 );
|
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 );
|
return rest_ensure_response( $response );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue