Make WordPress Core


Ignore:
Timestamp:
06/27/2023 05:34:12 AM (3 years ago)
Author:
isabel_brison
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php

    r55992 r56051  
    151151     *
    152152     * @since 6.1.0
     153     * @since 6.3.0 Ignore empty templates.
    153154     *
    154155     * @param WP_REST_Request $request The request instance.
     
    156157     */
    157158    public function get_template_fallback( $request ) {
    158         $hierarchy         = get_template_hierarchy( $request['slug'], $request['is_custom'], $request['template_prefix'] );
    159         $fallback_template = resolve_block_template( $request['slug'], $hierarchy, '' );
    160         $response          = $this->prepare_item_for_response( $fallback_template, $request );
     159        $hierarchy = get_template_hierarchy( $request['slug'], $request['is_custom'], $request['template_prefix'] );
     160
     161        do {
     162            $fallback_template = resolve_block_template( $request['slug'], $hierarchy, '' );
     163            array_shift( $hierarchy );
     164        } while ( ! empty( $hierarchy ) && empty( $fallback_template->content ) );
     165
     166        $response = $this->prepare_item_for_response( $fallback_template, $request );
     167
    161168        return rest_ensure_response( $response );
    162169    }
Note: See TracChangeset for help on using the changeset viewer.