Make WordPress Core


Ignore:
Timestamp:
02/03/2023 12:13:52 AM (2 years ago)
Author:
hellofromTonya
Message:

Widgets: Preserve classic sidebars when switching to a block theme.

When switching to a block theme, classic sidebars were orphaned and their widgets remapping to the 'wp_inactive_widgets' sidebar . This changeset preserves the sidebars and their widgets, providing a migration path to a block theme without losing the widgets.

Classic sidebars are now:

  • Stored in a new theme mod called 'wp_classic_sidebars';
  • Restored to the $wp_registered_sidebars global variable when the 'widgets_init' action fires (via a new internal function called _wp_block_theme_register_classic_sidebars());
  • And marked as 'inactive' when interacting with sidebars REST API endpoint.

References:

Follow-up to [50995], [6334].

Props mamaduka, audrasjb, hellofromTonya, ironprogrammer, jameskoster, joen, matveb, mukesh27, noisysocks, poena, youknowriad.
Fixes #57531.

File:
1 edited

Legend:

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

    r55014 r55200  
    734734 * @global WP_Customize_Manager $wp_customize
    735735 * @global array                $sidebars_widgets
     736 * @global array                $wp_registered_sidebars
    736737 *
    737738 * @param string $stylesheet Stylesheet name.
    738739 */
    739740function switch_theme( $stylesheet ) {
    740     global $wp_theme_directories, $wp_customize, $sidebars_widgets;
     741    global $wp_theme_directories, $wp_customize, $sidebars_widgets, $wp_registered_sidebars;
    741742
    742743    $requirements = validate_theme_requirements( $stylesheet );
     
    813814            remove_theme_mod( 'sidebars_widgets' );
    814815        }
     816    }
     817
     818    // Stores classic sidebars for later use by block themes.
     819    if ( $new_theme->is_block_theme() ) {
     820        set_theme_mod( 'wp_classic_sidebars', $wp_registered_sidebars );
    815821    }
    816822
Note: See TracChangeset for help on using the changeset viewer.