Skip to content

Commit

Permalink
fixed number controls default value when it is not selected
Browse files Browse the repository at this point in the history
  • Loading branch information
nk-o committed May 22, 2024
1 parent d4960b9 commit c9ed9c4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion classes/class-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,9 @@ public function prepare_block_attributes( $controls, $child_of = '', $block = nu
if ( isset( $control['type'] ) && isset( $all_controls[ $control['type'] ] ) ) {
$attribute_data['type'] = $all_controls[ $control['type'] ]['type'];

if ( 'number' === $attribute_data['type'] && null !== $attribute_data['default'] ) {
// We also check for an empty string, as it is the default value when no default is provided.
// If this empty string is converted to a float, the control will default to `0`.
if ( 'number' === $attribute_data['type'] && null !== $attribute_data['default'] && '' !== $attribute_data['default'] ) {
$attribute_data['default'] = (float) $attribute_data['default'];
}
}
Expand Down

0 comments on commit c9ed9c4

Please sign in to comment.