[wp-trac] [WordPress Trac] #44375: `update_option` in `WP_Widget::update` breaks Customizer
WordPress Trac
noreply at wordpress.org
Fri Jun 15 16:24:28 UTC 2018
#44375: `update_option` in `WP_Widget::update` breaks Customizer
--------------------------+-----------------------------
Reporter: bor0 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Widgets | Version: trunk
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Thanks to @westi for explaining
[https://github.com/WordPress/WordPress/blob/b13e73d/wp-includes/class-wp-
customize-widgets.php#L1945-L1967 this code] to me.
It seems that we keep track of the number of `update_option` calls which
is what powers the ability for the Customizer to show a bunch of changes
live that haven't been applied yet.
So as a consequence, we are not supposed to change any options within
`WP_Widget::update`, by design, or otherwise it will
[https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-
customize-widgets.php#L1456-L1459 fail].
We discussed with @westi and we both agree that it isn't expected that
widgets directly manage options but instead the API manages the widget's
settings for it so the widget doesn't have to be multi-use aware.
However, it should be made somewhat explicit in WordPress I believe, as it
only fails in the Customizer, and not when you do these changes from `wp-
admin/widgets.php`. It's kind of like a "hidden" bug :)
I am not sure if we want to just call a `_doing_it_wrong()` or rework this
part to allow devs to call `update_option` within `WP_Widget::update`.
Steps to reproduce:
1. Have a widget that calls `update_option` within the `update` method.
Example widget
[https://gist.github.com/bor0/f70a3db039f66d15cdc15b1bf8fa066f here].
2. Change the title through `wp-admin/widgets.php`
Expected = Actual: Title saves fine
3. Change the title through Customizer
Actual: `An error has occurred. Please reload the page and try again.`
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44375>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list