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
This commit is contained in:
parent
5a6c222bfa
commit
49c1d2066c
|
@ -302,6 +302,7 @@ function _register_remote_theme_patterns() {
|
||||||
* - Keywords (comma-separated values)
|
* - Keywords (comma-separated values)
|
||||||
* - Block Types (comma-separated values)
|
* - Block Types (comma-separated values)
|
||||||
* - Post Types (comma-separated values)
|
* - Post Types (comma-separated values)
|
||||||
|
* - Template Types (comma-separated values)
|
||||||
* - Inserter (yes/no)
|
* - Inserter (yes/no)
|
||||||
*
|
*
|
||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
|
@ -318,6 +319,7 @@ function _register_theme_block_patterns() {
|
||||||
'blockTypes' => 'Block Types',
|
'blockTypes' => 'Block Types',
|
||||||
'postTypes' => 'Post Types',
|
'postTypes' => 'Post Types',
|
||||||
'inserter' => 'Inserter',
|
'inserter' => 'Inserter',
|
||||||
|
'templateTypes' => 'Template Types',
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -388,7 +390,7 @@ function _register_theme_block_patterns() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// For properties of type array, parse data as comma-separated.
|
// 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 ] ) ) {
|
if ( ! empty( $pattern_data[ $property ] ) ) {
|
||||||
$pattern_data[ $property ] = array_filter(
|
$pattern_data[ $property ] = array_filter(
|
||||||
preg_split(
|
preg_split(
|
||||||
|
|
|
@ -173,6 +173,7 @@ class WP_REST_Block_Patterns_Controller extends WP_REST_Controller {
|
||||||
'keywords' => 'keywords',
|
'keywords' => 'keywords',
|
||||||
'content' => 'content',
|
'content' => 'content',
|
||||||
'inserter' => 'inserter',
|
'inserter' => 'inserter',
|
||||||
|
'templateTypes' => 'template_types',
|
||||||
);
|
);
|
||||||
$data = array();
|
$data = array();
|
||||||
foreach ( $keys as $item_key => $rest_key ) {
|
foreach ( $keys as $item_key => $rest_key ) {
|
||||||
|
@ -248,6 +249,12 @@ class WP_REST_Block_Patterns_Controller extends WP_REST_Controller {
|
||||||
'readonly' => true,
|
'readonly' => true,
|
||||||
'context' => array( 'view', 'edit', 'embed' ),
|
'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(
|
'content' => array(
|
||||||
'description' => __( 'The pattern content.' ),
|
'description' => __( 'The pattern content.' ),
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue