diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 09be9e576b..f10dc6f280 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -626,6 +626,7 @@ add_filter( 'nav_menu_css_class', 'wp_nav_menu_remove_menu_item_has_children_cla add_action( 'after_setup_theme', 'wp_setup_widgets_block_editor', 1 ); add_action( 'init', 'wp_widgets_init', 1 ); add_action( 'change_locale', array( 'WP_Widget_Media', 'reset_default_labels' ) ); +add_action( 'widgets_init', '_wp_block_theme_register_classic_sidebars', 1 ); // Admin Bar. // Don't remove. Wrong way to disable. diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php index 449ad6bb5b..88a10a0a42 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php @@ -339,6 +339,10 @@ class WP_REST_Sidebars_Controller extends WP_REST_Controller { $sidebar['class'] = ''; } + if ( wp_is_block_theme() ) { + $sidebar['status'] = 'inactive'; + } + $fields = $this->get_fields_for_response( $request ); if ( rest_is_field_included( 'widgets', $fields ) ) { $sidebars = wp_get_sidebars_widgets(); diff --git a/wp-includes/theme.php b/wp-includes/theme.php index c3a4206530..c1623f4058 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -733,11 +733,12 @@ function locale_stylesheet() { * @global array $wp_theme_directories * @global WP_Customize_Manager $wp_customize * @global array $sidebars_widgets + * @global array $wp_registered_sidebars * * @param string $stylesheet Stylesheet name. */ function switch_theme( $stylesheet ) { - global $wp_theme_directories, $wp_customize, $sidebars_widgets; + global $wp_theme_directories, $wp_customize, $sidebars_widgets, $wp_registered_sidebars; $requirements = validate_theme_requirements( $stylesheet ); if ( is_wp_error( $requirements ) ) { @@ -814,6 +815,11 @@ function switch_theme( $stylesheet ) { } } + // Stores classic sidebars for later use by block themes. + if ( $new_theme->is_block_theme() ) { + set_theme_mod( 'wp_classic_sidebars', $wp_registered_sidebars ); + } + update_option( 'theme_switched', $old_theme->get_stylesheet() ); /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 48a326793a..292bd25de3 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.2-alpha-55199'; +$wp_version = '6.2-alpha-55200'; /** * 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 015cb3c48a..dc643ffe1c 100644 --- a/wp-includes/widgets.php +++ b/wp-includes/widgets.php @@ -2105,3 +2105,29 @@ function wp_check_widget_editor_deps() { } } } + +/** + * Registers the previous theme's sidebars for the block themes. + * + * @since 6.2.0 + * @access private + * + * @global array $wp_registered_sidebars Registered sidebars. + */ +function _wp_block_theme_register_classic_sidebars() { + global $wp_registered_sidebars; + + if ( ! wp_is_block_theme() ) { + return; + } + + $classic_sidebars = get_theme_mod( 'wp_classic_sidebars' ); + if ( empty( $classic_sidebars ) ) { + return; + } + + // Don't use `register_sidebar` since it will enable the `widgets` support for a theme. + foreach ( $classic_sidebars as $sidebar ) { + $wp_registered_sidebars[ $sidebar['id'] ] = $sidebar; + } +}