WordPress / gutenberg-examples

Examples for extending WordPress/Gutenberg with blocks.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wp_enqueue_script() was called incorrectly. "wp-editor" script should not be enqueued together with the new widgets editor

tishonator opened this issue · comments

Hi Gutenberg Team,

I followed your examples (i.e. https://github.com/WordPress/gutenberg-examples/blob/c091ad9551bbba7d2e64063007e7e313cd3995bc/05-recipe-card/index.php) to build custom Gutenberg blocks.

All worked fine until latest WordPress upgrade (ver. 5.8)

Now when I navigate to Admin Panel -> Left Menu -> Appearance -> Widgets, the following error appears:

Notice: wp_enqueue_script() was called incorrectly. "wp-editor" script should not be enqueued together with the new widgets editor (wp-edit-widgets or wp-customize-widgets). Please see Debugging in WordPress for more information. (This message was added in version 5.8.0.) in /var/www/html/wp-includes/functions.php on line 5535

the code which causes the issue:

`function tishonator_register_blocks() {

// Skills Block
wp_register_script(
    'tishonator-skill-block',
    get_stylesheet_directory_uri() . '/blocks/skill.js',
    array( 'wp-editor',
        'wp-blocks',
        'wp-i18n',
        'wp-element', )
);

register_block_type( 'tishonator/skill-block', array(
    'editor_script' => 'tishonator-skill-block',
) );

}
add_action( 'init', 'tishonator_register_blocks' );`

If I DELETE 'wp-editor' from the above array, the error disappears, but the block is no more available (neither in widgets or posts/pages Gutenberg editor).

Probably, I need to use another action (instead of 'init') but I still haven't found a working action.

So, I would be very thankful for any help

Thanks,
Tihomir
Tishonator Team

I applied the following fix for blocks to be working on both Gutenberg editor and widgets page (in case someone else have the same issue):

`function tishonator_get_block_dependencies() {

global $pagenow;

if ( $pagenow === 'widgets.php' ) {
    return array( 'wp-edit-widgets',
        'wp-blocks',
        'wp-i18n',
        'wp-element', );
}

return array( 'wp-editor',
        'wp-blocks',
        'wp-i18n',
        'wp-element', );

}

function tishonator_register_blocks() {

// Skills Block
wp_register_script(
'tishonator-skill-block',
get_stylesheet_directory_uri() . '/blocks/skill.js',
tishonator_get_block_dependencies()
);

register_block_type( 'tishonator/skill-block', array(
'editor_script' => 'tishonator-skill-block',
) );

}
add_action( 'init', 'tishonator_register_blocks' );`

I believe this is answered? I'll close this issue now but feel free to reopen it if there're unanswered questions :).