Editor: allow filtering block patterns by source.

Extends the REST API endpoint for block patterns to provide a source attribute that can be used to filter patterns.

Props aaronrobertshaw, mukesh27, talldanwp, ramonopoly.
Fixes 58622.


git-svn-id: https://develop.svn.wordpress.org/trunk@56063 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Isabel Brison
2023-06-27 11:11:02 +00:00
parent 27cee0b0d1
commit c27f776a6a
3 changed files with 33 additions and 5 deletions
@@ -76,6 +76,7 @@ class Tests_REST_WpRestBlockPatternsController extends WP_Test_REST_Controller_T
'viewportWidth' => 1440,
'categories' => array( 'test' ),
'templateTypes' => array( 'page' ),
'source' => 'theme',
)
);
@@ -86,6 +87,7 @@ class Tests_REST_WpRestBlockPatternsController extends WP_Test_REST_Controller_T
'content' => '<!-- wp:paragraph --><p>Two</p><!-- /wp:paragraph -->',
'categories' => array( 'test' ),
'templateTypes' => array( 'single' ),
'source' => 'core',
)
);
@@ -95,6 +97,7 @@ class Tests_REST_WpRestBlockPatternsController extends WP_Test_REST_Controller_T
'title' => 'Pattern Three',
'content' => '<!-- wp:paragraph --><p>Three</p><!-- /wp:paragraph -->',
'categories' => array( 'test', 'buttons', 'query' ),
'source' => 'pattern-directory/featured',
)
);
}
@@ -124,7 +127,7 @@ class Tests_REST_WpRestBlockPatternsController extends WP_Test_REST_Controller_T
wp_set_current_user( self::$admin_id );
$request = new WP_REST_Request( 'GET', static::REQUEST_ROUTE );
$request['_fields'] = 'name,content,template_types';
$request['_fields'] = 'name,content,source,template_types';
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
@@ -135,6 +138,7 @@ class Tests_REST_WpRestBlockPatternsController extends WP_Test_REST_Controller_T
'name' => 'test/one',
'content' => '<!-- wp:heading {"level":1} --><h1>One</h1><!-- /wp:heading -->',
'template_types' => array( 'page' ),
'source' => 'theme',
),
$data[0],
'WP_REST_Block_Patterns_Controller::get_items() should return test/one'
@@ -144,6 +148,7 @@ class Tests_REST_WpRestBlockPatternsController extends WP_Test_REST_Controller_T
'name' => 'test/two',
'content' => '<!-- wp:paragraph --><p>Two</p><!-- /wp:paragraph -->',
'template_types' => array( 'single' ),
'source' => 'core',
),
$data[1],
'WP_REST_Block_Patterns_Controller::get_items() should return test/two'