Skip to content
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/wp-admin/includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -2232,6 +2232,7 @@ function get_block_editor_server_block_settings() {
'styles' => 'styles',
'textdomain' => 'textdomain',
'parent' => 'parent',
'ancestor' => 'ancestor',
'keywords' => 'keywords',
'example' => 'example',
'variations' => 'variations',
Expand Down
12 changes: 12 additions & 0 deletions src/wp-includes/class-wp-block-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ class WP_Block_Type {
*/
public $parent = null;

/**
* Setting ancestor makes a block available only inside the specified
* block types at any position of the ancestor's block subtree.
*
* @since 6.0.0
* @var array|null
*/
public $ancestor = null;

/**
* Block type icon.
*
Expand Down Expand Up @@ -207,6 +216,7 @@ class WP_Block_Type {
* @since 5.6.0 Added the `api_version` property.
* @since 5.8.0 Added the `variations` property.
* @since 5.9.0 Added the `view_script` property.
* @since 6.0.0 Added the `ancestor` property.
*
* @see register_block_type()
*
Expand All @@ -221,6 +231,8 @@ class WP_Block_Type {
* search interfaces to arrange block types by category.
* @type array|null $parent Setting parent lets a block require that it is only
* available when nested within the specified blocks.
* @type array|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 $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 @@ -266,6 +266,7 @@ public function prepare_item_for_response( $item, $request ) {
'category',
'keywords',
'parent',
'ancestor',
'provides_context',
'uses_context',
'supports',
Expand Down Expand Up @@ -645,6 +646,16 @@ public function get_item_schema() {
'context' => array( 'embed', 'view', 'edit' ),
'readonly' => true,
),
'ancestor' => array(
'description' => __( 'Ancestor blocks.' ),
'type' => array( 'array', 'null' ),
'items' => array(
'type' => 'string',
),
'default' => null,
'context' => array( 'embed', 'view', 'edit' ),
'readonly' => true,
),
'keywords' => $keywords_definition,
'example' => $example_definition,
),
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/tests/admin/includesPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ public function test_get_block_editor_server_block_settings() {
'icon' => 'text',
'category' => 'common',
'render_callback' => 'foo',
'ancestor' => array( 'core/test-ancestor' ),
);

register_block_type( $name, $settings );
Expand All @@ -846,6 +847,7 @@ public function test_get_block_editor_server_block_settings() {
'usesContext' => array(),
'category' => 'common',
'styles' => array(),
'ancestor' => array( 'core/test-ancestor' ),
'keywords' => array(),
'variations' => array(),
),
Expand Down
7 changes: 6 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 @@ -221,6 +221,7 @@ public function test_get_item_invalid() {
'keywords' => 'invalid_keywords',
'example' => 'invalid_example',
'parent' => 'invalid_parent',
'ancestor' => 'invalid_ancestor',
'supports' => 'invalid_supports',
'styles' => 'invalid_styles',
'render_callback' => 'invalid_callback',
Expand All @@ -246,6 +247,7 @@ public function test_get_item_invalid() {
$this->assertSameSets( array( 'invalid_uses_context' ), $data['uses_context'] );
$this->assertSameSets( array( 'invalid_keywords' ), $data['keywords'] );
$this->assertSameSets( array( 'invalid_parent' ), $data['parent'] );
$this->assertSameSets( array( 'invalid_ancestor' ), $data['ancestor'] );
$this->assertSameSets( array(), $data['supports'] );
$this->assertSameSets( array(), $data['styles'] );
$this->assertNull( $data['example'] );
Expand Down Expand Up @@ -275,6 +277,7 @@ public function test_get_item_defaults() {
'style' => false,
'keywords' => false,
'parent' => false,
'ancestor' => false,
'supports' => false,
'styles' => false,
'render_callback' => false,
Expand All @@ -301,6 +304,7 @@ public function test_get_item_defaults() {
$this->assertSameSets( array(), $data['uses_context'] );
$this->assertSameSets( array(), $data['keywords'] );
$this->assertSameSets( array(), $data['parent'] );
$this->assertSameSets( array(), $data['ancestor'] );
$this->assertSameSets( array(), $data['supports'] );
$this->assertSameSets( array(), $data['styles'] );
$this->assertNull( $data['example'] );
Expand Down Expand Up @@ -378,7 +382,7 @@ public function test_get_item_schema() {
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
$properties = $data['schema']['properties'];
$this->assertCount( 22, $properties );
$this->assertCount( 23, $properties );
$this->assertArrayHasKey( 'api_version', $properties );
$this->assertArrayHasKey( 'title', $properties );
$this->assertArrayHasKey( 'icon', $properties );
Expand All @@ -401,6 +405,7 @@ public function test_get_item_schema() {
$this->assertArrayHasKey( 'uses_context', $properties );
$this->assertArrayHasKey( 'provides_context', $properties );
$this->assertArrayHasKey( 'variations', $properties );
$this->assertArrayHasKey( 'ancestor', $properties );
}

/**
Expand Down