Skip to content

Commit

Permalink
Add backwards compatible method for getting custom category
Browse files Browse the repository at this point in the history
The method will work with old block_categories hook with different argument type.
  • Loading branch information
dingo-d committed Feb 1, 2022
1 parent 5d768da commit 80db717
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/Blocks/AbstractBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,40 @@ public function render(array $attributes, string $innerBlockContent): string
*
* This category will be shown on all blocks list in "Add Block" button.
*
* @param array[] $categories Array of all block categories.
* @hook block_categories_all Available from WP 5.8.
*
* @param array[] $categories Array of categories for block types.
* @param \WP_Block_Editor_Context $blockEditorContext The current block editor context.
*
* @return array[] Array of categories for block types.
*/
public function getCustomCategory(array $categories, \WP_Block_Editor_Context $blockEditorContext): array
{
return array_merge(
$categories,
[
[
'slug' => 'eightshift',
'title' => \esc_html__('Eightshift', 'eightshift-libs'),
'icon' => 'admin-settings',
],
]
);
}

/**
* Create custom category to assign all custom blocks
*
* This category will be shown on all blocks list in "Add Block" button.
*
* @hook block_categories This is a WP 5 - WP 5.7 compatible hook callback. Will not work with WP 5.8!
*
* @param array[] $categories Array of categories for block types.
* @param \WP_Post $post Post being loaded.
*
* @return array[] Array of block categories.
* @return array[] Array of categories for block types.
*/
public function getCustomCategory(array $categories, \WP_Post $post): array
public function getCustomCategoryOld(array $categories, \WP_Post $post): array
{
return array_merge(
$categories,
Expand Down

0 comments on commit 80db717

Please sign in to comment.