Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Fix: Display the correct title for templates from theme #6452

Merged
merged 5 commits into from Jun 21, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/BlockTemplatesController.php
Expand Up @@ -184,6 +184,28 @@ public function add_block_templates( $query_result, $query, $template_type ) {
// We need to remove theme (i.e. filesystem) templates that have the same slug as a customised one.
// This only affects saved templates that were saved BEFORE a theme template with the same slug was added.
$query_result = BlockTemplateUtils::remove_theme_templates_with_custom_alternative( $query_result );

/**
* WC templates from theme aren't included in `$this->get_block_templates()` but are handled by Gutenberg.
* We need to do additional search through all templates file to update title and description for WC
* templates that aren't listed in theme.json.
*/
$query_result = array_map(
function( $template ) {
if ( 'theme' === $template->origin ) {
return $template;
}
if ( $template->title === $template->slug ) {
$template->title = BlockTemplateUtils::get_block_template_title( $template->slug );
}
if ( ! $template->description ) {
$template->description = BlockTemplateUtils::get_block_template_description( $template->slug );
}
return $template;
},
$query_result
);

return $query_result;
}

Expand Down