Inner Blocks allowedBlocks property doesn't work
- This topic has 1 reply, 2 voices, and was last updated 11 hours, 24 minutes ago by
Peter.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
September 7, 2025 at 6:40 PM #48938
Wolfgang
ParticipantHey there,
i'm in the process of creating a new site with mb_blocks and a custom theme. I've installed MB using composer and everything works fine.
Now, I wanted to add my first block "hero" and it seems that allowedBlocks doesn't work as expected.
I have the following code
functions.php:
/** * Block Register */ add_filter('rwmb_meta_boxes', function ($meta_boxes) { $block_files = glob(get_template_directory() . '/blocks/mb/*/block.php'); if (! empty($block_files)) { foreach ($block_files as $block_file) { $meta_boxes[] = require $block_file; } } return $meta_boxes; });
block.php:
<?php return [ 'title' => 'Hero Content', 'id' => 'hero-content', 'description' => 'A custom hero content block', // Block settings. 'type' => 'block', 'icon' => 'awards', 'category' => 'layout', 'context' => 'side', 'render_template' => get_template_directory() . '/blocks/mb/hero/template.php', // 'enqueue_style' => get_template_directory_uri() . '/blocks/mb/hero/style.css', // CSS am besten auch hier ablegen // 'supports' => [ // ], 'fields' => [ [ 'type' => 'file_advanced', 'id' => 'media', 'name' => 'Media', "max_file_uploads" => 1, 'mime_type' => 'video/mp4,image/*', 'desc' => 'Upload an image or a video (mp4).', ] ], ];
template.php:
<?php $media_outer_array = $attributes['media'] ?? null; // reset() holt den Wert des ERSTEN Elements, egal welchen Key es hat. $media = $media_outer_array ? reset($media_outer_array) : null; $is_video = false; if ($media) { if (isset($media['mime_type']) && str_starts_with($media['mime_type'], 'video/')) { $is_video = true; } } ?> <div class="hero-block"> <?php if ($media): ?> <?php if ($is_video): ?> <video controls muted autoplay loop playsinline> <source src="<?= esc_url($media['url']); ?>" type="<?= esc_attr($media['mime_type']); ?>"> </video> <?php else: ?> <img src="<?= esc_url($media['url']); ?>" alt="<?= esc_attr($media['title']); ?>"> <?php endif; ?> <?php endif; ?> <div class="hero-content"> <h1><?php echo esc_html($title); ?></h1> <p><?php echo esc_html($content); ?></p> <InnerBlocks template="<?= esc_attr(json_encode([ ['core/heading', ['placeholder' => 'Titel eingeben...', 'level' => 1]], ])) ?>" allowedBlocks="<?= esc_attr(json_encode([ 'core/heading', ])) ?>" /> </div> </div>
For some reason i can still insert any block i want as Innerblock. Anyone an idea what is going wrong here?
September 8, 2025 at 9:31 PM #48944Peter
ModeratorHello,
Thank you for your feedback.
There could be an issue with the
allowedBlocks
setting of the inner blocks. I've escalated this issue to the development team to check it and get back to you when I have more information. -
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.