Changeset 55194 for trunk/src/wp-includes/block-template-utils.php
- Timestamp:
- 02/02/2023 07:36:29 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-template-utils.php
r55086 r55194 1326 1326 } 1327 1327 1328 $matches = array(); 1329 1328 1330 $template_hierarchy = array( $slug ); 1329 1330 1331 // Most default templates don't have `$template_prefix` assigned. 1331 if ( $template_prefix) {1332 if ( ! empty( $template_prefix ) ) { 1332 1333 list( $type ) = explode( '-', $template_prefix ); 1333 // These checks are needed because the `$slug` above is always added.1334 // We need these checks because we always add the `$slug` above. 1334 1335 if ( ! in_array( $template_prefix, array( $slug, $type ), true ) ) { 1335 1336 $template_hierarchy[] = $template_prefix; … … 1338 1339 $template_hierarchy[] = $type; 1339 1340 } 1340 } 1341 1341 } else if ( preg_match( '/^(author|category|archive|tag|page)-.+$/', $slug, $matches ) ) { 1342 $template_hierarchy[] = $matches[1]; 1343 } else if ( preg_match( '/^(taxonomy|single)-(.+)$/', $slug, $matches ) ) { 1344 $type = $matches[1]; 1345 $slug_remaining = $matches[2]; 1346 1347 $items = 'single' === $type ? get_post_types() : get_taxonomies(); 1348 foreach ( $items as $item ) { 1349 if ( ! str_starts_with( $slug_remaining, $item ) ) { 1350 continue; 1351 } 1352 1353 // If $slug_remaining is equal to $post_type or $taxonomy we have 1354 // the single-$post_type template or the taxonomy-$taxonomy template. 1355 if ( $slug_remaining === $item ) { 1356 $template_hierarchy[] = $type; 1357 break; 1358 } 1359 1360 // If $slug_remaining is single-$post_type-$slug template. 1361 if ( strlen( $slug_remaining ) > strlen( $item ) + 1 ) { 1362 $template_hierarchy[] = "$type-$item"; 1363 $template_hierarchy[] = $type; 1364 break; 1365 } 1366 } 1367 } 1342 1368 // Handle `archive` template. 1343 1369 if ( … … 1354 1380 $template_hierarchy[] = 'single'; 1355 1381 } 1356 1357 1382 // Handle `singular` template. 1358 1383 if ( … … 1363 1388 $template_hierarchy[] = 'singular'; 1364 1389 } 1365 1366 1390 $template_hierarchy[] = 'index'; 1367 1368 1391 return $template_hierarchy; 1369 1392 }
Note: See TracChangeset
for help on using the changeset viewer.