Unable to register blocks from a plugin
- This topic has 2 replies, 3 voices, and was last updated 10 months ago by
Wilhem.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
February 6, 2025 at 11:17 PM #47611
Wilhem Arnoldy
ParticipantHello team,
I fail registering new Gutenberg blocks from a plugin :
function register_custom_blocks() { // Blocks add_filter( 'rwmb_meta_boxes', 'register_testimony_blocks', 10); } add_filter( 'plugin_loaded', 'register_custom_blocks' ); function register_testimony_blocks( $meta_boxes ) { $prefix = 'waff_golfs_'; /** * Test block */ $meta_boxes[] = [ 'title' => __( 'Testimony', 'wa-golfs' ), 'description' => esc_html__( 'Display random testimonies.', 'wa-golfs' ), 'keywords' => ['testimony', 'posts'], 'id' => 'wa-golfs-testimony', 'category' => 'layout', // 'icon' => 'format-standard', 'icon' => [ 'foreground' => '#1d7c43', 'src' => 'format-standard', ], 'supports' => [ 'anchor' => true, 'customClassName' => true, 'align' => ['wide', 'full'], ], 'type' => 'block', 'context' => 'side', // Fields 'fields' => [ [ 'id' => $prefix . 't_background_class', 'type' => 'text', 'name' => esc_html__( 'CSS background color', 'wa-golfs' ), 'std' => 'bg-action-1', ], [ 'id' => $prefix . 't_text_class', 'type' => 'text', 'name' => esc_html__( 'CSS text color', 'waff' ), 'std' => 'text-dark', ], ], // Render 'render_callback' => function( $attributes, $preview, $post_id ) { ?> <div class="testimonial"> <?= mb_get_block_field( 'waff_golfs_t_background_class' ) ?> <?= mb_get_block_field( 'waff_golfs_t_text_class' ) ?> <b>Default block page :</b> <div class="testimonial__text"> Inner blocks : <InnerBlocks /> </div> </div> <?php }, ]; // wp_die( '<pre>' . print_r($meta_boxes, true) . '</pre>' ); return $meta_boxes; }Can you help me ?
Best, Wilhem
February 7, 2025 at 10:43 PM #47617Peter
ModeratorHello Wilhem,
Could it be your custom plugin is loaded before loading Meta Box plugins? If you put the code to register the custom block to the file functions.php in a theme folder, does it work?
February 10, 2025 at 8:00 PM #47631Wilhem
ParticipantHello Peter,
It is the same, but I just found the issue, some plugin hooked
allowed_block_types_allafter & hide my new block.Solved !
Best regards, Wilhem -
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.