[wp-trac] [WordPress Trac] #31690: Text widget inadvertently sets filter setting to true when passing instance data to update callback

WordPress Trac noreply at wordpress.org
Thu Mar 19 09:20:43 UTC 2015


#31690: Text widget inadvertently sets filter setting to true when passing instance
data to update callback
--------------------------+----------------------------
 Reporter:  westonruter   |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Future Release
Component:  Widgets       |    Version:  2.8
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+----------------------------
 The `WP_Widget_Text::update()` method is written in a way that is only
 compatible with for submissions where the `filter` setting is presented as
 a checkbox, and so to opt-in means that `isset( $new_instance['filter'] )`
 will be true. If the filter checkbox is not set, then a false value is
 stored in `$instance['filter']`. However, if you pass such an `$instance`
 array containing `$instance['filter'] === false` into the widget's
 `update` callback (as the widgets in the Customizer often do), then when
 the `$instance` array is returned from the `update` method, it then
 becomes that `$instance['filter'] === true` because it is then not a
 `null` value.

 So this line in `WP_Widget_Text::update()`:

 {{{#!php
 $instance['filter'] = isset( $new_instance['filter'] );
 }}}

 Needs to become something like:

 {{{#!php
 $instance['filter'] = ! empty( $new_instance['filter'] );
 }}}

 The use of `empty` is in fact already used when the widget is rendered:

 {{{#!php
 <div class="textwidget"><?php echo !empty( $instance['filter'] ) ?
 wpautop( $text ) : $text; ?></div>
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/31690>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list