[wp-trac] [WordPress Trac] #6605: WordPress-related widget upgrade issue

WordPress Trac wp-trac at lists.automattic.com
Sat Apr 5 20:26:54 GMT 2008


#6605: WordPress-related widget upgrade issue
-------------------------------+--------------------------------------------
 Reporter:  Denis-de-Bernardy  |       Owner:  anonymous
     Type:  defect             |      Status:  new      
 Priority:  normal             |   Milestone:  2.5.1    
Component:  General            |     Version:  2.5      
 Severity:  major              |    Keywords:           
-------------------------------+--------------------------------------------
 while debugging upgrade scripts from WP 2.1.3 to WP 2.5, I ran into a
 particularly nasty bug whereby sidebars get essentially flushed from their
 contents upon upgrading. Basically, the bug applies to the legacy category
 widget and to other widgets that, like it, went from single widget status
 to multi-widget status at some point.

 changing wp_get_sidebars_widgets() fixes the issue:

 {{{
         switch ( $sidebars_widgets['array_version'] ) {
                 case 1 :
                         foreach ( $sidebars_widgets as $index => $sidebar
 )
                         if ( is_array($sidebar) )
                         foreach ( $sidebar as $i => $name ) {
                                 $id = strtolower($name);
                                 if ( isset($wp_registered_widgets[$id]) )
 {
                                         $_sidebars_widgets[$index][$i] =
 $id;
                                         continue;
                                 }
                                 $id = sanitize_title($name);
                                 if ( isset($wp_registered_widgets[$id]) )
 {
                                         $_sidebars_widgets[$index][$i] =
 $id;
                                         continue;
                                 }

                                 $found = false;

                                 foreach ( $wp_registered_widgets as
 $widget_id => $widget )
                                 {
                                         if ( strtolower($widget['name'])
 == strtolower($name) )
                                         {
 $_sidebars_widgets[$index][$i] = $widget['id'];
                                                 $found = true;
                                                 break;
                                         }
                                         elseif (
 sanitize_title($widget['name']) == sanitize_title($name) )
                                         {
 $_sidebars_widgets[$index][$i] = $widget['id'];
                                                 $found = true;
                                                 break;
                                         }
                                 }

                                 if ( $found )
                                 {
                                         continue;
                                 }

                                 unset($_sidebars_widgets[$index][$i]);
                         }
                         $_sidebars_widgets['array_version'] = 2;
                         $sidebars_widgets = $_sidebars_widgets;
                         unset($_sidebars_widgets);

 }}}

 basically, if it fails to spot the id, it does a "last chance" try by
 scanning the entire wp_registerd_widgets array in order to match the
 legacy ID against the new name.

 D.

-- 
Ticket URL: <http://trac.wordpress.org/ticket/6605>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list