Make WordPress Core

Opened 9 years ago

Last modified 5 years ago

#33180 new defect (bug)

Widgets not preserved after switching theme and deactivate plugins

Reported by: pavelevap's profile pavelevap Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.8
Component: Widgets Keywords: dev-feedback 2nd-opinion
Focuses: Cc:


Steps to reproduce:

  • Activate any plugin with available widget.
  • Use this widget in sidebar of actual theme.
  • Deactivate all plugins.
  • Switch theme (for example Twenty Fifteen).

Note: These steps are frequently used for debugging problems.

  • Switch back to previous theme.
  • Activate all plugins.

Expected result: Widget is still active and visible.

Current result: Widget is missing. When used together with any core widget, then this widget is preserved during workflow above.

Change History (5)

#1 @westonruter
9 years ago

  • Version changed from trunk to 2.8

This is expected behavior, though it certainly isn't desireable. See retrieve_widgets() where when it builds the list of widgets to apply to the newly switched-to theme, it only includes widget instances that are currently registered:

                foreach ( $widgets as $widget ) {
                        if ( isset($wp_registered_widgets[$widget]) )
                                $_widgets[] = $widget;

So if the plugin that registers a widget is deactivated when the theme is switched, then it will be stripped from the sidebar. However, note that a deactivated widget will also be removed from a sidebar when you reorder the widgets in a sidebar, since the sidebars_widgets setting will be updated to whatever widget IDs are present in the current view (thus excluding widgets that are not registered).

#2 follow-up: @pavelevap
9 years ago

Thank you for explanation!

I thought that it was fixed several years ago and widgets are no longer missed during switch? When a new theme is activated, I thought that current widgets are saved somewhere in options as theme_mods and when theme is reactivated again it should simply work and use saved widgets...

I trusted that deactivating plugins and switching theme should work without problems. It is common workflow suggested everywhere in any case of problems with WordPress. But later I found that one important widget was missing :-(

#3 in reply to: ↑ 2 @SergeyBiryukov
9 years ago

Replying to pavelevap:

I thought that it was fixed several years ago and widgets are no longer missed during switch?

Yes, in #17979. However, as mentioned above, only currently active widgets are transferred.

#4 @welcher
9 years ago

  • Keywords dev-feedback 2nd-opinion added

Is there any action to take here? Seems like a wontfix.

#5 @pavelevap
9 years ago

I read it once again and maybe we are not talking about the same thing? There is no problem when I switch from Theme1 to Theme2 and I understand that there will be no widgets related to deactivated plugins. But I do not understand why is widget missing when I am returning back from Theme2 to Theme1? I thought that when I switch to another theme, then all current widgets are saved (serialized valued in database). And so when I switch back (and activate plugins), then all previous widgets will be loaded and everything will be as it was before switch...

Note: See TracTickets for help on using tickets.