Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST API: Improve the block type schema for the name field #5278

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
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.
*
Expand Down Expand Up @@ -402,6 +404,8 @@ public function get_item_schema() {
'name' => array(
'description' => __( 'The name of the inner block.' ),
'type' => 'string',
'pattern' => self::NAME_PATTERN,
'required' => true,
),
'attributes' => array(
'description' => __( 'The attributes of the inner block.' ),
Expand Down Expand Up @@ -479,7 +483,8 @@ public function get_item_schema() {
'name' => array(
'description' => __( 'Unique name identifying the block type.' ),
'type' => 'string',
'default' => '',
'pattern' => self::NAME_PATTERN,
'required' => true,
'context' => array( 'embed', 'view', 'edit' ),
'readonly' => true,
),
Expand Down Expand Up @@ -689,7 +694,8 @@ public function get_item_schema() {
'description' => __( 'Parent blocks.' ),
'type' => array( 'array', 'null' ),
'items' => array(
'type' => 'string',
'type' => 'string',
'pattern' => self::NAME_PATTERN,
),
'default' => null,
'context' => array( 'embed', 'view', 'edit' ),
Expand All @@ -699,7 +705,8 @@ public function get_item_schema() {
'description' => __( 'Ancestor blocks.' ),
'type' => array( 'array', 'null' ),
'items' => array(
'type' => 'string',
'type' => 'string',
'pattern' => self::NAME_PATTERN,
),
'default' => null,
'context' => array( 'embed', 'view', 'edit' ),
Expand All @@ -711,7 +718,7 @@ public function get_item_schema() {
'description' => __( 'This block is automatically inserted near any occurence of the block types used as keys of this map, into a relative position given by the corresponding value.' ),
'type' => 'object',
'patternProperties' => array(
'^[a-zA-Z0-9-]+/[a-zA-Z0-9-]+$' => array(
self::NAME_PATTERN => array(
'type' => 'string',
'enum' => array( 'before', 'after', 'first_child', 'last_child' ),
),
Expand Down
Loading