mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-04 14:47:02 +00:00
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:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user