diff --git a/lib/compat/wordpress-5.9/block-template-utils.php b/lib/compat/wordpress-5.9/block-template-utils.php index 37ae365ccc4f0b..4b693237e5cad4 100644 --- a/lib/compat/wordpress-5.9/block-template-utils.php +++ b/lib/compat/wordpress-5.9/block-template-utils.php @@ -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', diff --git a/packages/block-library/src/template-part/index.php b/packages/block-library/src/template-part/index.php index 1eb8e39d780e39..20bc6900f83bb0 100644 --- a/packages/block-library/src/template-part/index.php +++ b/packages/block-library/src/template-part/index.php @@ -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