Roots Discourse

Sage 10 | Wordpress 5.8.1 widgets

Hello

I want to use the Gutenberg editor for widgets but after entering widgets I get the error:

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.)

How can i fix this problem?

1 Like

I’m using a workaround. Certainly not the best method.
Replace the enqueue_block_editor_assets filter in setup.php by:

add_action('enqueue_block_editor_assets', function () {
    $currentScreen = get_current_screen();
    $manifest = asset('scripts/manifest.asset.php')->load();
    if ($manifest && 'widgets' != $currentScreen->base) {
        wp_enqueue_script('sage/vendor.js', asset('scripts/vendor.js')->uri(), ...array_values($manifest));
        wp_enqueue_script('sage/editor.js', asset('scripts/editor.js')->uri(), ['sage/vendor.js'], null, true);

        wp_add_inline_script('sage/vendor.js', asset('scripts/manifest.js')->contents(), 'before');
    }

    wp_enqueue_style('sage/editor.css', asset('styles/editor.css')->uri(), false, null);
}, 100);

Just leaving this here until someone comes up with a better approach.

1 Like