From 4fbb3b91a172741bdf79ca982ebd56d01f7d5fe0 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Tue, 20 Sep 2022 16:27:44 +0000 Subject: [PATCH] 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 --- src/wp-includes/block-patterns.php | 4 +++- .../endpoints/class-wp-rest-block-patterns-controller.php | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/block-patterns.php b/src/wp-includes/block-patterns.php index 91d239db52..074ed33c84 100644 --- a/src/wp-includes/block-patterns.php +++ b/src/wp-includes/block-patterns.php @@ -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 @@ -203,6 +204,7 @@ function _register_theme_block_patterns() { 'categories' => 'Categories', 'keywords' => 'Keywords', 'blockTypes' => 'Block Types', + 'postTypes' => 'Post Types', 'inserter' => 'Inserter', ); @@ -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( diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-patterns-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-block-patterns-controller.php index 15a7c28279..60064abf05 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-patterns-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-block-patterns-controller.php @@ -124,6 +124,7 @@ class WP_REST_Block_Patterns_Controller extends WP_REST_Controller { 'description' => 'description', 'viewportWidth' => 'viewport_width', 'blockTypes' => 'block_types', + 'postTypes' => 'post_types', 'categories' => 'categories', 'keywords' => 'keywords', 'content' => 'content', @@ -185,6 +186,12 @@ class WP_REST_Block_Patterns_Controller extends WP_REST_Controller { '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',