From ee44500e17b466a652fb4c9dc0f1e14c98bda286 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Thu, 2 May 2024 16:03:14 +0000 Subject: [PATCH] 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 --- .../rest-api/endpoints/class-wp-rest-templates-controller.php | 3 ++- wp-includes/version.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php index 9eb64707ae..1c2a7697c4 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php @@ -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 ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 36103aa4d2..f001d823c4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.