Make WordPress Core


Ignore:
Timestamp:
04/08/2024 04:45:22 PM (15 months ago)
Author:
jorgefilipecosta
Message:

Honor template_hierarchy filters when creating a template in the Site Editor.

Currently, in blocks themes it's possible to use the ${type}_template_hierarchy filter to alter the template hierarchy. However, those filters are not taken into consideration by the Choose a pattern popup screen that appears when creating a new template in the Site Editor, causing a mismatch between the editor and the frontend.

Props aljullu, mukesh27, ntsekouras, jorgefilipecosta, gziolo.
Fixes #60846.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/block-templates/getTemplateHierarchy.php

    r55194 r57944  
    4242
    4343    /**
     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    /**
    4458     * Data provider.
    4559     *
Note: See TracChangeset for help on using the changeset viewer.