Skip to content

Commit

Permalink
General: Add allowed_blocks field to block registration and REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Jan 31, 2024
1 parent 6dd00b1 commit 1a83218
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
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
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

0 comments on commit 1a83218

Please sign in to comment.