[wp-trac] [WordPress Trac] #33442: Widgets not displayed if no $instance data is set

WordPress Trac noreply at wordpress.org
Thu Aug 20 04:11:36 UTC 2015


#33442: Widgets not displayed if no $instance data is set
--------------------------+--------------------
 Reporter:  johnnyb       |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  4.3.1
Component:  Widgets       |     Version:  4.3
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+--------------------

Comment (by westonruter):

 Replying to [comment:2 dd32]:
 > Moving for review, Seems that change in r32602 needs to be reverted.
 >
 > @westonruter was there any specific reason for that change, other than
 it not being rather obvious why it was set like that?

 The reason for the change from `array_key_exists()` to using `isset()` was
 that I had found that `array_key_exists()` was not compatible with
 `ArrayObject`/`ArrayIterator` instances. Or actually, I think I had
 specifically found this for `array_keys()` and I assumed that it was also
 true for `array_key_exists()`. However, in actually testing it seems that
 using `array_key_exists()` works just fine: https://3v4l.org/vIFPF

 And with testing, yes, it is specifically that `array_keys()` has this
 problem: https://3v4l.org/bdoq5

 So yes, it looks like we can indeed go back to using `array_key_exists()`
 since it is compatible with both intrinsic arrays and array objects.

 @johnnyb Nevertheless, I think it is a plugin error to return anything but
 an array from the `update` callback. If you look at
 `WP_Widget::update_callback()` in core, it calls the `update` method and
 is expecting its return value as being an array, which it then passes into
 the `widget_update_callback` filter. If there are other plugins filtering
 this value, then they would be generating PHP warnings/notices when
 encountering a `null` value. The default base `WP_Widget::update()` method
 is defined as returning an array as well, so all subclasses should also
 have methods that return arrays.

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


More information about the wp-trac mailing list