Changeset 57944
- Timestamp:
- 04/08/2024 04:45:22 PM (5 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-template-utils.php
r57928 r57944 1398 1398 function get_template_hierarchy( $slug, $is_custom = false, $template_prefix = '' ) { 1399 1399 if ( 'index' === $slug ) { 1400 return array( 'index' ); 1400 /** This filter is documented in wp-includes/template.php */ 1401 return apply_filters( 'index_template_hierarchy', array( 'index' ) ); 1401 1402 } 1402 1403 if ( $is_custom ) { 1403 return array( 'page', 'singular', 'index' ); 1404 /** This filter is documented in wp-includes/template.php */ 1405 return apply_filters( 'page_template_hierarchy', array( 'page', 'singular', 'index' ) ); 1404 1406 } 1405 1407 if ( 'front-page' === $slug ) { 1406 return array( 'front-page', 'home', 'index' ); 1408 /** This filter is documented in wp-includes/template.php */ 1409 return apply_filters( 'frontpage_template_hierarchy', array( 'front-page', 'home', 'index' ) ); 1407 1410 } 1408 1411 … … 1470 1473 } 1471 1474 $template_hierarchy[] = 'index'; 1475 1476 $template_type = ''; 1477 if ( ! empty( $template_prefix ) ) { 1478 list( $template_type ) = explode( '-', $template_prefix ); 1479 } else { 1480 list( $template_type ) = explode( '-', $slug ); 1481 } 1482 $valid_template_types = array( '404', 'archive', 'attachment', 'author', 'category', 'date', 'embed', 'frontpage', 'home', 'index', 'page', 'paged', 'privacypolicy', 'search', 'single', 'singular', 'tag', 'taxonomy' ); 1483 if ( in_array( $template_type, $valid_template_types ) ) { 1484 /** This filter is documented in wp-includes/template.php */ 1485 return apply_filters( "{$template_type}_template_hierarchy", $template_hierarchy ); 1486 } 1472 1487 return $template_hierarchy; 1473 1488 } -
trunk/tests/phpunit/tests/block-templates/getTemplateHierarchy.php
r55194 r57944 42 42 43 43 /** 44 * @ticket 60846 45 */ 46 public function test_get_template_hierarchy_with_hooks() { 47 add_filter( 48 'date_template_hierarchy', 49 function ( $templates ) { 50 return array_merge( array( 'date-custom' ), $templates ); 51 } 52 ); 53 $expected = array( 'date-custom', 'date', 'archive', 'index' ); 54 $this->assertSame( $expected, get_template_hierarchy( 'date' ) ); 55 } 56 57 /** 44 58 * Data provider. 45 59 *
Note: See TracChangeset
for help on using the changeset viewer.