Skip to content

Commit

Permalink
Return a 404 error when no fallback templates are found (wp/v2/templa…
Browse files Browse the repository at this point in the history
…tes/lookup)
  • Loading branch information
creativecoder committed May 10, 2024
1 parent e3eab49 commit ff35fb0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ 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 );

return rest_ensure_response( $response );
Expand Down
13 changes: 8 additions & 5 deletions packages/edit-post/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,13 @@ export const getEditedPostTemplate = createRegistrySelector(
const defaultTemplateId = select( coreStore ).getDefaultTemplateId( {
slug: slugToCheck,
} );
return select( coreStore ).getEditedEntityRecord(
'postType',
'wp_template',
defaultTemplateId
);

return defaultTemplateId
? select( coreStore ).getEditedEntityRecord(
'postType',
'wp_template',
defaultTemplateId
)
: null;
}
);

0 comments on commit ff35fb0

Please sign in to comment.