Proposal: add subcategories to block.json #64706
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As discussed in the ongoing GitHub issue #53431, the current implementation of block categories in WordPress allows for a flat structure where blocks are grouped into high-level categories such as "text," "media," "design," etc. However, as the ecosystem of blocks grows, this flat structure becomes increasingly difficult to manage and navigate, especially when dealing with more complex themes and plugins.
Subcategories offer a solution by allowing blocks to be further organized within parent categories, adding valuable granularity. In this proposal, I’m suggesting an addition to the
block.json
schema that enables the use of subcategories and constrains their assignment to specific parent categories. This approach ensures a well-documented and structured categorization system, preventing misuse and maintaining consistency across blocks.Proposed Schema
Parent-Child Relationships in the Proposed Schema
The category property represents the primary grouping of blocks. Categories are broad and cover major areas like "text," "media," "design," "widgets," "theme," and "embed." Each block must be assigned to one of these categories.
Suggested initial Subcategories (based on Style Book: Iterate on presentation and design #53431)
Schema Constraints and Relationships
The schema introduces constraints that bind specific subcategories to their appropriate parent categories. This ensures that a subcategory can only be used under its designated parent category.
Implementation Example
The subcategory property includes a parent field that references the valid parent category from the category enum. For example:
In this example, "Site Identity," "Design," "Posts," and "Comments" are subcategories that can only exist under the "theme" category.
Enforced Relationships
The schema ensures that subcategories are only available within their designated parent category. For example, the "Design" subcategory is valid under "theme" but cannot be mistakenly used under another category like "text" or "media." This strict enforcement maintains logical and consistent block organization.
Benefits