Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#6605 closed defect (bug) (fixed)

WordPress-related widget upgrade issue

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

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 5 years ago.

Download all attachments as: .zip

Change History (8)

  • Keywords has-patch added

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

comment:2   ryan5 years ago

  • Owner changed from anonymous to mdawaffe

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

+1 untested

comment:5   ryan5 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

comment:6   ryan5 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

thank you soo much!

D.

Note: See TracTickets for help on using tickets.