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 Apr 20, 2024
1 parent 0926d97 commit 91434e7
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 @@ -84,6 +84,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 @@ -615,10 +615,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 91434e7

Please sign in to comment.