mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-05 05:04:31 +00:00
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`. See #53437. Fixes #53569. Props zieladam, spacedmonkey, TimothyBlynJacobs, andraganescu, dlh. git-svn-id: https://develop.svn.wordpress.org/trunk@51388 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user