Changeset 52247 for trunk/src/wp-includes/block-template-utils.php
- Timestamp:
- 11/25/2021 10:57:19 AM (4 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/block-template-utils.php (modified) (3 diffs)
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 ) {
Note: See TracChangeset
for help on using the changeset viewer.