metabox block category null in WP_Block_Type_Registry
- This topic has 8 replies, 2 voices, and was last updated 7 months ago by
Nicholas Cox.
-
AuthorPosts
-
September 9, 2024 at 3:57 AM #46372
Nicholas Cox
ParticipantHi
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
September 11, 2024 at 6:32 AM #46407Peter
ModeratorHello 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>";
September 11, 2024 at 9:07 PM #46415Nicholas Cox
ParticipantOk 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.
September 11, 2024 at 10:56 PM #46423Peter
ModeratorYou can try to deactivate all plugins except Meta Box, MB extension plugins, switch to a WordPress theme and check this issue again.
September 16, 2024 at 8:03 PM #46469Nicholas Cox
ParticipantHi, 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); } } }
September 16, 2024 at 8:17 PM #46470Nicholas Cox
Participantalso even if i change the registered block to a default category e.g. 'widgets' then the issue still persists (null category).
September 16, 2024 at 9:54 PM #46476Nicholas Cox
ParticipantAlso 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)
September 16, 2024 at 10:30 PM #46479Peter
ModeratorPlease share your site admin account by submitting this contact form https://metabox.io/contact/
I will take a look.September 16, 2024 at 11:55 PM #46481Nicholas Cox
ParticipantHi,
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
-
AuthorPosts
- You must be logged in to reply to this topic.