From f7e6949804ce5c8660bbc136e2ba82d7813cebd2 Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Tue, 23 Feb 2021 14:44:04 -0800 Subject: [PATCH 01/14] Add support for block variants --- src/wp-admin/includes/post.php | 1 + src/wp-includes/blocks.php | 1 + src/wp-includes/class-wp-block-type.php | 6 +++ .../class-wp-rest-block-types-controller.php | 53 +++++++++++++++++++ 4 files changed, 61 insertions(+) diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index 1a0fef056e6d2..808dbf6e384f5 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -2254,6 +2254,7 @@ function get_block_editor_server_block_settings() { 'parent' => 'parent', 'keywords' => 'keywords', 'example' => 'example', + 'variations' => 'variations', ); 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 b37ff94ddce91..c0ac9b6b1d8a6 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -230,6 +230,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { 'styles' => 'styles', 'example' => 'example', 'apiVersion' => 'api_version', + 'variations' => 'variations', ); foreach ( $property_mappings as $key => $mapped_key ) { diff --git a/src/wp-includes/class-wp-block-type.php b/src/wp-includes/class-wp-block-type.php index f4a22d638bd75..2c935d8db4b33 100644 --- a/src/wp-includes/class-wp-block-type.php +++ b/src/wp-includes/class-wp-block-type.php @@ -99,6 +99,12 @@ class WP_Block_Type { */ public $styles = array(); + /** + * Block variations. + * @var array + */ + public $variations = array(); + /** * Supported features. * 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 64a1ce653acdb..a6ae61d83d4a4 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 @@ -512,6 +512,59 @@ public function get_item_schema() { 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), + 'variations' => array( + 'description' => __( 'Block variations.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'object', + 'properties' => array( + 'name' => array( + 'description' => __( 'The unique and machine-readable name.' ), + 'type' => 'string', + 'required' => true, + ), + 'title' => array( + 'description' => __( 'A human-readable variation title.' ), + 'type' => 'string', + 'required' => true, + ), + 'description' => array( + 'description' => __( 'A detailed variation description.' ), + 'type' => 'string', + 'required' => false, + ), + 'category' => array( + 'description' => __( 'Block type category classification, used in search interfaces to arrange block types by category.' ), + 'type' => 'string', + 'required' => false, + ), + 'icon' => array( + 'description' => __( 'An icon helping to visualize the variation.' ), + 'type' => array( 'string', 'null' ), + 'required' => false, + ), + 'isDefault' => array( + 'description' => __( 'Indicates whether the current variation is the default one. Defaults to `false`' ), + 'type' => 'boolean', + 'required' => false, + 'default' => false, + ), + 'attributes' => array( + 'description' => __( 'Block attributes.' ), + 'type' => array( 'object', 'null' ), + 'properties' => array(), + 'default' => null, + 'additionalProperties' => array( + 'type' => 'object', + ), + ), + //TODO: innerBlocks, example, scope, keywords, isActive + ), + ), + 'readonly' => true, + 'context' => array( 'embed', 'view', 'edit' ), + 'default' => array(), + ), 'textdomain' => array( 'description' => __( 'Public text domain.' ), 'type' => array( 'string', 'null' ), From 3924b88f865962577c1ab8a558e34579c93c2433 Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Wed, 17 Feb 2021 15:12:54 -0800 Subject: [PATCH 02/14] whitespace --- .../rest-api/endpoints/class-wp-rest-block-types-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a6ae61d83d4a4..eb52307ea8d5f 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 @@ -543,7 +543,7 @@ public function get_item_schema() { 'type' => array( 'string', 'null' ), 'required' => false, ), - 'isDefault' => array( + 'isDefault' => array( 'description' => __( 'Indicates whether the current variation is the default one. Defaults to `false`' ), 'type' => 'boolean', 'required' => false, From 7703401ae84d0dbf0b6705e133b79ded83f0c1a7 Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Mon, 22 Feb 2021 10:57:58 -0800 Subject: [PATCH 03/14] Fix existing test and add remaining variation fields to schema --- .../class-wp-rest-block-types-controller.php | 79 ++++++++++++++++++- tests/phpunit/tests/admin/includesPost.php | 1 + 2 files changed, 78 insertions(+), 2 deletions(-) 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 eb52307ea8d5f..0b959891e10cf 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 @@ -544,7 +544,7 @@ public function get_item_schema() { 'required' => false, ), 'isDefault' => array( - 'description' => __( 'Indicates whether the current variation is the default one. Defaults to `false`' ), + 'description' => __( 'Indicates whether the current variation is the default one.' ), 'type' => 'boolean', 'required' => false, 'default' => false, @@ -558,7 +558,82 @@ public function get_item_schema() { 'type' => 'object', ), ), - //TODO: innerBlocks, example, scope, keywords, isActive + 'innerBlocks' => array( + 'description' => __( 'Initial configuration of nested blocks.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'object', + 'properties' => array( + 'name' => array( + 'description' => __( 'The name of the inner block.' ), + 'type' => 'string', + ), + 'attributes' => array( + 'description' => __( 'The attributes of the inner block.' ), + 'type' => 'object', + ), + 'innerBlocks' => array( + 'description' => __( "A list of the inner block's own inner blocks. This is a recursive definition following the parent innerBlocks schema." ), + 'type' => 'array', + ), + ), + ), + ), + 'example' => array( + 'description' => __( 'Example provides structured data for the block preview. Set this to `null` to disable the preview shown for the block type.' ), + 'type' => array( 'object', 'null' ), + 'default' => null, + 'properties' => array( + 'attributes' => array( + 'description' => __( 'The attributes used in the example.' ), + 'type' => 'object', + ), + 'innerBlocks' => array( + 'description' => __( 'The list of inner blocks used in the example.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'object', + 'properties' => array( + 'name' => array( + 'description' => __( 'The name of the inner block.' ), + 'type' => 'string', + ), + 'attributes' => array( + 'description' => __( 'The attributes of the inner block.' ), + 'type' => 'object', + ), + 'innerBlocks' => array( + 'description' => __( "A list of the inner block's own inner blocks. This is a recursive definition following the parent innerBlocks schema." ), + 'type' => 'array', + ), + ), + ), + ), + ), + ), + 'scope' => array( + 'description' => __( 'The list of scopes where the variation is applicable. When not provided, it assumes all available scopes.' ), + 'type' => array( 'array', 'null' ), + 'default' => null, + 'items' => array( + 'type' => 'string', + 'enum' => array( 'block', 'inserter', 'transform' ), + ), + 'readonly' => true, + ), + 'keywords' => array( + 'description' => __( 'An array of terms (which can be translated) that help users discover the variation while searching' ), + 'type' => 'array', + 'items' => array( + 'type' => 'string', + ), + 'default' => array(), + ), + 'icon' => array( + 'description' => __( 'An icon helping to visualize the variation.' ), + 'type' => array( 'string', 'null' ), + 'default' => null, + ), ), ), 'readonly' => true, diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index 4dffffd0d0ac3..915f1fbd04bdb 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -847,6 +847,7 @@ function test_get_block_editor_server_block_settings() { 'category' => 'common', 'styles' => array(), 'keywords' => array(), + 'variations' => array(), ), $blocks[ $name ] ); From 6f43d3a4c2baf56bde41f33b93e7285fd09dd882 Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Mon, 22 Feb 2021 14:20:15 -0800 Subject: [PATCH 04/14] fixup rest-block-type-controller tests --- .../endpoints/class-wp-rest-block-types-controller.php | 3 ++- tests/phpunit/tests/rest-api/rest-block-type-controller.php | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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 0b959891e10cf..c8b0dddd8a12a 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 @@ -274,6 +274,7 @@ public function prepare_item_for_response( $block_type, $request ) { 'script', 'editor_style', 'style', + 'variations', ); foreach ( $extra_fields as $extra_field ) { if ( rest_is_field_included( $extra_field, $fields ) ) { @@ -638,7 +639,7 @@ public function get_item_schema() { ), 'readonly' => true, 'context' => array( 'embed', 'view', 'edit' ), - 'default' => array(), + 'default' => null, ), 'textdomain' => array( 'description' => __( 'Public text domain.' ), 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 7bd1712f948c7..2de03b924d9f2 100644 --- a/tests/phpunit/tests/rest-api/rest-block-type-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-type-controller.php @@ -275,6 +275,7 @@ public function test_get_item_defaults() { 'render_callback' => false, 'textdomain' => false, 'example' => false, + 'variations' => false, ); register_block_type( $block_type, $settings ); wp_set_current_user( self::$admin_id ); @@ -301,6 +302,7 @@ public function test_get_item_defaults() { $this->assertNull( $data['example'] ); $this->assertNull( $data['textdomain'] ); $this->assertFalse( $data['is_dynamic'] ); + $this->assertSameSets( array(), $data['variations'] ); } /** @@ -312,7 +314,7 @@ public function test_get_item_schema() { $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $properties = $data['schema']['properties']; - $this->assertCount( 20, $properties ); + $this->assertCount( 21, $properties ); $this->assertArrayHasKey( 'api_version', $properties ); $this->assertArrayHasKey( 'title', $properties ); $this->assertArrayHasKey( 'icon', $properties ); @@ -333,6 +335,7 @@ public function test_get_item_schema() { $this->assertArrayHasKey( 'example', $properties ); $this->assertArrayHasKey( 'uses_context', $properties ); $this->assertArrayHasKey( 'provides_context', $properties ); + $this->assertArrayHasKey( 'variations', $properties ); } /** From 50506a8e6f54e1b36ac8ab2476600a4e48a79086 Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Tue, 23 Feb 2021 13:03:58 -0800 Subject: [PATCH 05/14] Sketch out test cases --- .../rest-api/rest-block-type-controller.php | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) 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 2de03b924d9f2..220589026bdec 100644 --- a/tests/phpunit/tests/rest-api/rest-block-type-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-type-controller.php @@ -224,6 +224,7 @@ public function test_get_item_invalid() { 'styles' => 'invalid_styles', 'render_callback' => 'invalid_callback', 'textdomain' => true, + 'variations' => 'invalid_variations', ); register_block_type( $block_type, $settings ); wp_set_current_user( self::$admin_id ); @@ -249,6 +250,9 @@ public function test_get_item_invalid() { $this->assertNull( $data['category'] ); $this->assertNull( $data['textdomain'] ); $this->assertFalse( $data['is_dynamic'] ); + // TODO: this is unexpected, but it looks like we're transforming scalars to arrays in rest_sanitize_value_from_schema + // This actually returns array( array() ); Need to step through to see what's happening + $this->assertSameSets( array(), $data['variations'] ); } /** @@ -305,6 +309,45 @@ public function test_get_item_defaults() { $this->assertSameSets( array(), $data['variations'] ); } + public function test_get_variation() { + $block_type = 'fake/variations'; + $settings = array( + 'title' => 'variations block test', + 'description' => 'a variations block test', + 'attributes' => array( 'kind' => array( 'type' => 'string' ) ), + 'variations' => array( + array( + 'name' => 'Foo', + 'title' => 'Foo Variation', + 'attributes' => array( 'kind' => 'foo' ), + ), + ), + ); + register_block_type( $block_type, $settings ); + wp_set_current_user( self::$admin_id ); + $request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type ); + $response = rest_get_server()->dispatch( $request ); + $data = $response->get_data(); + $this->assertSame( $block_type, $data['name'] ); + $this->assertArrayHasKey( 'variations', $data ); + $this->assertSame( 1, count( $data['variations'] ) ); + $variation = $data['variations'][0]; + $this->assertArrayHasKey( 'attributes', $variation ); + //TODO: this is getting wiped by: + // $data[ $extra_field ] = rest_sanitize_value_from_schema( $field, $schema['properties'][ $extra_field ] ); + // in class-wp-rest-block-types-controller.php + $this->assertSameSets( + array( + array( + 'name' => 'Foo', + 'title' => 'Foo Variation', + 'attributes' => array( 'kind' => 'foo' ), + ), + ), + $variation['attributes'] + ); + } + /** * @ticket 47620 */ From 298bbd1007128fb4def74948e5b1ab774c3f10fa Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Wed, 24 Feb 2021 13:43:05 -0800 Subject: [PATCH 06/14] Add item_link and item_link_description labels --- src/wp-includes/post.php | 12 ++++++++++-- src/wp-includes/taxonomy.php | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 93a1b59adf172..83b69443f8d51 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -22,7 +22,9 @@ function create_initial_post_types() { 'post', array( 'labels' => array( - 'name_admin_bar' => _x( 'Post', 'add new from admin bar' ), + 'name_admin_bar' => _x( 'Post', 'add new from admin bar' ), + 'item_link' => _x( 'Post Link', 'navigation link block title' ), + 'item_link_description' => _x( 'A link to a post.', 'navigation link block description' ), ), 'public' => true, '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ @@ -46,7 +48,9 @@ function create_initial_post_types() { 'page', array( 'labels' => array( - 'name_admin_bar' => _x( 'Page', 'add new from admin bar' ), + 'name_admin_bar' => _x( 'Page', 'add new from admin bar' ), + 'item_link' => _x( 'Page Link', 'navigation link block title' ), + 'item_link_description' => _x( 'A link to a page.', 'navigation link block description' ), ), 'public' => true, 'publicly_queryable' => false, @@ -1703,6 +1707,8 @@ function _post_type_meta_capabilities( $capabilities = null ) { * - `item_scheduled` - Label used when an item is scheduled for publishing. Default is 'Post scheduled.' / * 'Page scheduled.' * - `item_updated` - Label used when an item is updated. Default is 'Post updated.' / 'Page updated.' + * - `item_link` - Title for a navigation link block variation. Default null/null. + * - `item_link_description` - Description for a navigation link block variation. Default null/null. * * Above, the first default value is for non-hierarchical post types (like posts) * and the second one is for hierarchical post types (like pages). @@ -1757,6 +1763,8 @@ function get_post_type_labels( $post_type_object ) { 'item_reverted_to_draft' => array( __( 'Post reverted to draft.' ), __( 'Page reverted to draft.' ) ), 'item_scheduled' => array( __( 'Post scheduled.' ), __( 'Page scheduled.' ) ), 'item_updated' => array( __( 'Post updated.' ), __( 'Page updated.' ) ), + 'item_link' => array( null, null ), + 'item_link_description' => array( null, null ), ); $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index c8633d8ea27f3..63ee621275490 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -68,6 +68,10 @@ function create_initial_taxonomies() { 'show_ui' => true, 'show_admin_column' => true, '_builtin' => true, + 'labels' => array( + 'item_link' => _x( 'Category Link', 'navigation link block title' ), + 'item_link_description' => _x( 'A link to a category.', 'navigation link block description' ), + ), 'capabilities' => array( 'manage_terms' => 'manage_categories', 'edit_terms' => 'edit_categories', @@ -91,6 +95,10 @@ function create_initial_taxonomies() { 'show_ui' => true, 'show_admin_column' => true, '_builtin' => true, + 'labels' => array( + 'item_link' => _x( 'Tag Link', 'navigation link block title' ), + 'item_link_description' => _x( 'A link to a tag.', 'navigation link block description' ), + ), 'capabilities' => array( 'manage_terms' => 'manage_post_tags', 'edit_terms' => 'edit_post_tags', @@ -576,6 +584,10 @@ function unregister_taxonomy( $taxonomy ) { * @type string $items_list Label for the table hidden heading. * @type string $most_used Title for the Most Used tab. Default 'Most Used'. * @type string $back_to_items Label displayed after a term has been updated. + * @type string $item_link Title for a navigation link block variation. + * Default null/null. + * @type string $item_link_description Description for a navigation link block variation. + * Default null/null. * } */ function get_taxonomy_labels( $tax ) { @@ -613,6 +625,9 @@ function get_taxonomy_labels( $tax ) { /* translators: Tab heading when selecting from the most used terms. */ 'most_used' => array( _x( 'Most Used', 'tags' ), _x( 'Most Used', 'categories' ) ), 'back_to_items' => array( __( '← Go to Tags' ), __( '← Go to Categories' ) ), + 'item_link' => array( null, null ), + 'item_link_description' => array( null, null ), + ); $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; From 496c72edb5ad2d68d5348e7ebcf793ee2d7669fc Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Wed, 24 Feb 2021 14:24:50 -0800 Subject: [PATCH 07/14] Simplify attributes schema and fix test --- .../class-wp-rest-block-types-controller.php | 9 ++------- .../tests/rest-api/rest-block-type-controller.php | 11 +---------- 2 files changed, 3 insertions(+), 17 deletions(-) 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 c8b0dddd8a12a..e7d3c15dc68a2 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 @@ -551,13 +551,8 @@ public function get_item_schema() { 'default' => false, ), 'attributes' => array( - 'description' => __( 'Block attributes.' ), - 'type' => array( 'object', 'null' ), - 'properties' => array(), - 'default' => null, - 'additionalProperties' => array( - 'type' => 'object', - ), + 'description' => __( 'The attributes of the variation' ), + 'type' => 'object', ), 'innerBlocks' => array( 'description' => __( 'Initial configuration of nested blocks.' ), 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 220589026bdec..105245ed8efba 100644 --- a/tests/phpunit/tests/rest-api/rest-block-type-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-type-controller.php @@ -333,17 +333,8 @@ public function test_get_variation() { $this->assertSame( 1, count( $data['variations'] ) ); $variation = $data['variations'][0]; $this->assertArrayHasKey( 'attributes', $variation ); - //TODO: this is getting wiped by: - // $data[ $extra_field ] = rest_sanitize_value_from_schema( $field, $schema['properties'][ $extra_field ] ); - // in class-wp-rest-block-types-controller.php $this->assertSameSets( - array( - array( - 'name' => 'Foo', - 'title' => 'Foo Variation', - 'attributes' => array( 'kind' => 'foo' ), - ), - ), + array( 'kind' => 'foo' ), $variation['attributes'] ); } From b38ea86b6ec35b99490a09b3a6f360b6ca6e2768 Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Wed, 24 Feb 2021 15:07:51 -0800 Subject: [PATCH 08/14] fill out variation test case further --- .../rest-api/rest-block-type-controller.php | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) 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 105245ed8efba..3fd3649b30057 100644 --- a/tests/phpunit/tests/rest-api/rest-block-type-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-type-controller.php @@ -317,9 +317,17 @@ public function test_get_variation() { 'attributes' => array( 'kind' => array( 'type' => 'string' ) ), 'variations' => array( array( - 'name' => 'Foo', - 'title' => 'Foo Variation', - 'attributes' => array( 'kind' => 'foo' ), + 'name' => 'Foo', + 'title' => 'Foo Variation', + 'description' => 'Foo Description', + 'category' => 'media', + 'icon' => 'dog', + 'attributes' => array( 'kind' => 'foo' ), + 'isDefault' => true, + 'example' => array( 'attributes' => array( 'kind' => 'example' ) ), + 'scope' => array( 'inserter', 'block' ), + 'keywords' => array( 'dogs', 'cats', 'mice' ), + 'innerBlocks' => array( array( 'name' => 'fake/bar', 'attributes' => array( 'label' => 'hi' ) ) ), ), ), ); @@ -332,7 +340,14 @@ public function test_get_variation() { $this->assertArrayHasKey( 'variations', $data ); $this->assertSame( 1, count( $data['variations'] ) ); $variation = $data['variations'][0]; - $this->assertArrayHasKey( 'attributes', $variation ); + $this->assertSame( 'Foo Variation', $variation['title'] ); + $this->assertSame( 'Foo Description', $variation['description'] ); + $this->assertSame( 'media', $variation['category'] ); + $this->assertSame( 'dog', $variation['icon'] ); + $this->assertSameSets( array( 'inserter', 'block' ), $variation['scope'] ); + $this->assertSameSets( array( 'dogs', 'cats', 'mice' ), $variation['keywords'] ); + $this->assertSameSets( array( 'attributes' => array( 'kind' => 'example' ) ), $variation['example'] ); + $this->assertSameSets( array( array( 'name' => 'fake/bar', 'attributes' => array( 'label' => 'hi' ) ) ), $variation['innerBlocks'] ); $this->assertSameSets( array( 'kind' => 'foo' ), $variation['attributes'] From bc52a9d078577da7d6c941a766ed73805b2ad0e3 Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Wed, 24 Feb 2021 19:45:06 -0800 Subject: [PATCH 09/14] remove duplicate icon, update test expectation --- .../class-wp-rest-block-types-controller.php | 5 ----- .../rest-api/rest-block-type-controller.php | 18 ++++++++---------- 2 files changed, 8 insertions(+), 15 deletions(-) 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 e7d3c15dc68a2..3b6d903c6a728 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 @@ -625,11 +625,6 @@ public function get_item_schema() { ), 'default' => array(), ), - 'icon' => array( - 'description' => __( 'An icon helping to visualize the variation.' ), - 'type' => array( 'string', 'null' ), - 'default' => null, - ), ), ), '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 3fd3649b30057..87b9102d2f36f 100644 --- a/tests/phpunit/tests/rest-api/rest-block-type-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-type-controller.php @@ -250,9 +250,7 @@ public function test_get_item_invalid() { $this->assertNull( $data['category'] ); $this->assertNull( $data['textdomain'] ); $this->assertFalse( $data['is_dynamic'] ); - // TODO: this is unexpected, but it looks like we're transforming scalars to arrays in rest_sanitize_value_from_schema - // This actually returns array( array() ); Need to step through to see what's happening - $this->assertSameSets( array(), $data['variations'] ); + $this->assertSameSets( array( array() ), $data['variations'] ); } /** @@ -317,11 +315,11 @@ public function test_get_variation() { 'attributes' => array( 'kind' => array( 'type' => 'string' ) ), 'variations' => array( array( - 'name' => 'Foo', - 'title' => 'Foo Variation', - 'description' => 'Foo Description', + 'name' => 'variation', + 'title' => 'variation title', + 'description' => 'variation description', 'category' => 'media', - 'icon' => 'dog', + 'icon' => 'checkmark', 'attributes' => array( 'kind' => 'foo' ), 'isDefault' => true, 'example' => array( 'attributes' => array( 'kind' => 'example' ) ), @@ -340,10 +338,10 @@ public function test_get_variation() { $this->assertArrayHasKey( 'variations', $data ); $this->assertSame( 1, count( $data['variations'] ) ); $variation = $data['variations'][0]; - $this->assertSame( 'Foo Variation', $variation['title'] ); - $this->assertSame( 'Foo Description', $variation['description'] ); + $this->assertSame( 'variation title', $variation['title'] ); + $this->assertSame( 'variation description', $variation['description'] ); $this->assertSame( 'media', $variation['category'] ); - $this->assertSame( 'dog', $variation['icon'] ); + $this->assertSame( 'checkmark', $variation['icon'] ); $this->assertSameSets( array( 'inserter', 'block' ), $variation['scope'] ); $this->assertSameSets( array( 'dogs', 'cats', 'mice' ), $variation['keywords'] ); $this->assertSameSets( array( 'attributes' => array( 'kind' => 'example' ) ), $variation['example'] ); From 49c198486ca94506b4920a3d8d1ab57c785588b9 Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Wed, 24 Feb 2021 20:02:49 -0800 Subject: [PATCH 10/14] fix phpcs errors, move shared definitions to php variables --- .../class-wp-rest-block-types-controller.php | 181 +++++++----------- .../rest-api/rest-block-type-controller.php | 17 +- 2 files changed, 79 insertions(+), 119 deletions(-) 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 3b6d903c6a728..cc275d0ec171d 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 @@ -362,6 +362,63 @@ public function get_item_schema() { return $this->add_additional_fields_schema( $this->schema ); } + //rest_validate_value_from_schema doesn't understand $refs, pull out reused definitions for readability. + $inner_blocks_definition = array( + 'description' => __( 'The list of inner blocks used in the example.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'object', + 'properties' => array( + 'name' => array( + 'description' => __( 'The name of the inner block.' ), + 'type' => 'string', + ), + 'attributes' => array( + 'description' => __( 'The attributes of the inner block.' ), + 'type' => 'object', + ), + 'innerBlocks' => array( + 'description' => __( "A list of the inner block's own inner blocks. This is a recursive definition following the parent innerBlocks schema." ), + 'type' => 'array', + ), + ), + ), + ); + + $example_definition = array( + 'description' => __( 'Block example.' ), + 'type' => array( 'object', 'null' ), + 'default' => null, + 'properties' => array( + 'attributes' => array( + 'description' => __( 'The attributes used in the example.' ), + 'type' => 'object', + ), + 'innerBlocks' => $inner_blocks_definition, + ), + 'context' => array( 'embed', 'view', 'edit' ), + 'readonly' => true, + ); + + $keywords_definition = array( + 'description' => __( 'Block keywords.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'string', + ), + 'default' => array(), + 'context' => array( 'embed', 'view', 'edit' ), + 'readonly' => true, + ); + + $icon_definition = array( + 'description' => __( 'Icon of block type.' ), + 'type' => array( 'string', 'null' ), + 'default' => null, + 'context' => array( 'embed', 'view', 'edit' ), + 'readonly' => true, + ); + $schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'block-type', @@ -395,13 +452,7 @@ public function get_item_schema() { 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), - 'icon' => array( - 'description' => __( 'Icon of block type.' ), - 'type' => array( 'string', 'null' ), - 'default' => null, - 'context' => array( 'embed', 'view', 'edit' ), - 'readonly' => true, - ), + 'icon' => $icon_definition, 'attributes' => array( 'description' => __( 'Block attributes.' ), 'type' => array( 'object', 'null' ), @@ -539,11 +590,7 @@ public function get_item_schema() { 'type' => 'string', 'required' => false, ), - 'icon' => array( - 'description' => __( 'An icon helping to visualize the variation.' ), - 'type' => array( 'string', 'null' ), - 'required' => false, - ), + 'icon' => $icon_definition, 'isDefault' => array( 'description' => __( 'Indicates whether the current variation is the default one.' ), 'type' => 'boolean', @@ -554,59 +601,8 @@ public function get_item_schema() { 'description' => __( 'The attributes of the variation' ), 'type' => 'object', ), - 'innerBlocks' => array( - 'description' => __( 'Initial configuration of nested blocks.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'object', - 'properties' => array( - 'name' => array( - 'description' => __( 'The name of the inner block.' ), - 'type' => 'string', - ), - 'attributes' => array( - 'description' => __( 'The attributes of the inner block.' ), - 'type' => 'object', - ), - 'innerBlocks' => array( - 'description' => __( "A list of the inner block's own inner blocks. This is a recursive definition following the parent innerBlocks schema." ), - 'type' => 'array', - ), - ), - ), - ), - 'example' => array( - 'description' => __( 'Example provides structured data for the block preview. Set this to `null` to disable the preview shown for the block type.' ), - 'type' => array( 'object', 'null' ), - 'default' => null, - 'properties' => array( - 'attributes' => array( - 'description' => __( 'The attributes used in the example.' ), - 'type' => 'object', - ), - 'innerBlocks' => array( - 'description' => __( 'The list of inner blocks used in the example.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'object', - 'properties' => array( - 'name' => array( - 'description' => __( 'The name of the inner block.' ), - 'type' => 'string', - ), - 'attributes' => array( - 'description' => __( 'The attributes of the inner block.' ), - 'type' => 'object', - ), - 'innerBlocks' => array( - 'description' => __( "A list of the inner block's own inner blocks. This is a recursive definition following the parent innerBlocks schema." ), - 'type' => 'array', - ), - ), - ), - ), - ), - ), + 'innerBlocks' => $inner_blocks_definition, + 'example' => $example_definition, 'scope' => array( 'description' => __( 'The list of scopes where the variation is applicable. When not provided, it assumes all available scopes.' ), 'type' => array( 'array', 'null' ), @@ -617,14 +613,7 @@ public function get_item_schema() { ), 'readonly' => true, ), - 'keywords' => array( - 'description' => __( 'An array of terms (which can be translated) that help users discover the variation while searching' ), - 'type' => 'array', - 'items' => array( - 'type' => 'string', - ), - 'default' => array(), - ), + 'keywords' => $keywords_definition, ), ), 'readonly' => true, @@ -648,50 +637,8 @@ public function get_item_schema() { 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), - 'keywords' => array( - 'description' => __( 'Block keywords.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'string', - ), - 'default' => array(), - 'context' => array( 'embed', 'view', 'edit' ), - 'readonly' => true, - ), - 'example' => array( - 'description' => __( 'Block example.' ), - 'type' => array( 'object', 'null' ), - 'default' => null, - 'properties' => array( - 'attributes' => array( - 'description' => __( 'The attributes used in the example.' ), - 'type' => 'object', - ), - 'innerBlocks' => array( - 'description' => __( 'The list of inner blocks used in the example.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'object', - 'properties' => array( - 'name' => array( - 'description' => __( 'The name of the inner block.' ), - 'type' => 'string', - ), - 'attributes' => array( - 'description' => __( 'The attributes of the inner block.' ), - 'type' => 'object', - ), - 'innerBlocks' => array( - 'description' => __( "A list of the inner block's own inner blocks. This is a recursive definition following the parent innerBlocks schema." ), - 'type' => 'array', - ), - ), - ), - ), - ), - 'context' => array( 'embed', 'view', 'edit' ), - 'readonly' => true, - ), + 'keywords' => $keywords_definition, + 'example' => $example_definition, ), ); 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 87b9102d2f36f..3958c9bd1978b 100644 --- a/tests/phpunit/tests/rest-api/rest-block-type-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-type-controller.php @@ -325,7 +325,12 @@ public function test_get_variation() { 'example' => array( 'attributes' => array( 'kind' => 'example' ) ), 'scope' => array( 'inserter', 'block' ), 'keywords' => array( 'dogs', 'cats', 'mice' ), - 'innerBlocks' => array( array( 'name' => 'fake/bar', 'attributes' => array( 'label' => 'hi' ) ) ), + 'innerBlocks' => array( + array( + 'name' => 'fake/bar', + 'attributes' => array( 'label' => 'hi' ), + ), + ), ), ), ); @@ -345,7 +350,15 @@ public function test_get_variation() { $this->assertSameSets( array( 'inserter', 'block' ), $variation['scope'] ); $this->assertSameSets( array( 'dogs', 'cats', 'mice' ), $variation['keywords'] ); $this->assertSameSets( array( 'attributes' => array( 'kind' => 'example' ) ), $variation['example'] ); - $this->assertSameSets( array( array( 'name' => 'fake/bar', 'attributes' => array( 'label' => 'hi' ) ) ), $variation['innerBlocks'] ); + $this->assertSameSets( + array( + array( + 'name' => 'fake/bar', + 'attributes' => array( 'label' => 'hi' ), + ), + ), + $variation['innerBlocks'] + ); $this->assertSameSets( array( 'kind' => 'foo' ), $variation['attributes'] From 4fb70c610525ec7fee4d985a210d361a32ddf1b6 Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Thu, 25 Feb 2021 10:35:15 -0800 Subject: [PATCH 11/14] add category definition, update variant attribute description to reduce confusion --- .../class-wp-rest-block-types-controller.php | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) 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 cc275d0ec171d..f2f277e5eb94f 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 @@ -419,6 +419,14 @@ public function get_item_schema() { 'readonly' => true, ); + $category_definition = array( + 'description' => __( 'Block category.' ), + 'type' => array( 'string', 'null' ), + 'default' => null, + 'context' => array( 'embed', 'view', 'edit' ), + 'readonly' => true, + ); + $schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'block-type', @@ -493,13 +501,7 @@ public function get_item_schema() { 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), - 'category' => array( - 'description' => __( 'Block category.' ), - 'type' => array( 'string', 'null' ), - 'default' => null, - 'context' => array( 'embed', 'view', 'edit' ), - 'readonly' => true, - ), + 'category' => $category_definition, 'is_dynamic' => array( 'description' => __( 'Is the block dynamically rendered.' ), 'type' => 'boolean', @@ -585,11 +587,7 @@ public function get_item_schema() { 'type' => 'string', 'required' => false, ), - 'category' => array( - 'description' => __( 'Block type category classification, used in search interfaces to arrange block types by category.' ), - 'type' => 'string', - 'required' => false, - ), + 'category' => $category_definition, 'icon' => $icon_definition, 'isDefault' => array( 'description' => __( 'Indicates whether the current variation is the default one.' ), @@ -598,7 +596,7 @@ public function get_item_schema() { 'default' => false, ), 'attributes' => array( - 'description' => __( 'The attributes of the variation' ), + 'description' => __( 'The initial values for attributes.' ), 'type' => 'object', ), 'innerBlocks' => $inner_blocks_definition, From 5ba189a8fb6482e0214a5b226d7122ce8e31089b Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Mon, 1 Mar 2021 09:01:04 -0800 Subject: [PATCH 12/14] Provide defaults for item_link and item_link_description labels --- src/wp-includes/post.php | 65 +++++++++++++++++++----------------- src/wp-includes/taxonomy.php | 27 +++++++-------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 83b69443f8d51..6fa70bd75e70e 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -22,9 +22,7 @@ function create_initial_post_types() { 'post', array( 'labels' => array( - 'name_admin_bar' => _x( 'Post', 'add new from admin bar' ), - 'item_link' => _x( 'Post Link', 'navigation link block title' ), - 'item_link_description' => _x( 'A link to a post.', 'navigation link block description' ), + 'name_admin_bar' => _x( 'Post', 'add new from admin bar' ), ), 'public' => true, '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ @@ -48,9 +46,7 @@ function create_initial_post_types() { 'page', array( 'labels' => array( - 'name_admin_bar' => _x( 'Page', 'add new from admin bar' ), - 'item_link' => _x( 'Page Link', 'navigation link block title' ), - 'item_link_description' => _x( 'A link to a page.', 'navigation link block description' ), + 'name_admin_bar' => _x( 'Page', 'add new from admin bar' ), ), 'public' => true, 'publicly_queryable' => false, @@ -1707,8 +1703,9 @@ function _post_type_meta_capabilities( $capabilities = null ) { * - `item_scheduled` - Label used when an item is scheduled for publishing. Default is 'Post scheduled.' / * 'Page scheduled.' * - `item_updated` - Label used when an item is updated. Default is 'Post updated.' / 'Page updated.' - * - `item_link` - Title for a navigation link block variation. Default null/null. - * - `item_link_description` - Description for a navigation link block variation. Default null/null. + * - `item_link` - Title for a navigation link block variation. Default is 'Post Link' / 'Page Link'. + * - `item_link_description` - Description for a navigation link block variation. Default is 'A link to a post.' / + * 'A link to a page.' * * Above, the first default value is for non-hierarchical post types (like posts) * and the second one is for hierarchical post types (like pages). @@ -1732,7 +1729,7 @@ function _post_type_meta_capabilities( $capabilities = null ) { * @return object Object with all the labels as member variables. */ function get_post_type_labels( $post_type_object ) { - $nohier_vs_hier_defaults = array( + $nohier_vs_hier_defaults = array( 'name' => array( _x( 'Posts', 'post type general name' ), _x( 'Pages', 'post type general name' ) ), 'singular_name' => array( _x( 'Post', 'post type singular name' ), _x( 'Page', 'post type singular name' ) ), 'add_new' => array( _x( 'Add New', 'post' ), _x( 'Add New', 'page' ) ), @@ -1763,35 +1760,41 @@ function get_post_type_labels( $post_type_object ) { 'item_reverted_to_draft' => array( __( 'Post reverted to draft.' ), __( 'Page reverted to draft.' ) ), 'item_scheduled' => array( __( 'Post scheduled.' ), __( 'Page scheduled.' ) ), 'item_updated' => array( __( 'Post updated.' ), __( 'Page updated.' ) ), - 'item_link' => array( null, null ), - 'item_link_description' => array( null, null ), + 'item_link' => array( + _x( 'Post Link', 'navigation link block title' ), + _x( 'Page Link', 'navigation link block title' ), + ), + 'item_link_description' => array( + _x( 'A link to a post.', 'navigation link block description' ), + _x( 'A link to a page.', 'navigation link block description' ), + ), ); - $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; + $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; - $labels = _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults ); + $labels = _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults ); - $post_type = $post_type_object->name; + $post_type = $post_type_object->name; - $default_labels = clone $labels; + $default_labels = clone $labels; - /** - * Filters the labels of a specific post type. - * - * The dynamic portion of the hook name, `$post_type`, refers to - * the post type slug. - * - * @since 3.5.0 - * - * @see get_post_type_labels() for the full list of labels. - * - * @param object $labels Object with labels for the post type as member variables. - */ - $labels = apply_filters( "post_type_labels_{$post_type}", $labels ); + /** + * Filters the labels of a specific post type. + * + * The dynamic portion of the hook name, `$post_type`, refers to + * the post type slug. + * + * @since 3.5.0 + * + * @see get_post_type_labels() for the full list of labels. + * + * @param object $labels Object with labels for the post type as member variables. + */ + $labels = apply_filters( "post_type_labels_{$post_type}", $labels ); - // Ensure that the filtered labels contain all required default values. - $labels = (object) array_merge( (array) $default_labels, (array) $labels ); + // Ensure that the filtered labels contain all required default values. + $labels = (object) array_merge( (array) $default_labels, (array) $labels ); - return $labels; + return $labels; } /** diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 63ee621275490..3961fceecd79c 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -68,10 +68,6 @@ function create_initial_taxonomies() { 'show_ui' => true, 'show_admin_column' => true, '_builtin' => true, - 'labels' => array( - 'item_link' => _x( 'Category Link', 'navigation link block title' ), - 'item_link_description' => _x( 'A link to a category.', 'navigation link block description' ), - ), 'capabilities' => array( 'manage_terms' => 'manage_categories', 'edit_terms' => 'edit_categories', @@ -95,10 +91,6 @@ function create_initial_taxonomies() { 'show_ui' => true, 'show_admin_column' => true, '_builtin' => true, - 'labels' => array( - 'item_link' => _x( 'Tag Link', 'navigation link block title' ), - 'item_link_description' => _x( 'A link to a tag.', 'navigation link block description' ), - ), 'capabilities' => array( 'manage_terms' => 'manage_post_tags', 'edit_terms' => 'edit_post_tags', @@ -584,10 +576,10 @@ function unregister_taxonomy( $taxonomy ) { * @type string $items_list Label for the table hidden heading. * @type string $most_used Title for the Most Used tab. Default 'Most Used'. * @type string $back_to_items Label displayed after a term has been updated. - * @type string $item_link Title for a navigation link block variation. - * Default null/null. - * @type string $item_link_description Description for a navigation link block variation. - * Default null/null. + * @type string $item_link Used in the block editor. Title for a navigation link block variation. + * Default 'Tag Link'/'Category Link'. + * @type string $item_link_description Used in the block editor. Description for a navigation link block + * variation. Default 'A link to a tag.'/'A link to a category'. * } */ function get_taxonomy_labels( $tax ) { @@ -625,9 +617,14 @@ function get_taxonomy_labels( $tax ) { /* translators: Tab heading when selecting from the most used terms. */ 'most_used' => array( _x( 'Most Used', 'tags' ), _x( 'Most Used', 'categories' ) ), 'back_to_items' => array( __( '← Go to Tags' ), __( '← Go to Categories' ) ), - 'item_link' => array( null, null ), - 'item_link_description' => array( null, null ), - + 'item_link' => array( + _x( 'Tag Link', 'navigation link block title' ), + _x( 'Category Link', 'navigation link block description' ), + ), + 'item_link_description' => array( + _x( 'A link to a tag.', 'navigation link block description' ), + _x( 'A link to a category.', 'navigation link block description' ), + ), ); $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; From 10725326bb67328f3974494f6c2739c4289a0661 Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Mon, 1 Mar 2021 09:03:40 -0800 Subject: [PATCH 13/14] drop unnecessary whitespace change --- src/wp-includes/post.php | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 6fa70bd75e70e..f4a2f48fae823 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -1769,32 +1769,32 @@ function get_post_type_labels( $post_type_object ) { _x( 'A link to a page.', 'navigation link block description' ), ), ); - $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; + $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; - $labels = _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults ); + $labels = _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults ); - $post_type = $post_type_object->name; + $post_type = $post_type_object->name; - $default_labels = clone $labels; + $default_labels = clone $labels; - /** - * Filters the labels of a specific post type. - * - * The dynamic portion of the hook name, `$post_type`, refers to - * the post type slug. - * - * @since 3.5.0 - * - * @see get_post_type_labels() for the full list of labels. - * - * @param object $labels Object with labels for the post type as member variables. - */ - $labels = apply_filters( "post_type_labels_{$post_type}", $labels ); + /** + * Filters the labels of a specific post type. + * + * The dynamic portion of the hook name, `$post_type`, refers to + * the post type slug. + * + * @since 3.5.0 + * + * @see get_post_type_labels() for the full list of labels. + * + * @param object $labels Object with labels for the post type as member variables. + */ + $labels = apply_filters( "post_type_labels_{$post_type}", $labels ); - // Ensure that the filtered labels contain all required default values. - $labels = (object) array_merge( (array) $default_labels, (array) $labels ); + // Ensure that the filtered labels contain all required default values. + $labels = (object) array_merge( (array) $default_labels, (array) $labels ); - return $labels; + return $labels; } /** From eae37b9367601b871ede8e33ecbb6c82813de0f1 Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Mon, 1 Mar 2021 09:09:06 -0800 Subject: [PATCH 14/14] drop variations integration with register_block_type_from_metadata --- src/wp-includes/blocks.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index c0ac9b6b1d8a6..b37ff94ddce91 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -230,7 +230,6 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { 'styles' => 'styles', 'example' => 'example', 'apiVersion' => 'api_version', - 'variations' => 'variations', ); foreach ( $property_mappings as $key => $mapped_key ) {