From c5df163698b7c7583af70957bd95b9b5d161ff09 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Fri, 14 Dec 2007 08:06:08 +0000 Subject: [PATCH] Fix registration of multiple sidebars. Props watson. fixes #5352 git-svn-id: https://develop.svn.wordpress.org/trunk@6381 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/widgets.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php index 789b2a1543..a6a5aa068c 100644 --- a/wp-includes/widgets.php +++ b/wp-includes/widgets.php @@ -13,6 +13,7 @@ $wp_register_widget_defaults = false; /* Template tags & API functions */ function register_sidebars($number = 1, $args = array()) { + global $wp_registered_sidebars; $number = (int) $number; if ( is_string($args) ) @@ -20,12 +21,23 @@ function register_sidebars($number = 1, $args = array()) { for ( $i=1; $i <= $number; $i++ ) { $_args = $args; + if ( $number > 1 ) { - $_args['name'] = isset($args['name']) ? $args['name'] : sprintf(__('Sidebar %d'), $i); + $_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i); } else { $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar'); } - $_args['id'] = isset($args['id']) ? $args['id'] : "sidebar-$i"; + + if (isset($args['id'])) { + $_args['id'] = $args['id']; + } else { + $n = count($wp_registered_sidebars); + do { + $n++; + $_args['id'] = "sidebar-$n"; + } while (isset($wp_registered_sidebars[$_args['id']])); + } + register_sidebar($_args); } }