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