WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 3 months ago

#17078 new defect (bug)

is_active_sidebar() doesn't work with Numeric sidebar ID's

Reported by: lanceo Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 2.8
Component: Widgets Keywords:
Focuses: 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 (4)

comment:1 kawauso3 years ago

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',
) );

comment:2 nacin3 years ago

  • Version set to 2.8

comment:3 dd323 years ago

  • Summary changed from functions not compatible to is_active_sidebar() doesn't work with Numeric sidebar ID's

Just updating the title to something descriptive. I think I've interpreted the issue here correctly..

comment:4 nacin3 months ago

  • Component changed from General to Widgets
  • Milestone changed from Awaiting Review to Future Release

I think there is a more established ticket somewhere.

Note: See TracTickets for help on using tickets.