[wp-trac] [WordPress Trac] #39693: Fix missing assignment of widgets on theme switch

WordPress Trac noreply at wordpress.org
Wed Sep 6 17:42:14 UTC 2017


#39693: Fix missing assignment of widgets on theme switch
--------------------------------------+------------------------
 Reporter:  melchoyce                 |       Owner:  obenland
     Type:  enhancement               |      Status:  reviewing
 Priority:  normal                    |   Milestone:  4.9
Component:  Widgets                   |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+------------------------
Changes (by westonruter):

 * owner:  westonruter => obenland


Comment:

 Replying to [comment:91 obenland]:
 > That kind of expectation would probably be good to cover in a unit test.
 FWIW, the addition of `sidebar-1` should be redundant because we're
 looking for `*sidebar*` with the next slug.

 OK, good point. Yes, I agree it should be included in the unit test. Here
 are the scenarios I was testing with: https://github.com/xwp/wp-theme-nav-
 menu-widget-sidebar-permutations/blob/master/tests/widget-
 sidebars/scenarios.json Don't expect to recognize this file format, it's
 ad hoc. But you can see which theme was switched from and which was
 switched to, and which sidebars were populated.

 > Good catch! Unfortunately the link doesn't seem to work?

 Apologies. I messed up the URL. Fixed in the comment above, and here it is
 again: https://github.com/xwp/wordpress-develop/blob/206f97d/src/wp-
 includes/widgets.php#L1152-L1158

 If you want an old single widget to test with, you can use this one:
 https://gist.github.com/westonruter/7141599

 > What we could do is to check wp_inactive_widgets for the ids in that
 third sidebar. Overall however I think the expectation that they map right
 back to where they were is only reasonable for immediate switch backs,
 yes?

 I was thinking that when switching from a 2-sidebar theme back to a
 3-sidebar theme, that WP should try to restore each widget that was in the
 original 3rd sidebar ''unless'' the widget was moved to one of the other 2
 sidebars when the 2-sidebar theme was active. So yeah, basically it would
 remove any widget IDs from the 3rd sidebar being restored to the 3-sidebar
 theme if those widget IDs now exist among the widgets in the 2-sidebar
 theme.

 (Don't feel compelled to amend the PR I opened with additional commits. I
 was using it for testing and review and my own work.)

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39693#comment:92>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list