Opened 16 years ago
Closed 16 years ago
#10136 closed defect (bug) (fixed)
is_active_sidebar() should use wp_get_sidebars_widgets()
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 2.8.1 | Priority: | normal |
Severity: | normal | Version: | 2.8 |
Component: | Widgets | Keywords: | has-patch tested |
Focuses: | Cc: |
Description
Some themes and plugins use the sidebars_widgets
filter hook to disable a particular sidebar (see: http://justintadlock.com/archives/2009/03/06/disable-widget-areas-without-touching-theme-templates).
This gives themes/plugins more flexibility, which is what I'm sure we were aiming for with the is_active_sidebar()
function. But, since is_active_sidebar()
uses get_option()
to check for sidebars, the sidebars_widgets
filter hook is bypassed.
What I propose is a one-line change of:
$sidebars_widgets = get_option( 'sidebars_widgets', array() );
To:
$sidebars_widgets = wp_get_sidebars_widgets();
I haven't had any issues with this change. And, I can think of no other ways to disable a sidebar.
Attachments (1)
Change History (15)
#1
@
16 years ago
- Milestone 2.8.1 deleted
- Resolution set to wontfix
- Status changed from new to closed
#2
@
16 years ago
- Milestone set to 2.8.1
- Resolution wontfix deleted
- Status changed from closed to reopened
I was under the impression that unregister_widget()
literally unregisters a widget, making it not available for use. That's what I've been using it for.
What I'm taking about is having the ability to disable a sidebar when I need to or a theme/plugin user's sidebar.
A function like this should do it:
add_filter( 'sidebars_widgets', 'disable_primary_sidebar' ); function disable_primary_sidebar( $sidebars_widgets ) { if ( is_home() ) $sidebars_widgets['primary'] = false; return $sidebars_widgets; }
That disables the primary sidebar on the home page. I'm sorry, but I don't see how this can be accomplished with unregister_widget()
.
#3
@
16 years ago
- Keywords needs-patch close added
- Type changed from defect (bug) to enhancement
Sorry, read this a bit too quickly. There also are unregister_sidebar() and unregister_sidebar_widget(), btw. At any event:
- wp_sidebars_widgets() is slower than is needed here
- we may get side effects due to the built-in recent comments widget (or is that recent posts?), which calls it as part of the widget
- there are several plugins that let you disable a widget on a per context basis, and these plugins can now access the sidebar (it's $args[id])
Suggesting wontfix either way.
#5
@
16 years ago
Maybe I haven't completely explained this well enough. I don't consider this an enhancement. I consider it a bug with the current implementation.
If someone sets a sidebar to FALSE
through the sidebars_widgets
filter hook, then is_active_sidebar()
should return FALSE
for that particular sidebar, but it does not. It returns TRUE
.
To me, this is a bug. If no one else considers this a bug, then I don't see a reason for having the is_active_sidebar()
conditional tag at all.
The focus of this ticket has been too much on using wp_get_sidebars_widgets()
rather than finding a solution. If that function is too slow, then a new filter hook needs to be added within is_active_sidebar()
or a new function created.
unregister_sidebar()
won't work becauseis_active_widget()
will still returnTRUE
.unregister_sidebar_widget()
won't work because we're talking about the entire sidebar and not any widget in particular.- All of the plugins I've encountered won't work because they only conditionally show/hide a widget and
is_active_sidebar()
still returnsTRUE
even when no widgets are being shown. In fact, they might work better ifis_active_sidebar()
could be filtered somehow.
#6
@
16 years ago
There are two hooks you can use already: pre_option_sidebars_widgets, and option_sidebars_widgets. But adding a patch nonetheless.
use the unregister_widget() function instead.