WordPress.org

Make WordPress Core

Opened 12 years ago

Closed 11 years ago

Last modified 10 years ago

#6605 closed defect (bug) (fixed)

WordPress-related widget upgrade issue

Reported by: Denis-de-Bernardy Owned by: mdawaffe
Milestone: 2.5.1 Priority: normal
Severity: major Version: 2.5
Component: General Keywords: has-patch
Focuses: Cc:
PR Number:

Description

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.

Attachments (1)

widgets.diff (922 bytes) - added by Denis-de-Bernardy 12 years ago.

Download all attachments as: .zip

Change History (8)

#1 @Denis-de-Bernardy
12 years ago

  • Keywords has-patch added

not sure the diff will work, I did it using my own svn server

#2 @ryan
12 years ago

  • Owner changed from anonymous to mdawaffe

#3 @Denis-de-Bernardy
12 years ago

any odds we can commit this? it has been working fine for at least a dozen users so far...

#4 @mdawaffe
11 years ago

+1 untested

#5 @ryan
11 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [7735]) If widget ID not found, scan the entire registered widgets array looking for legacy IDs. Props Denis-de-Bernardy. fixes #6605

#6 @ryan
11 years ago

(In [7736]) If widget ID not found, scan the entire registered widgets array looking for legacy IDs. Props Denis-de-Bernardy. fixes #6605 for trunk

#7 @Denis-de-Bernardy
11 years ago

thank you soo much!

D.

Note: See TracTickets for help on using tickets.