Widget ID auto-increments conflict for concurrent users
|Reported by:||westonruter||Owned by:||westonruter|
Each WP_Widget 2.0 “multi-widget” gets an index number associated with each instance of a give type. When you add a widget, this number gets incremented (widget.set( 'multi_number', widget.get( 'multi_number' ) + 1 );). The initial multi-number is calculated from the next_widget_id_number() function which takes the max number currently used, and increments it by one. The same approach is used in the widgets admin page and the Widget Customizer.
For frequently-used widgets, the above problem will happen frequently where two users will try to add the same widget at the same time, and thus they will start out with the same initial multi_number, resulting in the same widget ID. When they both save their changes, one user's widget will override the other user's widget: whoever saves last. Likewise, it is possible for multiple widgets to be deleted in one session (from the widgets admin page, since Customizer only removes widgets by moving them to the Inactive Widgets sidebar) then new ones added back in other sessions and the initial multi_number will not be consistent. In other words, the multi_number for each widget type needs to be synced across each Customizer session along with the actual setting values.
For concurrent editing of widgets, see: