diff --git a/lib/full-site-editing/block-templates.php b/lib/full-site-editing/block-templates.php index 38e35d6648bc2..47cddf2163247 100644 --- a/lib/full-site-editing/block-templates.php +++ b/lib/full-site-editing/block-templates.php @@ -59,6 +59,11 @@ function _gutenberg_get_template_file( $template_type, $slug ) { if ( 'wp_template_part' === $template_type ) { return _gutenberg_add_template_part_area_info( $new_template_item ); } + + if ( 'wp_template' === $template_type ) { + return _gutenberg_add_template_info( $new_template_item ); + } + return $new_template_item; } } @@ -107,8 +112,10 @@ function _gutenberg_get_template_files( $template_type ) { if ( 'wp_template_part' === $template_type ) { $template_files[] = _gutenberg_add_template_part_area_info( $new_template_item ); - } else { - $template_files[] = $new_template_item; + } + + if ( 'wp_template' === $template_type ) { + $template_files[] = _gutenberg_add_template_info( $new_template_item ); } } } @@ -116,6 +123,26 @@ function _gutenberg_get_template_files( $template_type ) { return $template_files; } +/** + * Attempts to add custom template information to the template item. + * + * @param array $template_item Template to add information to (requires 'slug' field). + * @return array Template + */ +function _gutenberg_add_template_info( $template_item ) { + if ( ! WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) { + return $template_item; + } + + $theme_data = WP_Theme_JSON_Resolver_Gutenberg::get_theme_data()->get_custom_templates(); + if ( isset( $theme_data[ $template_item['slug'] ] ) ) { + $template_item['title'] = $theme_data[ $template_item['slug'] ]['title']; + $template_item['postTypes'] = $theme_data[ $template_item['slug'] ]['postTypes']; + } + + return $template_item; +} + /** * Attempts to add the template part's area information to the input template. * @@ -222,7 +249,7 @@ function _gutenberg_build_template_result_from_file( $template_file, $template_t $template->slug = $template_file['slug']; $template->source = 'theme'; $template->type = $template_type; - $template->title = $template_file['slug']; + $template->title = ! empty( $template_file['title'] ) ? $template_file['title'] : $template_file['slug']; $template->status = 'publish'; $template->has_theme_file = true;