Opened 9 years ago
Last modified 7 years ago
#32183 accepted defect (bug)
Widget ID auto-increments conflict for concurrent users
Reported by: | westonruter | Owned by: | westonruter |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 2.8 |
Component: | Widgets | Keywords: | needs-patch |
Focuses: | Cc: |
Description
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:
#31436: Handle conflicts in concurrent Customizer sessions
#12722: Concurrent editing of widgets (on admin page)
Change History (5)
#3
@
9 years ago
- Keywords has-patch added; needs-patch removed
- Milestone changed from 4.3 to Future Release
I neglected to update here that I have a feature plugin that implements concurrent-user autoincrements for widget IDs
It's in the Customize Widgets Plus plugin's “Widget Number Incrementing” module.
The functionality is in these files:
https://github.com/xwp/wp-customize-widgets-plus/blob/master/php/class-widget-number-incrementing.php
https://github.com/xwp/wp-customize-widgets-plus/blob/master/js/widget-number-incrementing.js
https://github.com/xwp/wp-customize-widgets-plus/blob/master/js/widget-number-incrementing-customizer.js
https://github.com/xwp/wp-customize-widgets-plus/blob/master/core-patched/wp-admin/js/widgets.js
I'm adding has-patch
to refer to this feature plugin.
#4
@
7 years ago
I think this should be handled as part of storing widgets in a custom post type (#35669). When adding a new widget in the customizer, it should create an auto-draft
widget post which then gets transitioned to publish
when the customizer is saved. This is what was done for adding page/post stubs to the customizer, and it is also what is proposed for nav menus in #38072.
One approach to solving this would be to have
wp_ajax_save_widget()
and (I think)WP_Customize_Widgets::wp_ajax_update_widget()
check for a conflicting multi_number whenadd_new
is set; if it is, return an incremented number, and have the controls switch to that.wp_ajax_save_widget
doesn't currently return data though.That'd make it transparent to the user, but I'm not yet sure if the broader approaches to concurrent widget editing might fix this in a general way.
Does that sound like a sane solution?