Make WordPress Core


Ignore:
Timestamp:
12/02/2021 11:35:20 PM (2 years ago)
Author:
audrasjb
Message:

Editor: Allow child theme PHP templates to take precedence over parent theme block templates.

This change fixes template resolution to give precedence to child theme PHP templates over parent theme block templates with equal specificity.

Before this change, when a theme was using a PHP template of a certain specificity (e.g. page-home.php), and it happened to be a child theme of another theme which had a block template for the same specificity (e.g. page-home.html), WordPress was picking the parent theme’s block template over the child theme’s PHP template to render the page. If the PHP and block template have equal specificity, the child theme's template should be used.

The issue was fixed before in Gutenberg so the fix now needs to happen in Core.

This change also re-enables the preexisting template resolution unit tests.

Follow-up to [51003].

Props bernhard-reiter, youknowriad.
Fixes #54515.

File:
1 edited

Legend:

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

    r52266 r52308  
    9090     *
    9191     * Covers https://github.com/WordPress/gutenberg/pull/31123.
     92     * Covers https://core.trac.wordpress.org/ticket/54515.
    9293     *
    9394     */
    9495    function test_child_theme_php_template_takes_precedence_over_equally_specific_parent_theme_block_template() {
    95         /**
    96          * @todo This test is currently marked as skipped, since it wouldn't pass. Turns out that in Gutenberg,
    97          * it only passed due to a erroneous test setup.
    98          * For details, see https://github.com/WordPress/wordpress-develop/pull/1920#issuecomment-975929818.
    99          */
    100         $this->markTestSkipped( 'The block template resolution algorithm needs fixing in order for this test to pass.' );
    101 
    10296        switch_theme( 'block-theme-child' );
    10397
Note: See TracChangeset for help on using the changeset viewer.