Make WordPress Core


Ignore:
Timestamp:
05/02/2024 04:01:29 PM (9 months ago)
Author:
jorbin
Message:

REST API: Return empty object when no fallback templates are found (wp/v2/templates/lookup)

This prevents a number of php notices that are surfaced due to the endpoint being called on load of the post editor even when there are no templates.

Props grantmkin, CookiesForDevo, britner, wildworks, jorbin.
Fixes #60909.

File:
1 edited

Legend:

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

    r57919 r58079  
    166166        } while ( ! empty( $hierarchy ) && empty( $fallback_template->content ) );
    167167
    168         $response = $this->prepare_item_for_response( $fallback_template, $request );
     168        // To maintain original behavior, return an empty object rather than a 404 error when no template is found.
     169        $response = $fallback_template ? $this->prepare_item_for_response( $fallback_template, $request ) : new stdClass();
    169170
    170171        return rest_ensure_response( $response );
Note: See TracChangeset for help on using the changeset viewer.