[wp-trac] [WordPress Trac] #53766: Legacy Widget block triggers update() method multiple times for one update

WordPress Trac noreply at wordpress.org
Wed Jul 28 10:27:18 UTC 2021


#53766: Legacy Widget block triggers update() method multiple times for one update
-------------------------------+------------------------------
 Reporter:  GDragoN            |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Widgets            |     Version:
 Severity:  critical           |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:
-------------------------------+------------------------------

Comment (by GDragoN):

 All my plugins use a similar basic widget structure and base class.
 Plugin: https://wordpress.org/plugins/gd-members-directory-for-bbpress/
 has one widget, and I have noticed the problem because of one of the
 settings.

 Base widget class has a setting '_caps' that is in widget stored as an
 array. But, in the plugin interface, it is a single INPUT TEXT field. When
 the update() method is called, the plugin takes value from this text input
 and converts it into an array to save it. But, when using Legacy Widget,
 the update method is called more than once, and the update() function
 expects the input value for _caps to be string, and convert it to the
 array, on subsequent calls, update() seems to be called with the $Instace
 array that is already processed and _caps is already array at that point.

 As I said, I added dummy/fake value in an update() method to see it gets'
 propagated to the second update() call (value set to 0, with ++
 operation), it should end up as 1, but, because the second call, it ends
 up as 2, providing the duplicated call to update() method.

 With a lot of widgets, this is not a big deal, but if the update() method
 does some additional processing to settings, changing types, it is
 noticeable problem. And, my widgets usually do this for BOOLEAN values
 too.

 Milan

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


More information about the wp-trac mailing list