Opened 11 years ago
Last modified 2 months ago
#24283 new defect (bug)
is_active_widget() incorrect logic
Reported by: | valllabh | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Widgets | Keywords: | dev-feedback |
Focuses: | Cc: |
Description
is_active_widget()
only returns 'true' only if widget used inside sidebar.
But there is a provision to use widget directly using the_widget()
function. I believe there is a need of alter the logic of just checking inside sidebars.
Change History (3)
#3
@
2 months ago
below script would be helpful:
function is_active_widget_extended( $widget_id ) {
global $wp_registered_widgets;
foreach ( $wp_registered_widgets as $widget ) {
if ( $widget_id == $widgetid? && is_active_widget( false, false, $widgetid?, true ) ) {
return true;
}
}
ob_start();
the_widget( $widget_id );
$widget_output = ob_get_clean();
if ( ! empty( $widget_output ) ) {
return true;
}
return false;
}
Note: See
TracTickets for help on using
tickets.
I'm not sure this can be addressed practically.
is_active_widget()
just checks to see if a widget is assigned to a sidebar, and the reporter is right thatthe_widget()
can render an arbitrary widget anywhere in a theme or plugin.If a widget is assigned to a sidebar, then
is_active_widget()
knows its state at start of rendering the page. But if something callsis_active_widget()
on a widget beforethe_widget()
has been called to render it, WordPress can't see into the future.A couple possible solutions:
is_active_widget()
and rename it tois_widget_assigned_to_sidebar()
or something does the exact same thing, but better reflects what it tests.is_active_widget()
return true ifthe_widget()
has been called for a widget type in the current page so far. I could see this being confusing.