WordPress.org

Make WordPress Core

Opened 9 years ago

Last modified 6 months ago

#17078 new defect (bug)

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

Reported by: lanceo Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.8
Component: Widgets Keywords: needs-patch
Focuses: Cc:
PR Number:

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 (8)

#1 @kawauso
9 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',
) );

#2 @nacin
8 years ago

  • Version set to 2.8

#3 @dd32
8 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..

#4 @nacin
6 years ago

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

I think there is a more established ticket somewhere.

#5 @chriscct7
4 years ago

  • Keywords needs-patch added

#6 @DrewAPicture
4 years ago

In 34816:

Widgets: Add tests for dynamic_sidebar() where sidebars were registered with 1) no supplied ID, 2) a numeric ID, 3) a string ID.

See #17078.

#7 @DrewAPicture
4 years ago

In 34817:

Widgets: Add more tests for registering and unregistering sidebars with 1) no ID, 2) a string ID, 3) a numeric ID.

See #17078.

#8 @DrewAPicture
4 years ago

In 37344:

Tests: Remove debug cruft left over from [34816].

See #17078.

Note: See TracTickets for help on using tickets.