Skip to content

Commit

Permalink
Jetpack: Fix authors widget 'all' checkbox (#40878)
Browse files Browse the repository at this point in the history
The block-based legacy widget editor sends the instance data through the
`update()` function multiple times, for preview and again on save. This
widget doing `isset( $new_instance['all'] )` was therefore going from
unset to `false` on preview and then from `false` to `true` on save.

Instead let's do like other widgets with checkboxes do, and cast the
value to boolean when set.

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/12658870949

Upstream-Ref: Automattic/jetpack@d3eb144
  • Loading branch information
anomiex authored and matticbot committed Jan 7, 2025
1 parent 955c1bb commit 55bac24
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
This is an alpha version! The changes listed here are not final.

### Bug fixes
- Authors widget: Fix saving of unchecked "Display all authors" checkbox in the legacy widget editor.
- Fix custom roles settings are not sticking for Jetpack Stats

### Other changes <!-- Non-user-facing changes go here. This section will not be copied to readme.txt. -->
Expand Down
2 changes: 1 addition & 1 deletion modules/widgets/authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public function form( $instance ) {
*/
public function update( $new_instance, $old_instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$new_instance['title'] = wp_strip_all_tags( $new_instance['title'] );
$new_instance['all'] = isset( $new_instance['all'] );
$new_instance['all'] = isset( $new_instance['all'] ) ? (bool) $new_instance['all'] : false;
$new_instance['number'] = (int) $new_instance['number'];
$new_instance['avatar_size'] = (int) $new_instance['avatar_size'];

Expand Down

0 comments on commit 55bac24

Please sign in to comment.