-
-
Notifications
You must be signed in to change notification settings - Fork 0
Register Custom Block Category: Tour Operator #403
Description
Description
This issue tracks the creation and registration of a custom block category called Tour Operator for the Tour Operator plugin. This custom category will group all relevant blocks together, enhancing their discoverability within the block editor.
Currently, the Tour Operator (TO) blocks are scattered throughout the Block Inserter. We need to organise these blocks under a single heading in the Block Inserter for improved user experience and easier access. Only selected blocks should display in the Block Editor, while template-related blocks should be shown in the Site Editor's Block Inserter.
Requirements:
- Create a new category in the Block Inserter for Tour Operator blocks.
- All TO blocks should be grouped under this heading.
- Display only selected blocks in the Block Editor.
- Ensure that only relevant blocks appear when users are editing posts or pages.
- Template-related blocks should be displayed in the Site Editor’s Block Inserter.
Tasks
-
Decide on specific block categories that will be used within the Tour Operator plugin.
-
Ensure blocks are registered on the server side using the PHP function and
register_block_typeon the client side using the JavaScript function and on the client side using the JavaScript functionregisterBlockType. -
Use metadata in the
block.jsonfile for each block, following the standard schema:
Here’s a code snippet for registering a custom pattern category for the Tour Operator Plugin using the register_block_pattern_category() function:{ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "tour-operator/tour-collections", "title": "Tour Collections", "category": "tour-operator", "icon": "compass", "description": "Tour Operator content collections block for display tours, destinations and accommodation", "keywords": [ "accommodation", "tours", "destinations" ], "version": "1.0.0" }
Acceptance Criteria
- Depends on Create Compass Dashicon #401
- Custom block category
Tour Operatoris successfully registered and visible in the block inserter. - All related blocks are properly categorized under
Tour Operator. - Custom category can be filtered and managed according to user needs.
- All TO blocks are grouped under a single Tour Operator heading in the Block Inserter.
- Only selected blocks are visible in the Block Editor.
- Template-related blocks are visible in the Site Editor’s Block Inserter.
Additional Notes:
- Ensure that the categorisation improves the user experience, making it easier for users to find and use the relevant blocks.
References
- Registering custom block categories
-
register_block_type -
registerBlockType. - Managing block categories
- block_categories_all
- Before WordPress 5.8, this hook was known as block_categories, which is now deprecated. If you need to support older versions of WordPress, you might need a way to detect which filter should be used. You can check if block_categories is safe to use by seeing if the WP_Block_Editor_Context class exists, which was introduced in 5.8.
- It is possible to filter the list of default block categories using the block_categories_all filter. You can do it on the server by implementing a function which returns a list of categories. It is going to be used during block registration and to group blocks in the inserter. You can also use the second provided parameter $editor_context to filter the based on its content.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status