[wp-trac] [WordPress Trac] #55121: classic widgets with no settings won't show up in 5.9

WordPress Trac noreply at wordpress.org
Fri Feb 11 16:02:50 UTC 2022


#55121: classic widgets with no settings won't show up in 5.9
----------------------------+----------------------
 Reporter:  joncampbell     |       Owner:  (none)
     Type:  defect (bug)    |      Status:  closed
 Priority:  normal          |   Milestone:
Component:  Widgets         |     Version:  5.9
 Severity:  normal          |  Resolution:  invalid
 Keywords:  has-patch php8  |     Focuses:
----------------------------+----------------------

Comment (by sc0ttkclark):

 Just ran into this with some old code for a project that was written long
 ago by other developers.

 Part of the issue is related to the My_Widget class example at
 https://developer.wordpress.org/themes/functionality/widgets/#your-widget-
 class

 Yeah, the code is noted for how to use the update function elsewhere but
 it's not immediately apparent because the example has no return:


 {{{#!php
     public function update( $new_instance, $old_instance ) {
         // processes widget options to be saved
     }
 }}}

 And then the summary text right below it says something maybe perhaps more
 troubling:

 > update: Save the widget options to the database. If your widget doesn’t
 have any options, you can skip this function (although it is still best
 practice to include it even if it’s empty).

 It's that "although it is still best practice to include it even if it’s
 empty" text that is very misleading, as it says you should include it even
 if it is empty. It should be saying it should at least return the
 $new_instance argument.

 If nothing else happens to resolve this problem reported in this ticket, I
 definitely think this should be addressed there in the theme handbook
 page: https://developer.wordpress.org/themes/functionality/widgets/#your-
 widget-class

 I still agree that it would be useful to check for and catch null above
 line 477 in WP_Widget::update_callback() in file class-wp-widget.php:

 {{{#!php
 // Catch cases where the instance was not returned by an empty update()
 method.
 if ( null === $instance ) {
     $instance = [];
 }
 }}}

 NULL will always result it bugged widgets in WP 5.9+, but an empty array
 is a better way to deal with those cases.

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


More information about the wp-trac mailing list