Skip to content

Commit

Permalink
Blocks: Ensure theme category is only added when not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Mar 22, 2021
1 parent ec3677d commit 2701788
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ The Block Editor allows you to indicate the category your block belongs in, maki
- media
- design
- widgets
- theme
- embed

[Read more about categories.](/docs/reference-guides/block-api/block-metadata.md#category)
Expand Down
1 change: 1 addition & 0 deletions docs/reference-guides/block-api/block-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ The core provided categories are:
- media
- design
- widgets
- theme
- embed

Plugins and Themes can also register [custom block categories](/docs/reference-guides/filters/block-filters.md#managing-block-categories).
Expand Down
3 changes: 1 addition & 2 deletions docs/reference-guides/block-api/block-registration.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ The core provided categories are:
- media
- design
- widgets
- theme
- embed

```js
Expand Down Expand Up @@ -226,8 +227,6 @@ example: {

Similarly to how the block's style variations can be declared, a block type can define block variations that the user can pick from. The difference is that, rather than changing only the visual appearance, this field provides a way to apply initial custom attributes and inner blocks at the time when a block is inserted. See the [Block Variations API](/docs/reference-guides/block-api/block-variations.md) for more details.



#### supports (optional)

- **_Type:_** `Object`
Expand Down
19 changes: 17 additions & 2 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,26 @@ function gutenberg_register_legacy_social_link_blocks() {

/**
* Filters the default block categories array to add a new one for themes.
* Should be removed and turned into a core.trac ticket for merge.
*
* @param array $categories The list of default block categories.
* This can be removed when plugin support requires WordPress 5.8.0+.
*
* @see https://core.trac.wordpress.org/ticket/52883
*
* @param array[] $categories The list of default block categories.
*
* @return array[] Filtered block categories.
*/
function gutenberg_register_theme_block_category( $categories ) {
foreach ( $categories as $category ) {
// Skip when the category is already set in WordPress core.
if (
isset( $category['slug'] ) &&
'theme' === $category['slug']
) {
return $categories;
}
}

$categories[] = array(
'slug' => 'theme',
'title' => _x( 'Theme', 'block category', 'gutenberg' ),
Expand Down
4 changes: 4 additions & 0 deletions packages/create-block/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Scaffolded plugin requires WordPress 5.7 now ([#29757](https://github.com/WordPress/gutenberg/pull/29757)).

### New Features

- Add new `theme` category to select for the block type ([#30089](https://github.com/WordPress/gutenberg/pull/30089)).

## 2.1.0 (2021-03-17)

### New Features
Expand Down
2 changes: 1 addition & 1 deletion packages/create-block/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ The following configurable variables are used with the template files. Template
- `title` (no default) - a display title for your block.
- `description` (no default) - a short description for your block.
- `dashicon` (no default) - an icon property thats makes it easier to identify a block, see https://developer.wordpress.org/resource/dashicons/.
- `category` (default: `'widgets'`) - blocks are grouped into categories to help users browse and discover them. The categories provided by core are `text`, `media`, `design`, `widgets`, and `embed`.
- `category` (default: `'widgets'`) - blocks are grouped into categories to help users browse and discover them. The categories provided by core are `text`, `media`, `design`, `widgets`, `theme`, and `embed`.
- `attributes` (no default) - see https://developer.wordpress.org/block-editor/developers/block-api/block-attributes/.
- `supports` (no default) - optional block extended support features, see https://developer.wordpress.org/block-editor/developers/block-api/block-supports/.
- `author` (default: `'The WordPress Contributors'`)
Expand Down
2 changes: 1 addition & 1 deletion packages/create-block/lib/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const category = {
type: 'list',
name: 'category',
message: 'The category name to help users browse and discover your block:',
choices: [ 'text', 'media', 'design', 'widgets', 'embed' ],
choices: [ 'text', 'media', 'design', 'widgets', 'theme', 'embed' ],
};

const author = {
Expand Down

0 comments on commit 2701788

Please sign in to comment.