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

Commit c952fa1

Browse files
authored
Fix: Display the correct title for templates from theme (#6452)
1 parent b6caa1d commit c952fa1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/BlockTemplatesController.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,28 @@ public function add_block_templates( $query_result, $query, $template_type ) {
184184
// We need to remove theme (i.e. filesystem) templates that have the same slug as a customised one.
185185
// This only affects saved templates that were saved BEFORE a theme template with the same slug was added.
186186
$query_result = BlockTemplateUtils::remove_theme_templates_with_custom_alternative( $query_result );
187+
188+
/**
189+
* WC templates from theme aren't included in `$this->get_block_templates()` but are handled by Gutenberg.
190+
* We need to do additional search through all templates file to update title and description for WC
191+
* templates that aren't listed in theme.json.
192+
*/
193+
$query_result = array_map(
194+
function( $template ) {
195+
if ( 'theme' === $template->origin ) {
196+
return $template;
197+
}
198+
if ( $template->title === $template->slug ) {
199+
$template->title = BlockTemplateUtils::get_block_template_title( $template->slug );
200+
}
201+
if ( ! $template->description ) {
202+
$template->description = BlockTemplateUtils::get_block_template_description( $template->slug );
203+
}
204+
return $template;
205+
},
206+
$query_result
207+
);
208+
187209
return $query_result;
188210
}
189211

0 commit comments

Comments
 (0)