← All changes
|
includes/elementor/modules/checkout/fields/select.php
+63
-25
1.1.4
→
2.7.0
View file →
| @@ -39,9 +39,9 @@ | ||
| 39 | 39 | if ( 'billing_state' === $key ) { |
| 40 | 40 | $country_key = 'sellkit-checkout-billing-cc'; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - $country_code = filter_input( INPUT_COOKIE, $country_key, FILTER_SANITIZE_STRING ); | |
| 43 | + $country_code = sellkit_htmlspecialchars( INPUT_COOKIE, $country_key ); | |
| 44 | 44 | |
| 45 | 45 | $states = WC()->countries->get_states( $country_code ); |
| 46 | 46 | |
| 47 | 47 | if ( ( 'billing_state' === $key || 'shipping_state' === $key ) && ( ! is_array( $states ) || empty( $states ) ) ) { |
| @@ -62,18 +62,18 @@ | ||
| 62 | 62 | * @return void |
| 63 | 63 | * @since 1.1.0 |
| 64 | 64 | */ |
| 65 | 65 | public function field( $field, $args, $key ) { |
| 66 | - echo '<i class="fa fa-angle-down sellkit-select-appearance"></i>'; | |
| 66 | + echo '<span class="sellkit-select-appearance"><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 512"><path d="M201.4 342.6c12.5 12.5 32.8 12.5 45.3 0l160-160c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L224 274.7 86.6 137.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l160 160z"/></svg></span>'; | |
| 67 | 67 | |
| 68 | + $default_value = ''; | |
| 69 | + if ( array_key_exists( 'default', $args ) ) { | |
| 70 | + $default_value = $args['default']; | |
| 71 | + } | |
| 72 | + | |
| 68 | 73 | if ( 'shipping_country' === $key || 'billing_country' === $key ) { |
| 69 | - $default = ''; | |
| 70 | - if ( array_key_exists( 'default', $args ) ) { | |
| 71 | - $default = $args['default']; | |
| 72 | - } | |
| 74 | + $this->woocommerce_field_country( $key, $default_value ); | |
| 73 | 75 | |
| 74 | - $this->woocommerce_field_country( $key, $default ); | |
| 75 | - | |
| 76 | 76 | return; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | if ( 'shipping_state' === $key || 'billing_state' === $key ) { |
| @@ -88,14 +88,17 @@ | ||
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | $states = WC()->countries->get_states( $country_code ); |
| 91 | 91 | |
| 92 | - $this->woocommerce_field_state( $key, $args, $states ); | |
| 92 | + $this->woocommerce_field_state( $key, $args, $states, $default_value ); | |
| 93 | 93 | |
| 94 | 94 | return; |
| 95 | 95 | } |
| 96 | + | |
| 97 | + $placeholder = $this->placeholder_required_value( $args ); | |
| 98 | + | |
| 96 | 99 | ?> |
| 97 | - <p id="<?php echo $key; ?>_field"> | |
| 100 | + <p id="<?php echo esc_attr( $key ); ?>_field"> | |
| 98 | 101 | <span class="woocommerce-input-wrapper"> |
| 99 | 102 | <select |
| 100 | 103 | name="<?php echo esc_attr( $key ); ?>" |
| 101 | 104 | id="<?php echo esc_attr( $key ); ?>" |
| @@ -100,14 +103,11 @@ | ||
| 100 | 103 | name="<?php echo esc_attr( $key ); ?>" |
| 101 | 104 | id="<?php echo esc_attr( $key ); ?>" |
| 102 | 105 | class="" |
| 103 | 106 | autocomplete="country" |
| 104 | - data-placeholder="<?php echo ( array_key_exists( 'label', $args ) ) ? esc_attr( $args['label'] ) : ''; ?>" | |
| 107 | + data-placeholder="<?php echo esc_attr( $placeholder ); ?>" | |
| 105 | 108 | data-label="<?php echo ( array_key_exists( 'label', $args ) ) ? esc_attr( $args['label'] ) : ''; ?>" |
| 106 | 109 | > |
| 107 | - <?php | |
| 108 | - $default_value = ( array_key_exists( 'default', $args ) ) ? $args['default'] : ''; | |
| 109 | - ?> | |
| 110 | 110 | <?php foreach ( $args['options'] as $value => $label ) : ?> |
| 111 | 111 | <?php |
| 112 | 112 | if ( $value === $default_value ) { |
| 113 | 113 | echo sprintf( |
| @@ -113,9 +113,9 @@ | ||
| 113 | 113 | echo sprintf( |
| 114 | 114 | /** Translators: 1:value 2: label */ |
| 115 | 115 | '<option selected value="%1$s">%2$s</option>', |
| 116 | 116 | esc_attr( $value ), |
| 117 | - esc_html( $label ), | |
| 117 | + esc_html( $label ) | |
| 118 | 118 | ); |
| 119 | 119 | |
| 120 | 120 | continue; |
| 121 | 121 | } |
| @@ -123,9 +123,9 @@ | ||
| 123 | 123 | echo sprintf( |
| 124 | 124 | /** Translators: 1:value 2: label */ |
| 125 | 125 | '<option value="%1$s">%2$s</option>', |
| 126 | 126 | esc_attr( $value ), |
| 127 | - esc_html( $label ), | |
| 127 | + esc_html( $label ) | |
| 128 | 128 | ); |
| 129 | 129 | ?> |
| 130 | 130 | <?php endforeach; ?> |
| 131 | 131 | </select> |
| @@ -143,9 +143,9 @@ | ||
| 143 | 143 | * @return void |
| 144 | 144 | */ |
| 145 | 145 | private function woocommerce_field_country( $key, $default ) { |
| 146 | 146 | ?> |
| 147 | - <p id="<?php echo $key; ?>_field"> | |
| 147 | + <p id="<?php echo esc_attr( $key ); ?>_field"> | |
| 148 | 148 | <span class="woocommerce-input-wrapper"> |
| 149 | 149 | <?php |
| 150 | 150 | $countries = WC()->countries->get_shipping_countries(); |
| 151 | 151 | |
| @@ -167,9 +167,27 @@ | ||
| 167 | 167 | |
| 168 | 168 | $field .= '</select>'; |
| 169 | 169 | $field .= '<noscript><input type="submit" name="woocommerce_checkout_update_totals" value="' . esc_attr__( 'Update country', 'sellkit' ) . '" /></noscript>'; |
| 170 | 170 | |
| 171 | - echo $field; | |
| 171 | + $allowed_html = [ | |
| 172 | + 'select' => [ | |
| 173 | + 'name' => true, | |
| 174 | + 'id' => true, | |
| 175 | + 'class' => true, | |
| 176 | + ], | |
| 177 | + 'option' => [ | |
| 178 | + 'value' => true, | |
| 179 | + 'selected' => true, | |
| 180 | + ], | |
| 181 | + 'noscript' => [], | |
| 182 | + 'input' => [ | |
| 183 | + 'type' => true, | |
| 184 | + 'name' => true, | |
| 185 | + 'value' => true, | |
| 186 | + ], | |
| 187 | + ]; | |
| 188 | + | |
| 189 | + echo wp_kses( $field, $allowed_html ); | |
| 172 | 190 | ?> |
| 173 | 191 | </span> |
| 174 | 192 | </p> |
| 175 | 193 | <?php |
| @@ -180,14 +198,17 @@ | ||
| 180 | 198 | * |
| 181 | 199 | * @param string $key field key. |
| 182 | 200 | * @param array $args field options. |
| 183 | 201 | * @param array $states country states. |
| 202 | + * @param string $default_value field default value. | |
| 184 | 203 | * @since 1.1.0 |
| 185 | 204 | * @return void |
| 186 | 205 | */ |
| 187 | - private function woocommerce_field_state( $key, $args, $states ) { | |
| 206 | + private function woocommerce_field_state( $key, $args, $states, $default_value ) { | |
| 207 | + $placeholder = $this->placeholder_required_value( $args ); | |
| 208 | + | |
| 188 | 209 | ?> |
| 189 | - <p id="<?php echo $key; ?>_field"> | |
| 210 | + <p id="<?php echo esc_attr( $key ); ?>_field"> | |
| 190 | 211 | <span class="woocommerce-input-wrapper"> |
| 191 | 212 | <?php |
| 192 | 213 | if ( ! is_array( $states ) || empty( $states ) ) { |
| 193 | 214 | $state = filter_input( INPUT_COOKIE, 'sellkit-checkout-billing-state' ); |
| @@ -202,27 +223,44 @@ | ||
| 202 | 223 | |
| 203 | 224 | echo sprintf( |
| 204 | 225 | /* translators: 1: placeholder 2: name 3: id 4: default value */ |
| 205 | 226 | '<input type="text" placeholder="%1$s" name="%2$s" id="%3$s" value="%4$s">', |
| 206 | - esc_attr( $args['label'] ), | |
| 227 | + esc_attr( $placeholder ), | |
| 207 | 228 | esc_attr__( 'State', 'sellkit' ), |
| 208 | 229 | esc_attr( 'sellkit-' . $key ), |
| 209 | - esc_attr( $state ), | |
| 230 | + esc_attr( $state ) | |
| 210 | 231 | ); |
| 211 | 232 | |
| 212 | 233 | return; |
| 213 | 234 | } |
| 214 | 235 | |
| 215 | - $field = '<select id="sellkit-' . $key . '" name="' . esc_attr( $key ) . '" placeholder="' . esc_attr( $args['label'] ) . '"> | |
| 236 | + $field = '<select id="sellkit-' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" placeholder="' . esc_attr( $args['label'] ) . '"> | |
| 216 | 237 | <option value="">' . esc_html__( 'Select a state…', 'sellkit' ) . '</option>'; |
| 217 | 238 | |
| 218 | 239 | foreach ( $states as $state_key => $state_label ) { |
| 219 | - $field .= '<option value="' . esc_attr( $state_key ) . '" >' . esc_html( $state_label ) . '</option>'; | |
| 240 | + $selected = ''; | |
| 241 | + | |
| 242 | + if ( $default_value === $state_key ) { | |
| 243 | + $selected = 'selected'; | |
| 244 | + } | |
| 245 | + $field .= '<option ' . $selected . ' value="' . esc_attr( $state_key ) . '" >' . esc_html( $state_label ) . '</option>'; | |
| 220 | 246 | } |
| 221 | 247 | |
| 222 | 248 | $field .= '</select>'; |
| 223 | 249 | |
| 224 | - echo $field; | |
| 250 | + $allowed_html = [ | |
| 251 | + 'select' => [ | |
| 252 | + 'id' => true, | |
| 253 | + 'name' => true, | |
| 254 | + 'placeholder' => true, | |
| 255 | + ], | |
| 256 | + 'option' => [ | |
| 257 | + 'value' => true, | |
| 258 | + 'selected' => true, | |
| 259 | + ], | |
| 260 | + ]; | |
| 261 | + | |
| 262 | + echo wp_kses( $field, $allowed_html ); | |
| 225 | 263 | ?> |
| 226 | 264 | </span> |
| 227 | 265 | </p> |
| 228 | 266 | <?php |