WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 years ago

#10440 closed defect (bug) (duplicate)

is_active_sidebar not working as advertised

Reported by: mortenf Owned by: azaozz
Milestone: 2.9 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)

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

Download all attachments as: .zip

Change History (8)

comment:1 mortenf5 years ago

  • Cc morten@… added
  • Keywords has_patch added

comment:2 scribu5 years ago

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

comment:3 follow-up: CharlesClarkson4 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',));
unregister_sidebar('sidebar-2');

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.

comment:4 in reply to: ↑ 3 CharlesClarkson4 years ago

Replying to CharlesClarkson:

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

comment:5 scribu4 years ago

Cross referencing: #11160

comment:7 azaozz4 years ago

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

Seems to be the same problem as in #11160.

Note: See TracTickets for help on using tickets.