Skip to content

Commit c7446a5

Browse files
committed
#4043 - Float precision loss for color_rgba when show_default is set to true.
1 parent 8f47b89 commit c7446a5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

redux-core/inc/classes/class-redux-page-render.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,13 +950,28 @@ private function get_default_output_string( array $field ): string {
950950
}
951951
} else {
952952
foreach ( $field['default'] as $defaultk => $defaultv ) {
953+
$defaultk = is_numeric( $defaultk ) ? (string) $defaultk : $defaultk;
954+
$defaultv = is_numeric( $defaultv ) ? (string) $defaultv : $defaultv;
955+
953956
if ( ! empty( $field['options'][ $defaultv ]['alt'] ) ) {
954957
$default_output .= $field['options'][ $defaultv ]['alt'] . ', ';
955958
} elseif ( ! empty( $field['options'][ $defaultv ] ) ) {
956959
$default_output .= $field['options'][ $defaultv ] . ', ';
957960
} elseif ( ! empty( $field['options'][ $defaultk ] ) ) {
958961
$default_output .= $field['options'][ $defaultk ] . ', ';
959962
} elseif ( ! empty( $defaultv ) ) {
963+
if ( is_array( $defaultv ) ) {
964+
foreach ( $defaultv as $k => $v ) {
965+
if( is_array( $v ) ) {
966+
$defaultv = implode( ', ', $v );
967+
}
968+
}
969+
970+
if ( is_array( $defaultv ) ) {
971+
$defaultv = implode( ', ', $defaultv );
972+
}
973+
}
974+
960975
$default_output .= $defaultv . ', ';
961976
}
962977
}

sample/sections/color-selection/color-rgba.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
'subtitle' => esc_html__( 'Gives you the RGBA color.', 'your-textdomain-here' ),
2424
'default' => array(
2525
'color' => '#7e33dd',
26-
'alpha' => '.8',
26+
'alpha' => .8,
2727
),
2828
'output' => array(
2929
'color' => '.posted-on, .wp-block-post-date a',

0 commit comments

Comments
 (0)