Ticket #5352 (closed defect (bug): fixed)

Opened 4 years ago

Last modified 4 years ago

register_sidebars does not handle names or multiple calls correctly

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

Description

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.

Example:

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

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

Change History

watson4 years ago

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

comment:2   ryan4 years ago

  • Owner changed from anonymous to ryan

comment:3   ryan4 years ago

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

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

  • 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.