-// for the sake of PHP warnings
-if ( empty( $sidebars_widgets[$sidebar] ) )
- $sidebars_widgets[$sidebar] = array();
-
-$http_post = 'post' == strtolower($_SERVER['REQUEST_METHOD']);
-
-// We're updating a sidebar
-if ( $http_post && isset($sidebars_widgets[$_POST['sidebar']]) ) {
- check_admin_referer( 'edit-sidebar_' . $_POST['sidebar'] );
-
- /* Hack #1
- * The widget_control is overloaded. It updates the widget's options AND echoes out the widget's HTML form.
- * Since we want to update before sending out any headers, we have to catch it with an output buffer,
- */
- ob_start();
- /* There can be multiple widgets of the same type, but the widget_control for that
- * widget type needs only be called once if it's a multi-widget.
- */
- $already_done = array();
-
- foreach ( $wp_registered_widget_controls as $name => $control ) {
- if ( in_array( $control['callback'], $already_done ) )
- continue;
-
- if ( is_callable( $control['callback'] ) ) {
- call_user_func_array( $control['callback'], $control['params'] );
- $control_output = ob_get_contents();
- if ( false !== strpos( $control_output, '%i%' ) ) // if it's a multi-widget, only call control function once.
- $already_done[] = $control['callback'];
- }
+// look for "lost" widgets, this has to run at least on each theme change
+function retrieve_widgets() {
+ global $wp_registered_widget_updates, $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets;
+
+ $_sidebars_widgets = array();
+ $sidebars = array_keys($wp_registered_sidebars);
+
+ unset( $sidebars_widgets['array_version'] );