Make WordPress Core

Changeset 54860


Ignore:
Timestamp:
11/21/2022 04:48:33 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Site Editor: Show correct theme per template or template part.

Child themes inherit templates and template parts from the parent theme. In Site Editor, the "Added by" column for a template defaults to displaying the child theme, even though it is inherited from the parent, creating confusion as to where the actual templates are located.

This commit ensures that the parent theme is correctly displayed in that scenario.

Follow-up to [51003], [52062].

Props ptahdunbar, WoutPitje, petaryoast, costdev, poena, audrasjb, SergeyBiryukov.
Fixes #55437.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-template-utils.php

    r54831 r54860  
    504504    $template                 = new WP_Block_Template();
    505505    $template->id             = $theme . '//' . $template_file['slug'];
    506     $template->theme          = $theme;
     506    $template->theme          = ! empty( $template_file['theme'] ) ? $template_file['theme'] : $theme;
    507507    $template->content        = _inject_theme_attribute_in_block_template_content( $template_content );
    508508    $template->slug           = $template_file['slug'];
  • trunk/tests/phpunit/tests/block-template-utils.php

    r54402 r54860  
    124124    }
    125125
     126    /**
     127     * Tests that _build_block_template_result_from_post() returns the correct theme
     128     * for the template when a child theme is active.
     129     *
     130     * @ticket 55437
     131     *
     132     * @covers ::_build_block_template_result_from_post
     133     */
     134    function test_build_block_template_result_from_post_with_child_theme() {
     135        switch_theme( 'block-theme-child' );
     136
     137        $template = _build_block_template_result_from_post(
     138            self::$template_post,
     139            'wp_template'
     140        );
     141
     142        $this->assertSame( self::TEST_THEME, $template->theme );
     143    }
     144
    126145    function test_build_block_template_result_from_file() {
    127146        $template = _build_block_template_result_from_file(
     
    160179        $this->assertSame( 'wp_template_part', $template_part->type );
    161180        $this->assertSame( WP_TEMPLATE_PART_AREA_HEADER, $template_part->area );
     181    }
     182
     183    /**
     184     * Tests that _build_block_template_result_from_file() returns the correct theme
     185     * for the template when a child theme is active.
     186     *
     187     * @ticket 55437
     188     *
     189     * @covers ::_build_block_template_result_from_file
     190     */
     191    function test_build_block_template_result_from_file_with_child_theme() {
     192        switch_theme( 'block-theme-child' );
     193
     194        $template = _build_block_template_result_from_file(
     195            array(
     196                'slug'  => 'single',
     197                'path'  => __DIR__ . '/../data/templates/template.html',
     198                'theme' => self::TEST_THEME,
     199            ),
     200            'wp_template'
     201        );
     202
     203        $this->assertSame( self::TEST_THEME, $template->theme );
    162204    }
    163205
Note: See TracChangeset for help on using the changeset viewer.