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

git-svn-id: http://svn.automattic.com/wordpress/trunk@19340 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2011-11-18 19:50:17 +00:00
parent d89f81d168
commit 2c9244965a
1 changed files with 17 additions and 11 deletions

View File

@ -1164,19 +1164,25 @@ function _wp_sidebars_changed() {
function retrieve_widgets() { function retrieve_widgets() {
global $wp_registered_widget_updates, $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets; global $wp_registered_widget_updates, $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets;
$_sidebars_widgets = array(); $registered_sidebar_keys = array_keys( $wp_registered_sidebars );
$sidebars = array_keys($wp_registered_sidebars);
$old_sidebars_widgets = get_theme_mod( 'sidebars_widgets' ); $old_sidebars_widgets = get_theme_mod( 'sidebars_widgets' );
if ( is_array( $old_sidebars_widgets ) ) { if ( is_array( $old_sidebars_widgets ) ) {
// time() that sidebars were stored is in $old_sidebars_widgets['time'] // time() that sidebars were stored is in $old_sidebars_widgets['time']
$old_sidebars = $old_sidebars_widgets['data']; $_sidebars_widgets = $old_sidebars_widgets['data'];
// make sure the saved sidebars match
foreach ( $sidebars as $sidebar_id ) {
$_sidebars_widgets[$sidebar_id] = isset($old_sidebars[$sidebar_id]) ? $old_sidebars[$sidebar_id] : array();
}
remove_theme_mod( 'sidebars_widgets' ); remove_theme_mod( 'sidebars_widgets' );
$orphaned = 0;
foreach ( $_sidebars_widgets as $sidebar => $widgets ) {
if ( 'wp_inactive_widgets' == $sidebar || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) )
continue;
if ( !in_array( $sidebar, $registered_sidebar_keys ) ) {
$_sidebars_widgets['orphaned_widgets_' . ++$orphaned] = $widgets;
unset( $_sidebars_widgets[$sidebar] );
}
}
} else { } else {
if ( empty( $sidebars_widgets ) ) if ( empty( $sidebars_widgets ) )
return; return;
@ -1185,9 +1191,9 @@ function retrieve_widgets() {
$old = array_keys($sidebars_widgets); $old = array_keys($sidebars_widgets);
sort($old); sort($old);
sort($sidebars); sort($registered_sidebar_keys);
if ( $old == $sidebars ) if ( $old == $registered_sidebar_keys )
return; return;
$_sidebars_widgets = array( $_sidebars_widgets = array(