Make WordPress Core


Ignore:
Timestamp:
09/21/2017 06:45:03 PM (7 years ago)
Author:
obenland
Message:

Widgets: Improved sidebar mapping on theme switch

Builds on efforts brought forward in #17979.

This will send sidebars through three levels of mapping:

  1. If both themes have only one sidebar, that gets mapped.
  2. If both themes have sidebars with the same slug, they get mapped.
  3. Sidebars that (even partially) match slugs from a similar kind of sidebar will get mapped.

Finally, if the theme has previously been active and we have a record of its
sidebar configuration then, any unmapped sidebar will be restored to its
previous state.

Props westonruter, obenland, alexvorn2, timmydcrawford.
See #39693.

File:
1 edited

Legend:

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

    r41353 r41555  
    682682    $_sidebars_widgets = null;
    683683    if ( 'wp_ajax_customize_save' === current_action() ) {
    684         $_sidebars_widgets = $wp_customize->post_value( $wp_customize->get_setting( 'old_sidebars_widgets_data' ) );
     684        $old_sidebars_widgets_data_setting = $wp_customize->get_setting( 'old_sidebars_widgets_data' );
     685        if ( $old_sidebars_widgets_data_setting ) {
     686            $_sidebars_widgets = $wp_customize->post_value( $old_sidebars_widgets_data_setting );
     687        }
    685688    } elseif ( is_array( $sidebars_widgets ) ) {
    686689        $_sidebars_widgets = $sidebars_widgets;
     
    688691
    689692    if ( is_array( $_sidebars_widgets ) ) {
    690         set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $_sidebars_widgets ) );
     693        set_theme_mod( 'sidebars_widgets', $_sidebars_widgets );
    691694    }
    692695
Note: See TracChangeset for help on using the changeset viewer.