Skip to content

Commit

Permalink
Templates: Search for old template names in the parent theme too (#36910
Browse files Browse the repository at this point in the history
)

* Templates: Search for old template names in the parent theme too

* check for the directory rather than the file

* Fix template part file lookup

Co-authored-by: Riad Benguella <benguella@gmail.com>
  • Loading branch information
2 people authored and noisysocks committed Dec 14, 2021
1 parent 3826b68 commit 95b4f40
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/compat/wordpress-5.9/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function get_block_theme_folders( $theme_stylesheet = null ) {
$root_dir = get_theme_root( $theme_name );
$theme_dir = "$root_dir/$theme_name";

if ( is_readable( $theme_dir . '/block-templates/index.html' ) ) {
if ( file_exists( $theme_dir . '/block-templates' ) || file_exists( $theme_dir . '/block-template-parts' ) ) {
return array(
'wp_template' => 'block-templates',
'wp_template_part' => 'block-template-parts',
Expand Down
7 changes: 5 additions & 2 deletions packages/block-library/src/template-part/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ function render_block_core_template_part( $attributes ) {
} else {
// Else, if the template part was provided by the active theme,
// render the corresponding file content.
$theme_folders = get_block_theme_folders();
$template_part_file_path = get_theme_file_path( '/' . $theme_folders['wp_template_part'] . '/' . $attributes['slug'] . '.html' );
$parent_theme_folders = get_block_theme_folders( get_template() );
$child_theme_folders = get_block_theme_folders( get_stylesheet() );
$child_theme_part_file_path = get_theme_file_path( '/' . $child_theme_folders['wp_template_part'] . '/' . $attributes['slug'] . '.html' );
$parent_theme_part_file_path = get_theme_file_path( '/' . $parent_theme_folders['wp_template_part'] . '/' . $attributes['slug'] . '.html' );
$template_part_file_path = 0 === validate_file( $attributes['slug'] ) && file_exists( $child_theme_part_file_path ) ? $child_theme_part_file_path : $parent_theme_part_file_path;
if ( 0 === validate_file( $attributes['slug'] ) && file_exists( $template_part_file_path ) ) {
$content = file_get_contents( $template_part_file_path );
$content = is_string( $content ) && '' !== $content
Expand Down

0 comments on commit 95b4f40

Please sign in to comment.