Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#5352 closed defect (bug) (fixed)

register_sidebars does not handle names or multiple calls correctly

Reported by: watson's profile watson Owned by: ryan's profile ryan
Milestone: 2.5 Priority: normal
Severity: normal Version: 2.3.1
Component: General Keywords:
Focuses: Cc:


In the function register_sidebars() in wp-includes/widgets.php the $args['name'] attribute is not filtered through sprintf(). This means that the following call to register_sidebars() will have unexpected results:

register_sidebars(2, array('name' => 'Foobar %d'));

Instead of producing two sidebars with the names Foobar 1 and Foobar 2 it will produce two sidebars with the same name: Foobar %d.

Secondly, multiple calls to register_sidebars() will fail if you do not specifically supply the $args['id'] attribute. This is because register_sidebars() maintains an internal counter that auto-generates an id for the specific sidebar (if one is not given as an argument). This counter re-starts at 1 on each call to register_sidebars(), effectively overwriting previously created sidebars on subsequent calls.


register_sidebars(2, array('name' => 'Foo %d'));
register_sidebars(2, array('name' => 'Bar %d'));

This will only create 2 sidebars - not 4. The two sidebars that will be created will be the ones from the last call: Bar %d

Attachments (1)

register_sidebars_patch.diff (1.1 KB) - added by watson 16 years ago.

Download all attachments as: .zip

Change History (5)

#1 @watson
16 years ago

Ups... there where an error in the patch. It has been fixed now and the patch file have been replaced.

#2 @ryan
16 years ago

  • Owner changed from anonymous to ryan

#3 @ryan
16 years ago

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

(In [6381]) Fix registration of multiple sidebars. Props watson. fixes #5352

#4 @darkdragon
16 years ago

  • Milestone changed from 2.5 to 2.4

I asssume this was fixed on trunk (2.4).

Note: See TracTickets for help on using tickets.