Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Templates: Use "title" from the theme.json #35592

Merged
merged 1 commit into from
Oct 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 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 Expand Up @@ -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;

Expand Down