|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
4
|
|
|
exit; // Exit if accessed directly |
|
5
|
|
|
} |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* A component class for rendering a bootstrap alert. |
|
9
|
|
|
* |
|
10
|
|
|
* @since 1.0.0 |
|
11
|
|
|
*/ |
|
12
|
|
|
class AUI_Component_Input { |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Build the component. |
|
16
|
|
|
* |
|
17
|
|
|
* @param array $args |
|
18
|
|
|
* |
|
19
|
|
|
* @return string The rendered component. |
|
20
|
|
|
*/ |
|
21
|
|
|
public static function input( $args = array() ) { |
|
22
|
|
|
global $aui_bs5; |
|
23
|
|
|
|
|
24
|
|
|
$defaults = array( |
|
25
|
|
|
'type' => 'text', |
|
26
|
|
|
'name' => '', |
|
27
|
|
|
'class' => '', |
|
28
|
|
|
'wrap_class' => '', |
|
29
|
|
|
'id' => '', |
|
30
|
|
|
'placeholder' => '', |
|
31
|
|
|
'title' => '', |
|
32
|
|
|
'value' => '', |
|
33
|
|
|
'required' => false, |
|
34
|
|
|
'size' => '', // sm, lg, small, large |
|
35
|
|
|
'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
36
|
|
|
'with_hidden' => false, // Append hidden field for single checkbox. |
|
37
|
|
|
'label' => '', |
|
38
|
|
|
'label_after' => false, |
|
39
|
|
|
'label_class' => '', |
|
40
|
|
|
'label_col' => '2', |
|
41
|
|
|
'label_type' => '', // top, horizontal, empty = hidden |
|
42
|
|
|
'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
43
|
|
|
// sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
44
|
|
|
'help_text' => '', |
|
45
|
|
|
'validation_text' => '', |
|
46
|
|
|
'validation_pattern' => '', |
|
47
|
|
|
'no_wrap' => false, |
|
48
|
|
|
'input_group_right' => '', |
|
49
|
|
|
'input_group_left' => '', |
|
50
|
|
|
'input_group_right_inside' => false, |
|
51
|
|
|
// forces the input group inside the input |
|
52
|
|
|
'input_group_left_inside' => false, |
|
53
|
|
|
// forces the input group inside the input |
|
54
|
|
|
'form_group_class' => '', |
|
55
|
|
|
'step' => '', |
|
56
|
|
|
'switch' => false, |
|
57
|
|
|
// to show checkbox as a switch |
|
58
|
|
|
'checked' => false, |
|
59
|
|
|
// set a checkbox or radio as selected |
|
60
|
|
|
'password_toggle' => true, |
|
61
|
|
|
// toggle view/hide password |
|
62
|
|
|
'element_require' => '', |
|
63
|
|
|
// [%element_id%] == "1" |
|
64
|
|
|
'extra_attributes' => array(), |
|
65
|
|
|
// an array of extra attributes |
|
66
|
|
|
'wrap_attributes' => array() |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Parse incoming $args into an array and merge it with $defaults |
|
71
|
|
|
*/ |
|
72
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
73
|
|
|
$output = ''; |
|
74
|
|
|
if ( ! empty( $args['type'] ) ) { |
|
75
|
|
|
// hidden label option needs to be empty |
|
76
|
|
|
$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
77
|
|
|
|
|
78
|
|
|
$type = sanitize_html_class( $args['type'] ); |
|
79
|
|
|
|
|
80
|
|
|
$help_text = ''; |
|
81
|
|
|
$label = ''; |
|
82
|
|
|
$label_after = $args['label_after']; |
|
83
|
|
|
$label_args = array( |
|
84
|
|
|
'title' => $args['label'], |
|
85
|
|
|
'for' => $args['id'], |
|
86
|
|
|
'class' => $args['label_class'] . " ", |
|
87
|
|
|
'label_type' => $args['label_type'], |
|
88
|
|
|
'label_col' => $args['label_col'] |
|
89
|
|
|
); |
|
90
|
|
|
|
|
91
|
|
|
// floating labels need label after |
|
92
|
|
|
if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
93
|
|
|
$label_after = true; |
|
94
|
|
|
$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
// size |
|
98
|
|
|
$size = ''; |
|
99
|
|
|
if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
100
|
|
|
$size = 'lg'; |
|
101
|
|
|
$args['class'] .= ' form-control-lg'; |
|
102
|
|
|
}elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
103
|
|
|
$size = 'sm'; |
|
104
|
|
|
$args['class'] .= ' form-control-sm'; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
// clear function |
|
108
|
|
|
$clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
109
|
|
|
|
|
110
|
|
|
// Some special sauce for files |
|
111
|
|
|
if ( $type == 'file' ) { |
|
112
|
|
|
$label_after = true; // if type file we need the label after |
|
113
|
|
|
$args['class'] .= ' custom-file-input '; |
|
114
|
|
|
} elseif ( $type == 'checkbox' ) { |
|
115
|
|
|
$label_after = true; // if type file we need the label after |
|
116
|
|
|
$args['class'] .= $aui_bs5 ? ' form-check-input' : ' custom-control-input '; |
|
117
|
|
|
} elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
118
|
|
|
$orig_type = $type; |
|
119
|
|
|
$type = 'text'; |
|
120
|
|
|
$args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
121
|
|
|
$clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
122
|
|
|
|
|
123
|
|
|
$args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
124
|
|
|
|
|
125
|
|
|
// Disable native datetime inputs. |
|
126
|
|
|
if ( ( $orig_type == 'timepicker' || ! empty( $args['extra_attributes']['data-enable-time'] ) ) && ! isset( $args['extra_attributes']['data-disable-mobile'] ) ) { |
|
127
|
|
|
$args['extra_attributes']['data-disable-mobile'] = 'true'; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
// set a way to clear field if empty |
|
131
|
|
|
if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
132
|
|
|
$args['input_group_right_inside'] = true; |
|
133
|
|
|
$args['clear_icon'] = true; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
// enqueue the script |
|
137
|
|
|
$aui_settings = AyeCode_UI_Settings::instance(); |
|
138
|
|
|
$aui_settings->enqueue_flatpickr(); |
|
139
|
|
|
} elseif ( $type == 'iconpicker' ) { |
|
140
|
|
|
$type = 'text'; |
|
141
|
|
|
//$args['class'] .= ' aui-flatpickr bg-initial '; |
|
142
|
|
|
// $args['class'] .= ' bg-initial '; |
|
143
|
|
|
|
|
144
|
|
|
$args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
145
|
|
|
$args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
146
|
|
|
|
|
147
|
|
|
$args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
148
|
|
|
// $args['input_group_right_inside'] = true; |
|
149
|
|
|
// enqueue the script |
|
150
|
|
|
$aui_settings = AyeCode_UI_Settings::instance(); |
|
151
|
|
|
$aui_settings->enqueue_iconpicker(); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
if ( $type == 'checkbox' && ( ( ! empty( $args['name'] ) && strpos( $args['name'], '[' ) === false ) || ! empty( $args['with_hidden'] ) ) ) { |
|
155
|
|
|
$output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
// allow clear icon |
|
159
|
|
|
if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
160
|
|
|
$font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
161
|
|
|
$args['input_group_right_inside'] = true; |
|
162
|
|
|
$align_class = $aui_bs5 ? ' h-100 py-0' : ''; |
|
163
|
|
|
$args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none ' . $align_class . '" onclick="' . $clear_function . '"><span style="font-size: '.$font_size.'rem" aria-hidden="true" class="close">×</span></span>'; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
// open/type |
|
167
|
|
|
$output .= '<input type="' . $type . '" '; |
|
168
|
|
|
|
|
169
|
|
|
// name |
|
170
|
|
|
if ( ! empty( $args['name'] ) ) { |
|
171
|
|
|
$output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
// id |
|
175
|
|
|
if ( ! empty( $args['id'] ) ) { |
|
176
|
|
|
$output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
// placeholder |
|
180
|
|
|
if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
181
|
|
|
$output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
// title |
|
185
|
|
|
if ( ! empty( $args['title'] ) ) { |
|
186
|
|
|
$output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
// value |
|
190
|
|
|
if ( ! empty( $args['value'] ) ) { |
|
191
|
|
|
$output .= AUI_Component_Helper::value( $args['value'] ); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
// checked, for radio and checkboxes |
|
195
|
|
|
if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
196
|
|
|
$output .= ' checked '; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
// validation text |
|
200
|
|
|
if ( ! empty( $args['validation_text'] ) ) { |
|
201
|
|
|
$output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
202
|
|
|
$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
// validation_pattern |
|
206
|
|
|
if ( ! empty( $args['validation_pattern'] ) ) { |
|
207
|
|
|
$output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
// step (for numbers) |
|
211
|
|
|
if ( ! empty( $args['step'] ) ) { |
|
212
|
|
|
$output .= ' step="' . $args['step'] . '" '; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
// required |
|
216
|
|
|
if ( ! empty( $args['required'] ) ) { |
|
217
|
|
|
$output .= ' required '; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
// class |
|
221
|
|
|
$class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
222
|
|
|
$output .= $aui_bs5 && $type == 'checkbox' ? ' class="' . $class . '" ' : ' class="form-control ' . $class . '" '; |
|
223
|
|
|
|
|
224
|
|
|
// data-attributes |
|
225
|
|
|
$output .= AUI_Component_Helper::data_attributes( $args ); |
|
226
|
|
|
|
|
227
|
|
|
// extra attributes |
|
228
|
|
|
if ( ! empty( $args['extra_attributes'] ) ) { |
|
229
|
|
|
$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
// close |
|
233
|
|
|
$output .= ' >'; |
|
234
|
|
|
|
|
235
|
|
|
// help text |
|
236
|
|
|
if ( ! empty( $args['help_text'] ) ) { |
|
237
|
|
|
$help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
// label |
|
241
|
|
|
if ( ! empty( $args['label'] ) ) { |
|
242
|
|
|
$label_base_class = ''; |
|
243
|
|
|
if ( $type == 'file' ) { |
|
244
|
|
|
$label_base_class = ' custom-file-label'; |
|
245
|
|
|
} elseif ( $type == 'checkbox' ) { |
|
246
|
|
|
if ( ! empty( $args['label_force_left'] ) ) { |
|
247
|
|
|
$label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
248
|
|
|
$help_text = ''; |
|
249
|
|
|
//$label_args['class'] .= ' d-inline '; |
|
250
|
|
|
$args['wrap_class'] .= ' align-items-center '; |
|
251
|
|
|
}else{ |
|
252
|
|
|
|
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
$label_base_class = $aui_bs5 ? ' form-check-label' : ' custom-control-label'; |
|
256
|
|
|
} |
|
257
|
|
|
$label_args['class'] .= $label_base_class; |
|
258
|
|
|
$temp_label_args = $label_args; |
|
259
|
|
|
if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
260
|
|
|
$label = self::label( $temp_label_args, $type ); |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
|
|
264
|
|
|
|
|
265
|
|
|
|
|
266
|
|
|
// set help text in the correct position |
|
267
|
|
|
if ( $label_after ) { |
|
268
|
|
|
$output .= $label . $help_text; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
// some input types need a separate wrap |
|
272
|
|
|
if ( $type == 'file' ) { |
|
273
|
|
|
$output = self::wrap( array( |
|
274
|
|
|
'content' => $output, |
|
275
|
|
|
'class' => $aui_bs5 ? 'mb-3 custom-file' : 'form-group custom-file' |
|
276
|
|
|
) ); |
|
277
|
|
|
} elseif ( $type == 'checkbox' ) { |
|
278
|
|
|
|
|
279
|
|
|
$label_args['title'] = $args['label']; |
|
280
|
|
|
$label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
281
|
|
|
$label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
282
|
|
|
$switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
283
|
|
|
if ( $aui_bs5 ) { |
|
284
|
|
|
$wrap_class = $args['switch'] ? 'form-check form-switch' . $switch_size_class : 'form-check'; |
|
285
|
|
|
}else{ |
|
286
|
|
|
$wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class : 'custom-checkbox' ; |
|
287
|
|
|
} |
|
288
|
|
|
if ( ! empty( $args['label_force_left'] ) ) { |
|
289
|
|
|
$wrap_class .= $aui_bs5 ? '' : ' d-flex align-content-center'; |
|
290
|
|
|
$label = str_replace("form-check-label","", self::label( $label_args, 'cb' ) ); |
|
291
|
|
|
} |
|
292
|
|
|
$output = self::wrap( array( |
|
293
|
|
|
'content' => $output, |
|
294
|
|
|
'class' => $aui_bs5 ? $wrap_class : 'custom-control ' . $wrap_class |
|
295
|
|
|
) ); |
|
296
|
|
|
|
|
297
|
|
|
if ( $args['label_type'] == 'horizontal' ) { |
|
298
|
|
|
$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
299
|
|
|
$output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
300
|
|
|
} |
|
301
|
|
|
} elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
302
|
|
|
|
|
303
|
|
|
|
|
304
|
|
|
// allow password field to toggle view |
|
305
|
|
|
$args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
306
|
|
|
onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\'); |
|
307
|
|
|
var $eli = jQuery(this).parent().parent().find(\'input\'); |
|
308
|
|
|
if($el.hasClass(\'fa-eye\')) |
|
309
|
|
|
{$eli.attr(\'type\',\'text\');} |
|
310
|
|
|
else{$eli.attr(\'type\',\'password\');}" |
|
311
|
|
|
><i class="far fa-fw fa-eye-slash"></i></span>'; |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
// input group wraps |
|
315
|
|
|
if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
316
|
|
|
$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
317
|
|
|
$group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
318
|
|
|
$group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
319
|
|
|
|
|
320
|
|
|
if ( $args['input_group_left'] ) { |
|
321
|
|
|
$output = self::wrap( array( |
|
322
|
|
|
'content' => $output, |
|
323
|
|
|
'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
324
|
|
|
'input_group_left' => $args['input_group_left'], |
|
325
|
|
|
'input_group_left_inside' => $args['input_group_left_inside'] |
|
326
|
|
|
) ); |
|
327
|
|
|
} |
|
328
|
|
|
if ( $args['input_group_right'] ) { |
|
329
|
|
|
$output = self::wrap( array( |
|
330
|
|
|
'content' => $output, |
|
331
|
|
|
'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
332
|
|
|
'input_group_right' => $args['input_group_right'], |
|
333
|
|
|
'input_group_right_inside' => $args['input_group_right_inside'] |
|
334
|
|
|
) ); |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
if ( ! $label_after ) { |
|
340
|
|
|
$output .= $help_text; |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
|
|
344
|
|
|
if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
345
|
|
|
$output = self::wrap( array( |
|
346
|
|
|
'content' => $output, |
|
347
|
|
|
'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
348
|
|
|
) ); |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
if ( ! $label_after ) { |
|
352
|
|
|
$output = $label . $output; |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
// wrap |
|
356
|
|
|
if ( ! $args['no_wrap'] ) { |
|
357
|
|
|
if ( ! empty( $args['form_group_class'] ) ) { |
|
358
|
|
|
$fg_class = esc_attr( $args['form_group_class'] ); |
|
359
|
|
|
}else{ |
|
360
|
|
|
$fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
361
|
|
|
} |
|
362
|
|
|
$form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : $fg_class; |
|
363
|
|
|
$wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
364
|
|
|
$wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
365
|
|
|
$output = self::wrap( array( |
|
366
|
|
|
'content' => $output, |
|
367
|
|
|
'class' => $wrap_class, |
|
368
|
|
|
'element_require' => $args['element_require'], |
|
369
|
|
|
'argument_id' => $args['id'], |
|
370
|
|
|
'wrap_attributes' => $args['wrap_attributes'], |
|
371
|
|
|
) ); |
|
372
|
|
|
} |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
return $output; |
|
376
|
|
|
} |
|
377
|
|
|
|
|
378
|
|
|
public static function label( $args = array(), $type = '' ) { |
|
379
|
|
|
global $aui_bs5; |
|
380
|
|
|
//<label for="exampleInputEmail1">Email address</label> |
|
381
|
|
|
$defaults = array( |
|
382
|
|
|
'title' => 'div', |
|
383
|
|
|
'for' => '', |
|
384
|
|
|
'class' => '', |
|
385
|
|
|
'label_type' => '', // empty = hidden, top, horizontal |
|
386
|
|
|
'label_col' => '', |
|
387
|
|
|
); |
|
388
|
|
|
|
|
389
|
|
|
/** |
|
390
|
|
|
* Parse incoming $args into an array and merge it with $defaults |
|
391
|
|
|
*/ |
|
392
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
393
|
|
|
$output = ''; |
|
394
|
|
|
|
|
395
|
|
|
if ( $args['title'] ) { |
|
396
|
|
|
|
|
397
|
|
|
// maybe hide labels //@todo set a global option for visibility class |
|
398
|
|
|
if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
399
|
|
|
$class = $args['class']; |
|
400
|
|
|
} else { |
|
401
|
|
|
$class = 'sr-only ' . $args['class']; |
|
402
|
|
|
} |
|
403
|
|
|
|
|
404
|
|
|
// maybe horizontal |
|
405
|
|
|
if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
406
|
|
|
$class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; |
|
407
|
|
|
} |
|
408
|
|
|
|
|
409
|
|
|
if( $aui_bs5 ){ $class .= ' form-label'; } |
|
410
|
|
|
|
|
411
|
|
|
// open |
|
412
|
|
|
$output .= '<label '; |
|
413
|
|
|
|
|
414
|
|
|
// for |
|
415
|
|
|
if ( ! empty( $args['for'] ) ) { |
|
416
|
|
|
$output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
417
|
|
|
} |
|
418
|
|
|
|
|
419
|
|
|
// class |
|
420
|
|
|
$class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
421
|
|
|
$output .= ' class="' . $class . '" '; |
|
422
|
|
|
|
|
423
|
|
|
// close |
|
424
|
|
|
$output .= '>'; |
|
425
|
|
|
|
|
426
|
|
|
|
|
427
|
|
|
// title, don't escape fully as can contain html |
|
428
|
|
|
if ( ! empty( $args['title'] ) ) { |
|
429
|
|
|
$output .= wp_kses_post( $args['title'] ); |
|
430
|
|
|
} |
|
431
|
|
|
|
|
432
|
|
|
// close wrap |
|
433
|
|
|
$output .= '</label>'; |
|
434
|
|
|
|
|
435
|
|
|
|
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
|
|
439
|
|
|
return $output; |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
|
|
/** |
|
443
|
|
|
* Wrap some content in a HTML wrapper. |
|
444
|
|
|
* |
|
445
|
|
|
* @param array $args |
|
446
|
|
|
* |
|
447
|
|
|
* @return string |
|
448
|
|
|
*/ |
|
449
|
|
|
public static function wrap( $args = array() ) { |
|
450
|
|
|
global $aui_bs5; |
|
451
|
|
|
$defaults = array( |
|
452
|
|
|
'type' => 'div', |
|
453
|
|
|
'class' => $aui_bs5 ? 'mb-3' : 'form-group', |
|
454
|
|
|
'content' => '', |
|
455
|
|
|
'input_group_left' => '', |
|
456
|
|
|
'input_group_right' => '', |
|
457
|
|
|
'input_group_left_inside' => false, |
|
458
|
|
|
'input_group_right_inside' => false, |
|
459
|
|
|
'element_require' => '', |
|
460
|
|
|
'argument_id' => '', |
|
461
|
|
|
'wrap_attributes' => array() |
|
462
|
|
|
); |
|
463
|
|
|
|
|
464
|
|
|
/** |
|
465
|
|
|
* Parse incoming $args into an array and merge it with $defaults |
|
466
|
|
|
*/ |
|
467
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
468
|
|
|
$output = ''; |
|
469
|
|
|
if ( $args['type'] ) { |
|
470
|
|
|
|
|
471
|
|
|
// open |
|
472
|
|
|
$output .= '<' . sanitize_html_class( $args['type'] ); |
|
473
|
|
|
|
|
474
|
|
|
// element require |
|
475
|
|
|
if ( ! empty( $args['element_require'] ) ) { |
|
476
|
|
|
$output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
477
|
|
|
$args['class'] .= " aui-conditional-field"; |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
|
|
// argument_id |
|
481
|
|
|
if ( ! empty( $args['argument_id'] ) ) { |
|
482
|
|
|
$output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
483
|
|
|
} |
|
484
|
|
|
|
|
485
|
|
|
// class |
|
486
|
|
|
$class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
487
|
|
|
$output .= ' class="' . $class . '" '; |
|
488
|
|
|
|
|
489
|
|
|
// Attributes |
|
490
|
|
|
if ( ! empty( $args['wrap_attributes'] ) ) { |
|
491
|
|
|
$output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
492
|
|
|
} |
|
493
|
|
|
|
|
494
|
|
|
// close wrap |
|
495
|
|
|
$output .= ' >'; |
|
496
|
|
|
|
|
497
|
|
|
|
|
498
|
|
|
// Input group left |
|
499
|
|
|
if ( ! empty( $args['input_group_left'] ) ) { |
|
500
|
|
|
$position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
501
|
|
|
$input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
502
|
|
|
$output .= $aui_bs5 ? $input_group_left : '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
503
|
|
|
// $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
504
|
|
|
} |
|
505
|
|
|
|
|
506
|
|
|
// content |
|
507
|
|
|
$output .= $args['content']; |
|
508
|
|
|
|
|
509
|
|
|
// Input group right |
|
510
|
|
|
if ( ! empty( $args['input_group_right'] ) ) { |
|
511
|
|
|
$position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
512
|
|
|
$input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
513
|
|
|
$output .= $aui_bs5 ? str_replace( 'input-group-text','input-group-text top-0 end-0', $input_group_right ) : '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
514
|
|
|
// $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
515
|
|
|
} |
|
516
|
|
|
|
|
517
|
|
|
|
|
518
|
|
|
// close wrap |
|
519
|
|
|
$output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
520
|
|
|
|
|
521
|
|
|
|
|
522
|
|
|
} else { |
|
523
|
|
|
$output = $args['content']; |
|
524
|
|
|
} |
|
525
|
|
|
|
|
526
|
|
|
return $output; |
|
527
|
|
|
} |
|
528
|
|
|
|
|
529
|
|
|
/** |
|
530
|
|
|
* Build the component. |
|
531
|
|
|
* |
|
532
|
|
|
* @param array $args |
|
533
|
|
|
* |
|
534
|
|
|
* @return string The rendered component. |
|
535
|
|
|
*/ |
|
536
|
|
|
public static function textarea( $args = array() ) { |
|
537
|
|
|
global $aui_bs5; |
|
538
|
|
|
|
|
539
|
|
|
$defaults = array( |
|
540
|
|
|
'name' => '', |
|
541
|
|
|
'class' => '', |
|
542
|
|
|
'wrap_class' => '', |
|
543
|
|
|
'id' => '', |
|
544
|
|
|
'placeholder' => '', |
|
545
|
|
|
'title' => '', |
|
546
|
|
|
'value' => '', |
|
547
|
|
|
'required' => false, |
|
548
|
|
|
'label' => '', |
|
549
|
|
|
'label_after' => false, |
|
550
|
|
|
'label_class' => '', |
|
551
|
|
|
'label_type' => '', |
|
552
|
|
|
'label_col' => '', |
|
553
|
|
|
// sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
554
|
|
|
'input_group_right' => '', |
|
555
|
|
|
'input_group_left' => '', |
|
556
|
|
|
'input_group_right_inside' => false, |
|
557
|
|
|
'form_group_class' => '', |
|
558
|
|
|
'help_text' => '', |
|
559
|
|
|
'validation_text' => '', |
|
560
|
|
|
'validation_pattern' => '', |
|
561
|
|
|
'no_wrap' => false, |
|
562
|
|
|
'rows' => '', |
|
563
|
|
|
'wysiwyg' => false, |
|
564
|
|
|
'allow_tags' => false, |
|
565
|
|
|
// Allow HTML tags |
|
566
|
|
|
'element_require' => '', |
|
567
|
|
|
// [%element_id%] == "1" |
|
568
|
|
|
'extra_attributes' => array(), |
|
569
|
|
|
// an array of extra attributes |
|
570
|
|
|
'wrap_attributes' => array(), |
|
571
|
|
|
); |
|
572
|
|
|
|
|
573
|
|
|
/** |
|
574
|
|
|
* Parse incoming $args into an array and merge it with $defaults |
|
575
|
|
|
*/ |
|
576
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
577
|
|
|
$output = ''; |
|
578
|
|
|
$label = ''; |
|
579
|
|
|
|
|
580
|
|
|
// hidden label option needs to be empty |
|
581
|
|
|
$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
582
|
|
|
|
|
583
|
|
|
// floating labels don't work with wysiwyg so set it as top |
|
584
|
|
|
if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
585
|
|
|
$args['label_type'] = 'top'; |
|
586
|
|
|
} |
|
587
|
|
|
|
|
588
|
|
|
$label_after = $args['label_after']; |
|
589
|
|
|
|
|
590
|
|
|
// floating labels need label after |
|
591
|
|
|
if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
592
|
|
|
$label_after = true; |
|
593
|
|
|
$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
594
|
|
|
} |
|
595
|
|
|
|
|
596
|
|
|
// label |
|
597
|
|
|
if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
598
|
|
|
} elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
599
|
|
|
$label_args = array( |
|
600
|
|
|
'title' => $args['label'], |
|
601
|
|
|
'for' => $args['id'], |
|
602
|
|
|
'class' => $args['label_class'] . " ", |
|
603
|
|
|
'label_type' => $args['label_type'], |
|
604
|
|
|
'label_col' => $args['label_col'] |
|
605
|
|
|
); |
|
606
|
|
|
$label .= self::label( $label_args ); |
|
607
|
|
|
} |
|
608
|
|
|
|
|
609
|
|
|
// maybe horizontal label |
|
610
|
|
|
if ( $args['label_type'] == 'horizontal' ) { |
|
611
|
|
|
$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
612
|
|
|
$label .= '<div class="' . $input_col . '">'; |
|
613
|
|
|
} |
|
614
|
|
|
|
|
615
|
|
|
if ( ! empty( $args['wysiwyg'] ) ) { |
|
616
|
|
|
ob_start(); |
|
617
|
|
|
$content = $args['value']; |
|
618
|
|
|
$editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
619
|
|
|
$settings = array( |
|
620
|
|
|
'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
621
|
|
|
'quicktags' => false, |
|
622
|
|
|
'media_buttons' => false, |
|
623
|
|
|
'editor_class' => 'form-control', |
|
624
|
|
|
'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
625
|
|
|
'teeny' => true, |
|
626
|
|
|
); |
|
627
|
|
|
|
|
628
|
|
|
// maybe set settings if array |
|
629
|
|
|
if ( is_array( $args['wysiwyg'] ) ) { |
|
630
|
|
|
$settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
631
|
|
|
} |
|
632
|
|
|
|
|
633
|
|
|
wp_editor( $content, $editor_id, $settings ); |
|
634
|
|
|
$output .= ob_get_clean(); |
|
635
|
|
|
} else { |
|
636
|
|
|
|
|
637
|
|
|
// open |
|
638
|
|
|
$output .= '<textarea '; |
|
639
|
|
|
|
|
640
|
|
|
// name |
|
641
|
|
|
if ( ! empty( $args['name'] ) ) { |
|
642
|
|
|
$output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
643
|
|
|
} |
|
644
|
|
|
|
|
645
|
|
|
// id |
|
646
|
|
|
if ( ! empty( $args['id'] ) ) { |
|
647
|
|
|
$output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
648
|
|
|
} |
|
649
|
|
|
|
|
650
|
|
|
// placeholder |
|
651
|
|
|
if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
652
|
|
|
$output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
653
|
|
|
} |
|
654
|
|
|
|
|
655
|
|
|
// title |
|
656
|
|
|
if ( ! empty( $args['title'] ) ) { |
|
657
|
|
|
$output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
658
|
|
|
} |
|
659
|
|
|
|
|
660
|
|
|
// validation text |
|
661
|
|
|
if ( ! empty( $args['validation_text'] ) ) { |
|
662
|
|
|
$output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
663
|
|
|
$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
664
|
|
|
} |
|
665
|
|
|
|
|
666
|
|
|
// validation_pattern |
|
667
|
|
|
if ( ! empty( $args['validation_pattern'] ) ) { |
|
668
|
|
|
$output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
669
|
|
|
} |
|
670
|
|
|
|
|
671
|
|
|
// required |
|
672
|
|
|
if ( ! empty( $args['required'] ) ) { |
|
673
|
|
|
$output .= ' required '; |
|
674
|
|
|
} |
|
675
|
|
|
|
|
676
|
|
|
// rows |
|
677
|
|
|
if ( ! empty( $args['rows'] ) ) { |
|
678
|
|
|
$output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
679
|
|
|
} |
|
680
|
|
|
|
|
681
|
|
|
|
|
682
|
|
|
// class |
|
683
|
|
|
$class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
684
|
|
|
$output .= ' class="form-control ' . $class . '" '; |
|
685
|
|
|
|
|
686
|
|
|
// extra attributes |
|
687
|
|
|
if ( ! empty( $args['extra_attributes'] ) ) { |
|
688
|
|
|
$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
689
|
|
|
} |
|
690
|
|
|
|
|
691
|
|
|
// close tag |
|
692
|
|
|
$output .= ' >'; |
|
693
|
|
|
|
|
694
|
|
|
// value |
|
695
|
|
|
if ( ! empty( $args['value'] ) ) { |
|
696
|
|
|
if ( ! empty( $args['allow_tags'] ) ) { |
|
697
|
|
|
$output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
698
|
|
|
} else { |
|
699
|
|
|
$output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
700
|
|
|
} |
|
701
|
|
|
} |
|
702
|
|
|
|
|
703
|
|
|
// closing tag |
|
704
|
|
|
$output .= '</textarea>'; |
|
705
|
|
|
|
|
706
|
|
|
|
|
707
|
|
|
// input group wraps |
|
708
|
|
|
if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
709
|
|
|
$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
710
|
|
|
if ( $args['input_group_left'] ) { |
|
711
|
|
|
$output = self::wrap( array( |
|
712
|
|
|
'content' => $output, |
|
713
|
|
|
'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
714
|
|
|
'input_group_left' => $args['input_group_left'], |
|
715
|
|
|
'input_group_left_inside' => $args['input_group_left_inside'] |
|
716
|
|
|
) ); |
|
717
|
|
|
} |
|
718
|
|
|
if ( $args['input_group_right'] ) { |
|
719
|
|
|
$output = self::wrap( array( |
|
720
|
|
|
'content' => $output, |
|
721
|
|
|
'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
722
|
|
|
'input_group_right' => $args['input_group_right'], |
|
723
|
|
|
'input_group_right_inside' => $args['input_group_right_inside'] |
|
724
|
|
|
) ); |
|
725
|
|
|
} |
|
726
|
|
|
|
|
727
|
|
|
} |
|
728
|
|
|
|
|
729
|
|
|
|
|
730
|
|
|
} |
|
731
|
|
|
|
|
732
|
|
|
if ( ! empty( $args['label'] ) && $label_after ) { |
|
733
|
|
|
$label_args = array( |
|
734
|
|
|
'title' => $args['label'], |
|
735
|
|
|
'for' => $args['id'], |
|
736
|
|
|
'class' => $args['label_class'] . " ", |
|
737
|
|
|
'label_type' => $args['label_type'], |
|
738
|
|
|
'label_col' => $args['label_col'] |
|
739
|
|
|
); |
|
740
|
|
|
$output .= self::label( $label_args ); |
|
741
|
|
|
} |
|
742
|
|
|
|
|
743
|
|
|
// help text |
|
744
|
|
|
if ( ! empty( $args['help_text'] ) ) { |
|
745
|
|
|
$output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
746
|
|
|
} |
|
747
|
|
|
|
|
748
|
|
|
if ( ! $label_after ) { |
|
749
|
|
|
$output = $label . $output; |
|
750
|
|
|
} |
|
751
|
|
|
|
|
752
|
|
|
// maybe horizontal label |
|
753
|
|
|
if ( $args['label_type'] == 'horizontal' ) { |
|
754
|
|
|
$output .= '</div>'; |
|
755
|
|
|
} |
|
756
|
|
|
|
|
757
|
|
|
|
|
758
|
|
|
// wrap |
|
759
|
|
|
if ( ! $args['no_wrap'] ) { |
|
760
|
|
|
if ( ! empty( $args['form_group_class'] ) ) { |
|
761
|
|
|
$fg_class = esc_attr( $args['form_group_class'] ); |
|
762
|
|
|
}else{ |
|
763
|
|
|
$fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
764
|
|
|
} |
|
765
|
|
|
$form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : $fg_class; |
|
766
|
|
|
$wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
767
|
|
|
$wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
768
|
|
|
$output = self::wrap( array( |
|
769
|
|
|
'content' => $output, |
|
770
|
|
|
'class' => $wrap_class, |
|
771
|
|
|
'element_require' => $args['element_require'], |
|
772
|
|
|
'argument_id' => $args['id'], |
|
773
|
|
|
'wrap_attributes' => $args['wrap_attributes'], |
|
774
|
|
|
) ); |
|
775
|
|
|
} |
|
776
|
|
|
|
|
777
|
|
|
|
|
778
|
|
|
return $output; |
|
779
|
|
|
} |
|
780
|
|
|
|
|
781
|
|
|
/** |
|
782
|
|
|
* Build the component. |
|
783
|
|
|
* |
|
784
|
|
|
* @param array $args |
|
785
|
|
|
* |
|
786
|
|
|
* @return string The rendered component. |
|
787
|
|
|
*/ |
|
788
|
|
|
public static function select( $args = array() ) { |
|
789
|
|
|
global $aui_bs5; |
|
790
|
|
|
$defaults = array( |
|
791
|
|
|
'class' => '', |
|
792
|
|
|
'wrap_class' => '', |
|
793
|
|
|
'id' => '', |
|
794
|
|
|
'title' => '', |
|
795
|
|
|
'value' => '', |
|
796
|
|
|
// can be an array or a string |
|
797
|
|
|
'required' => false, |
|
798
|
|
|
'label' => '', |
|
799
|
|
|
'label_after' => false, |
|
800
|
|
|
'label_type' => '', |
|
801
|
|
|
'label_col' => '', |
|
802
|
|
|
// sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
803
|
|
|
'label_class' => '', |
|
804
|
|
|
'help_text' => '', |
|
805
|
|
|
'placeholder' => '', |
|
806
|
|
|
'options' => array(), |
|
807
|
|
|
// array or string |
|
808
|
|
|
'icon' => '', |
|
809
|
|
|
'multiple' => false, |
|
810
|
|
|
'select2' => false, |
|
811
|
|
|
'no_wrap' => false, |
|
812
|
|
|
'input_group_right' => '', |
|
813
|
|
|
'input_group_left' => '', |
|
814
|
|
|
'input_group_right_inside' => false, // forces the input group inside the input |
|
815
|
|
|
'input_group_left_inside' => false, // forces the input group inside the input |
|
816
|
|
|
'form_group_class' => '', |
|
817
|
|
|
'element_require' => '', |
|
818
|
|
|
// [%element_id%] == "1" |
|
819
|
|
|
'extra_attributes' => array(), |
|
820
|
|
|
// an array of extra attributes |
|
821
|
|
|
'wrap_attributes' => array(), |
|
822
|
|
|
); |
|
823
|
|
|
|
|
824
|
|
|
/** |
|
825
|
|
|
* Parse incoming $args into an array and merge it with $defaults |
|
826
|
|
|
*/ |
|
827
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
828
|
|
|
$output = ''; |
|
829
|
|
|
|
|
830
|
|
|
// for now lets hide floating labels |
|
831
|
|
|
if ( $args['label_type'] == 'floating' ) { |
|
832
|
|
|
$args['label_type'] = 'hidden'; |
|
833
|
|
|
} |
|
834
|
|
|
|
|
835
|
|
|
// hidden label option needs to be empty |
|
836
|
|
|
$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
837
|
|
|
|
|
838
|
|
|
|
|
839
|
|
|
$label_after = $args['label_after']; |
|
840
|
|
|
|
|
841
|
|
|
// floating labels need label after |
|
842
|
|
|
if ( $args['label_type'] == 'floating' ) { |
|
843
|
|
|
$label_after = true; |
|
844
|
|
|
$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
845
|
|
|
} |
|
846
|
|
|
|
|
847
|
|
|
// Maybe setup select2 |
|
848
|
|
|
$is_select2 = false; |
|
849
|
|
|
if ( ! empty( $args['select2'] ) ) { |
|
850
|
|
|
$args['class'] .= ' aui-select2'; |
|
851
|
|
|
$is_select2 = true; |
|
852
|
|
|
} elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
853
|
|
|
$is_select2 = true; |
|
854
|
|
|
} |
|
855
|
|
|
|
|
856
|
|
|
// select2 tags |
|
857
|
|
|
if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
858
|
|
|
$args['data-tags'] = 'true'; |
|
859
|
|
|
$args['data-token-separators'] = "[',']"; |
|
860
|
|
|
$args['multiple'] = true; |
|
861
|
|
|
} |
|
862
|
|
|
|
|
863
|
|
|
// select2 placeholder |
|
864
|
|
|
if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
865
|
|
|
$args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
866
|
|
|
$args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
867
|
|
|
} |
|
868
|
|
|
|
|
869
|
|
|
// Set hidden input to save empty value for multiselect. |
|
870
|
|
|
if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
871
|
|
|
$output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
872
|
|
|
} |
|
873
|
|
|
|
|
874
|
|
|
// open/type |
|
875
|
|
|
$output .= '<select '; |
|
876
|
|
|
|
|
877
|
|
|
// style |
|
878
|
|
|
if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
879
|
|
|
$output .= " style='width:100%;' "; |
|
880
|
|
|
} |
|
881
|
|
|
|
|
882
|
|
|
// element require |
|
883
|
|
|
if ( ! empty( $args['element_require'] ) ) { |
|
884
|
|
|
$output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
885
|
|
|
$args['class'] .= " aui-conditional-field"; |
|
886
|
|
|
} |
|
887
|
|
|
|
|
888
|
|
|
// class |
|
889
|
|
|
$class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
890
|
|
|
$select_class = $aui_bs5 ? 'form-select ' : 'custom-select '; |
|
891
|
|
|
$output .= AUI_Component_Helper::class_attr( $select_class . $class ); |
|
892
|
|
|
|
|
893
|
|
|
// name |
|
894
|
|
|
if ( ! empty( $args['name'] ) ) { |
|
895
|
|
|
$output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
896
|
|
|
} |
|
897
|
|
|
|
|
898
|
|
|
// id |
|
899
|
|
|
if ( ! empty( $args['id'] ) ) { |
|
900
|
|
|
$output .= AUI_Component_Helper::id( $args['id'] ); |
|
901
|
|
|
} |
|
902
|
|
|
|
|
903
|
|
|
// title |
|
904
|
|
|
if ( ! empty( $args['title'] ) ) { |
|
905
|
|
|
$output .= AUI_Component_Helper::title( $args['title'] ); |
|
906
|
|
|
} |
|
907
|
|
|
|
|
908
|
|
|
// data-attributes |
|
909
|
|
|
$output .= AUI_Component_Helper::data_attributes( $args ); |
|
910
|
|
|
|
|
911
|
|
|
// aria-attributes |
|
912
|
|
|
$output .= AUI_Component_Helper::aria_attributes( $args ); |
|
913
|
|
|
|
|
914
|
|
|
// extra attributes |
|
915
|
|
|
if ( ! empty( $args['extra_attributes'] ) ) { |
|
916
|
|
|
$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
917
|
|
|
} |
|
918
|
|
|
|
|
919
|
|
|
// required |
|
920
|
|
|
if ( ! empty( $args['required'] ) ) { |
|
921
|
|
|
$output .= ' required '; |
|
922
|
|
|
} |
|
923
|
|
|
|
|
924
|
|
|
// multiple |
|
925
|
|
|
if ( ! empty( $args['multiple'] ) ) { |
|
926
|
|
|
$output .= ' multiple '; |
|
927
|
|
|
} |
|
928
|
|
|
|
|
929
|
|
|
// close opening tag |
|
930
|
|
|
$output .= ' >'; |
|
931
|
|
|
|
|
932
|
|
|
// placeholder |
|
933
|
|
|
if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
934
|
|
|
$output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
935
|
|
|
} elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
936
|
|
|
$output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
937
|
|
|
} |
|
938
|
|
|
|
|
939
|
|
|
// Options |
|
940
|
|
|
if ( ! empty( $args['options'] ) ) { |
|
941
|
|
|
|
|
942
|
|
|
if ( ! is_array( $args['options'] ) ) { |
|
943
|
|
|
$output .= $args['options']; // not the preferred way but an option |
|
944
|
|
|
} else { |
|
945
|
|
|
foreach ( $args['options'] as $val => $name ) { |
|
946
|
|
|
$selected = ''; |
|
947
|
|
|
if ( is_array( $name ) ) { |
|
948
|
|
|
if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
949
|
|
|
$option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
950
|
|
|
|
|
951
|
|
|
$output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
952
|
|
|
} else { |
|
953
|
|
|
$option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
954
|
|
|
$option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
955
|
|
|
$extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
956
|
|
|
if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
957
|
|
|
$selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
|
|
|
|
|
958
|
|
|
} elseif ( ! empty( $args['value'] ) ) { |
|
959
|
|
|
$selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
960
|
|
|
} elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
961
|
|
|
$selected = selected( $option_value, $args['value'], false ); |
|
962
|
|
|
} |
|
963
|
|
|
|
|
964
|
|
|
$output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
965
|
|
|
} |
|
966
|
|
|
} else { |
|
967
|
|
|
if ( ! empty( $args['value'] ) ) { |
|
968
|
|
|
if ( is_array( $args['value'] ) ) { |
|
969
|
|
|
$selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
970
|
|
|
} elseif ( ! empty( $args['value'] ) ) { |
|
971
|
|
|
$selected = selected( $args['value'], $val, false ); |
|
972
|
|
|
} |
|
973
|
|
|
} elseif ( $args['value'] === $val ) { |
|
974
|
|
|
$selected = selected( $args['value'], $val, false ); |
|
975
|
|
|
} |
|
976
|
|
|
$output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
977
|
|
|
} |
|
978
|
|
|
} |
|
979
|
|
|
} |
|
980
|
|
|
|
|
981
|
|
|
} |
|
982
|
|
|
|
|
983
|
|
|
// closing tag |
|
984
|
|
|
$output .= '</select>'; |
|
985
|
|
|
|
|
986
|
|
|
$label = ''; |
|
987
|
|
|
$help_text = ''; |
|
988
|
|
|
// label |
|
989
|
|
|
if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
990
|
|
|
} elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
991
|
|
|
$label_args = array( |
|
992
|
|
|
'title' => $args['label'], |
|
993
|
|
|
'for' => $args['id'], |
|
994
|
|
|
'class' => $args['label_class'] . " ", |
|
995
|
|
|
'label_type' => $args['label_type'], |
|
996
|
|
|
'label_col' => $args['label_col'] |
|
997
|
|
|
); |
|
998
|
|
|
$label = self::label( $label_args ); |
|
999
|
|
|
} |
|
1000
|
|
|
|
|
1001
|
|
|
// help text |
|
1002
|
|
|
if ( ! empty( $args['help_text'] ) ) { |
|
1003
|
|
|
$help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
1004
|
|
|
} |
|
1005
|
|
|
|
|
1006
|
|
|
// input group wraps |
|
1007
|
|
|
if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
1008
|
|
|
$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
1009
|
|
|
if ( $args['input_group_left'] ) { |
|
1010
|
|
|
$output = self::wrap( array( |
|
1011
|
|
|
'content' => $output, |
|
1012
|
|
|
'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
1013
|
|
|
'input_group_left' => $args['input_group_left'], |
|
1014
|
|
|
'input_group_left_inside' => $args['input_group_left_inside'] |
|
1015
|
|
|
) ); |
|
1016
|
|
|
} |
|
1017
|
|
|
if ( $args['input_group_right'] ) { |
|
1018
|
|
|
$output = self::wrap( array( |
|
1019
|
|
|
'content' => $output, |
|
1020
|
|
|
'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
1021
|
|
|
'input_group_right' => $args['input_group_right'], |
|
1022
|
|
|
'input_group_right_inside' => $args['input_group_right_inside'] |
|
1023
|
|
|
) ); |
|
1024
|
|
|
} |
|
1025
|
|
|
|
|
1026
|
|
|
} |
|
1027
|
|
|
|
|
1028
|
|
|
if ( ! $label_after ) { |
|
1029
|
|
|
$output .= $help_text; |
|
1030
|
|
|
} |
|
1031
|
|
|
|
|
1032
|
|
|
|
|
1033
|
|
|
if ( $args['label_type'] == 'horizontal' ) { |
|
1034
|
|
|
$output = self::wrap( array( |
|
1035
|
|
|
'content' => $output, |
|
1036
|
|
|
'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
1037
|
|
|
) ); |
|
1038
|
|
|
} |
|
1039
|
|
|
|
|
1040
|
|
|
if ( ! $label_after ) { |
|
1041
|
|
|
$output = $label . $output; |
|
1042
|
|
|
} |
|
1043
|
|
|
|
|
1044
|
|
|
// maybe horizontal label |
|
1045
|
|
|
// if ( $args['label_type'] == 'horizontal' ) { |
|
1046
|
|
|
// $output .= '</div>'; |
|
1047
|
|
|
// } |
|
1048
|
|
|
|
|
1049
|
|
|
|
|
1050
|
|
|
// wrap |
|
1051
|
|
|
if ( ! $args['no_wrap'] ) { |
|
1052
|
|
|
if ( ! empty( $args['form_group_class'] ) ) { |
|
1053
|
|
|
$fg_class = esc_attr( $args['form_group_class'] ); |
|
1054
|
|
|
}else{ |
|
1055
|
|
|
$fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
1056
|
|
|
} |
|
1057
|
|
|
$wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
1058
|
|
|
$wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1059
|
|
|
$output = self::wrap( array( |
|
1060
|
|
|
'content' => $output, |
|
1061
|
|
|
'class' => $wrap_class, |
|
1062
|
|
|
'element_require' => $args['element_require'], |
|
1063
|
|
|
'argument_id' => $args['id'], |
|
1064
|
|
|
'wrap_attributes' => $args['wrap_attributes'], |
|
1065
|
|
|
) ); |
|
1066
|
|
|
} |
|
1067
|
|
|
|
|
1068
|
|
|
|
|
1069
|
|
|
return $output; |
|
1070
|
|
|
} |
|
1071
|
|
|
|
|
1072
|
|
|
/** |
|
1073
|
|
|
* Build the component. |
|
1074
|
|
|
* |
|
1075
|
|
|
* @param array $args |
|
1076
|
|
|
* |
|
1077
|
|
|
* @return string The rendered component. |
|
1078
|
|
|
*/ |
|
1079
|
|
|
public static function radio( $args = array() ) { |
|
1080
|
|
|
global $aui_bs5; |
|
1081
|
|
|
|
|
1082
|
|
|
$defaults = array( |
|
1083
|
|
|
'class' => '', |
|
1084
|
|
|
'wrap_class' => '', |
|
1085
|
|
|
'id' => '', |
|
1086
|
|
|
'title' => '', |
|
1087
|
|
|
'horizontal' => false, |
|
1088
|
|
|
// sets the lable horizontal |
|
1089
|
|
|
'value' => '', |
|
1090
|
|
|
'label' => '', |
|
1091
|
|
|
'label_class' => '', |
|
1092
|
|
|
'label_type' => '', |
|
1093
|
|
|
'label_col' => '', |
|
1094
|
|
|
// sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
1095
|
|
|
'help_text' => '', |
|
1096
|
|
|
'inline' => true, |
|
1097
|
|
|
'required' => false, |
|
1098
|
|
|
'options' => array(), |
|
1099
|
|
|
'icon' => '', |
|
1100
|
|
|
'no_wrap' => false, |
|
1101
|
|
|
'element_require' => '', |
|
1102
|
|
|
// [%element_id%] == "1" |
|
1103
|
|
|
'extra_attributes' => array(), |
|
1104
|
|
|
// an array of extra attributes |
|
1105
|
|
|
'wrap_attributes' => array() |
|
1106
|
|
|
); |
|
1107
|
|
|
|
|
1108
|
|
|
/** |
|
1109
|
|
|
* Parse incoming $args into an array and merge it with $defaults |
|
1110
|
|
|
*/ |
|
1111
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
1112
|
|
|
|
|
1113
|
|
|
// for now lets use horizontal for floating |
|
1114
|
|
|
if ( $args['label_type'] == 'floating' ) { |
|
1115
|
|
|
$args['label_type'] = 'horizontal'; |
|
1116
|
|
|
} |
|
1117
|
|
|
|
|
1118
|
|
|
$label_args = array( |
|
1119
|
|
|
'title' => $args['label'], |
|
1120
|
|
|
'class' => $args['label_class'] . " pt-0 ", |
|
1121
|
|
|
'label_type' => $args['label_type'], |
|
1122
|
|
|
'label_col' => $args['label_col'] |
|
1123
|
|
|
); |
|
1124
|
|
|
|
|
1125
|
|
|
$output = ''; |
|
1126
|
|
|
|
|
1127
|
|
|
|
|
1128
|
|
|
// label before |
|
1129
|
|
|
if ( ! empty( $args['label'] ) ) { |
|
1130
|
|
|
$output .= self::label( $label_args, 'radio' ); |
|
1131
|
|
|
} |
|
1132
|
|
|
|
|
1133
|
|
|
// maybe horizontal label |
|
1134
|
|
|
if ( $args['label_type'] == 'horizontal' ) { |
|
1135
|
|
|
$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1136
|
|
|
$output .= '<div class="' . $input_col . '">'; |
|
1137
|
|
|
} |
|
1138
|
|
|
|
|
1139
|
|
|
if ( ! empty( $args['options'] ) ) { |
|
1140
|
|
|
$count = 0; |
|
1141
|
|
|
foreach ( $args['options'] as $value => $label ) { |
|
1142
|
|
|
$option_args = $args; |
|
1143
|
|
|
$option_args['value'] = $value; |
|
1144
|
|
|
$option_args['label'] = $label; |
|
1145
|
|
|
$option_args['checked'] = $value == $args['value'] ? true : false; |
|
1146
|
|
|
$output .= self::radio_option( $option_args, $count ); |
|
1147
|
|
|
$count ++; |
|
1148
|
|
|
} |
|
1149
|
|
|
} |
|
1150
|
|
|
|
|
1151
|
|
|
// help text |
|
1152
|
|
|
$help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1153
|
|
|
$output .= $help_text; |
|
1154
|
|
|
|
|
1155
|
|
|
// maybe horizontal label |
|
1156
|
|
|
if ( $args['label_type'] == 'horizontal' ) { |
|
1157
|
|
|
$output .= '</div>'; |
|
1158
|
|
|
} |
|
1159
|
|
|
|
|
1160
|
|
|
// wrap |
|
1161
|
|
|
$fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
1162
|
|
|
$wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
1163
|
|
|
$wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1164
|
|
|
$output = self::wrap( array( |
|
1165
|
|
|
'content' => $output, |
|
1166
|
|
|
'class' => $wrap_class, |
|
1167
|
|
|
'element_require' => $args['element_require'], |
|
1168
|
|
|
'argument_id' => $args['id'], |
|
1169
|
|
|
'wrap_attributes' => $args['wrap_attributes'], |
|
1170
|
|
|
) ); |
|
1171
|
|
|
|
|
1172
|
|
|
|
|
1173
|
|
|
return $output; |
|
1174
|
|
|
} |
|
1175
|
|
|
|
|
1176
|
|
|
/** |
|
1177
|
|
|
* Build the component. |
|
1178
|
|
|
* |
|
1179
|
|
|
* @param array $args |
|
1180
|
|
|
* |
|
1181
|
|
|
* @return string The rendered component. |
|
1182
|
|
|
*/ |
|
1183
|
|
|
public static function radio_option( $args = array(), $count = '' ) { |
|
1184
|
|
|
$defaults = array( |
|
1185
|
|
|
'class' => '', |
|
1186
|
|
|
'id' => '', |
|
1187
|
|
|
'title' => '', |
|
1188
|
|
|
'value' => '', |
|
1189
|
|
|
'required' => false, |
|
1190
|
|
|
'inline' => true, |
|
1191
|
|
|
'label' => '', |
|
1192
|
|
|
'options' => array(), |
|
1193
|
|
|
'icon' => '', |
|
1194
|
|
|
'no_wrap' => false, |
|
1195
|
|
|
'extra_attributes' => array() // an array of extra attributes |
|
1196
|
|
|
); |
|
1197
|
|
|
|
|
1198
|
|
|
/** |
|
1199
|
|
|
* Parse incoming $args into an array and merge it with $defaults |
|
1200
|
|
|
*/ |
|
1201
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
1202
|
|
|
|
|
1203
|
|
|
$output = ''; |
|
1204
|
|
|
|
|
1205
|
|
|
// open/type |
|
1206
|
|
|
$output .= '<input type="radio"'; |
|
1207
|
|
|
|
|
1208
|
|
|
// class |
|
1209
|
|
|
$output .= ' class="form-check-input" '; |
|
1210
|
|
|
|
|
1211
|
|
|
// name |
|
1212
|
|
|
if ( ! empty( $args['name'] ) ) { |
|
1213
|
|
|
$output .= AUI_Component_Helper::name( $args['name'] ); |
|
1214
|
|
|
} |
|
1215
|
|
|
|
|
1216
|
|
|
// id |
|
1217
|
|
|
if ( ! empty( $args['id'] ) ) { |
|
1218
|
|
|
$output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1219
|
|
|
} |
|
1220
|
|
|
|
|
1221
|
|
|
// title |
|
1222
|
|
|
if ( ! empty( $args['title'] ) ) { |
|
1223
|
|
|
$output .= AUI_Component_Helper::title( $args['title'] ); |
|
1224
|
|
|
} |
|
1225
|
|
|
|
|
1226
|
|
|
// value |
|
1227
|
|
|
if ( isset( $args['value'] ) ) { |
|
1228
|
|
|
$output .= AUI_Component_Helper::value( $args['value'] ); |
|
1229
|
|
|
} |
|
1230
|
|
|
|
|
1231
|
|
|
// checked, for radio and checkboxes |
|
1232
|
|
|
if ( $args['checked'] ) { |
|
1233
|
|
|
$output .= ' checked '; |
|
1234
|
|
|
} |
|
1235
|
|
|
|
|
1236
|
|
|
// data-attributes |
|
1237
|
|
|
$output .= AUI_Component_Helper::data_attributes( $args ); |
|
1238
|
|
|
|
|
1239
|
|
|
// aria-attributes |
|
1240
|
|
|
$output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1241
|
|
|
|
|
1242
|
|
|
// extra attributes |
|
1243
|
|
|
if ( ! empty( $args['extra_attributes'] ) ) { |
|
1244
|
|
|
$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1245
|
|
|
} |
|
1246
|
|
|
|
|
1247
|
|
|
// required |
|
1248
|
|
|
if ( ! empty( $args['required'] ) ) { |
|
1249
|
|
|
$output .= ' required '; |
|
1250
|
|
|
} |
|
1251
|
|
|
|
|
1252
|
|
|
// close opening tag |
|
1253
|
|
|
$output .= ' >'; |
|
1254
|
|
|
|
|
1255
|
|
|
// label |
|
1256
|
|
|
if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1257
|
|
|
} elseif ( ! empty( $args['label'] ) ) { |
|
1258
|
|
|
$output .= self::label( array( |
|
1259
|
|
|
'title' => $args['label'], |
|
1260
|
|
|
'for' => $args['id'] . $count, |
|
1261
|
|
|
'class' => 'form-check-label' |
|
1262
|
|
|
), 'radio' ); |
|
1263
|
|
|
} |
|
1264
|
|
|
|
|
1265
|
|
|
// wrap |
|
1266
|
|
|
if ( ! $args['no_wrap'] ) { |
|
1267
|
|
|
$wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1268
|
|
|
|
|
1269
|
|
|
// Unique wrap class |
|
1270
|
|
|
$uniq_class = 'fwrap'; |
|
1271
|
|
|
if ( ! empty( $args['name'] ) ) { |
|
1272
|
|
|
$uniq_class .= '-' . $args['name']; |
|
1273
|
|
|
} else if ( ! empty( $args['id'] ) ) { |
|
1274
|
|
|
$uniq_class .= '-' . $args['id']; |
|
1275
|
|
|
} |
|
1276
|
|
|
|
|
1277
|
|
|
if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1278
|
|
|
$uniq_class .= '-' . $args['value']; |
|
1279
|
|
|
} else { |
|
1280
|
|
|
$uniq_class .= '-' . $count; |
|
1281
|
|
|
} |
|
1282
|
|
|
$wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1283
|
|
|
|
|
1284
|
|
|
$output = self::wrap( array( |
|
1285
|
|
|
'content' => $output, |
|
1286
|
|
|
'class' => $wrap_class |
|
1287
|
|
|
) ); |
|
1288
|
|
|
} |
|
1289
|
|
|
|
|
1290
|
|
|
return $output; |
|
1291
|
|
|
} |
|
1292
|
|
|
|
|
1293
|
|
|
} |