Changeset 52247
- Timestamp:
- 11/25/2021 10:57:19 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 2 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-template-utils.php
r52110 r52247 19 19 if ( ! defined( 'WP_TEMPLATE_PART_AREA_UNCATEGORIZED' ) ) { 20 20 define( 'WP_TEMPLATE_PART_AREA_UNCATEGORIZED', 'uncategorized' ); 21 } 22 23 /** 24 * For backward compatibility reasons, 25 * block themes might be using block-templates or block-template-parts, 26 * this function ensures we fallback to these folders properly. 27 * 28 * @since 5.9.0 29 * 30 * @param string $theme_stylesheet The stylesheet. Default is to leverage the main theme root. 31 * 32 * @return array Folder names used by block themes. 33 */ 34 function get_block_theme_folders( $theme_stylesheet = null ) { 35 $theme_name = null === $theme_stylesheet ? get_stylesheet() : $theme_stylesheet; 36 $root_dir = get_theme_root( $theme_name ); 37 $theme_dir = "$root_dir/$theme_name"; 38 39 if ( is_readable( $theme_dir . '/block-templates/index.html' ) ) { 40 return array( 41 'wp_template' => 'block-templates', 42 'wp_template_part' => 'block-template-parts', 43 ); 44 } 45 46 return array( 47 'wp_template' => 'templates', 48 'wp_template_part' => 'parts', 49 ); 21 50 } 22 51 … … 225 254 } 226 255 227 $template_base_paths = array( 228 'wp_template' => 'block-templates', 229 'wp_template_part' => 'block-template-parts', 230 ); 231 $themes = array( 256 $themes = array( 232 257 get_stylesheet() => get_stylesheet_directory(), 233 258 get_template() => get_template_directory(), 234 259 ); 235 260 foreach ( $themes as $theme_slug => $theme_dir ) { 236 $file_path = $theme_dir . '/' . $template_base_paths[ $template_type ] . '/' . $slug . '.html'; 261 $template_base_paths = get_block_theme_folders( $theme_slug ); 262 $file_path = $theme_dir . '/' . $template_base_paths[ $template_type ] . '/' . $slug . '.html'; 237 263 if ( file_exists( $file_path ) ) { 238 264 $new_template_item = array( … … 273 299 } 274 300 275 $template_base_paths = array( 276 'wp_template' => 'block-templates', 277 'wp_template_part' => 'block-template-parts', 278 ); 279 $themes = array( 301 $themes = array( 280 302 get_stylesheet() => get_stylesheet_directory(), 281 303 get_template() => get_template_directory(), 282 304 ); 283 284 305 $template_files = array(); 285 306 foreach ( $themes as $theme_slug => $theme_dir ) { 307 $template_base_paths = get_block_theme_folders( $theme_slug ); 286 308 $theme_template_files = _get_block_templates_paths( $theme_dir . '/' . $template_base_paths[ $template_type ] ); 287 309 foreach ( $theme_template_files as $template_file ) { -
trunk/src/wp-includes/theme.php
r52110 r52247 4085 4085 */ 4086 4086 function wp_is_block_template_theme() { 4087 return is_readable( get_theme_file_path( '/block-templates/index.html' ) ); 4088 } 4087 return is_readable( get_theme_file_path( '/block-templates/index.html' ) ) || 4088 is_readable( get_theme_file_path( '/templates/index.html' ) ); 4089 } -
trunk/tests/phpunit/tests/block-template.php
r52246 r52247 38 38 $resolved_template_path = locate_block_template( get_stylesheet_directory() . '/page-home.php', $type, $templates ); 39 39 $this->assertEquals( self::$template_canvas_path, $resolved_template_path ); 40 $this->assertStringEqualsFile( get_stylesheet_directory() . '/ block-templates/page-home.html', $_wp_current_template_content );40 $this->assertStringEqualsFile( get_stylesheet_directory() . '/templates/page-home.html', $_wp_current_template_content ); 41 41 } 42 42 … … 51 51 $resolved_template_path = locate_block_template( get_stylesheet_directory() . '/page.php', $type, $templates ); 52 52 $this->assertEquals( self::$template_canvas_path, $resolved_template_path ); 53 $this->assertStringEqualsFile( get_stylesheet_directory() . '/ block-templates/page.html', $_wp_current_template_content );53 $this->assertStringEqualsFile( get_stylesheet_directory() . '/templates/page.html', $_wp_current_template_content ); 54 54 } 55 55 … … 62 62 $resolved_template_path = locate_block_template( get_stylesheet_directory() . '/index.php', $type, $templates ); 63 63 $this->assertEquals( self::$template_canvas_path, $resolved_template_path ); 64 $this->assertStringEqualsFile( get_stylesheet_directory() . '/ block-templates/index.html', $_wp_current_template_content );64 $this->assertStringEqualsFile( get_stylesheet_directory() . '/templates/index.html', $_wp_current_template_content ); 65 65 } 66 66 … … 129 129 $resolved_template_path = locate_block_template( $parent_theme_page_template_path, $type, $templates ); 130 130 $this->assertEquals( self::$template_canvas_path, $resolved_template_path ); 131 $this->assertStringEqualsFile( get_stylesheet_directory() . '/ block-templates/page-1.html', $_wp_current_template_content );131 $this->assertStringEqualsFile( get_stylesheet_directory() . '/templates/page-1.html', $_wp_current_template_content ); 132 132 } 133 133
Note: See TracChangeset
for help on using the changeset viewer.