Unable to register blocks from a plugin

Support MB Blocks Unable to register blocks from a pluginResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #47611
    Wilhem ArnoldyWilhem Arnoldy
    Participant

    Hello 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

    #47617
    PeterPeter
    Moderator

    Hello 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?

    #47631
    WilhemWilhem
    Participant

    Hello Peter,

    It is the same, but I just found the issue, some plugin hooked allowed_block_types_all after & hide my new block.

    Solved !
    Best regards, Wilhem

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.