#10440 closed defect (bug) (duplicate)
is_active_sidebar not working as advertised
Reported by: | mortenf | Owned by: | azaozz |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.8.1 |
Component: | Widgets | Keywords: | has-patch |
Focuses: | Cc: |
Description
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)
Change History (9)
#2
@
15 years ago
- Keywords has-patch added; has_patch removed
- Milestone changed from Unassigned to 2.9
#4
in reply to:
↑ 3
@
15 years ago
Replying to CharlesClarkson:
Sorry. Wrong ticket. This applies to ticket #10956, which I also had open at the same time.
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.
This function also fails if the sidebar was registered with a different id from the default:
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.