Make WordPress Core


Ignore:
Timestamp:
09/15/2022 10:26:28 PM (2 years ago)
Author:
hellofromTonya
Message:

Editor: Fix get_block_templates() to get templates for a post type.

When a post type is passed to get_block_templates() in the query, return only the templates that match that post type.

Fixes an issue where:

  • when a block template provided by a theme has been edited by the user
  • and that template has specific defined postTypes
  • but after editing, the template was available for all post types.

Follow-up to [52062].

Props aljullu, bernhard-reiter, hellofromTonya.
Fixes #55881.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php

    r54036 r54184  
    155155            $theme_data->get_settings()
    156156        );
    157         $this->assertSameSets(
    158             array(
    159                 'page-home' => array(
    160                     'title'     => 'Szablon strony głównej',
    161                     'postTypes' => array( 'page' ),
    162                 ),
    163             ),
    164             $theme_data->get_custom_templates()
     157
     158        $custom_templates = $theme_data->get_custom_templates();
     159        $this->assertArrayHasKey( 'page-home', $custom_templates );
     160        $this->assertSame(
     161            $custom_templates['page-home'],
     162            array(
     163                'title'     => 'Szablon strony głównej',
     164                'postTypes' => array( 'page' ),
     165            )
    165166        );
    166167        $this->assertSameSets(
     
    341342            WP_Theme_JSON_Resolver::get_theme_data()->get_custom_templates(),
    342343            array(
    343                 'page-home' => array(
     344                'page-home'                   => array(
    344345                    'title'     => 'Homepage',
    345346                    'postTypes' => array( 'page' ),
     347                ),
     348                'custom-single-post-template' => array(
     349                    'title'     => 'Custom Single Post template',
     350                    'postTypes' => array( 'post' ),
    346351                ),
    347352            )
Note: See TracChangeset for help on using the changeset viewer.