Widgets: add a function, is_registered_sidebar() - helps us avoid touching the $wp_registered_sidebars global.

Props GaryJ, wonderboymusic.
Fixes #24878.


git-svn-id: https://develop.svn.wordpress.org/trunk@35102 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2015-10-13 01:32:27 +00:00
parent 9f551a4630
commit 3616fe5939
3 changed files with 25 additions and 12 deletions
+20 -3
View File
@@ -96,13 +96,14 @@ function register_sidebars( $number = 1, $args = array() ) {
if ( isset($args['id']) ) {
$_args['id'] = $args['id'];
$n = 2; // Start at -2 for conflicting custom ID's
while ( isset($wp_registered_sidebars[$_args['id']]) )
while ( is_registered_sidebar( $_args['id'] ) ) {
$_args['id'] = $args['id'] . '-' . $n++;
}
} else {
$n = count($wp_registered_sidebars);
$n = count( $wp_registered_sidebars );
do {
$_args['id'] = 'sidebar-' . ++$n;
} while ( isset($wp_registered_sidebars[$_args['id']]) );
} while ( is_registered_sidebar( $_args['id'] ) );
}
register_sidebar($_args);
}
@@ -205,6 +206,22 @@ function unregister_sidebar( $name ) {
unset( $wp_registered_sidebars[ $name ] );
}
/**
* Checks if a sidebar is registered.
*
* @since 4.4.0
*
* @global array $wp_registered_sidebars Registered sidebars.
*
* @param string $name The ID of the sidebar when it was added.
*
* @return bool True if the sidebar is registered, false otherwise.
*/
function is_registered_sidebar( $name ) {
global $wp_registered_sidebars;
return isset( $wp_registered_sidebars[ $name ] );
}
/**
* Register an instance of a widget.
*