Make WordPress Core

Changeset 51214


Ignore:
Timestamp:
06/23/2021 01:07:27 AM (3 years ago)
Author:
desrosj
Message:

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.

Location:
trunk/src/wp-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/default-filters.php

    r51207 r51214  
    598598
    599599// Widgets.
     600add_action( 'after_setup_theme', 'wp_setup_widgets_block_editor', 1 );
    600601add_action( 'init', 'wp_widgets_init', 1 );
    601602
  • trunk/src/wp-includes/theme.php

    r51197 r51214  
    24802480 * @since 5.5.0 The `custom-logo` feature now also accepts 'unlink-homepage-logo'.
    24812481 * @since 5.6.0 The `post-formats` feature warns if no array is passed.
     2482 * @since 5.8.0 The `widgets-block-editor` enables the Widgets block editor.
    24822483 *
    24832484 * @global array $_wp_theme_features
     
    25122513 *                          - 'wp-block-styles'
    25132514 *                          - 'widgets'
     2515 *                          - 'widgets-block-editor'
    25142516 * @param mixed  ...$args Optional extra arguments to pass along with certain features.
    25152517 * @return void|false Void on success, false on failure.
  • trunk/src/wp-includes/widgets.php

    r51107 r51214  
    18021802    register_widget( 'WP_Widget_Block' );
    18031803
    1804     add_theme_support( 'widgets-block-editor' );
    1805 
    18061804    /**
    18071805     * Fires after all default WordPress widgets have been registered.
     
    18101808     */
    18111809    do_action( 'widgets_init' );
     1810}
     1811
     1812/**
     1813 * Enables the widgets block editor. This is hooked into 'after_setup_theme' so
     1814 * that the block editor is enabled by default but can be disabled by themes.
     1815 *
     1816 * @since 5.8.0
     1817 *
     1818 * @access private
     1819 */
     1820function wp_setup_widgets_block_editor() {
     1821    add_theme_support( 'widgets-block-editor' );
    18121822}
    18131823
Note: See TracChangeset for help on using the changeset viewer.