← All changes
|
includes/elementor/modules/checkout/fields/base.php
+55
-5
1.2.9
→
2.7.0
View file →
| @@ -61,12 +61,19 @@ | ||
| 61 | 61 | protected function placeholder( $args ) { |
| 62 | 62 | if ( ! array_key_exists( 'label', $args ) ) { |
| 63 | 63 | return; |
| 64 | 64 | } |
| 65 | + | |
| 66 | + $label = $args['label']; | |
| 67 | + | |
| 68 | + if ( $this->placeholder_required_value( $args ) && 'multiselect' === $args['type'] ) { | |
| 69 | + $label .= ' *'; | |
| 70 | + } | |
| 71 | + | |
| 65 | 72 | ?> |
| 66 | 73 | <div style="position:relative"> |
| 67 | 74 | <span class="mini-title"> |
| 68 | - <?php echo $args['label']; ?> | |
| 75 | + <?php echo esc_html( $label ); ?> | |
| 69 | 76 | </span> |
| 70 | 77 | </div> |
| 71 | 78 | <?php |
| 72 | 79 | } |
| @@ -83,10 +90,12 @@ | ||
| 83 | 90 | $this->placeholder( $args ); |
| 84 | 91 | return; |
| 85 | 92 | } |
| 86 | 93 | |
| 94 | + $label = $this->placeholder_required_value( $args ); | |
| 95 | + | |
| 87 | 96 | ?> |
| 88 | - <label class="free_label"><?php echo $args['label']; ?></label> | |
| 97 | + <label class="free_label"><?php echo esc_html( $label ); ?></label> | |
| 89 | 98 | <?php |
| 90 | 99 | } |
| 91 | 100 | |
| 92 | 101 | /** |
| @@ -103,9 +112,9 @@ | ||
| 103 | 112 | |
| 104 | 113 | ?> |
| 105 | 114 | <div class="sellkit-required-validation"> |
| 106 | 115 | <span class="required-alarm"> |
| 107 | - <?php echo __( 'This field is required.', 'sellkit' ); ?> | |
| 116 | + <?php echo esc_html__( 'This field is required.', 'sellkit' ); ?> | |
| 108 | 117 | </span> |
| 109 | 118 | </div> |
| 110 | 119 | <?php |
| 111 | 120 | } |
| @@ -159,8 +168,40 @@ | ||
| 159 | 168 | return $args; |
| 160 | 169 | } |
| 161 | 170 | |
| 162 | 171 | /** |
| 172 | + * Check if this field is required. | |
| 173 | + * | |
| 174 | + * @param array $args field arguments. | |
| 175 | + * @since 1.3.1 | |
| 176 | + * @return boolean | |
| 177 | + */ | |
| 178 | + protected function is_this_required( $args ) { | |
| 179 | + if ( array_key_exists( 'required', $args ) && ( true === $args['required'] || 1 === $args['required'] ) ) { | |
| 180 | + return true; | |
| 181 | + } | |
| 182 | + | |
| 183 | + return false; | |
| 184 | + } | |
| 185 | + | |
| 186 | + /** | |
| 187 | + * Prepare placeholder value and add * to it for required fields. | |
| 188 | + * | |
| 189 | + * @param array $args fields arguments. | |
| 190 | + * @since 1.3.1 | |
| 191 | + * @return string | |
| 192 | + */ | |
| 193 | + protected function placeholder_required_value( $args ) { | |
| 194 | + $placeholder = ( array_key_exists( 'label', $args ) ) ? $args['label'] : ''; | |
| 195 | + | |
| 196 | + if ( $this->is_this_required( $args ) ) { | |
| 197 | + $placeholder .= ' *'; | |
| 198 | + } | |
| 199 | + | |
| 200 | + return $placeholder; | |
| 201 | + } | |
| 202 | + | |
| 203 | + /** | |
| 163 | 204 | * We make sure our fields basic class exists in class array, in order to not have any style issue. |
| 164 | 205 | * |
| 165 | 206 | * @param array $args checkout field option. |
| 166 | 207 | * @since 1.1.0 |
| @@ -171,8 +212,12 @@ | ||
| 171 | 212 | $defaults = [ 'sellkit-widget-checkout-fields', 'sellkit-checkout-fields-wrapper' ]; |
| 172 | 213 | $new_classes = []; |
| 173 | 214 | $is_width = true; |
| 174 | 215 | |
| 216 | + if ( ! is_array( $classes ) ) { | |
| 217 | + $classes = []; | |
| 218 | + } | |
| 219 | + | |
| 175 | 220 | foreach ( $defaults as $def ) { |
| 176 | 221 | if ( ! in_array( $def, $classes, true ) ) { |
| 177 | 222 | $new_classes[] = $def; |
| 178 | 223 | } |
| @@ -236,12 +281,13 @@ | ||
| 236 | 281 | * |
| 237 | 282 | * @param string $field html string. |
| 238 | 283 | * @param array $args checkout fields options. |
| 239 | 284 | * @param string $key key of field. |
| 285 | + * @param string $value value of field. | |
| 240 | 286 | * @return void |
| 241 | 287 | * @since 1.1.0 |
| 242 | 288 | */ |
| 243 | - public function final_html_structure( $field, $args, $key ) { | |
| 289 | + public function final_html_structure( $field, $args, $key, $value = null ) { | |
| 244 | 290 | $args = $this->additional_class( $args, $key ); |
| 245 | 291 | $args = $this->set_required_class( $args ); |
| 246 | 292 | $args = $this->make_sure_sellkit_native_classes_exists( $args ); |
| 247 | 293 | $args = $this->try_to_set_default_value( $args, $key ); |
| @@ -246,8 +292,12 @@ | ||
| 246 | 292 | $args = $this->make_sure_sellkit_native_classes_exists( $args ); |
| 247 | 293 | $args = $this->try_to_set_default_value( $args, $key ); |
| 248 | 294 | $class = implode( ' ', $args['class'] ); |
| 249 | 295 | |
| 296 | + if ( empty( $args['default'] ) && ! empty( $value ) ) { | |
| 297 | + $args['default'] = $value; | |
| 298 | + } | |
| 299 | + | |
| 250 | 300 | // Remove all classes of fields. |
| 251 | 301 | $field = preg_replace( '/class=".*?"/', '', $field, 1 ); |
| 252 | 302 | // Remove fields label. |
| 253 | 303 | $field = preg_replace( '~<label(.*?)</label>~Usi', '', $field ); |
| @@ -252,9 +302,9 @@ | ||
| 252 | 302 | // Remove fields label. |
| 253 | 303 | $field = preg_replace( '~<label(.*?)</label>~Usi', '', $field ); |
| 254 | 304 | |
| 255 | 305 | ?> |
| 256 | - <div class="<?php echo $class; ?> sellkit-checkout-fields-wrapper" id="wrapper-<?php echo $key; ?>"> | |
| 306 | + <div class="<?php echo esc_attr( $class ); ?> sellkit-checkout-fields-wrapper" id="wrapper-<?php echo esc_attr( $key ); ?>"> | |
| 257 | 307 | <?php |
| 258 | 308 | $this->label( $args ); |
| 259 | 309 | $this->field( $field, $args, $key ); |
| 260 | 310 | $this->required_validation( $args ); |