From 69868c96489231b0065f43bec403228e6e144932 Mon Sep 17 00:00:00 2001 From: desrosj Date: Fri, 9 Jul 2021 17:57:59 +0000 Subject: [PATCH] Widgets: Warn when `wp-editor` script or `wp-edit-post` style is enqueued in widgets editor It is common that plugins erroneously have `wp-editor` or `wp-edit-post` as a dependency in a script that is loaded in the new widgets editor. This is a smell since both `@wordpress/editor` and `@wordpress/edit-post` assume the existence of a global "post" object which the widgets editor does not have. [51387] fixes the user-facing errors typically caused by this mistake, but we can go a step further and warn developers about this by calling `_doing_it_wrong()` when we detect that the `wp-editor` script or `wp-edit-post` style is enqueued alongside `wp-edit-widgets` or `wp-customize-widgets`. Props zieladam, spacedmonkey, TimothyBlynJacobs, andraganescu, dlh, noisysocks. Merges [51388] to the 5.8 branch. Fixes #53569. See #53437. Built from https://develop.svn.wordpress.org/branches/5.8@51393 git-svn-id: http://core.svn.wordpress.org/branches/5.8@51004 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/default-filters.php | 1 + wp-includes/version.php | 2 +- wp-includes/widgets.php | 36 +++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 068ca78b4d..a446eed1c2 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -566,6 +566,7 @@ add_action( 'admin_print_scripts-index.php', 'wp_localize_community_events' ); add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' ); add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' ); add_filter( 'customize_controls_print_styles', 'wp_resource_hints', 1 ); +add_action( 'admin_head', 'wp_check_widget_editor_deps' ); // Global styles can be enqueued in both the header and the footer. See https://core.trac.wordpress.org/ticket/53494. add_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 3c4976b855..7132b532a5 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.8-RC2-51392'; +$wp_version = '5.8-RC2-51393'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php index 2a90d6ff0f..b2a6010cc1 100644 --- a/wp-includes/widgets.php +++ b/wp-includes/widgets.php @@ -2006,3 +2006,39 @@ function wp_render_widget_control( $id ) { return ob_get_clean(); } + +/** + * The 'wp-editor' script module is exposed as window.wp.editor. This overrides + * the legacy TinyMCE editor module which is required by the widgets editor. + * Because of that conflict, these two shouldn't be enqueued together. See + * https://core.trac.wordpress.org/ticket/53569. + * + * There is also another conflict related to styles where the block widgets + * editor is hidden if a block enqueues 'wp-edit-post' stylesheet. See + * https://core.trac.wordpress.org/ticket/53569. + * + * @since 5.8.0 + * @access private + */ +function wp_check_widget_editor_deps() { + global $wp_scripts, $wp_styles; + if ( + $wp_scripts->query( 'wp-edit-widgets', 'enqueued' ) || + $wp_scripts->query( 'wp-customize-widgets', 'enqueued' ) + ) { + if ( $wp_scripts->query( 'wp-editor', 'enqueued' ) ) { + _doing_it_wrong( + 'enqueue_script', + '"wp-editor" script should not be enqueued together with the new widgets editor (wp-edit-widgets or wp-customize-widgets).', + '5.8.0' + ); + } + if ( $wp_styles->query( 'wp-edit-post', 'enqueued' ) ) { + _doing_it_wrong( + 'enqueue_style', + '"wp-edit-post" style should not be enqueued together with the new widgets editor (wp-edit-widgets or wp-customize-widgets).', + '5.8.0' + ); + } + } +}