WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 5 years ago

#6071 closed defect (bug) (wontfix)

register_sidebars should allow name to be an array

Reported by: AaronCampbell Owned by: mdawaffe
Milestone: Priority: normal
Severity: normal Version:
Component: Widgets Keywords: has-patch needs-testing
Focuses: Cc:

Description

register_sidebars allows you to give a name with a %d in it, but you can't register multiple sidebars with unique names. It seems like you should be able to pass an array of names to be used, like this:
register_sidebars(array('name'=>array('left','right')));
Which would create two sidebars, one named left, and one named right.

Attachments (1)

wordpress-widgets.diff (694 bytes) - added by AaronCampbell 6 years ago.
Fix for register_sidebars

Download all attachments as: .zip

Change History (11)

AaronCampbell6 years ago

Fix for register_sidebars

comment:1 AaronCampbell6 years ago

Well, there was a problem in the diff AND in the description. I fixed the diff, and the register_sidebars call should look like this:
register_sidebars(2, array('name'=>array('left','right')));

comment:2 ryan6 years ago

  • Owner changed from anonymous to mdawaffe

comment:3 AaronCampbell6 years ago

Any idea where we stand on this? The patch is working great for me, even with 2.5

comment:4 AaronCampbell6 years ago

  • Milestone changed from 2.6 to 2.5.1

comment:5 mdawaffe6 years ago

How would (array) $argsname? match up with (string) $argsid??

comment:6 AaronCampbell6 years ago

Honestly, I've never used the ID option there, so I guess I overlooked it. I suppose we could either accept another array that we assume is in the same order as the name, or we could accept an array of arrays, each one containing name, id, etc.

It seems like it might be even easier to push more of the processing to register_sidebar(). For example, if there is only one sidebar, why aren't we passing it straight to sidebar? If there is more than one to add, it seems like we should check if $args is an array of string or an array of arrays. If it's an array of strings, we should call register_sidebar($args) $number times. If it's an array of arrays, then we should loop through $args, calling register_sidebar() for each, either using the [0] index for any extras (for example, $args contains 4 arrays, but 5 sidebars were requested to be added), or passing nothing to register_sidebar(), letting it use the defaults.

comment:7 ryan6 years ago

  • Milestone changed from 2.5.2 to 2.9

Milestone 2.5.2 deleted

comment:8 AaronCampbell6 years ago

  • Milestone changed from 2.9 to 2.8

comment:9 ryan5 years ago

  • Component changed from General to Widgets

comment:10 Denis-de-Bernardy5 years ago

  • Milestone 2.8 deleted
  • Resolution set to wontfix
  • Status changed from new to closed

ticket has been open and ignored for over a year, and you can do the same with register_sidebar() calls in a foreach loop.

Note: See TracTickets for help on using tickets.