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
This commit is contained in:
Jonathan Desrosiers
2021-06-23 01:07:27 +00:00
parent 1af21df75b
commit 834c0996cf
3 changed files with 15 additions and 2 deletions
+12 -2
View File
@@ -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