Make WordPress Core

Opened 7 years ago

Last modified 6 years ago

#44375 new defect (bug)

`update_option` in `WP_Widget::update` breaks Customizer

Reported by: bor0's profile bor0 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Widgets Keywords:
Focuses: Cc:

Description

Thanks to @westi for explaining 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 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 here.
  1. Change the title through wp-admin/widgets.php

Expected = Actual: Title saves fine

  1. Change the title through Customizer

Actual: An error has occurred. Please reload the page and try again.

Change History (1)

#1 @pento
6 years ago

  • Version trunk deleted
Note: See TracTickets for help on using tickets.