[wp-trac] [WordPress Trac] #53660: `$sidebar_widgets` out of sync during batch updates to widgets through the REST API

WordPress Trac noreply at wordpress.org
Thu Jul 15 15:16:59 UTC 2021


#53660: `$sidebar_widgets` out of sync during batch updates to widgets through the
REST API
--------------------------+-----------------------
 Reporter:  zieladam      |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  5.8.1
Component:  Widgets       |     Version:  trunk
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |     Focuses:  rest-api
--------------------------+-----------------------

Comment (by zieladam):

 This very relevant conversation happened on .org slack recently:

 @zieladam
 Does anyone know why we have both $_wp_sidebars_widgets AND
 $sidebars_widgets global variables?


 @hellofromtonya
 Great question @zieladam!
 Core uses $_wp_sidebars_widgets private global as a cache of the
 sidebars_widgets option to initialize $sidebars_widgets global when not in
 the admin. (Note: The cached version can be modified in memory to switch
 from single to multi widget.)
 $sidebars_widgets is the in memory working state of the widgets.


 @zieladam
 thank you @hellofromtonya! do you think we could refactor that to have
 just one? I just finished debugging
 https://github.com/WordPress/gutenberg/issues/33335  and a big part of it
 was that, after updating things, we refreshed only $_wp_sidebars_widgets
 but not $sidebars_widgets. I will patch it up and it will just work, but I
 think we’re in a non-future-proof situation and may introduce similar
 errors again (edited)


 @hellofromtonya
 Switching over now to look more deeply at the globals and managing their
 state.


 @hellofromtonya
 Hey @zieladam , the stack of handlers that have been added for inactive
 widgets and global states concerns me. 2 weird issues drove the need to
 add these. While it fixes both of them, I agree with you that
 fundamentally something is off. I agree that we should explore the 2
 globals.
 Caution: the globals and the code around them have existed a long time in
 Core. For those folks who choose to use the Classic Widgets, changes made
 in these functions and globals will need care to ensure backwards
 compatibility.

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


More information about the wp-trac mailing list