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.

Reviewed by joemcgill.
Merges [58079] to the 6.5 branch.

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

Built from https://develop.svn.wordpress.org/branches/6.5@58080


git-svn-id: http://core.svn.wordpress.org/branches/6.5@57545 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Aaron Jorbin 2024-05-02 16:29:14 +00:00
parent 4546b73afb
commit e19f9d5d06
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.5.3-alpha-58078';
$wp_version = '6.5.3-alpha-58080';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.