Make WordPress Core

Changeset 19340


Ignore:
Timestamp:
11/18/2011 07:50:17 PM (13 years ago)
Author:
azaozz
Message:

Prioritize the saved data over the current data when restoring widget positions, props SergeyBiryukov, see #19092

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/widgets.php

    r19333 r19340  
    11651165    global $wp_registered_widget_updates, $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets;
    11661166
    1167     $_sidebars_widgets = array();
    1168     $sidebars = array_keys($wp_registered_sidebars);
     1167    $registered_sidebar_keys = array_keys( $wp_registered_sidebars );
     1168
    11691169    $old_sidebars_widgets = get_theme_mod( 'sidebars_widgets' );
    11701170    if ( is_array( $old_sidebars_widgets ) ) {
    11711171        // time() that sidebars were stored is in $old_sidebars_widgets['time']
    1172         $old_sidebars = $old_sidebars_widgets['data'];
    1173 
    1174         // make sure the saved sidebars match
    1175         foreach ( $sidebars as $sidebar_id ) {
    1176             $_sidebars_widgets[$sidebar_id] = isset($old_sidebars[$sidebar_id]) ? $old_sidebars[$sidebar_id] : array();
    1177         }
    1178 
     1172        $_sidebars_widgets = $old_sidebars_widgets['data'];
    11791173        remove_theme_mod( 'sidebars_widgets' );
     1174 
     1175        $orphaned = 0;
     1176
     1177        foreach ( $_sidebars_widgets as $sidebar => $widgets ) {
     1178            if ( 'wp_inactive_widgets' == $sidebar || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) )
     1179                continue;
     1180
     1181            if ( !in_array( $sidebar, $registered_sidebar_keys ) ) {
     1182                $_sidebars_widgets['orphaned_widgets_' . ++$orphaned] = $widgets;
     1183                unset( $_sidebars_widgets[$sidebar] );
     1184            }
     1185        }
    11801186    } else {
    11811187        if ( empty( $sidebars_widgets ) )
     
    11861192        $old = array_keys($sidebars_widgets);
    11871193        sort($old);
    1188         sort($sidebars);
    1189 
    1190         if ( $old == $sidebars )
     1194        sort($registered_sidebar_keys);
     1195
     1196        if ( $old == $registered_sidebar_keys )
    11911197            return;
    11921198
Note: See TracChangeset for help on using the changeset viewer.