diff --git a/wp-includes/block-template-utils.php b/wp-includes/block-template-utils.php index 9b248c1453..6475ac36f2 100644 --- a/wp-includes/block-template-utils.php +++ b/wp-includes/block-template-utils.php @@ -20,6 +20,35 @@ if ( ! defined( 'WP_TEMPLATE_PART_AREA_UNCATEGORIZED' ) ) { define( 'WP_TEMPLATE_PART_AREA_UNCATEGORIZED', 'uncategorized' ); } +/** + * For backward compatibility reasons, + * block themes might be using block-templates or block-template-parts, + * this function ensures we fallback to these folders properly. + * + * @since 5.9.0 + * + * @param string $theme_stylesheet The stylesheet. Default is to leverage the main theme root. + * + * @return array Folder names used by block themes. + */ +function get_block_theme_folders( $theme_stylesheet = null ) { + $theme_name = null === $theme_stylesheet ? get_stylesheet() : $theme_stylesheet; + $root_dir = get_theme_root( $theme_name ); + $theme_dir = "$root_dir/$theme_name"; + + if ( is_readable( $theme_dir . '/block-templates/index.html' ) ) { + return array( + 'wp_template' => 'block-templates', + 'wp_template_part' => 'block-template-parts', + ); + } + + return array( + 'wp_template' => 'templates', + 'wp_template_part' => 'parts', + ); +} + /** * Returns a filtered list of allowed area values for template parts. * @@ -224,16 +253,13 @@ function _get_block_template_file( $template_type, $slug ) { return null; } - $template_base_paths = array( - 'wp_template' => 'block-templates', - 'wp_template_part' => 'block-template-parts', - ); - $themes = array( + $themes = array( get_stylesheet() => get_stylesheet_directory(), get_template() => get_template_directory(), ); foreach ( $themes as $theme_slug => $theme_dir ) { - $file_path = $theme_dir . '/' . $template_base_paths[ $template_type ] . '/' . $slug . '.html'; + $template_base_paths = get_block_theme_folders( $theme_slug ); + $file_path = $theme_dir . '/' . $template_base_paths[ $template_type ] . '/' . $slug . '.html'; if ( file_exists( $file_path ) ) { $new_template_item = array( 'slug' => $slug, @@ -272,17 +298,13 @@ function _get_block_templates_files( $template_type ) { return null; } - $template_base_paths = array( - 'wp_template' => 'block-templates', - 'wp_template_part' => 'block-template-parts', - ); - $themes = array( + $themes = array( get_stylesheet() => get_stylesheet_directory(), get_template() => get_template_directory(), ); - $template_files = array(); foreach ( $themes as $theme_slug => $theme_dir ) { + $template_base_paths = get_block_theme_folders( $theme_slug ); $theme_template_files = _get_block_templates_paths( $theme_dir . '/' . $template_base_paths[ $template_type ] ); foreach ( $theme_template_files as $template_file ) { $template_base_path = $template_base_paths[ $template_type ]; diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 838fe23596..9d43d1b2a2 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -4084,5 +4084,6 @@ function create_initial_theme_features() { * @return boolean Whether the current theme is a block-based theme or not. */ function wp_is_block_template_theme() { - return is_readable( get_theme_file_path( '/block-templates/index.html' ) ); + return is_readable( get_theme_file_path( '/block-templates/index.html' ) ) || + is_readable( get_theme_file_path( '/templates/index.html' ) ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 59c2be791d..b6a5ab7305 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-52246'; +$wp_version = '5.9-alpha-52247'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.