mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 15:08:10 +01:00
REST API: Improve the block type schema for the name
field
Align the schema between `block.json` defined in Gutenberg and the REST API endpoint for block types. It looks like the `name` field isn't validated in all places and when it uses pattern matching in the REST API code, then it was slightly different. Props spacedmonkey, ockham. See #59346. Built from https://develop.svn.wordpress.org/trunk@56676 git-svn-id: http://core.svn.wordpress.org/trunk@56188 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
97b85f2823
commit
158f4a8fcc
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
class WP_REST_Block_Types_Controller extends WP_REST_Controller {
|
class WP_REST_Block_Types_Controller extends WP_REST_Controller {
|
||||||
|
|
||||||
|
const NAME_PATTERN = '^[a-z][a-z0-9-]*/[a-z][a-z0-9-]*$';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance of WP_Block_Type_Registry.
|
* Instance of WP_Block_Type_Registry.
|
||||||
*
|
*
|
||||||
@ -402,6 +404,8 @@ class WP_REST_Block_Types_Controller extends WP_REST_Controller {
|
|||||||
'name' => array(
|
'name' => array(
|
||||||
'description' => __( 'The name of the inner block.' ),
|
'description' => __( 'The name of the inner block.' ),
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
|
'pattern' => self::NAME_PATTERN,
|
||||||
|
'required' => true,
|
||||||
),
|
),
|
||||||
'attributes' => array(
|
'attributes' => array(
|
||||||
'description' => __( 'The attributes of the inner block.' ),
|
'description' => __( 'The attributes of the inner block.' ),
|
||||||
@ -479,7 +483,8 @@ class WP_REST_Block_Types_Controller extends WP_REST_Controller {
|
|||||||
'name' => array(
|
'name' => array(
|
||||||
'description' => __( 'Unique name identifying the block type.' ),
|
'description' => __( 'Unique name identifying the block type.' ),
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'default' => '',
|
'pattern' => self::NAME_PATTERN,
|
||||||
|
'required' => true,
|
||||||
'context' => array( 'embed', 'view', 'edit' ),
|
'context' => array( 'embed', 'view', 'edit' ),
|
||||||
'readonly' => true,
|
'readonly' => true,
|
||||||
),
|
),
|
||||||
@ -689,7 +694,8 @@ class WP_REST_Block_Types_Controller extends WP_REST_Controller {
|
|||||||
'description' => __( 'Parent blocks.' ),
|
'description' => __( 'Parent blocks.' ),
|
||||||
'type' => array( 'array', 'null' ),
|
'type' => array( 'array', 'null' ),
|
||||||
'items' => array(
|
'items' => array(
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
|
'pattern' => self::NAME_PATTERN,
|
||||||
),
|
),
|
||||||
'default' => null,
|
'default' => null,
|
||||||
'context' => array( 'embed', 'view', 'edit' ),
|
'context' => array( 'embed', 'view', 'edit' ),
|
||||||
@ -699,7 +705,8 @@ class WP_REST_Block_Types_Controller extends WP_REST_Controller {
|
|||||||
'description' => __( 'Ancestor blocks.' ),
|
'description' => __( 'Ancestor blocks.' ),
|
||||||
'type' => array( 'array', 'null' ),
|
'type' => array( 'array', 'null' ),
|
||||||
'items' => array(
|
'items' => array(
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
|
'pattern' => self::NAME_PATTERN,
|
||||||
),
|
),
|
||||||
'default' => null,
|
'default' => null,
|
||||||
'context' => array( 'embed', 'view', 'edit' ),
|
'context' => array( 'embed', 'view', 'edit' ),
|
||||||
@ -711,7 +718,7 @@ class WP_REST_Block_Types_Controller extends WP_REST_Controller {
|
|||||||
'description' => __( 'This block is automatically inserted near any occurrence of the block types used as keys of this map, into a relative position given by the corresponding value.' ),
|
'description' => __( 'This block is automatically inserted near any occurrence of the block types used as keys of this map, into a relative position given by the corresponding value.' ),
|
||||||
'type' => 'object',
|
'type' => 'object',
|
||||||
'patternProperties' => array(
|
'patternProperties' => array(
|
||||||
'^[a-zA-Z0-9-]+/[a-zA-Z0-9-]+$' => array(
|
self::NAME_PATTERN => array(
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'enum' => array( 'before', 'after', 'first_child', 'last_child' ),
|
'enum' => array( 'before', 'after', 'first_child', 'last_child' ),
|
||||||
),
|
),
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.4-alpha-56675';
|
$wp_version = '6.4-alpha-56676';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
Block a user