WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/13/2015 01:32:27 AM (5 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.