Make WordPress Core

Opened 7 years ago

Last modified 7 years ago

#42987 new defect (bug)

is_active_sidebar returns true on after plugin deactivation

Reported by: tpaksu's profile tpaksu Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 2.8
Component: Widgets Keywords: needs-patch
Focuses: Cc:

Description

Hi,

Steps to reproduce:

code:

<?php if(is_active_sidebar("custom-sidebar")) : ?>
    Sidebar is active, and it contains widget(s).
<?php else: ?>
    Sidebar doesn't contain any widget.
<?php endif;?>
  1. Add a widget plugin to the custom-sidebar
  2. Disable the widget plugin
  3. Reload the page

The page is still showing sidebar is active. and wp_get_sidebars_widgets() still contains the disabled plugin's widget info.

Is this something intended? Or is it a bug?

Change History (6)

#1 @alexvorn2
7 years ago

I think it is by design, so it checks in database if it has something inside, so that widget should get removed before or after plugin deactivation.

#2 @tpaksu
7 years ago

I solved it on my theme by using retrieve_widgets function which internally calls _wp_remove_unregistered_widgets that I think clears the inactive and disabled widgets from the database. But I don't feel comfortable with that solution that runs on every page render.

This ticket was mentioned in Slack in #core by hdalive. View the logs.


7 years ago

This ticket was mentioned in Slack in #core-customize by westonruter. View the logs.


7 years ago

#5 @westonruter
7 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release
  • Version changed from 4.9.1 to 2.8

Yeah, is_active_sidebar() should be more robust and check to see if the widgets in it are actually valid.

#6 @mdifelice
7 years ago

The retrieve_widgets() documentation says it has to run at least on each theme change. Should not be called when a plugin is deactivated too?

Note: See TracTickets for help on using tickets.