Make WordPress Core

Changeset 35102


Ignore:
Timestamp:
10/13/2015 01:32:27 AM (9 years ago)
Author:
wonderboymusic
Message:

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

Props GaryJ, wonderboymusic.
Fixes #24878.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/widgets.php

    r35015 r35102  
    9090        continue;
    9191
    92     if ( !isset( $wp_registered_sidebars[ $sidebar_id ] ) ) {
     92    if ( ! is_registered_sidebar( $sidebar_id ) ) {
    9393        if ( ! empty( $widgets ) ) { // register the inactive_widgets area as sidebar
    9494            register_sidebar(array(
     
    156156        /**
    157157         * Fires immediately after a widget has been marked for deletion.
    158          * 
     158         *
    159159         * @since 4.4.0
    160160         *
  • trunk/src/wp-includes/class-wp-customize-widgets.php

    r34563 r35102  
    366366            }
    367367
    368             $is_registered_sidebar = isset( $wp_registered_sidebars[ $sidebar_id ] );
     368            $is_registered_sidebar = is_registered_sidebar( $sidebar_id );
    369369            $is_inactive_widgets   = ( 'wp_inactive_widgets' === $sidebar_id );
    370370            $is_active_sidebar     = ( $is_registered_sidebar && ! $is_inactive_widgets );
     
    11031103     * @access public
    11041104     *
    1105      * @global array $wp_registered_sidebars
    1106      *
    11071105     * @param bool   $is_active  Whether the sidebar is active.
    11081106     * @param string $sidebar_id Sidebar ID.
     
    11101108     */
    11111109    public function tally_sidebars_via_is_active_sidebar_calls( $is_active, $sidebar_id ) {
    1112         if ( isset( $GLOBALS['wp_registered_sidebars'][$sidebar_id] ) ) {
     1110        if ( is_registered_sidebar( $sidebar_id ) ) {
    11131111            $this->rendered_sidebars[] = $sidebar_id;
    11141112        }
     
    11311129     * @access public
    11321130     *
    1133      * @global array $wp_registered_sidebars
    1134      *
    11351131     * @param bool   $has_widgets Whether the current sidebar has widgets.
    11361132     * @param string $sidebar_id  Sidebar ID.
     
    11381134     */
    11391135    public function tally_sidebars_via_dynamic_sidebar_calls( $has_widgets, $sidebar_id ) {
    1140         if ( isset( $GLOBALS['wp_registered_sidebars'][$sidebar_id] ) ) {
     1136        if ( is_registered_sidebar( $sidebar_id ) ) {
    11411137            $this->rendered_sidebars[] = $sidebar_id;
    11421138        }
  • trunk/src/wp-includes/widget-functions.php

    r34566 r35102  
    9797            $_args['id'] = $args['id'];
    9898            $n = 2; // Start at -2 for conflicting custom ID's
    99             while ( isset($wp_registered_sidebars[$_args['id']]) )
     99            while ( is_registered_sidebar( $_args['id'] ) ) {
    100100                $_args['id'] = $args['id'] . '-' . $n++;
     101            }
    101102        } else {
    102             $n = count($wp_registered_sidebars);
     103            $n = count( $wp_registered_sidebars );
    103104            do {
    104105                $_args['id'] = 'sidebar-' . ++$n;
    105             } while ( isset($wp_registered_sidebars[$_args['id']]) );
     106            } while ( is_registered_sidebar( $_args['id'] ) );
    106107        }
    107108        register_sidebar($_args);
     
    204205
    205206    unset( $wp_registered_sidebars[ $name ] );
     207}
     208
     209/**
     210 * Checks if a sidebar is registered.
     211 *
     212 * @since 4.4.0
     213 *
     214 * @global array $wp_registered_sidebars Registered sidebars.
     215 *
     216 * @param string $name The ID of the sidebar when it was added.
     217 *
     218 * @return bool True if the sidebar is registered, false otherwise.
     219 */
     220function is_registered_sidebar( $name ) {
     221    global $wp_registered_sidebars;
     222    return isset( $wp_registered_sidebars[ $name ] );
    206223}
    207224
Note: See TracChangeset for help on using the changeset viewer.