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.

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


git-svn-id: http://core.svn.wordpress.org/trunk@57544 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Aaron Jorbin 2024-05-02 16:03:14 +00:00
parent 4551e209cd
commit ee44500e17
2 changed files with 3 additions and 2 deletions

View File

@ -165,7 +165,8 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
array_shift( $hierarchy );
} while ( ! empty( $hierarchy ) && empty( $fallback_template->content ) );
$response = $this->prepare_item_for_response( $fallback_template, $request );
// 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 );
}

View File

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