From 20a430c8fbf7b348c8dbe2d5242fd42d54f4e45b Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Sun, 14 Mar 2010 11:58:53 +0000 Subject: [PATCH] Revert [13699], It breaks dynamic_sidebar() compatibility. Use a safer loop for clashes. See #12606 git-svn-id: https://develop.svn.wordpress.org/trunk@13700 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/widgets.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php index 4c7e11ccd9..e1f57b72fc 100644 --- a/wp-includes/widgets.php +++ b/wp-includes/widgets.php @@ -481,6 +481,7 @@ function register_sidebars($number = 1, $args = array()) { if ( is_string($args) ) parse_str($args, $args); + $n = count($wp_registered_sidebars); for ( $i = 1; $i <= $number; $i++ ) { $_args = $args; @@ -489,13 +490,17 @@ function register_sidebars($number = 1, $args = array()) { else $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar'); - $id = isset($args['id']) ? $args['id'] : 'sidebar'; - $_args['id'] = $id; - - $n = count($wp_registered_sidebars); - while ( isset($wp_registered_sidebars[$_args['id']]) ) - $_args['id'] = $id . '-' . $n++; - + // Custom specified ID's are suffixed if they exist already. + // Automatically generated sidebar names need to be suffixed regardless. + if ( isset($args['id']) ) { + $_args['id'] = $args['id']; + while ( isset($wp_registered_sidebars[$_args['id']]) ) + $_args['id'] = $args['id'] . '-' . $n++; + } else { + do { + $_args['id'] = 'sidebar-' . $n++; + } while ( isset($wp_registered_sidebars[$_args['id']]) ); + } register_sidebar($_args); } }