WordPress.org

Make WordPress Core

Opened 14 months ago

Last modified 9 months ago

#24283 new defect (bug)

is_active_widget() incorrect logic

Reported by: valllabh Owned by:
Milestone: Awaiting Review 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 (2)

comment:1 alex-ye14 months ago

  • Cc nashwan.doaqan@… added

comment:2 csixty49 months 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.