Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 9 years ago

#10440 closed defect (bug) (duplicate)

is_active_sidebar not working as advertised

Reported by: mortenf's profile mortenf Owned by: azaozz's profile azaozz
Milestone: Priority: normal
Severity: normal Version: 2.8.1
Component: Widgets Keywords: has-patch
Focuses: Cc:


Per the inline documentation for "is_active_sidebar", the single ("mixed $index") parameter is a "sidebar name, id or number to check".

However, the function only works correctly in the case of number (an integer). In the case of id (e.g. "foobar-1") it only works correctly, when the id survives a trip through "sanitize_title".

In the case of trying to use a name, the function doesn't work at all, due to the array returned from "wp_get_sidebars_widgets" being keyed on sidebar ids (e.g. "foobar-1").

Either the inline documentation should be changed to reflect reality (use of a sidebar name is not possible), or the function should be fixed, perhaps by using attached patch, that uses a copy of a code fragment from "dynamic_sidebar" (a code fragment that could also exist by itself in a new function "wp_sidebar_index($name)").

Attachments (1)

is_active_sidebar_names.diff (854 bytes) - added by mortenf 15 years ago.

Download all attachments as: .zip

Change History (9)

#1 @mortenf
15 years ago

  • Cc morten@… added
  • Keywords has_patch added

#2 @scribu
15 years ago

  • Keywords has-patch added; has_patch removed
  • Milestone changed from Unassigned to 2.9

#3 follow-up: @CharlesClarkson
15 years ago

  • Cc cclarkson@… added

The patched function fails if a lower numbered sidebar is unregistered (unregister_sidebar()) than the one be searched for. In my test case I tried to test sidebar-5 by the sidebar name (Sidebar Top) after having removed sidebar-2. This version of the function has no way to "know" that an array key was unset and in a 5 sidebar theme (with 1 removed) it never tests for sidebar-5 because $i never gets that high.

register_sidebar(array('name'=>'Sidebar Bottom Left',));
register_sidebar(array('name'=>'Sidebar Bottom Right',));
register_sidebar(array('name'=>'468x60 Header Banner',));
register_sidebar(array('name'=>'468x60 Post Banner',));
register_sidebar(array('name'=>'Sidebar Top',));

This function also fails if the sidebar was registered with a different id from the default:

register_sidebar(array('name'=>'Sidebar Top','id'=>'top-sidebar'));

Without an internal id that cannot be changed by users, checking a sidebar by an integer ( is_active_sidebar(1) ) is not guaranteed to work.

#4 in reply to: ↑ 3 @CharlesClarkson
15 years ago

Replying to CharlesClarkson:

Sorry. Wrong ticket. This applies to ticket #10956, which I also had open at the same time.

#5 @scribu
15 years ago

Cross referencing: #11160

#7 @azaozz
15 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

Seems to be the same problem as in #11160.

#8 @DrewAPicture
9 years ago

  • Milestone 2.9 deleted
Note: See TracTickets for help on using tickets.