Make WordPress Core

Opened 13 years ago

Last modified 4 years ago

#17078 new defect (bug)

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

Reported by: lanceo's profile lanceo Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.8
Component: Widgets Keywords: close 2nd-opinion
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 (10)

#1 @kawauso
13 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
13 years ago

  • Version set to 2.8

#3 @dd32
13 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
11 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
9 years ago

  • Keywords needs-patch added

#6 @DrewAPicture
9 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
9 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
8 years ago

In 37344:

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

See #17078.

#9 @Howdy_McGee
4 years ago

WordPress defaults to sidebar-$index when given a numeric sidebar ID. If we were to allow numeric sidebar IDs there's no way to tell if the user is asking for sidebar-$index or index 123 since both could exist. Even if we prioritize sidebar-$index then 123 it wouldn't be clear if/when one loads over the other. I guess my point is that it makes backwards compatibility rough and we likely need to choose one over the other. Since sidebar-$index is the default we should stick with that methodology and alert the user otherwise.

I guess the next question is, should we force register_sidebar() to fail when given a numeric ID accompanied with a __doing_it_wrong() notice or?...

#10 @Howdy_McGee
4 years ago

  • Keywords close 2nd-opinion added; needs-patch removed
Note: See TracTickets for help on using tickets.