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: http://svn.automattic.com/wordpress/trunk@13698 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9b0e7e79d0
commit
c6daeea61e
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue