Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions src/wp-admin/includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
1 change: 1 addition & 0 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions src/wp-includes/class-wp-block-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ public function prepare_item_for_response( $item, $request ) {
'view_style_handles',
'variations',
'block_hooks',
'allowed_blocks',
),
$deprecated_fields
);
Expand Down Expand Up @@ -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,
),
),
);

Expand Down
4 changes: 3 additions & 1 deletion tests/phpunit/tests/rest-api/rest-block-type-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,15 @@ 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 );
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/block-types' );
$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 );
Expand All @@ -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 );
Expand Down