From 834c0996cf19a7d3309ae81ccfebed988e9afc93 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Wed, 23 Jun 2021 01:07:27 +0000 Subject: [PATCH] Widgets: Add support for the Widgets Editor on `after_setup_theme` instead of `widgets_init`. This better aligns with developer expectations, as `add_theme_support()` and `remove_theme_support()` are meant to be called within functions attached to the `after_setup_theme` hook. This also adds the `widgets-block-editor` feature to the docblock for `add_theme_support()`. Props kevin940726, caseymilne, jamesros161, noisysocks, Mamaduka, audrasjb, zieladam, hellofromTonya, desrosj. Fixes #53424. git-svn-id: https://develop.svn.wordpress.org/trunk@51214 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/default-filters.php | 1 + src/wp-includes/theme.php | 2 ++ src/wp-includes/widgets.php | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 144ddc8ccd..f5d3fb6b06 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -597,6 +597,7 @@ add_filter( 'plupload_default_settings', 'wp_show_heic_upload_error' ); add_filter( 'nav_menu_item_id', '_nav_menu_item_id_use_once', 10, 2 ); // Widgets. +add_action( 'after_setup_theme', 'wp_setup_widgets_block_editor', 1 ); add_action( 'init', 'wp_widgets_init', 1 ); // Admin Bar. diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index a1a4af1946..499d616763 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -2479,6 +2479,7 @@ function get_theme_starter_content() { * @since 5.5.0 The `core-block-patterns` feature was added and is enabled by default. * @since 5.5.0 The `custom-logo` feature now also accepts 'unlink-homepage-logo'. * @since 5.6.0 The `post-formats` feature warns if no array is passed. + * @since 5.8.0 The `widgets-block-editor` enables the Widgets block editor. * * @global array $_wp_theme_features * @@ -2511,6 +2512,7 @@ function get_theme_starter_content() { * - 'title-tag' * - 'wp-block-styles' * - 'widgets' + * - 'widgets-block-editor' * @param mixed ...$args Optional extra arguments to pass along with certain features. * @return void|false Void on success, false on failure. */ diff --git a/src/wp-includes/widgets.php b/src/wp-includes/widgets.php index 877357606b..124428a622 100644 --- a/src/wp-includes/widgets.php +++ b/src/wp-includes/widgets.php @@ -1801,8 +1801,6 @@ function wp_widgets_init() { register_widget( 'WP_Widget_Block' ); - add_theme_support( 'widgets-block-editor' ); - /** * Fires after all default WordPress widgets have been registered. * @@ -1811,6 +1809,18 @@ function wp_widgets_init() { do_action( 'widgets_init' ); } +/** + * Enables the widgets block editor. This is hooked into 'after_setup_theme' so + * that the block editor is enabled by default but can be disabled by themes. + * + * @since 5.8.0 + * + * @access private + */ +function wp_setup_widgets_block_editor() { + add_theme_support( 'widgets-block-editor' ); +} + /** * Whether or not to use the block editor to manage widgets. Defaults to true * unless a theme has removed support for widgets-block-editor or a plugin has