Support Forum
I am experiencing an issue with the „MB Blocks“ extension in Meta Box AIO, where a custom Gutenberg block is not being registered or displayed in the Gutenberg editor. I have tried various steps to resolve the issue, but it persists. Here are the details:
Environment:
WordPress Version: 6.7.2
Theme: GeneratePress (no other plugins installed except Meta Box AIO)
Plugin: Meta Box AIO (latest version, as of February 2025, e.g., version 5.x or higher), with the „MB Blocks“ extension activated
Development Environment: Local Sites (local on my computer, with all necessary PHP extensions like mbstring, dom, json enabled)
Problem:
I have created a custom Gutenberg block with „MB Blocks“ that includes text, color picker, and font family fields. However, the block is not registered or displayed in the Gutenberg editor.
The debug.log consistently shows that „MB Blocks extension is NOT loaded!“ and „mb_block_register does not exist!“ (see logs below).
Attempted Solutions:
Activating, deactivating, and reactivating „MB Blocks“ and Meta Box AIO.
Reinstalling Meta Box AIO (deactivating, deleting, redownloading the latest version, and reactivating).
Testing with older WordPress versions (e.g., 6.7.1), with no success.
Changing the PHP version (from 8.2.23 to 8.1.x), with no success.
Checking the server configuration in Local Sites (PHP extensions, permissions set to 755/644, restarting Local).
Testing with a minimal setup (only GeneratePress and Meta Box AIO, no other plugins).
Result:
Despite all efforts, the block is still not registered, and „MB Blocks“ remains not loaded. The debug.log consistently shows the same issue.
Relevant Code in functions.php (GeneratePress Child Theme „nookoa“):
<?php
/**
* Nookoa Child Theme Functions
*
* @package Nookoa
* @since 1.0
*/
/**
* Load the parent theme's functions
*/
require_once get_template_directory() . '/functions.php';
/**
* Load styles and register the block in the backend
*/
add_action('admin_init', 'nookoa_init');
function nookoa_init() {
// Styles for frontend (commented out for backend testing)
if (!is_admin()) {
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
error_log('Styles are loaded in the frontend!');
} else {
error_log('Admin hook is executed in the backend – block registration prepared!');
}
// Register the Meta Box block with priority 50
add_filter('meta_box_blocks', 'register_custom_gutenberg_block', 50);
error_log('Admin hook registered meta_box_blocks filter with priority 50!');
}
// Debug allowed block types
add_filter('allowed_block_types_all', 'debug_and_allow_block_types', 10, 2);
function debug_and_allow_block_types($allowed_block_types, $post) {
error_log('Allowed block types before change: ' . print_r($allowed_block_types, true));
// Allow all blocks or specifically add your blocks
if (is_array($allowed_block_types)) {
if (!in_array('meta-box/custom-text-block', $allowed_block_types)) {
$allowed_block_types[] = 'meta-box/custom-text-block'; // Adjust the block name if necessary
}
if (!in_array('meta-box/manual-test-block', $allowed_block_types)) {
$allowed_block_types[] = 'meta-box/manual-test-block';
}
} else {
$allowed_block_types = ['meta-box/custom-text-block', 'meta-box/manual-test-block']; // Or return true for all blocks
}
error_log('Allowed block types after change: ' . print_r($allowed_block_types, true));
return $allowed_block_types;
}
// Register the Meta Box block
function register_custom_gutenberg_block($blocks) {
error_log('Filter meta_box_blocks is called!'); // Test if the filter is triggered
$new_block = [
'name' => 'Custom Text Block',
'icon' => 'text',
'render_callback' => 'render_custom_text_block',
'fields' => [
[
'name' => 'text_content',
'label' => 'Text',
'type' => 'textarea',
],
[
'name' => 'text_color',
'label' => 'Text Color',
'type' => 'color',
'options' => [
'#000000' => 'Black',
'#FFFFFF' => 'White',
'#FF0000' => 'Red',
],
],
[
'name' => 'font_family',
'label' => 'Font Family',
'type' => 'select',
'options' => [
'Arial' => 'Arial',
'Helvetica' => 'Helvetica',
'Times New Roman' => 'Times New Roman',
],
],
[
'name' => 'background_color',
'label' => 'Background Color',
'type' => 'color',
'options' => [
'#F0F0F0' => 'Light Gray',
'#000000' => 'Black',
'#FFFFFF' => 'White',
],
],
],
];
$blocks['custom-text-block'] = $new_block;
error_log('Meta Box Block (Custom Text) is registered: ' . print_r($blocks, true));
return $blocks;
}
// Render function for the Custom Text Block
function render_custom_text_block($fields, $attributes) {
$text = !empty($fields['text_content']) ? $fields['text_content'] : '';
$text_color = !empty($fields['text_color']) ? $fields['text_color'] : '#000000';
$font_family = !empty($fields['font_family']) ? $fields['font_family'] : 'Arial';
$background_color = !empty($fields['background_color']) ? $fields['background_color'] : '#FFFFFF';
$style = "color: $text_color; font-family: $font_family; background-color: $background_color; padding: 20px;";
return "<div style='$style'>" . esc_html($text) . "</div>";
}
// Extended check if MB Blocks is loaded
add_action('plugins_loaded', 'debug_mb_blocks_load');
function debug_mb_blocks_load() {
error_log('Plugins loaded – checking MB Blocks...');
if (class_exists('MB_Blocks')) {
error_log('MB Blocks extension is loaded!');
} else {
error_log('MB Blocks extension is NOT loaded – checking Meta Box AIO...');
if (class_exists('RWMB_Loader')) { // Check if Meta Box AIO is loaded
error_log('Meta Box AIO is loaded, but MB Blocks is missing.');
} else {
error_log('Meta Box AIO is NOT loaded!');
}
}
}
// Minimal test block to test MB Blocks
add_action('admin_init', 'test_mb_block_manually');
function test_mb_block_manually() {
if (class_exists('MB_Blocks') && function_exists('mb_block_register')) {
mb_block_register('manual-test-block', [
'name' => 'Manual Test Block',
'icon' => 'text',
'render_callback' => function() {
return '<div>Manual Test Block</div>';
},
'fields' => [],
]);
error_log('Manual MB Block registered!');
} else {
error_log('MB Blocks or mb_block_register does not exist!');
}
}
Logs from debug.log
[27-Feb-2025 08:23:25 UTC] MB Blocks extension is NOT loaded!
[27-Feb-2025 08:23:25 UTC] MB Blocks or mb_block_register does not exist!
Additional Notes:
I have already verified that all PHP extensions and permissions are correctly set, but the issue persists.
I am working locally with Local Sites, I hope you can assist me in resolving this issue, as I urgently need to use this block in my project. Thank you in advance for your support!
Hello Sven,
Meta Box doesn't support the filter hook meta_box_blocks
. Can you please let me know where you get it? Is it noted in the documentation?
We only support one filter hook rwmb_meta_boxes
to register all types: custom fields, blocks, settings page ...
If you want to register the custom block with PHP code, please follow the documentation
https://docs.metabox.io/extensions/mb-blocks/#block-registration-without-blockjson
Thanks for your support. no idea where that hook came from