Skip to content

Commit

Permalink
Custom Templates: Use title from the theme.json (#35592)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka authored Oct 18, 2021
1 parent 7da0f6d commit ec67990
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions lib/full-site-editing/block-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -107,15 +112,37 @@ 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 );
}
}
}

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.
*
Expand Down

0 comments on commit ec67990

Please sign in to comment.