From daeb8205fa708d06770954812b03d1fc3fcef813 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Tue, 20 Jun 2023 17:03:46 +1200 Subject: [PATCH 01/17] Rename Reusable blocks to Patterns --- src/wp-includes/block-editor.php | 2 +- src/wp-includes/post.php | 41 ++++++++++++++------------- tests/phpunit/tests/blocks/editor.php | 2 +- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index 476d89e9846f6..cb48055a8ca83 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -48,7 +48,7 @@ function get_default_block_categories() { ), array( 'slug' => 'reusable', - 'title' => _x( 'Reusable Blocks', 'block category' ), + 'title' => _x( 'Patterns', 'block category' ), 'icon' => null, ), ); diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 1d543fe9860e5..d7dbcab28ae9a 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -282,26 +282,26 @@ function create_initial_post_types() { 'wp_block', array( 'labels' => array( - 'name' => _x( 'Reusable blocks', 'post type general name' ), - 'singular_name' => _x( 'Reusable block', 'post type singular name' ), - 'add_new' => _x( 'Add New', 'Reusable block' ), - 'add_new_item' => __( 'Add new Reusable block' ), - 'new_item' => __( 'New Reusable block' ), - 'edit_item' => __( 'Edit Reusable block' ), - 'view_item' => __( 'View Reusable block' ), - 'view_items' => __( 'View Reusable blocks' ), - 'all_items' => __( 'All Reusable blocks' ), - 'search_items' => __( 'Search Reusable blocks' ), - 'not_found' => __( 'No reusable blocks found.' ), - 'not_found_in_trash' => __( 'No reusable blocks found in Trash.' ), - 'filter_items_list' => __( 'Filter reusable blocks list' ), - 'items_list_navigation' => __( 'Reusable blocks list navigation' ), - 'items_list' => __( 'Reusable blocks list' ), - 'item_published' => __( 'Reusable block published.' ), - 'item_published_privately' => __( 'Reusable block published privately.' ), - 'item_reverted_to_draft' => __( 'Reusable block reverted to draft.' ), - 'item_scheduled' => __( 'Reusable block scheduled.' ), - 'item_updated' => __( 'Reusable block updated.' ), + 'name' => _x( 'Patterns', 'post type general name' ), + 'singular_name' => _x( 'Pattern', 'post type singular name' ), + 'add_new' => _x( 'Add New', 'Pattern' ), + 'add_new_item' => __( 'Add new Pattern' ), + 'new_item' => __( 'New Pattern' ), + 'edit_item' => __( 'Edit Pattern' ), + 'view_item' => __( 'View Pattern' ), + 'view_items' => __( 'View Patterns' ), + 'all_items' => __( 'All Patterns' ), + 'search_items' => __( 'Search Patterns' ), + 'not_found' => __( 'No patterns found.' ), + 'not_found_in_trash' => __( 'No patterns found in Trash.' ), + 'filter_items_list' => __( 'Filter patterns list' ), + 'items_list_navigation' => __( 'Patterns list navigation' ), + 'items_list' => __( 'Patterns list' ), + 'item_published' => __( 'Pattern published.' ), + 'item_published_privately' => __( 'Pattern published privately.' ), + 'item_reverted_to_draft' => __( 'Pattern reverted to draft.' ), + 'item_scheduled' => __( 'Pattern scheduled.' ), + 'item_updated' => __( 'Pattern updated.' ), ), 'public' => false, '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ @@ -328,6 +328,7 @@ function create_initial_post_types() { 'title', 'editor', 'revisions', + 'custom-fields', ), ) ); diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index 0769cbc31c411..23b4dde0cecf9 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -234,7 +234,7 @@ public function test_get_default_block_editor_settings() { ), array( 'slug' => 'reusable', - 'title' => 'Reusable Blocks', + 'title' => 'Patterns', 'icon' => null, ), ), From 4c0252ade5146fa09a6917ac6f8dd4f86010a41e Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Tue, 20 Jun 2023 17:14:52 +1200 Subject: [PATCH 02/17] Update fixture --- tests/qunit/fixtures/wp-api-generated.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index d64b68fa40923..22ac5655af416 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -11922,7 +11922,7 @@ mockedApiResponse.TypesCollection = { "description": "", "hierarchical": false, "has_archive": false, - "name": "Reusable blocks", + "name": "Patterns", "slug": "wp_block", "icon": null, "taxonomies": [], From 30d7fad8236289ee98f2c1c20b334be6e9123025 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Tue, 20 Jun 2023 17:31:22 +1200 Subject: [PATCH 03/17] Add postmeta --- src/wp-includes/default-filters.php | 3 +++ src/wp-includes/post.php | 35 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 063199269c48c..e8ba499b7c5e9 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -720,4 +720,7 @@ // User preferences. add_action( 'init', 'wp_register_persisted_preferences_meta' ); +// CPT wp_block custom postmeta field. +add_action( 'init', 'wp_register_wp_block_postmeta' ); + unset( $filter, $action ); diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index d7dbcab28ae9a..cbc9e47204bb3 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -8019,3 +8019,38 @@ function use_block_editor_for_post_type( $post_type ) { */ return apply_filters( 'use_block_editor_for_post_type', true, $post_type ); } + +/** + * Adds sync_status meta field to the wp_block post type so an unsynced option can be added. + * + * @since 6.3.0 + * + * @see https://github.com/WordPress/gutenberg/pull/51144 + * + * @return void + */ +function wp_register_wp_block_postmeta() { + $post_type = 'wp_block'; + register_post_meta( + $post_type, + 'sync_status', + array( + 'auth_callback' => function() { + return current_user_can( 'edit_posts' ); + }, + 'sanitize_callback' => 'sanitize_text_field', + 'single' => true, + 'type' => 'string', + 'show_in_rest' => array( + 'schema' => array( + 'type' => 'string', + 'properties' => array( + 'sync_status' => array( + 'type' => 'string', + ), + ), + ), + ), + ) + ); +} From 531eacbff8516f6737a71005f7fd843cb4d0adc8 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Tue, 20 Jun 2023 17:34:47 +1200 Subject: [PATCH 04/17] remove whitespace --- src/wp-includes/post.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index cbc9e47204bb3..98a1473194090 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -8024,7 +8024,7 @@ function use_block_editor_for_post_type( $post_type ) { * Adds sync_status meta field to the wp_block post type so an unsynced option can be added. * * @since 6.3.0 - * + * * @see https://github.com/WordPress/gutenberg/pull/51144 * * @return void From 1c4ebfcd5fdb96d5aceee9ed1ac58a3f6bb65807 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 21 Jun 2023 09:39:39 +1200 Subject: [PATCH 05/17] add meta to fixture --- tests/qunit/fixtures/wp-api-generated.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index 22ac5655af416..f57ba82808d65 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -11928,6 +11928,9 @@ mockedApiResponse.TypesCollection = { "taxonomies": [], "rest_base": "blocks", "rest_namespace": "wp/v2", + "meta": { + "sync_status": "" + }, "_links": { "collection": [ { From 2dcc3136fc93bc42ad8c8f162854a1427d6a32c8 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 21 Jun 2023 10:48:10 +1200 Subject: [PATCH 06/17] Revert fixture change --- tests/qunit/fixtures/wp-api-generated.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index f57ba82808d65..d64b68fa40923 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -11922,15 +11922,12 @@ mockedApiResponse.TypesCollection = { "description": "", "hierarchical": false, "has_archive": false, - "name": "Patterns", + "name": "Reusable blocks", "slug": "wp_block", "icon": null, "taxonomies": [], "rest_base": "blocks", "rest_namespace": "wp/v2", - "meta": { - "sync_status": "" - }, "_links": { "collection": [ { From 4fdf7fb9c05dc564be70bd090c2fcfd45810a3e2 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 21 Jun 2023 11:24:08 +1200 Subject: [PATCH 07/17] Add rebuilt js fixture --- tests/qunit/fixtures/wp-api-generated.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index d64b68fa40923..f0de044b8b09d 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -4539,6 +4539,12 @@ mockedApiResponse.Schema = { }, "required": false }, + "meta": { + "description": "Meta fields.", + "type": "object", + "properties": [], + "required": false + }, "template": { "description": "The theme file to use to display the post.", "type": "string", @@ -4695,6 +4701,12 @@ mockedApiResponse.Schema = { }, "required": false }, + "meta": { + "description": "Meta fields.", + "type": "object", + "properties": [], + "required": false + }, "template": { "description": "The theme file to use to display the post.", "type": "string", @@ -5011,6 +5023,12 @@ mockedApiResponse.Schema = { }, "required": false }, + "meta": { + "description": "Meta fields.", + "type": "object", + "properties": [], + "required": false + }, "template": { "description": "The theme file to use to display the post.", "type": "string", @@ -11922,7 +11940,7 @@ mockedApiResponse.TypesCollection = { "description": "", "hierarchical": false, "has_archive": false, - "name": "Reusable blocks", + "name": "Patterns", "slug": "wp_block", "icon": null, "taxonomies": [], From 615e369a331a645db8040ae5cc919094f57a3b1a Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 21 Jun 2023 12:04:34 +1200 Subject: [PATCH 08/17] Add test to check new postmeta sync_status is returned in API --- .../tests/rest-api/rest-blocks-controller.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/phpunit/tests/rest-api/rest-blocks-controller.php b/tests/phpunit/tests/rest-api/rest-blocks-controller.php index 48208d2175ba3..cf59b33e662a5 100644 --- a/tests/phpunit/tests/rest-api/rest-blocks-controller.php +++ b/tests/phpunit/tests/rest-api/rest-blocks-controller.php @@ -220,4 +220,33 @@ public function test_content() { $data['content'] ); } + + /** + * Check that the postmeta sync_status field is returned in the response. + * + * @ticket 58577 + */ + public function test_postmeta() { + wp_set_current_user( self::$user_ids['editor'] ); + + $request = new WP_REST_Request( 'POST', '/wp/v2/blocks' ); + $request->set_body_params( + array( + 'title' => 'Test', + 'content' => '

Test

', + 'meta' => array( + 'sync_status' => 'unsynced', + ), + ) + ); + + $response = rest_get_server()->dispatch( $request ); + $data = $response->get_data(); + $this->assertSame( + array( + 'sync_status' => 'unsynced', + ), + $data['meta'] + ); + } } From f50707b1ee19725b59a94e15ab948f9f330c6cac Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 21 Jun 2023 12:10:28 +1200 Subject: [PATCH 09/17] Remove whitespace --- tests/phpunit/tests/rest-api/rest-blocks-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/rest-api/rest-blocks-controller.php b/tests/phpunit/tests/rest-api/rest-blocks-controller.php index cf59b33e662a5..8a2e248bf2372 100644 --- a/tests/phpunit/tests/rest-api/rest-blocks-controller.php +++ b/tests/phpunit/tests/rest-api/rest-blocks-controller.php @@ -223,7 +223,7 @@ public function test_content() { /** * Check that the postmeta sync_status field is returned in the response. - * + * * @ticket 58577 */ public function test_postmeta() { From 82226cc70fac50f2eb4b704f12b095c8ec5e7144 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 21 Jun 2023 15:07:39 +1200 Subject: [PATCH 10/17] Remove unit tests as the filter isn't added to add the postmeta when these run --- .../tests/rest-api/rest-blocks-controller.php | 29 ------------------- 1 file changed, 29 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-blocks-controller.php b/tests/phpunit/tests/rest-api/rest-blocks-controller.php index 8a2e248bf2372..48208d2175ba3 100644 --- a/tests/phpunit/tests/rest-api/rest-blocks-controller.php +++ b/tests/phpunit/tests/rest-api/rest-blocks-controller.php @@ -220,33 +220,4 @@ public function test_content() { $data['content'] ); } - - /** - * Check that the postmeta sync_status field is returned in the response. - * - * @ticket 58577 - */ - public function test_postmeta() { - wp_set_current_user( self::$user_ids['editor'] ); - - $request = new WP_REST_Request( 'POST', '/wp/v2/blocks' ); - $request->set_body_params( - array( - 'title' => 'Test', - 'content' => '

Test

', - 'meta' => array( - 'sync_status' => 'unsynced', - ), - ) - ); - - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - $this->assertSame( - array( - 'sync_status' => 'unsynced', - ), - $data['meta'] - ); - } } From 4a1dcf34b25269f0582b374df16ea80077501db3 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 23 Jun 2023 16:07:33 +1200 Subject: [PATCH 11/17] Changes from review --- src/wp-includes/block-editor.php | 1 + src/wp-includes/default-filters.php | 2 +- src/wp-includes/post.php | 9 ++++----- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index cb48055a8ca83..5c77b648c985e 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -11,6 +11,7 @@ * Returns the list of default categories for block types. * * @since 5.8.0 + * @since 6.3.0 Reusable Blocks renamed to Patterns * * @return array[] Array of categories for block types. */ diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index e8ba499b7c5e9..aad39ae3c6f34 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -721,6 +721,6 @@ add_action( 'init', 'wp_register_persisted_preferences_meta' ); // CPT wp_block custom postmeta field. -add_action( 'init', 'wp_register_wp_block_postmeta' ); +add_action( 'init', 'wp_register_initial_post_meta' ); unset( $filter, $action ); diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 98a1473194090..955e5b2097f05 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -8021,15 +8021,14 @@ function use_block_editor_for_post_type( $post_type ) { } /** - * Adds sync_status meta field to the wp_block post type so an unsynced option can be added. + * Registers any additional post meta fields. * - * @since 6.3.0 + * @since 6.3.0 Adds sync_status meta field to the wp_block post type so an unsynced option can be added. * - * @see https://github.com/WordPress/gutenberg/pull/51144 + * @link https://github.com/WordPress/gutenberg/pull/51144 * - * @return void */ -function wp_register_wp_block_postmeta() { +function wp_register_initial_post_meta() { $post_type = 'wp_block'; register_post_meta( $post_type, From acc702f29137c46ffc4768e558389d56991d43e7 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 23 Jun 2023 16:38:37 +1200 Subject: [PATCH 12/17] Fix rest schema --- src/wp-includes/post.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 955e5b2097f05..fea03c734fe9c 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -8042,12 +8042,8 @@ function wp_register_initial_post_meta() { 'type' => 'string', 'show_in_rest' => array( 'schema' => array( - 'type' => 'string', - 'properties' => array( - 'sync_status' => array( - 'type' => 'string', - ), - ), + 'type' => 'string', + 'enum' => array( 'partial', 'unsynced' ), ), ), ) From 49fea3603675d247eb0b7480c7939e18fa7c1436 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 23 Jun 2023 16:43:26 +1200 Subject: [PATCH 13/17] remove auth callback --- src/wp-includes/post.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index fea03c734fe9c..e7998c14462ef 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -8034,9 +8034,6 @@ function wp_register_initial_post_meta() { $post_type, 'sync_status', array( - 'auth_callback' => function() { - return current_user_can( 'edit_posts' ); - }, 'sanitize_callback' => 'sanitize_text_field', 'single' => true, 'type' => 'string', From e5919fbdf9ba5f40f4bf069489c3950f8788222a Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 23 Jun 2023 17:03:01 +1200 Subject: [PATCH 14/17] change to wp_create_initial_post_meta --- src/wp-includes/default-filters.php | 2 +- src/wp-includes/post.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index aad39ae3c6f34..4ddaf291bb115 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -721,6 +721,6 @@ add_action( 'init', 'wp_register_persisted_preferences_meta' ); // CPT wp_block custom postmeta field. -add_action( 'init', 'wp_register_initial_post_meta' ); +add_action( 'init', 'wp_create_initial_post_meta' ); unset( $filter, $action ); diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index e7998c14462ef..c37d8d25fbc07 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -8028,7 +8028,7 @@ function use_block_editor_for_post_type( $post_type ) { * @link https://github.com/WordPress/gutenberg/pull/51144 * */ -function wp_register_initial_post_meta() { +function wp_create_initial_post_meta() { $post_type = 'wp_block'; register_post_meta( $post_type, From 5d9e2de9fab0f065dd545bca36d98b095a626749 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 26 Jun 2023 09:56:10 +1200 Subject: [PATCH 15/17] Remove surplus doc line Co-authored-by: Felix Arntz --- src/wp-includes/post.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index c37d8d25fbc07..c91e3f19fee10 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -8026,7 +8026,6 @@ function use_block_editor_for_post_type( $post_type ) { * @since 6.3.0 Adds sync_status meta field to the wp_block post type so an unsynced option can be added. * * @link https://github.com/WordPress/gutenberg/pull/51144 - * */ function wp_create_initial_post_meta() { $post_type = 'wp_block'; From e2b0ec50c3ad3cca4bb253a0cec5ab79fa437105 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 26 Jun 2023 09:56:50 +1200 Subject: [PATCH 16/17] Add punctuation to doc comment Co-authored-by: Felix Arntz --- src/wp-includes/block-editor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index 5c77b648c985e..34e589ea6402d 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -11,7 +11,7 @@ * Returns the list of default categories for block types. * * @since 5.8.0 - * @since 6.3.0 Reusable Blocks renamed to Patterns + * @since 6.3.0 Reusable Blocks renamed to Patterns. * * @return array[] Array of categories for block types. */ From 53337c7c076526914cd6945a4766805981e80c71 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 26 Jun 2023 15:53:03 +1200 Subject: [PATCH 17/17] hard code block type for register_post_meta call Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> --- src/wp-includes/post.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index c91e3f19fee10..af267b9dc9493 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -8028,9 +8028,8 @@ function use_block_editor_for_post_type( $post_type ) { * @link https://github.com/WordPress/gutenberg/pull/51144 */ function wp_create_initial_post_meta() { - $post_type = 'wp_block'; register_post_meta( - $post_type, + 'wp_block', 'sync_status', array( 'sanitize_callback' => 'sanitize_text_field',