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

Props GaryJ, wonderboymusic.
Fixes #24878.

Built from https://develop.svn.wordpress.org/trunk@35102


git-svn-id: http://core.svn.wordpress.org/trunk@35067 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-10-13 01:33:25 +00:00
parent ff0b621719
commit aa92c9555a
4 changed files with 26 additions and 13 deletions

View File

@ -89,7 +89,7 @@ foreach ( $sidebars_widgets as $sidebar_id => $widgets ) {
if ( 'wp_inactive_widgets' == $sidebar_id )
continue;
if ( !isset( $wp_registered_sidebars[ $sidebar_id ] ) ) {
if ( ! is_registered_sidebar( $sidebar_id ) ) {
if ( ! empty( $widgets ) ) { // register the inactive_widgets area as sidebar
register_sidebar(array(
'name' => __( 'Inactive Sidebar (not used)' ),
@ -155,7 +155,7 @@ if ( isset($_POST['savewidget']) || isset($_POST['removewidget']) ) {
/**
* Fires immediately after a widget has been marked for deletion.
*
*
* @since 4.4.0
*
* @param string $widget_id ID of the widget marked for deletion.

View File

@ -365,7 +365,7 @@ final class WP_Customize_Widgets {
$sidebar_widget_ids = array();
}
$is_registered_sidebar = isset( $wp_registered_sidebars[ $sidebar_id ] );
$is_registered_sidebar = is_registered_sidebar( $sidebar_id );
$is_inactive_widgets = ( 'wp_inactive_widgets' === $sidebar_id );
$is_active_sidebar = ( $is_registered_sidebar && ! $is_inactive_widgets );
@ -1102,14 +1102,12 @@ final class WP_Customize_Widgets {
* @since 3.9.0
* @access public
*
* @global array $wp_registered_sidebars
*
* @param bool $is_active Whether the sidebar is active.
* @param string $sidebar_id Sidebar ID.
* @return bool
*/
public function tally_sidebars_via_is_active_sidebar_calls( $is_active, $sidebar_id ) {
if ( isset( $GLOBALS['wp_registered_sidebars'][$sidebar_id] ) ) {
if ( is_registered_sidebar( $sidebar_id ) ) {
$this->rendered_sidebars[] = $sidebar_id;
}
/*
@ -1130,14 +1128,12 @@ final class WP_Customize_Widgets {
* @since 3.9.0
* @access public
*
* @global array $wp_registered_sidebars
*
* @param bool $has_widgets Whether the current sidebar has widgets.
* @param string $sidebar_id Sidebar ID.
* @return bool
*/
public function tally_sidebars_via_dynamic_sidebar_calls( $has_widgets, $sidebar_id ) {
if ( isset( $GLOBALS['wp_registered_sidebars'][$sidebar_id] ) ) {
if ( is_registered_sidebar( $sidebar_id ) ) {
$this->rendered_sidebars[] = $sidebar_id;
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-35101';
$wp_version = '4.4-alpha-35102';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

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.
*