Opened 2 years ago
Last modified 20 months ago
#17078 new defect (bug)
is_active_sidebar() doesn't work with Numeric sidebar ID's
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | General | Version: | 2.8 |
| Severity: | normal | Keywords: | |
| Cc: |
Description
This needs a small fix:
Function is_active_sidebar( $index) converts $index to a string
then uses wp_get_sidebars_widgets() to see if the sidebar is active
..but keys in the array wp_get_sidebars_widgets() generates can be integers if the ID's of the registered sidebars are integers
Change History (3)
Note: See
TracTickets for help on using
tickets.

Using an integer breaks dynamic_sidebar() as well, so the sidebar would never be displayed anyway. Also noticed that even using a numeric string breaks a sidebar's widgets from being displayed in the dashboard, but does work with dynamic_sidebar() and related.
Numeric sidebar IDs sound like bad practice too.
Code to reproduce:
add_action( 'wp_head', 'sidebar_dump' ); function sidebar_dump() { echo '<pre>'; var_dump( wp_get_sidebars_widgets() ); echo '</pre>'; } add_action( 'wp_head', 'sidebar_display' ); function sidebar_display() { echo '<pre>Sidebar integer: '; var_dump(dynamic_sidebar(5)); echo 'Sidebar string: '; var_dump(dynamic_sidebar('6')); echo '</pre>'; } register_sidebar( array( 'id' => 5, 'name' => 'Mambo No. 5', 'description' => 'I break themes', ) ); register_sidebar( array( 'id' => '6', 'name' => 'Mambo Number 6', 'description' => 'I break themes', ) );