Support Forum
Hi
I have registered a custom cateogry for the block editor.
add_filter( 'block_categories_all', [ $this, 'createBlockCustomCategory' ], 10, 2 );
public function createBlockCustomCategory( $block_categories ) {
$block_categories[] = array(
'slug' => 'dc-blocks',
'title' => __( 'DC Blocks', 'text-domain' ),
);
return $block_categories;
}
public function createGutenbergBlock( $meta_boxes ) {
$meta_boxes[] = [
'title' => 'Product Listing Block',
'id' => 'dc-product-listing-block',
'description' => 'Product listing layouts for your store',
'type' => 'block',
'icon' => 'screenoptions',
'category' => 'dc-blocks',
...
But when i use 'get_all_registered' below the block category names are not appearing in the following array of objects? the category name is null.
WP_Block_Type_Registry::get_instance()->get_all_registered();
any ideas why? The blocks appear correctly under the new category name in the block editor (when adding a new block).
thanks
Hello Nick,
I use your code to register a new block category and it appears in the custom block as well. Please check this screenshot https://imgur.com/6nXaoHr
echo "<pre>";
var_dump( WP_Block_Type_Registry::get_instance()->get_all_registered() );
echo "</pre>";
Ok I have it all setup but the output is still not displaying the category, see below. I have tested quote a few times and still the same issue. Not sure what to look into next.
You can try to deactivate all plugins except Meta Box, MB extension plugins, switch to a WordPress theme and check this issue again.
Hi, I have done what you said but the issue still persists.
I run this code in my footer on the front end to check if its working and no luck
$editorblocks = WP_Block_Type_Registry::get_instance()->get_all_registered();
foreach ($editorblocks as $block) {
if ($block->category){
if ($block->category == 'dc-blocks'){
var_dump($block);
}
}
}
also even if i change the registered block to a default category e.g. 'widgets' then the issue still persists (null category).
Also the metabox block title and description do not show either? e.g.
'meta-box/dc-product-listing-block' =>
object(WP_Block_Type)[1127]
public 'api_version' => int 1
public 'name' => string 'meta-box/dc-product-listing-block' (length=33)
public 'title' => string '' (length=0)
public 'category' => null
public 'parent' => null
public 'ancestor' => null
public 'allowed_blocks' => null
public 'icon' => null
public 'description' => string '' (length=0)
public 'keywords' =>
array (size=0)
empty
public 'textdomain' => null
public 'styles' =>
array (size=0)
empty
private 'variations' => null
public 'variation_callback' => null
public 'selectors' =>
array (size=0)
empty
public 'supports' => null
public 'example' => null
public 'render_callback' =>
array (size=2)
0 =>
object(MBBlocks\Block)[1125]
...
1 => string 'render' (length=6)
public 'attributes' =>
array (size=3)
'lock' =>
array (size=1)
...
'metadata' =>
array (size=1)
...
'className' =>
array (size=1)
...
private 'uses_context' =>
array (size=0)
empty
public 'provides_context' => null
public 'block_hooks' =>
array (size=0)
empty
public 'editor_script_handles' =>
array (size=1)
0 => string 'mb-blocks' (length=9)
public 'script_handles' =>
array (size=0)
empty
public 'view_script_handles' =>
array (size=0)
empty
public 'view_script_module_ids' =>
array (size=0)
empty
public 'editor_style_handles' =>
array (size=1)
0 => string 'mb-blocks' (length=9)
public 'style_handles' =>
array (size=0)
empty
public 'view_style_handles' =>
array (size=0)
empty
private 'deprecated_properties' =>
array (size=5)
0 => string 'editor_script' (length=13)
1 => string 'script' (length=6)
2 => string 'view_script' (length=11)
3 => string 'editor_style' (length=12)
4 => string 'style' (length=5)
Please share your site admin account by submitting this contact form https://metabox.io/contact/
I will take a look.
Hi,
I have added the test plugin to the new site (test site) where i have sent you an email using the contact form.
I have outputted the code in the footer.php file in the theme named drip-create.
echo "<pre>";
var_dump( WP_Block_Type_Registry::get_instance()->get_all_registered() );
echo "</pre>";
the test plugin i made so you can see the issue with metabox blocks
wp-content\plugins\drip-create-plugin-test\includes/run.php
with the 'dc-container-block' as the test block i made up for you.
wp-content\plugins\drip-create-plugin-test\includes\dc-container/dc-container.php
you will see the issue on the homepage e.g.
["meta-box/dc-container-block"]=>
object(WP_Block_Type)#1079 (30) {
["api_version"]=>
int(1)
["name"]=>
string(27) "meta-box/dc-container-block"
["title"]=>
string(0) ""
["category"]=>
NULL
["parent"]=>
NULL
["ancestor"]=>
NULL
["allowed_blocks"]=>
NULL
["icon"]=>
NULL
["description"]=>
string(0) ""
["keywords"]=>
array(0) {
}
["textdomain"]=>
NULL
thanks