Skip to content

Commit

Permalink
Editor: Add post types property to wp-rest-block-patterns-controller.…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
jorgefilipecosta committed Sep 20, 2022
1 parent 6663deb commit 4fbb3b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/wp-includes/block-patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ function _register_remote_theme_patterns() {
* - Categories (comma-separated values)
* - Keywords (comma-separated values)
* - Block Types (comma-separated values)
* - Post Types (comma-separated values)
* - Inserter (yes/no)
*
* @since 6.0.0
Expand All @@ -203,6 +204,7 @@ function _register_theme_block_patterns() {
'categories' => 'Categories',
'keywords' => 'Keywords',
'blockTypes' => 'Block Types',
'postTypes' => 'Post Types',
'inserter' => 'Inserter',
);

Expand Down Expand Up @@ -274,7 +276,7 @@ function _register_theme_block_patterns() {
}

// For properties of type array, parse data as comma-separated.
foreach ( array( 'categories', 'keywords', 'blockTypes' ) as $property ) {
foreach ( array( 'categories', 'keywords', 'blockTypes', 'postTypes' ) as $property ) {
if ( ! empty( $pattern_data[ $property ] ) ) {
$pattern_data[ $property ] = array_filter(
preg_split(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public function prepare_item_for_response( $item, $request ) {
'description' => 'description',
'viewportWidth' => 'viewport_width',
'blockTypes' => 'block_types',
'postTypes' => 'post_types',
'categories' => 'categories',
'keywords' => 'keywords',
'content' => 'content',
Expand Down Expand Up @@ -185,6 +186,12 @@ public function get_item_schema() {
'readonly' => true,
'context' => array( 'view', 'edit', 'embed' ),
),
'post_types' => array(
'description' => __( ' An array of post types that the pattern is restricted to be used with.' ),
'type' => 'array',
'readonly' => true,
'context' => array( 'view', 'edit', 'embed' ),
),
'categories' => array(
'description' => __( 'The pattern category slugs.' ),
'type' => 'array',
Expand Down

0 comments on commit 4fbb3b9

Please sign in to comment.