From c9ed9c4197b2a2868aa84697dd0e9df73e87a40e Mon Sep 17 00:00:00 2001 From: Nikita Date: Thu, 23 May 2024 00:39:31 +0300 Subject: [PATCH] fixed number controls default value when it is not selected --- classes/class-blocks.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/classes/class-blocks.php b/classes/class-blocks.php index 1e82a58b..778a7be8 100644 --- a/classes/class-blocks.php +++ b/classes/class-blocks.php @@ -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']; } }