'Wordpress React Block "block is already registered"
First time creating blocks in Wordpress with the react style. I belive my index.php registering multiple scripts is spouting out console errors in js.
JS console error - Block "plugin/block-close-box" is already registered
Other SO posts refer to only having one wp_register_script for all the blocks but unsure if that is true or if it is what is the correct way.
class loadTheBlocks{
function __construct(){
add_action('init', array($this, 'loadBlocks'));
}
function loadBlocks(){
wp_register_script('card_close_box', plugin_dir_url(__FILE__) . 'build/index.js', array('wp-blocks', 'wp-element'));
register_block_type('plugin/block-close-box',array(
'editor_script' => 'card_close_box',
'render_callback' => array($this, 'close_box_block')
));
wp_register_script('background-card-block', plugin_dir_url(__FILE__) . 'build/index.js', array('wp-blocks', 'wp-element'));
register_block_type('plugin/card-block',array(
'editor_script' => 'background-card-block',
'render_callback' => array($this, 'background_card_block')
));
wp_register_script('top-card-bg', plugin_dir_url(__FILE__) . 'build/index.js', array('wp-blocks', 'wp-element'));
register_block_type('plugin/top-card-bg',array(
'editor_script' => 'top-card-bg',
'render_callback' => array($this, 'top_card_block')
));
}
}
$loadTheBlocks = new loadTheBlocks;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
