Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#42719 closed enhancement (fixed)

Always attempt to restore widgets' previous assignment

Reported by: andondesign's profile andon.design Owned by: obenland's profile obenland
Milestone: 4.9.2 Priority: normal
Severity: normal Version: 4.9
Component: Widgets Keywords:
Focuses: ui, administration, template Cc:

Description

What I used for testing:

  • WordPress 4.9
  • no plugins active
  • only default WP themes tested
  • Browsers used for testing: Firefox v57.0 and Chrome v62.0.3202.94

Steps to reproduce the issue:

  1. Set the current active theme to "Twenty Seventeen".
  2. Go to Appearance -> Widgets.
  3. Assign new or move existing widget(s) to "Footer 1" and "Footer 2" widget areas.
  4. Active the "Twenty Fifteen" theme.
  5. Now active the "Twenty Seventeen" theme again.
  6. Go back to the Appearance -> Widgets page and inspect the theme's widget areas.

Result:
The widgets were not located where they were left last as were assigned prior to switching themes, however in my testing they were consistently either missing from "Footer 1" and "Footer 2" widget areas or moved to the "Blog Sidebar". Some were moved to Inactive Widgets section.

My understanding is that the issues with theme switching and widgets should have been addressed in WP 4.9.

I can replicate this with other themes that have different widget areas.

Attachments (1)

42719.diff (4.8 KB) - added by obenland 7 years ago.

Download all attachments as: .zip

Change History (8)

#1 @westonruter
7 years ago

See #39693.

@obenland Aren't the previous theme's widget/sidebar assignments supposed to be restored after switching back?

#2 @obenland
7 years ago

  • Milestone changed from Awaiting Review to 4.9.2
  • Owner set to obenland
  • Status changed from new to accepted

It should. Looks like there is a bug in that logic.

#3 follow-up: @obenland
7 years ago

After debugging, it's not a bug per se, but more of an unfortunate edge case :)

Switching from 2015 to 2017, widgets from Footer 1 get mapped to 2015's Widget Area, widgets from Footer 2 are moved into inactive sidebar, since there are no more sidebars to map to.

Switching 2015 back to 2017, Widget Area widgets get assigned to Blog Sidebar since both have the same id, sidebar-1. There are no more active widgets, so the mapping stops at that point and just maintains the inactive sidebar.

I guess what we could do however is to not bail here and always try to restore from previous settings, essentially just giving that logic a chance to retrieve previously active widgets from the inactive side bar. That would still not move widgets back to Footer 1 (rightfully, I'd argue), but it would restore Footer 2.

Thoughts?

@obenland
7 years ago

#4 in reply to: ↑ 3 @westonruter
7 years ago

Replying to obenland:

I guess what we could do however is to not bail here and always try to restore from previous settings, essentially just giving that logic a chance to retrieve previously active widgets from the inactive side bar. That would still not move widgets back to Footer 1 (rightfully, I'd argue), but it would restore Footer 2.

I think this sounds right to me.

#5 @obenland
7 years ago

  • Summary changed from Widgets lost or moved when themes are switched... to Always attempt to restore widgets' previous assignment
  • Type changed from defect (bug) to enhancement

#6 @obenland
7 years ago

In 42374:

Widgets: Always try restoring widget assignments

For code-historic reasons, restoring widget assignments would not be attempted if there were no sidebars to map.
Restoring previous assignments is something unrelated to sidebar mappings however, so now it will be attempted on every theme switch.

See #42719.

#7 @obenland
7 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 42375:

Widgets: Always try restoring widget assignments

For code-historic reasons, restoring widget assignments would not be attempted if there were no sidebars to map.
Restoring previous assignments is something unrelated to sidebar mappings however, so now it will be attempted on every theme switch.

Fixes #42719.

Merges [42374] to the 4.9 branch.

Note: See TracTickets for help on using tickets.