Ticket #19291: 19291.patch
File 19291.patch, 2.7 KB (added by , 13 years ago) |
---|
-
wp-includes/widgets.php
1164 1164 function retrieve_widgets() { 1165 1165 global $wp_registered_widget_updates, $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets; 1166 1166 1167 $_sidebars_widgets = array(); 1168 $sidebars = array_keys($wp_registered_sidebars); 1167 $registered_sidebar_keys = array_keys( $wp_registered_sidebars ); 1168 1169 $orphaned = 0; 1170 1169 1171 $old_sidebars_widgets = get_theme_mod( 'sidebars_widgets' ); 1170 1172 if ( is_array( $old_sidebars_widgets ) ) { 1171 1173 // time() that sidebars were stored is in $old_sidebars_widgets['time'] 1172 $old_sidebars = $old_sidebars_widgets['data']; 1174 $_sidebars_widgets = $old_sidebars_widgets['data']; 1175 remove_theme_mod( 'sidebars_widgets' ); 1173 1176 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 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 } 1177 1185 } 1178 1179 remove_theme_mod( 'sidebars_widgets' );1180 1186 } else { 1181 1187 if ( empty( $sidebars_widgets ) ) 1182 1188 return; … … 1185 1191 1186 1192 $old = array_keys($sidebars_widgets); 1187 1193 sort($old); 1188 sort($ sidebars);1194 sort($registered_sidebar_keys); 1189 1195 1190 if ( $old == $ sidebars )1196 if ( $old == $registered_sidebar_keys ) 1191 1197 return; 1192 1198 1193 1199 $_sidebars_widgets = array( … … 1199 1205 foreach ( $wp_registered_sidebars as $id => $settings ) 1200 1206 $_sidebars_widgets[$id] = array_shift( $sidebars_widgets ); 1201 1207 1202 $orphaned = 0;1203 1204 1208 foreach ( $sidebars_widgets as $val ) { 1205 1209 if ( is_array($val) && ! empty( $val ) ) 1206 1210 $_sidebars_widgets['orphaned_widgets_' . ++$orphaned] = $val; … … 1228 1232 unset($_sidebars_widgets, $_widgets); 1229 1233 1230 1234 // find hidden/lost multi-widget instances 1231 $lost_widgets = array();1232 1235 foreach ( $wp_registered_widgets as $key => $val ) { 1233 1236 if ( in_array($key, $shown_widgets, true) ) 1234 1237 continue; … … 1238 1241 if ( 2 > (int) $number ) 1239 1242 continue; 1240 1243 1241 $lost_widgets[] = $key; 1244 // Any lost widgets from previous sidebars become orphans 1245 $sidebars_widgets['orphaned_widgets_' . ++$orphaned] = array( $key ); 1242 1246 } 1243 1247 1244 $sidebars_widgets['wp_inactive_widgets'] = array_merge($lost_widgets, (array) $sidebars_widgets['wp_inactive_widgets']);1245 1248 wp_set_sidebars_widgets($sidebars_widgets); 1246 1249 1247 1250 return $sidebars_widgets;