From 7368e869942a68cd731662d5f1d03672e5317778 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Tue, 22 Jun 2021 16:54:50 +0000 Subject: [PATCH] Widgets: Stop loading `wp-editor` and the Block Directory assets on the widgets screen. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using the text widget, a `wp.editor.initialize is not a function` notice is encountered. This happens when `wp-editor` is loaded as a dependency, which assigns `wp.oldEditor = wp.editor` and then redefines `wp.editor`. `wp-editor` is only used for the Classic block, which is not supported in the new widgets editor. [51198-51199] updated `@wordpress/block-library` to remove `wp-editor` as a dependency, but it’s still listed as a dependency of the `wp-block-directory` script handle. Since the Block directory is not supported within the widgets editor, the related assets can safely be blocked from enqueueing. Props noisysocks, gziolo, Mamaduka, mkaz. Fixes #53437. See #53397. git-svn-id: https://develop.svn.wordpress.org/trunk@51202 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/widgets-form-blocks.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/widgets-form-blocks.php b/src/wp-admin/widgets-form-blocks.php index 6921ff7a15..7f3b6b2f65 100644 --- a/src/wp-admin/widgets-form-blocks.php +++ b/src/wp-admin/widgets-form-blocks.php @@ -29,6 +29,11 @@ $editor_settings = get_block_editor_settings( $block_editor_context ); +// The widgets editor does not support the Block Directory, so don't load any of +// its assets. This also prevents 'wp-editor' from being enqueued which we +// cannot load in the widgets screen because many widget scripts rely on `wp.editor`. +remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' ); + wp_add_inline_script( 'wp-edit-widgets', sprintf( @@ -67,7 +72,7 @@ require_once ABSPATH . 'wp-admin/admin-header.php'; do_action( 'widgets_admin_page' ); ?> -
+