Skip to content

Commit 4fbb3b9

Browse files
Editor: Add post types property to wp-rest-block-patterns-controller.php.
Backports PHP changes in WordPress/gutenberg#41791 to the core. Adds the post types property to the rest API patterns endpoint. Props mcsf, ntsekouras, matveb. See #56467. git-svn-id: https://develop.svn.wordpress.org/trunk@54263 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6663deb commit 4fbb3b9

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/wp-includes/block-patterns.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ function _register_remote_theme_patterns() {
189189
* - Categories (comma-separated values)
190190
* - Keywords (comma-separated values)
191191
* - Block Types (comma-separated values)
192+
* - Post Types (comma-separated values)
192193
* - Inserter (yes/no)
193194
*
194195
* @since 6.0.0
@@ -203,6 +204,7 @@ function _register_theme_block_patterns() {
203204
'categories' => 'Categories',
204205
'keywords' => 'Keywords',
205206
'blockTypes' => 'Block Types',
207+
'postTypes' => 'Post Types',
206208
'inserter' => 'Inserter',
207209
);
208210

@@ -274,7 +276,7 @@ function _register_theme_block_patterns() {
274276
}
275277

276278
// For properties of type array, parse data as comma-separated.
277-
foreach ( array( 'categories', 'keywords', 'blockTypes' ) as $property ) {
279+
foreach ( array( 'categories', 'keywords', 'blockTypes', 'postTypes' ) as $property ) {
278280
if ( ! empty( $pattern_data[ $property ] ) ) {
279281
$pattern_data[ $property ] = array_filter(
280282
preg_split(

src/wp-includes/rest-api/endpoints/class-wp-rest-block-patterns-controller.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public function prepare_item_for_response( $item, $request ) {
124124
'description' => 'description',
125125
'viewportWidth' => 'viewport_width',
126126
'blockTypes' => 'block_types',
127+
'postTypes' => 'post_types',
127128
'categories' => 'categories',
128129
'keywords' => 'keywords',
129130
'content' => 'content',
@@ -185,6 +186,12 @@ public function get_item_schema() {
185186
'readonly' => true,
186187
'context' => array( 'view', 'edit', 'embed' ),
187188
),
189+
'post_types' => array(
190+
'description' => __( ' An array of post types that the pattern is restricted to be used with.' ),
191+
'type' => 'array',
192+
'readonly' => true,
193+
'context' => array( 'view', 'edit', 'embed' ),
194+
),
188195
'categories' => array(
189196
'description' => __( 'The pattern category slugs.' ),
190197
'type' => 'array',

0 commit comments

Comments
 (0)