Ensure that for multiple sidebar additions, the ID is unique (even if specified). Append -2.. for > 1 sidebars. Props minusfive. Fixes #12606

git-svn-id: https://develop.svn.wordpress.org/trunk@13698 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse 2010-03-14 10:55:17 +00:00
parent 47426465ed
commit a486d9ed55
1 changed files with 9 additions and 7 deletions

View File

@ -461,7 +461,8 @@ function unregister_widget($widget_class) {
* The default for the name is "Sidebar #", with '#' being replaced with the * The default for the name is "Sidebar #", with '#' being replaced with the
* number the sidebar is currently when greater than one. If first sidebar, the * number the sidebar is currently when greater than one. If first sidebar, the
* name will be just "Sidebar". The default for id is "sidebar-" followed by the * name will be just "Sidebar". The default for id is "sidebar-" followed by the
* number the sidebar creation is currently at. * number the sidebar creation is currently at. If the id is provided, and mutliple
* sidebars are being defined, the id will have "-2" appended, and so on.
* *
* @since 2.2.0 * @since 2.2.0
* *
@ -480,23 +481,24 @@ function register_sidebars($number = 1, $args = array()) {
if ( is_string($args) ) if ( is_string($args) )
parse_str($args, $args); parse_str($args, $args);
for ( $i=1; $i <= $number; $i++ ) { for ( $i = 1; $i <= $number; $i++ ) {
$_args = $args; $_args = $args;
if ( $number > 1 ) { if ( $number > 1 )
$_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i); $_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i);
} else { else
$_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar'); $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar');
}
if (isset($args['id'])) { if ( isset($args['id']) ) {
$_args['id'] = $args['id']; $_args['id'] = $args['id'];
if ( $number > 1 ) // Ensure that for multiple additions, the ID is unique (even if specified). Append -xx for > 1 sidebars.
$_args['id'] .= '-' . $i;
} else { } else {
$n = count($wp_registered_sidebars); $n = count($wp_registered_sidebars);
do { do {
$n++; $n++;
$_args['id'] = "sidebar-$n"; $_args['id'] = "sidebar-$n";
} while (isset($wp_registered_sidebars[$_args['id']])); } while ( isset($wp_registered_sidebars[$_args['id']]) );
} }
register_sidebar($_args); register_sidebar($_args);