PluginProbe
WANotifier for Forms and Actions / 2.7.7
WANotifier for Forms and Actions v2.7.7
3.1.1 3.1.0 3.0.4 2.7.10 2.7.11 2.7.12 2.7.13 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 3.0.0 3.0.1 3.0.2 3.0.3 trunk 0.1.0 0.1.1 1.0.0 1.0.1 1.0.2 All 67 releases
notifier / includes / functions / functions-notifier-meta-box-fields.php

functions-notifier-meta-box-fields.php in WANotifier for Forms and Actions 2.7.7, at includes/functions/functions-notifier-meta-box-fields.php

813 lines 27.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Notifier Meta Box Functions
4 *
5 * @package Notifier
6 */
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly
9 }
10
11 /**
12 * Output a text input box.
13 *
14 * @param array $field
15 */
16 function notifier_wp_text_input( $field ) {
17 global $post;
18
19 $field = apply_filters ('notifier_wp_text_input_args', $field, $post);
20
21 $field = wp_parse_args(
22 $field, array(
23 'label' => '',
24 'placeholder' => '',
25 'class' => 'form-control',
26 'style' => '',
27 'wrapper_class' => '',
28 'value' => '',
29 'name' => $field['id'],
30 'description' => '',
31 'type' => 'text',
32 'limit' => 0,
33 'conditional_logic' => '',
34 'show_wrapper' => true,
35 'custom_attributes' => array(),
36 'data_type' => '',
37 'required' => false,
38 'invalid_message' => 'This is a required field.',
39 'conditional_operator' => 'OR',
40 'datalist' => array()
41 )
42 );
43
44 $field['conditional_logic'] = ( '' != $field['conditional_logic'] ) ? json_encode($field['conditional_logic']) : '';
45
46 switch ( $field['data_type'] ) {
47 case 'url':
48 $field['class'] .= ' notifier_input_url';
49 $field['value'] = esc_url( $field['value'] );
50 break;
51
52 default:
53 break;
54 }
55
56 $show_limit_text = '';
57 if ( 0 != $field['limit'] ) {
58 $show_limit_text = '<span class="limit-text"><span class="limit-used">0</span> / <span>' . $field['limit'] . '</span></span>';
59 $field['custom_attributes']['data-limit'] = $field['limit'];
60 $field['class'] = $field['class'] . ' force-text-limit';
61 }
62
63 // Custom attribute handling
64 $custom_attributes = array();
65
66 if ( isset($field['custom_attributes']['disabled']) && 'disabled' == $field['custom_attributes']['disabled'] ) {
67 $field['custom_attributes']['data-disabled'] = 'yes';
68 }
69
70 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
71 foreach ( $field['custom_attributes'] as $attribute => $value ) {
72 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
73 }
74 }
75
76 if ( $field['required'] ) {
77 $custom_attributes[] = 'required="required"';
78 }
79
80 $custom_attributes_string = implode( ' ', $custom_attributes );
81
82 if ( $field['show_wrapper'] ) {
83 do_action('notifier_before_meta_field_wrapper', $field, $post);
84 echo '<p class="form-field mb-3 ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '" data-conditions="' . esc_js( $field['conditional_logic'] ) . '" data-conditions-operator="' . esc_js( $field['conditional_operator'] ) . '">';
85 }
86
87 if ( '' != $field['label'] ) {
88 echo '<label for="' . esc_attr( $field['id'] ) . '" class="form-label">' . wp_kses_post( $field['label'] . $show_limit_text ) . '</label>';
89 }
90
91 $datalist_attr = '';
92 if(!empty($field['datalist'])){
93 $datalist_attr = ' list="' . esc_attr( $field['id'] ) . '_datalist" data-min-length="0" data-no-results-text=""';
94 $field['class'] = $field['class'] . ' datalist-field';
95 }
96
97 do_action('notifier_before_meta_field', $field, $post);
98
99 echo '<input type="' . esc_attr( $field['type'] ) . '" class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" ' . $custom_attributes_string . $datalist_attr . ' /> ';
100
101 if(!empty($field['datalist'])){
102 echo '<datalist id="' . esc_attr( $field['id'] ) . '_datalist">';
103 foreach($field['datalist'] as $item){
104 echo '<option value="'.$item.'">';
105 }
106 echo '</datalist>';
107 }
108
109 if ( $field['required'] ) {
110 echo '<span class="invalid-feedback">' . wp_kses_post($field['invalid_message']) . '</span>';
111 }
112
113 do_action('notifier_after_meta_field', $field, $post);
114
115 if ( '' != $field['description'] ) {
116 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
117 }
118
119 do_action('notifier_after_meta_field_description', $field, $post);
120
121 if ( $field['show_wrapper'] ) {
122 echo '</p>';
123 do_action('notifier_after_meta_field_wrapper', $field, $post);
124 }
125 }
126
127 /**
128 * Output a hidden input box.
129 *
130 * @param array $field
131 */
132 function notifier_wp_hidden_input( $field ) {
133 global $post;
134
135 $field = apply_filters ('notifier_wp_hidden_input', $field, $post);
136
137 $field = wp_parse_args(
138 $field, array(
139 'class' => '',
140 'value' => ''
141 )
142 );
143
144 do_action('notifier_before_meta_field', $field, $post);
145
146 echo '<input type="hidden" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['id'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" /> ';
147
148 do_action('notifier_after_meta_field', $field, $post);
149 }
150
151 /**
152 * Output a textarea input box.
153 *
154 * @param array $field
155 */
156 function notifier_wp_textarea_input( $field ) {
157 global $post;
158
159 $field = apply_filters ('notifier_wp_textarea_input', $field, $post);
160
161 $field = wp_parse_args(
162 $field, array(
163 'label' => '',
164 'placeholder' => '',
165 'class' => 'form-control',
166 'style' => '',
167 'wrapper_class' => '',
168 'value' => '',
169 'name' => $field['id'],
170 'description' => '',
171 'limit' => 0,
172 'conditional_logic' => '',
173 'show_wrapper' => true,
174 'custom_attributes' => array(),
175 'rows' => 2,
176 'cols' => 20,
177 'required' => false,
178 'conditional_operator' => 'OR'
179 )
180 );
181
182 $field['conditional_logic'] = ( '' != $field['conditional_logic'] ) ? json_encode($field['conditional_logic']) : '';
183
184 $show_limit_text = '';
185 if ( $field['limit'] != 0 ) {
186 $show_limit_text = '<span class="limit-text"><span class="limit-used">0</span> / <span>' . $field['limit'] . '</span></span>';
187 $field['custom_attributes']['data-limit'] = $field['limit'];
188 $field['class'] = $field['class'] . ' force-text-limit';
189 }
190
191 // Custom attribute handling
192 $custom_attributes = array();
193
194 if ( isset($field['custom_attributes']['disabled']) && 'disabled' == $field['custom_attributes']['disabled'] ) {
195 $field['custom_attributes']['data-disabled'] = 'yes';
196 }
197
198 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
199 foreach ( $field['custom_attributes'] as $attribute => $value ) {
200 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
201 }
202 }
203
204 if ( $field['required'] ) {
205 $custom_attributes[] = 'required="required"';
206 }
207
208 $custom_attributes_string = implode( ' ', $custom_attributes );
209
210 if ( $field['show_wrapper'] ) {
211 do_action('notifier_before_meta_field_wrapper', $field, $post);
212 echo '<p class="form-field mb-3 ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '" data-conditions="' . esc_js( $field['conditional_logic'] ) . '" data-conditions-operator="' . esc_js( $field['conditional_operator'] ) . '">';
213 }
214
215 if ( '' != $field['label'] ) {
216 echo '<label for="' . esc_attr( $field['id'] ) . '" class="form-label">' . wp_kses_post( $field['label'] . $show_limit_text ) . '</label>';
217 }
218
219 do_action('notifier_before_meta_field', $field, $post);
220
221 echo '<textarea class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" rows="' . esc_attr( $field['rows'] ) . '" cols="' . esc_attr( $field['cols'] ) . '" ' . $custom_attributes_string . ' >' . esc_textarea( $field['value'] ) . '</textarea> ';
222
223 if ( $field['required'] ) {
224 echo '<span class="invalid-feedback">This is a required field.</span>';
225 }
226
227 do_action('notifier_after_meta_field', $field, $post);
228
229 if ( '' != $field['description'] ) {
230 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
231 }
232
233 do_action('notifier_after_meta_field_description', $field, $post);
234
235 if ( $field['show_wrapper'] ) {
236 echo '</p>';
237 do_action('notifier_after_meta_field_wrapper', $field, $post);
238 }
239 }
240
241 /**
242 * Output a checkbox input box.
243 *
244 * @param array $field
245 */
246 function notifier_wp_checkbox( $field ) {
247 global $post;
248
249 $field = apply_filters ('notifier_wp_checkbox', $field, $post);
250
251 $field = wp_parse_args(
252 $field, array(
253 'label' => '',
254 'class' => 'form-control',
255 'style' => '',
256 'wrapper_class' => '',
257 'value' => '',
258 'cbvalue' => 'yes',
259 'name' => $field['id'],
260 'description' => '',
261 'conditional_logic' => '',
262 'show_wrapper' => true,
263 'custom_attributes' => array(),
264 'required' => false
265 )
266 );
267
268 $field['conditional_logic'] = ( '' != $field['conditional_logic'] ) ? json_encode($field['conditional_logic']) : '';
269
270 // Custom attribute handling
271 $custom_attributes = array();
272
273 if ( isset($field['custom_attributes']['disabled']) && 'disabled' == $field['custom_attributes']['disabled'] ) {
274 $field['custom_attributes']['data-disabled'] = 'yes';
275 }
276
277 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
278 foreach ( $field['custom_attributes'] as $attribute => $value ) {
279 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
280 }
281 }
282
283 if ( $field['required'] ) {
284 $custom_attributes[] = 'required="required"';
285 }
286
287 $custom_attributes_string = implode( ' ', $custom_attributes );
288
289 if ( $field['show_wrapper'] ) {
290 do_action('notifier_before_meta_field_wrapper', $field, $post);
291 echo '<p class="form-field mb-3 ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '" data-conditions="' . esc_js( $field['conditional_logic'] ) . '">';
292 }
293
294 if ( '' != $field['label'] ) {
295 echo '<label for="' . esc_attr( $field['id'] ) . '" class="form-label">' . wp_kses_post( $field['label'] ) . '</label>';
296 }
297
298 do_action('notifier_before_meta_field', $field, $post);
299
300 echo '<input type="checkbox" class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['cbvalue'] ) . '" ' . checked( $field['value'], $field['cbvalue'], false ) . ' ' . $custom_attributes_string . '/> ';
301
302 if ( $field['required'] ) {
303 echo '<span class="invalid-feedback">This is a required field.</span>';
304 }
305
306 do_action('notifier_after_meta_field', $field, $post);
307
308 if ( '' != $field['description'] ) {
309 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
310 }
311
312 do_action('notifier_after_meta_field_description', $field, $post);
313
314 if ( $field['show_wrapper'] ) {
315 echo '</p>';
316 do_action('notifier_after_meta_field_wrapper', $field, $post);
317 }
318 }
319
320 /**
321 * Output multiple checkboxes
322 *
323 * @param array $field
324 */
325 function notifier_wp_multi_checkboxes( $field ) {
326 global $post;
327
328 $field = apply_filters ('notifier_wp_multi_checkboxes', $field, $post);
329
330 $field = wp_parse_args(
331 $field, array(
332 'label' => '',
333 'class' => 'form-check-input',
334 'style' => '',
335 'wrapper_class' => '',
336 'value' => '',
337 'name' => $field['id'],
338 'description' => '',
339 'conditional_logic' => '',
340 'show_wrapper' => true,
341 'custom_attributes' => array(),
342 'required' => false
343 )
344 );
345
346 $field['conditional_logic'] = ( '' != $field['conditional_logic'] ) ? json_encode($field['conditional_logic']) : '';
347
348 // Custom attribute handling
349 $custom_attributes = array();
350
351 if ( isset($field['custom_attributes']['disabled']) && 'disabled' == $field['custom_attributes']['disabled'] ) {
352 $field['custom_attributes']['data-disabled'] = 'yes';
353 }
354
355 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
356 foreach ( $field['custom_attributes'] as $attribute => $value ) {
357 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
358 }
359 }
360
361 $custom_attributes_string = implode( ' ', $custom_attributes );
362
363 if ( $field['show_wrapper'] ) {
364 do_action('notifier_before_meta_field_wrapper', $field, $post);
365 echo '<fieldset class="form-field mb-3 mt-1 ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '" data-conditions="' . esc_js($field['conditional_logic']) . '">';
366 }
367
368 if ( '' != $field['label'] ) {
369 echo '<legend class="form-label">' . wp_kses_post( $field['label'] ) . '</legend>';
370 }
371
372 do_action('notifier_before_meta_field', $field, $post);
373
374 echo '<div class="multi-checkbox-wrapper">';
375
376 foreach ( $field['options'] as $key => $value ) {
377 if(in_array($key, (array) $field['value'])){
378 $checked = true;
379 $checked_class = 'form-check-checked';
380 }
381 else{
382 $checked = false;
383 $checked_class = '';
384 }
385
386 echo '<div class="form-check '.$checked_class.'"><label class="form-check-label"><input
387 name="' . esc_attr( $field['name'] ) . '"
388 value="' . esc_attr( $key ) . '"
389 type="checkbox"
390 class="' . esc_attr( $field['class'] ) . '"
391 style="' . esc_attr( $field['style'] ) . '"
392 ' . checked( $checked, true, false ) . '
393 ' . $custom_attributes_string . '
394 /> ' . esc_html( $value ) . '</label>
395 </div>';
396 }
397
398 echo '</div>';
399
400 if ( $field['required'] ) {
401 echo '<span class="invalid-feedback">Please select at least one '.wp_kses_post( strtolower($field['label']) ).'.</span>';
402 }
403
404 do_action('notifier_after_meta_field', $field, $post);
405
406 if ( '' != $field['description'] ) {
407 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
408 }
409
410 do_action('notifier_after_meta_field_description', $field, $post);
411
412 if ( $field['show_wrapper'] ) {
413 echo '</fieldset>';
414 do_action('notifier_after_meta_field_wrapper', $field, $post);
415 }
416
417 }
418
419 /**
420 * Output a select input box.
421 *
422 * @param array $field Data about the field to render.
423 */
424 function notifier_wp_select( $field ) {
425 global $post;
426
427 $field = apply_filters ('notifier_wp_select', $field, $post);
428
429 $field = wp_parse_args(
430 $field, array(
431 'label' => '',
432 'class' => 'form-select',
433 'style' => '',
434 'wrapper_class' => '',
435 'value' => '',
436 'name' => $field['id'],
437 'description' => '',
438 'conditional_logic' => '',
439 'show_wrapper' => true,
440 'custom_attributes' => array(),
441 'required' => false
442 )
443 );
444
445 $field['conditional_logic'] = ( '' != $field['conditional_logic'] ) ? json_encode($field['conditional_logic']) : '';
446
447 // Custom attribute handling
448 $custom_attributes = array();
449
450 if ( isset($field['custom_attributes']['disabled']) && 'disabled' == $field['custom_attributes']['disabled'] ) {
451 $field['custom_attributes']['data-disabled'] = 'yes';
452 }
453
454 if ( $field['required'] ) {
455 $custom_attributes[] = 'required="required"';
456 }
457
458 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
459 foreach ( $field['custom_attributes'] as $attribute => $value ) {
460 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
461 }
462 }
463
464 $custom_attributes_string = implode( ' ', $custom_attributes );
465
466 $description = ! empty( $field['description'] ) ? $field['description'] : '';
467
468 if ( $field['show_wrapper'] ) {
469 do_action('notifier_before_meta_field_wrapper', $field, $post);
470 echo '<p class="form-field mb-3 ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '" data-conditions="' . esc_js( $field['conditional_logic'] ) . '">';
471 }
472
473 if ( '' != $field['label'] ) {
474 echo '<label for="' . esc_attr( $field['id'] ) . '" class="form-label">' . wp_kses_post( $field['label'] ) . '</label>';
475 }
476
477 do_action('notifier_before_meta_field', $field, $post);
478
479 echo '<select class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '"' . $custom_attributes_string . '/> ';
480
481 foreach ( $field['options'] as $key => $value ) {
482 if ( is_array($value) ) {
483 $opt_group_options = $value;
484 echo '<optgroup label="' . esc_attr($key) . '">';
485 foreach ( $opt_group_options as $opt_key => $opt_val ) {
486 if(is_array($field['value'])){
487 $selected = in_array($opt_key, $field['value']) ? 'selected' : '';
488 }
489 else{
490 $selected = selected( $opt_key, $field['value'], false);
491 }
492 echo '<option value="' . esc_attr( $opt_key ) . '"' . $selected . '>' . esc_html( $opt_val ) . '</option>';
493 }
494 echo '</optgroup>';
495 } else {
496 echo '<option value="' . esc_attr( $key ) . '"' . selected( $key, $field['value'], false) . '>' . esc_html( $value ) . '</option>';
497 }
498 }
499
500 echo '</select>';
501
502 if ( $field['required'] ) {
503 echo '<span class="invalid-feedback">This is a required field.</span>';
504 }
505
506 do_action('notifier_after_meta_field', $field, $post);
507
508 if ( '' != $field['description'] ) {
509 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
510 }
511
512 do_action('notifier_after_meta_field_description', $field, $post);
513
514 if ( $field['show_wrapper'] ) {
515 echo '</p>';
516 do_action('notifier_after_meta_field_wrapper', $field, $post);
517 }
518 }
519
520 /**
521 * Output a radio input box.
522 *
523 * @param array $field
524 */
525 function notifier_wp_radio( $field ) {
526 global $post;
527
528 $field = apply_filters ('notifier_wp_radio', $field, $post);
529
530 $field = wp_parse_args(
531 $field, array(
532 'label' => '',
533 'class' => 'form-check-input',
534 'style' => '',
535 'wrapper_class' => '',
536 'value' => '',
537 'name' => $field['id'],
538 'description' => '',
539 'conditional_logic' => '',
540 'show_wrapper' => true,
541 'custom_attributes' => array()
542 )
543 );
544
545 $field['conditional_logic'] = ( '' != $field['conditional_logic'] ) ? json_encode($field['conditional_logic']) : '';
546
547 // Custom attribute handling
548 $custom_attributes = array();
549
550 if ( isset($field['custom_attributes']['disabled']) && 'disabled' == $field['custom_attributes']['disabled'] ) {
551 $field['custom_attributes']['data-disabled'] = 'yes';
552 }
553
554 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
555 foreach ( $field['custom_attributes'] as $attribute => $value ) {
556 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
557 }
558 }
559
560 $custom_attributes_string = implode( ' ', $custom_attributes );
561
562 if ( $field['show_wrapper'] ) {
563 do_action('notifier_before_meta_field_wrapper', $field, $post);
564 echo '<fieldset class="form-field mb-3 ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '" data-conditions="' . esc_js($field['conditional_logic']) . '">';
565 }
566
567 if ( '' != $field['label'] ) {
568 echo '<legend class="form-label">' . wp_kses_post( $field['label'] ) . '</legend>';
569 }
570
571 do_action('notifier_before_meta_field', $field, $post);
572
573 foreach ( $field['options'] as $key => $value ) {
574 echo '<div class="form-check form-check-inline"><label class="form-check-label"><input
575 name="' . esc_attr( $field['name'] ) . '"
576 value="' . esc_attr( $key ) . '"
577 type="radio"
578 class="' . esc_attr( $field['class'] ) . '"
579 style="' . esc_attr( $field['style'] ) . '"
580 ' . checked( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '
581 ' . $custom_attributes_string . '
582 /> ' . esc_html( $value ) . '</label>
583 </div>';
584 }
585
586 do_action('notifier_after_meta_field', $field, $post);
587
588 if ( '' != $field['description'] ) {
589 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
590 }
591
592 do_action('notifier_after_meta_field_description', $field, $post);
593
594 if ( $field['show_wrapper'] ) {
595 echo '</fieldset>';
596 do_action('notifier_after_meta_field_wrapper', $field, $post);
597 }
598
599 }
600
601 /**
602 * Output a file upload input box.
603 *
604 * @param array $field
605 */
606 function notifier_wp_file_input( $field ) {
607 global $post;
608
609 $field = apply_filters ('notifier_wp_text_input_args', $field, $post);
610
611 $field = wp_parse_args(
612 $field, array(
613 'label' => '',
614 'placeholder' => '',
615 'class' => '',
616 'wrapper_class' => '',
617 'value' => '',
618 'name' => $field['id'],
619 'description' => '',
620 'conditional_logic' => '',
621 'show_wrapper' => true,
622 'custom_attributes' => array(),
623 'file_types' => array(),
624 'required' => false
625 )
626 );
627
628 $field['conditional_logic'] = ( '' != $field['conditional_logic'] ) ? json_encode($field['conditional_logic']) : '';
629
630 $image_thumb = '';
631 $video_url = '';
632 $show_image = 'd-none';
633 $show_video = 'd-none';
634 $show_wrapper = 'd-none';
635
636 $attachment_id = isset($field['value']) ? $field['value'] : '';
637
638 $attachment_data = wp_get_attachment_metadata($attachment_id);
639
640 if ( '' != $attachment_id ) {
641 $file_types = $field['file_types'];
642 $media_url = isset($attachment_data['url']) ? $attachment_data['url'] : '';
643 if ( in_array('video/mp4', $file_types) ) {
644 $video_url = $media_url;
645 $show_image = 'd-none';
646 $show_video = '';
647 $field['custom_attributes']['data-url'] = $video_url;
648 } else {
649 $image_thumb = isset($attachment_data['thumb_url']) ? $attachment_data['thumb_url'] : $media_url;
650 $file_mime_type = get_post_mime_type($attachment_id);
651 $file_mime_type = explode('/', $file_mime_type);
652 $show_image = '';
653 $show_video = 'd-none';
654 $field['custom_attributes']['data-url'] = $image_thumb;
655 }
656 }
657
658 if ( $show_image == '' || $show_video == '' ) {
659 $show_wrapper = '';
660 }
661
662 $field['custom_attributes']['accept'] = implode( ',', $field['file_types'] );
663
664 $is_disabled = false;
665 if ( isset($field['custom_attributes']['disabled']) && $field['custom_attributes']['disabled'] == 'disabled' ) {
666 $is_disabled = true;
667 }
668
669 // Custom attribute handling
670 $custom_attributes = array();
671
672 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
673 foreach ( $field['custom_attributes'] as $attribute => $v ) {
674 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $v ) . '"';
675 }
676 }
677
678 $required_field = '';
679 if ( $field['required'] ) {
680 $required_field = 'required="required"';
681 }
682
683 $custom_attributes_string = implode( ' ', $custom_attributes );
684
685 if ( $field['show_wrapper'] ) {
686 do_action('notifier_before_meta_field_wrapper', $field, $post);
687 echo '<p class="form-field mb-3 ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '" data-conditions="' . esc_js( $field['conditional_logic'] ) . '">';
688 }
689
690 if ( '' != $field['label'] ) {
691 echo '<label for="' . esc_attr( $field['id'] ) . '" class="form-label">' . wp_kses_post( $field['label'] ) . '</label>';
692 }
693
694 do_action('notifier_before_meta_field', $field, $post);
695
696 echo '<span class="wa-notifier-media-preview ' . $show_wrapper . '">';
697 echo '<img id="' . esc_attr( $field['id'] ) . '_preview_image" class="wa-notifier-media-preview-item ' . esc_attr($show_image) . '" src="' . esc_url($image_thumb) . '" />';
698 echo '<video id="' . esc_attr( $field['id'] ) . '_preview_video" class="wa-notifier-media-preview-item ' . esc_attr($show_video) . '" width="300" height="169" controls muted><source src="' . esc_url($video_url) . '" type="video/mp4"></video><br/>';
699 echo '</span>';
700
701 echo '<input id="' . esc_attr( $field['id'] ) . '_uploader" class="wa-notifier-media-upload" type="file" ' . $custom_attributes_string . '>';
702
703 echo '<input id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $attachment_id ) . '" name="' . esc_attr( $field['name'] ) . '" class="wa-notifier-media" type="hidden" ' . $required_field . '>';
704
705 if ( ! $is_disabled ) {
706 echo '<button class="btn btn-primary btn-sm wa-notifier-media-trigger-upload me-2 ' . esc_attr( $field['class'] ) . '">Choose File</button>';
707 echo '<button class="btn btn-secondary btn-sm wa-notifier-media-delete">Remove</button>';
708 }
709
710 echo '<span class="wa-notifier-media-upload-status d-none wa-notifier-media-uploading"><i class="bx bx-loader bx-spin"></i> Uploading...</span>';
711 echo '<span class="wa-notifier-media-upload-status d-none wa-notifier-media-upload-done text-success"><i class="bx bx-check"></i> Upload done!</span>';
712 echo '<span class="wa-notifier-media-upload-status d-none wa-notifier-media-upload-error text-danger"><i class="bx bxs-error"></i> There was an error during upload. Please try again later.</span>';
713
714 if ( $field['required'] ) {
715 echo '<span class="invalid-feedback">This is a required field.</span>';
716 }
717
718 do_action('notifier_after_meta_field', $field, $post);
719
720 if ( '' != $field['description'] ) {
721 echo '<span class="clearfix"></span><span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
722 }
723
724 do_action('notifier_after_meta_field_description', $field, $post);
725
726 if ( $field['show_wrapper'] ) {
727 echo '</p>';
728 do_action('notifier_after_meta_field_wrapper', $field, $post);
729 }
730 }
731
732 /**
733 * Notifier repeater field
734 *
735 * @param array $fields_data
736 */
737 function notifier_wp_repeater($fields_data) {
738 $fields_data = wp_parse_args(
739 $fields_data, array(
740 'label' => '',
741 'name' => $fields_data['id'],
742 'wrapper_class' => '',
743 'conditional_logic' => '',
744 'conditional_operator' => 'OR'
745 )
746 );
747
748 echo '<div class="form-field mb-3' . esc_attr( $fields_data['id'] ) . '_field ' . esc_attr( $fields_data['wrapper_class'] ) . '" data-conditions="' . esc_js( $fields_data['conditional_logic'] ) . '">';
749
750 echo '<label class="form-label">' . $fields_data['label'] . '</label>';
751
752 echo '<table class="fields-repeater">';
753
754 // Table header
755 echo '<thead>';
756 echo '<tr>';
757 foreach($fields_data['fields'] as $field){
758 echo '<th>' . $field['label'] . '</th>';
759 }
760 echo '<th></th>';
761 echo '</tr>';
762 echo '</thead>';
763
764 echo '<tbody>';
765 echo '<tr class="d-none">';
766 foreach($fields_data['fields'] as $field){
767 $field['custom_attributes'] = array('disabled' => 'disabled');
768 $field['label'] = '';
769 $field['name'] = $field['id'] . '[]';
770 $field['id'] = $field['id'] . '_dummy';
771 echo '<td>';
772 switch($field['type']) {
773 case 'text':
774 notifier_wp_text_input($field);
775 break;
776 }
777 echo '</td>';
778 }
779 echo '<td><a href="#" class="delete-repeater-field"><i class="bx bx-trash text-secondary"></i></a></td>';
780 echo '</tr>';
781
782 if(!empty($fields_data['values'])){
783 $x = 0;
784 foreach($fields_data['values'] as $values){
785 echo '<tr>';
786 foreach($fields_data['fields'] as $key => $field){
787 $field['label'] = '';
788 $field['value'] = $values[$key];
789 $field['name'] = $field['id'] . '[]';
790 $field['id'] = $field['id'] . '_' . $x;
791 echo '<td>';
792 switch($field['type']) {
793 case 'text':
794 notifier_wp_text_input($field);
795 break;
796 }
797 echo '</td>';
798 }
799 echo '<td><a href="#" class="delete-repeater-field"><i class="bx bx-trash text-secondary"></i></a></td>';
800 echo '</tr>';
801 $x++;
802 }
803 }
804 echo '</tbody>';
805 echo '</table>';
806
807 echo '<p class="description d-flex align-items-center mb-3 mt-1"><span>'.$fields_data['description'].'</span>
808 <a href="" class="add-repeater-item ms-auto"><i class="bx bx-plus"></i> '.$fields_data['button_name'].'</a>
809 </p>';
810
811 echo '</div>';
812 }
813