Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#31690 closed defect (bug) (fixed)

Text widget inadvertently sets filter setting to true when passing instance data to update callback

Reported by: westonruter's profile westonruter Owned by: ocean90's profile ocean90
Milestone: 4.2 Priority: normal
Severity: normal Version: 2.8
Component: Widgets Keywords: has-patch commit
Focuses: Cc:


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():

$instance['filter'] = isset( $new_instance['filter'] );

Needs to become something like:

$instance['filter'] = ! empty( $new_instance['filter'] );

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

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

Attachments (1)

31690.diff (594 bytes) - added by westonruter 9 years ago.

Download all attachments as: .zip

Change History (4)

#1 @westonruter
9 years ago

  • Keywords has-patch commit added
  • Milestone changed from Future Release to 4.2
  • Owner set to ocean90
  • Status changed from new to assigned

#2 @westonruter
9 years ago

  • Status changed from assigned to reviewing

#3 @ocean90
9 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 31886:

Text Widget: Use !empty() for checking if the filter setting is set.

props westonruter.
fixes #31690.

Note: See TracTickets for help on using tickets.