Handling of PHP's automatic array key conversion to int
This commit is contained in:
parent
900c8fc33f
commit
d2efef5a1c
|
@ -227,7 +227,9 @@ function woocommerce_wp_select( $field ) {
|
||||||
<select <?php echo wc_implode_html_attributes( $field_attributes ); // WPCS: XSS ok. ?>>
|
<select <?php echo wc_implode_html_attributes( $field_attributes ); // WPCS: XSS ok. ?>>
|
||||||
<?php
|
<?php
|
||||||
foreach ( $field['options'] as $key => $value ) {
|
foreach ( $field['options'] as $key => $value ) {
|
||||||
echo '<option value="' . esc_attr( $key ) . '" ' . selected( $field['value'] === $key || ( is_array( $field['value'] ) && in_array( $key, $field['value'], true ) ), true, false ) . '>' . esc_html( $value ) . '</option>';
|
// In case the value is an array, the $key from options might have been converted to int automatically by PHP,
|
||||||
|
// thus the comparison needs to check both $key and (string)$key.
|
||||||
|
echo '<option value="' . esc_attr( $key ) . '" ' . selected( $field['value'] === $key || ( is_array( $field['value'] ) && ( in_array( $key, $field['value'], true ) || in_array( (string) $key, $field['value'], true ) ) ), true, false ) . '>' . esc_html( $value ) . '</option>';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
|
|
Loading…
Reference in New Issue