Skip to content

Commit

Permalink
chore: create new block category for example custom blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
rise-erpelding committed Sep 26, 2023
1 parent fb2d4d6 commit 4242778
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/plugins/example-blocks/blocks/hello-world/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "example-blocks/hello-world",
"version": "0.1.0",
"title": "Hello World",
"category": "widgets",
"category": "example-custom-blocks",
"icon": "nametag",
"description": "Prints Hello World!",
"supports": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "example-blocks/reverse-string",
"version": "0.1.0",
"title": "Reverse String",
"category": "widgets",
"category": "example-custom-blocks",
"icon": "smiley",
"description": "Prints a user-entered string in reverse order.",
"supports": {
Expand Down
23 changes: 23 additions & 0 deletions src/plugins/example-blocks/example-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,26 @@ function create_block_example_blocks_block_init() {
}
}
add_action( 'init', 'create_block_example_blocks_block_init' );

/**
* Add a custom block category to the WordPress block editor (Gutenberg).
*
* This function is hooked to the 'block_categories_all' filter and adds a new
* block category named 'Example Custom Blocks' with the slug 'example-custom-blocks'
* to the block editor.
*
* @param array $categories An array of existing block categories.
* @param WP_Post $post The current post or page object.
*
* @return array Modified array of block categories.
*/
function create_category_example_custom_blocks( $categories, $post ) {

array_unshift( $categories, array(
'slug' => 'example-custom-blocks',
'title' => 'Example Custom Blocks'
) );

return $categories;
}
add_filter( 'block_categories_all', 'create_category_example_custom_blocks', 10, 2);

0 comments on commit 4242778

Please sign in to comment.