Opened 11 years ago
Closed 11 years ago
#31690 closed defect (bug) (fixed)
Text widget inadvertently sets filter setting to true when passing instance data to update callback
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.2 | Priority: | normal |
| Severity: | normal | Version: | 2.8 |
| Component: | Widgets | Keywords: | has-patch commit |
| Focuses: | Cc: |
Description
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>
https://github.com/xwp/wordpress-develop/pull/78