From 49c1d2066c345ed69ea4de8938e99346a6b9dd52 Mon Sep 17 00:00:00 2001 From: jorgefilipecosta Date: Tue, 31 Jan 2023 16:49:16 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@55168 git-svn-id: http://core.svn.wordpress.org/trunk@54701 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/block-patterns.php | 4 +++- .../endpoints/class-wp-rest-block-patterns-controller.php | 7 +++++++ wp-includes/version.php | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/wp-includes/block-patterns.php b/wp-includes/block-patterns.php index da35e019b4..05bb6817eb 100644 --- a/wp-includes/block-patterns.php +++ b/wp-includes/block-patterns.php @@ -302,6 +302,7 @@ function _register_remote_theme_patterns() { * - Keywords (comma-separated values) * - Block Types (comma-separated values) * - Post Types (comma-separated values) + * - Template Types (comma-separated values) * - Inserter (yes/no) * * @since 6.0.0 @@ -318,6 +319,7 @@ function _register_theme_block_patterns() { 'blockTypes' => 'Block Types', 'postTypes' => 'Post Types', 'inserter' => 'Inserter', + 'templateTypes' => 'Template Types', ); /* @@ -388,7 +390,7 @@ function _register_theme_block_patterns() { } // For properties of type array, parse data as comma-separated. - foreach ( array( 'categories', 'keywords', 'blockTypes', 'postTypes' ) as $property ) { + foreach ( array( 'categories', 'keywords', 'blockTypes', 'postTypes', 'templateTypes' ) as $property ) { if ( ! empty( $pattern_data[ $property ] ) ) { $pattern_data[ $property ] = array_filter( preg_split( diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-block-patterns-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-block-patterns-controller.php index adc4a0aade..4d50bfae04 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-block-patterns-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-block-patterns-controller.php @@ -173,6 +173,7 @@ class WP_REST_Block_Patterns_Controller extends WP_REST_Controller { 'keywords' => 'keywords', 'content' => 'content', 'inserter' => 'inserter', + 'templateTypes' => 'template_types', ); $data = array(); foreach ( $keys as $item_key => $rest_key ) { @@ -248,6 +249,12 @@ class WP_REST_Block_Patterns_Controller extends WP_REST_Controller { 'readonly' => true, 'context' => array( 'view', 'edit', 'embed' ), ), + 'template_types' => array( + 'description' => __( 'An array of template types where the pattern fits.' ), + 'type' => 'array', + 'readonly' => true, + 'context' => array( 'view', 'edit', 'embed' ), + ), 'content' => array( 'description' => __( 'The pattern content.' ), 'type' => 'string', diff --git a/wp-includes/version.php b/wp-includes/version.php index ca5b8727d5..87dc3dfc7b 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.2-alpha-55167'; +$wp_version = '6.2-alpha-55168'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.