Make WordPress Core

Opened 11 years ago

Last modified 5 years ago

#24283 new defect (bug)

is_active_widget() incorrect logic

Reported by: valllabh's profile valllabh Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Widgets Keywords: dev-feedback
Focuses: Cc:


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 (2)

#1 @alex-ye
11 years ago

  • Cc nashwan.doaqan@… added

#2 @csixty4
10 years ago

  • Keywords dev-feedback added

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 that the_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 calls is_active_widget() on a widget before the_widget() has been called to render it, WordPress can't see into the future.

A couple possible solutions:

  1. Keep the existing code as-is
  2. Deprecate is_active_widget() and rename it to is_widget_assigned_to_sidebar() or something does the exact same thing, but better reflects what it tests.
  3. Make is_active_widget() return true if the_widget() has been called for a widget type in the current page so far. I could see this being confusing.
  4. Provide a way for themes & plugins to declare what widgets they invoke directly. But that sets a precedent I'm not comfortable with, and the widgets can be rendered on a per-page basis which makes this kind of moot.
Note: See TracTickets for help on using tickets.