Make WordPress Core


Ignore:
Timestamp:
01/31/2023 04:47:58 PM (4 years ago)
Author:
jorgefilipecosta
Message:

Add: Template types to the patterns API.

Backports ​https://github.com/WordPress/gutenberg/pull/45814 into the core.
This commit adds a new templateType property to the patterns registration API.
This property allows a pattern to specify which template it makes sense on, e.g.: 404, single-post, single-product, category.

Props youknowriad, ntsekouras,
spacedmonkey.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/wpRestBlockPatternsController.php

    r55125 r55168  
    8282                                'viewportWidth' => 1440,
    8383                                'content'       => '<!-- wp:heading {"level":1} --><h1>One</h1><!-- /wp:heading -->',
     84                                'templateTypes' => array( 'page' ),
    8485                        )
    8586                );
    … …  
    8889                        'test/two',
    8990                        array(
    90                                 'title'      => 'Pattern Two',
    91                                 'categories' => array( 'test' ),
    92                                 'content'    => '<!-- wp:paragraph --><p>Two</p><!-- /wp:paragraph -->',
     91                                'title'         => 'Pattern Two',
     92                                'categories'    => array( 'test' ),
     93                                'content'       => '<!-- wp:paragraph --><p>Two</p><!-- /wp:paragraph -->',
     94                                'templateTypes' => array( 'single' ),
    9395                        )
    9496                );
    … …  
    129131
    130132                $request            = new WP_REST_Request( 'GET', static::REQUEST_ROUTE );
    131                 $request['_fields'] = 'name,content';
     133                $request['_fields'] = 'name,content,template_types';
    132134                $response           = rest_get_server()->dispatch( $request );
    133135                $data               = $response->get_data();
    … …  
    137139                $this->assertSame(
    138140                        array(
    139                                 'name'    => 'test/one',
    140                                 'content' => '<!-- wp:heading {"level":1} --><h1>One</h1><!-- /wp:heading -->',
     141                                'name'           => 'test/one',
     142                                'content'        => '<!-- wp:heading {"level":1} --><h1>One</h1><!-- /wp:heading -->',
     143                                'template_types' => array( 'page' ),
    141144                        ),
    142145                        $data[0],
    … …  
    145148                $this->assertSame(
    146149                        array(
    147                                 'name'    => 'test/two',
    148                                 'content' => '<!-- wp:paragraph --><p>Two</p><!-- /wp:paragraph -->',
     150                                'name'           => 'test/two',
     151                                'content'        => '<!-- wp:paragraph --><p>Two</p><!-- /wp:paragraph -->',
     152                                'template_types' => array( 'single' ),
    149153                        ),
    150154                        $data[1],
Note: See TracChangeset for help on using the changeset viewer.