diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index c93ac71bec525..90aaf2228e371 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -2303,6 +2303,7 @@ function get_block_editor_server_block_settings() { 'keywords' => 'keywords', 'example' => 'example', 'variations' => 'variations', + 'allowed_blocks' => 'allowedBlocks', ); foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) { diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index fdf97545f72d7..753b7f946ab28 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -424,6 +424,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { 'styles' => 'styles', 'variations' => 'variations', 'example' => 'example', + 'allowedBlocks' => 'allowed_blocks', ); $textdomain = ! empty( $metadata['textdomain'] ) ? $metadata['textdomain'] : null; $i18n_schema = get_block_metadata_i18n_schema(); diff --git a/src/wp-includes/class-wp-block-type.php b/src/wp-includes/class-wp-block-type.php index 5bdcee1504824..33825a7888320 100644 --- a/src/wp-includes/class-wp-block-type.php +++ b/src/wp-includes/class-wp-block-type.php @@ -68,6 +68,14 @@ class WP_Block_Type { */ public $ancestor = null; + /** + * Limits which block types can be inserted as children of this block type. + * + * @since 6.5.0 + * @var string[]|null + */ + public $allowed_blocks = null; + /** * Block type icon. * @@ -303,6 +311,7 @@ class WP_Block_Type { * available when nested within the specified blocks. * @type string[]|null $ancestor Setting ancestor makes a block available only inside the specified * block types at any position of the ancestor's block subtree. + * @type string[]|null $allowed_blocks Limits which block types can be inserted as children of this block type. * @type string|null $icon Block type icon. * @type string $description A detailed block type description. * @type string[] $keywords Additional keywords to produce block type as diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php index 9e8ba9e9299e3..52a511e2786b4 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php @@ -295,6 +295,7 @@ public function prepare_item_for_response( $item, $request ) { 'view_style_handles', 'variations', 'block_hooks', + 'allowed_blocks', ), $deprecated_fields ); @@ -738,6 +739,17 @@ public function get_item_schema() { 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), + 'allowed_blocks' => array( + 'description' => __( 'Allowed child block types.' ), + 'type' => array( 'array', 'null' ), + 'items' => array( + 'type' => 'string', + 'pattern' => self::NAME_PATTERN, + ), + 'default' => null, + 'context' => array( 'embed', 'view', 'edit' ), + 'readonly' => true, + ), ), ); diff --git a/tests/phpunit/tests/rest-api/rest-block-type-controller.php b/tests/phpunit/tests/rest-api/rest-block-type-controller.php index eca0e64a5fb55..d64a7b80427c0 100644 --- a/tests/phpunit/tests/rest-api/rest-block-type-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-type-controller.php @@ -550,6 +550,7 @@ public function test_get_variation() { * @ticket 47620 * @ticket 57585 * @ticket 59346 + * @ticket 60403 */ public function test_get_item_schema() { wp_set_current_user( self::$admin_id ); @@ -557,7 +558,7 @@ public function test_get_item_schema() { $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $properties = $data['schema']['properties']; - $this->assertCount( 31, $properties ); + $this->assertCount( 32, $properties ); $this->assertArrayHasKey( 'api_version', $properties ); $this->assertArrayHasKey( 'name', $properties ); $this->assertArrayHasKey( 'title', $properties ); @@ -577,6 +578,7 @@ public function test_get_item_schema() { $this->assertArrayHasKey( 'example', $properties ); $this->assertArrayHasKey( 'variations', $properties ); $this->assertArrayHasKey( 'block_hooks', $properties ); + $this->assertArrayHasKey( 'allowed_blocks', $properties ); $this->assertArrayHasKey( 'editor_script_handles', $properties ); $this->assertArrayHasKey( 'script_handles', $properties ); $this->assertArrayHasKey( 'view_script_handles', $properties );