Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport Rename Reusable blocks to Patterns #4646

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
3 changes: 2 additions & 1 deletion src/wp-includes/block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -48,7 +49,7 @@ function get_default_block_categories() {
),
array(
'slug' => 'reusable',
'title' => _x( 'Reusable Blocks', 'block category' ),
peterwilsoncc marked this conversation as resolved.
Show resolved Hide resolved
'title' => _x( 'Patterns', 'block category' ),
'icon' => null,
),
);
Expand Down
3 changes: 3 additions & 0 deletions src/wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,4 +720,7 @@
// User preferences.
add_action( 'init', 'wp_register_persisted_preferences_meta' );

// CPT wp_block custom postmeta field.
add_action( 'init', 'wp_create_initial_post_meta' );

unset( $filter, $action );
66 changes: 46 additions & 20 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,26 +282,26 @@ function create_initial_post_types() {
'wp_block',
array(
'labels' => array(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to say this one could have a @since 6.3.0 note too, but then I checked the create_initial_post_types doc block and there were no additions of the sort for previous changes, so I guess we might as well be consistent and leave it out 😅

'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. */
Expand All @@ -328,6 +328,7 @@ function create_initial_post_types() {
'title',
'editor',
'revisions',
'custom-fields',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is custom fields support actually needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my testing the postmeta sync_status field was not returned without this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are however going to look at returning it via REST as a top-level sync_status field rather than as post meta so we may be able to drop custom fields support if we go that way.

),
)
);
Expand Down Expand Up @@ -8018,3 +8019,28 @@ function use_block_editor_for_post_type( $post_type ) {
*/
return apply_filters( 'use_block_editor_for_post_type', true, $post_type );
}

/**
* Registers any additional post meta fields.
*
* @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() {
register_post_meta(
'wp_block',
'sync_status',
array(
'sanitize_callback' => 'sanitize_text_field',
'single' => true,
'type' => 'string',
'show_in_rest' => array(
'schema' => array(
'type' => 'string',
'enum' => array( 'partial', 'unsynced' ),
),
),
)
);
}
2 changes: 1 addition & 1 deletion tests/phpunit/tests/blocks/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public function test_get_default_block_editor_settings() {
),
array(
'slug' => 'reusable',
'title' => 'Reusable Blocks',
'title' => 'Patterns',
'icon' => null,
),
),
Expand Down
20 changes: 19 additions & 1 deletion tests/qunit/fixtures/wp-api-generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -11922,7 +11940,7 @@ mockedApiResponse.TypesCollection = {
"description": "",
"hierarchical": false,
"has_archive": false,
"name": "Reusable blocks",
"name": "Patterns",
"slug": "wp_block",
"icon": null,
"taxonomies": [],
Expand Down