From b32d8c1bf6a6a82582571985bb20056854cf4f3c Mon Sep 17 00:00:00 2001 From: desrosj Date: Tue, 22 Jun 2021 16:56:56 +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. Built from https://develop.svn.wordpress.org/trunk@51202 git-svn-id: http://core.svn.wordpress.org/trunk@50811 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/widgets-form-blocks.php | 7 ++++++- wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/wp-admin/widgets-form-blocks.php b/wp-admin/widgets-form-blocks.php index 6921ff7a15..7f3b6b2f65 100644 --- a/wp-admin/widgets-form-blocks.php +++ b/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' ); ?> -
+