Skip to content

Commit

Permalink
Uses empty object instead of 404 status to ensure backcompat
Browse files Browse the repository at this point in the history
  • Loading branch information
creativecoder committed May 10, 2024
1 parent ff35fb0 commit db773c7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,8 @@ public function get_template_fallback( $request ) {
array_shift( $hierarchy );
} while ( ! empty( $hierarchy ) && empty( $fallback_template->content ) );

if ( ! $fallback_template ) {
return new WP_Error( 'rest_template_not_found', __( 'No fallback templates exist for that slug.', 'default' ), array( 'status' => 404 ) );
}

$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 );
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,8 @@ export const getDefaultTemplateId =
const template = await apiFetch( {
path: addQueryArgs( '/wp/v2/templates/lookup', query ),
} );
if ( template ) {
// Endpoint may return an empty object if no template is found.
if ( template?.id ) {
dispatch.receiveDefaultTemplateId( query, template.id );
}
};
Expand Down

0 comments on commit db773c7

Please sign in to comment.