PluginProbe ʕ •ᴥ•ʔ
Advanced Custom Fields: Extended / trunk
Advanced Custom Fields: Extended vtrunk
0.9.2.6 0.9.2.5 0.8.6 0.8.6.1 0.8.6.3 0.8.6.5 0.8.6.6 0.8.6.7 0.8.6.8 0.8.6.9 0.8.7 0.8.7.1 0.8.7.2 0.8.7.3 0.8.7.4 0.8.7.5 0.8.7.6 0.8.8 0.8.8.1 0.8.8.10 0.8.8.11 0.8.8.2 0.8.8.3 0.8.8.4 0.8.8.5 0.8.8.6 0.8.8.7 0.8.8.8 0.8.8.9 0.8.9 0.8.9.1 0.8.9.2 0.8.9.3 0.8.9.4 0.8.9.5 0.9 0.9.0.1 0.9.0.2 0.9.0.3 0.9.0.4 0.9.0.5 0.9.0.6 0.9.0.7 0.9.0.8 0.9.0.9 0.9.1 0.9.1.1 0.9.2 0.9.2.1 0.9.2.2 0.9.2.3 0.9.2.4 trunk 0.5 0.5.1 0.5.2 0.5.2.1 0.5.2.3 0.5.5 0.5.5.1 0.5.8 0.5.8.1 0.6 0.6.0.1 0.6.0.2 0.6.1 0.6.3 0.6.5 0.6.7 0.6.7.2 0.7 0.7.0.3 0.7.5 0.7.5.5 0.7.8 0.7.9 0.7.9.3 0.7.9.4 0.7.9.9.8 0.7.9.9.9 0.8 0.8.1 0.8.2 0.8.3 0.8.3.1 0.8.4 0.8.4.1 0.8.4.5 0.8.4.6 0.8.5 0.8.5.5
acf-extended / includes / fields / field-forms.php
acf-extended / includes / fields Last commit date
field-advanced-link.php 1 month ago field-button.php 6 months ago field-checkbox.php 1 month ago field-clone.php 2 years ago field-code-editor.php 1 month ago field-column.php 3 years ago field-dynamic-render.php 3 years ago field-file.php 1 month ago field-flexible-content-actions-title.php 2 months ago field-flexible-content-actions-toggle.php 1 month ago field-flexible-content-actions.php 1 month ago field-flexible-content-async.php 2 months ago field-flexible-content-compatibility.php 1 month ago field-flexible-content-controls.php 7 months ago field-flexible-content-hide.php 1 month ago field-flexible-content-hooks.php 7 months ago field-flexible-content-modal-edit.php 7 months ago field-flexible-content-modal-select.php 1 month ago field-flexible-content-modal-settings.php 1 month ago field-flexible-content-popup.php 2 months ago field-flexible-content-preview.php 1 month ago field-flexible-content-state.php 7 months ago field-flexible-content-thumbnail.php 7 months ago field-flexible-content-wysiwyg.php 7 months ago field-flexible-content.php 1 month ago field-forms.php 1 month ago field-gallery.php 1 month ago field-google-map.php 1 month ago field-group.php 1 month ago field-hidden.php 3 years ago field-image.php 1 month ago field-post-object.php 1 month ago field-post-statuses.php 1 month ago field-post-types.php 1 month ago field-radio.php 1 month ago field-recaptcha.php 2 months ago field-relationship.php 1 month ago field-repeater.php 1 month ago field-select.php 1 month ago field-slug.php 11 months ago field-taxonomies.php 1 month ago field-taxonomy-terms.php 1 month ago field-taxonomy.php 1 month ago field-textarea.php 1 month ago field-user-roles.php 1 month ago field-user.php 1 month ago field-wysiwyg.php 1 month ago
field-forms.php
639 lines
1 <?php
2
3 if(!defined('ABSPATH')){
4 exit;
5 }
6
7 if(!class_exists('acfe_field_forms')):
8
9 class acfe_field_forms extends acfe_field{
10
11 /**
12 * initialize
13 */
14 function initialize(){
15
16 $this->name = 'acfe_forms';
17 $this->label = __('Forms', 'acfe');
18 $this->category = apply_filters('acfe/form_field_type_category', 'relational');
19 $this->defaults = array(
20 'forms' => array(),
21 'field_type' => 'checkbox',
22 'multiple' => 0,
23 'allow_null' => 0,
24 'choices' => array(),
25 'default_value' => '',
26 'ui' => 0,
27 'ajax' => 0,
28 'placeholder' => '',
29 'search_placeholder' => '',
30 'layout' => '',
31 'toggle' => 0,
32 'allow_custom' => 0,
33 'other_choice' => 0,
34 'return_format' => 'name',
35 );
36
37 }
38
39
40 /**
41 * render_field_settings
42 *
43 * @param $field
44 */
45 function render_field_settings($field){
46
47 if(isset($field['default_value'])){
48 $field['default_value'] = acf_encode_choices($field['default_value'], false);
49 }
50
51 // Allow Form
52 acf_render_field_setting($field, array(
53 'label' => __('Allow Forms','acf'),
54 'instructions' => '',
55 'type' => 'select',
56 'name' => 'forms',
57 'choices' => acfe_get_pretty_forms(),
58 'multiple' => 1,
59 'ui' => 1,
60 'allow_null' => 1,
61 'placeholder' => __("All forms",'acf'),
62 ));
63
64 // field_type
65 acf_render_field_setting($field, array(
66 'label' => __('Appearance','acf'),
67 'instructions' => __('Select the appearance of this field', 'acf'),
68 'type' => 'select',
69 'name' => 'field_type',
70 'optgroup' => true,
71 'choices' => array(
72 'checkbox' => __('Checkbox', 'acf'),
73 'radio' => __('Radio Buttons', 'acf'),
74 'select' => _x('Select', 'noun', 'acf')
75 )
76 ));
77
78 // default_value
79 acf_render_field_setting($field, array(
80 'label' => __('Default Value','acf'),
81 'instructions' => __('Enter each default value on a new line','acf'),
82 'name' => 'default_value',
83 'type' => 'textarea',
84 ));
85
86 // return_format
87 acf_render_field_setting($field, array(
88 'label' => __('Return Value', 'acf'),
89 'instructions' => '',
90 'type' => 'radio',
91 'name' => 'return_format',
92 'choices' => array(
93 'id' => __('Form ID', 'acfe'),
94 'name' => __('Form name', 'acfe')
95 ),
96 'layout' => 'horizontal',
97 ));
98
99 // Select + Radio: allow_null
100 acf_render_field_setting($field, array(
101 'label' => __('Allow Null?','acf'),
102 'instructions' => '',
103 'name' => 'allow_null',
104 'type' => 'true_false',
105 'ui' => 1,
106 'conditions' => array(
107 array(
108 array(
109 'field' => 'field_type',
110 'operator' => '==',
111 'value' => 'select',
112 ),
113 ),
114 array(
115 array(
116 'field' => 'field_type',
117 'operator' => '==',
118 'value' => 'radio',
119 ),
120 ),
121 )
122 ));
123
124 // Select: Placeholder
125 acf_render_field_setting($field, array(
126 'label' => __('Placeholder','acf'),
127 'instructions' => __('Appears within the input','acf'),
128 'type' => 'text',
129 'name' => 'placeholder',
130 'placeholder' => _x('Select', 'verb', 'acf'),
131 'conditional_logic' => array(
132 array(
133 array(
134 'field' => 'field_type',
135 'operator' => '==',
136 'value' => 'select',
137 ),
138 array(
139 'field' => 'ui',
140 'operator' => '==',
141 'value' => '0',
142 ),
143 array(
144 'field' => 'allow_null',
145 'operator' => '==',
146 'value' => '1',
147 ),
148 array(
149 'field' => 'multiple',
150 'operator' => '==',
151 'value' => '0',
152 ),
153 ),
154 array(
155 array(
156 'field' => 'field_type',
157 'operator' => '==',
158 'value' => 'select',
159 ),
160 array(
161 'field' => 'ui',
162 'operator' => '==',
163 'value' => '1',
164 ),
165 array(
166 'field' => 'allow_null',
167 'operator' => '==',
168 'value' => '1',
169 ),
170 ),
171 array(
172 array(
173 'field' => 'field_type',
174 'operator' => '==',
175 'value' => 'select',
176 ),
177 array(
178 'field' => 'ui',
179 'operator' => '==',
180 'value' => '1',
181 ),
182 array(
183 'field' => 'multiple',
184 'operator' => '==',
185 'value' => '1',
186 ),
187 ),
188 )
189 ));
190
191 // Select: Search Placeholder
192 acf_render_field_setting($field, array(
193 'label' => __('Search Input Placeholder','acf'),
194 'instructions' => __('Appears within the search input','acf'),
195 'type' => 'text',
196 'name' => 'search_placeholder',
197 'placeholder' => '',
198 'conditional_logic' => array(
199 array(
200 array(
201 'field' => 'field_type',
202 'operator' => '==',
203 'value' => 'select',
204 ),
205 array(
206 'field' => 'ui',
207 'operator' => '==',
208 'value' => '1',
209 ),
210 array(
211 'field' => 'multiple',
212 'operator' => '==',
213 'value' => '0',
214 ),
215 ),
216 )
217 ));
218
219 // Select: multiple
220 acf_render_field_setting($field, array(
221 'label' => __('Select multiple values?','acf'),
222 'instructions' => '',
223 'name' => 'multiple',
224 'type' => 'true_false',
225 'ui' => 1,
226 'conditions' => array(
227 array(
228 array(
229 'field' => 'field_type',
230 'operator' => '==',
231 'value' => 'select',
232 ),
233 ),
234 )
235 ));
236
237 // Select: ui
238 acf_render_field_setting($field, array(
239 'label' => __('Stylised UI','acf'),
240 'instructions' => '',
241 'name' => 'ui',
242 'type' => 'true_false',
243 'ui' => 1,
244 'conditions' => array(
245 array(
246 array(
247 'field' => 'field_type',
248 'operator' => '==',
249 'value' => 'select',
250 ),
251 ),
252 )
253 ));
254
255
256 // Select: ajax
257 acf_render_field_setting($field, array(
258 'label' => __('Use AJAX to lazy load choices?','acf'),
259 'instructions' => '',
260 'name' => 'ajax',
261 'type' => 'true_false',
262 'ui' => 1,
263 'conditions' => array(
264 array(
265 array(
266 'field' => 'field_type',
267 'operator' => '==',
268 'value' => 'select',
269 ),
270 array(
271 'field' => 'ui',
272 'operator' => '==',
273 'value' => 1,
274 ),
275 ),
276 )
277 ));
278
279 // Radio: other_choice
280 acf_render_field_setting($field, array(
281 'label' => __('Other','acf'),
282 'instructions' => '',
283 'name' => 'other_choice',
284 'type' => 'true_false',
285 'ui' => 1,
286 'message' => __("Add 'other' choice to allow for custom values", 'acf'),
287 'conditions' => array(
288 array(
289 array(
290 'field' => 'field_type',
291 'operator' => '==',
292 'value' => 'radio',
293 ),
294 ),
295 )
296 ));
297
298
299 // Radio: save_other_choice
300 acf_render_field_setting($field, array(
301 'label' => __('Save Other','acf'),
302 'instructions' => '',
303 'name' => 'save_other_choice',
304 'type' => 'true_false',
305 'ui' => 1,
306 'message' => __("Save 'other' values to the field's choices", 'acf'),
307 'conditions' => array(
308 array(
309 array(
310 'field' => 'field_type',
311 'operator' => '==',
312 'value' => 'radio',
313 ),
314 array(
315 'field' => 'other_choice',
316 'operator' => '==',
317 'value' => 1,
318 ),
319 ),
320 )
321 ));
322
323 // Checkbox: layout
324 acf_render_field_setting($field, array(
325 'label' => __('Layout','acf'),
326 'instructions' => '',
327 'type' => 'radio',
328 'name' => 'layout',
329 'layout' => 'horizontal',
330 'choices' => array(
331 'vertical' => __("Vertical",'acf'),
332 'horizontal' => __("Horizontal",'acf')
333 ),
334 'conditions' => array(
335 array(
336 array(
337 'field' => 'field_type',
338 'operator' => '==',
339 'value' => 'checkbox',
340 ),
341 ),
342 array(
343 array(
344 'field' => 'field_type',
345 'operator' => '==',
346 'value' => 'radio',
347 ),
348 ),
349 )
350 ));
351
352 // Checkbox: toggle
353 acf_render_field_setting($field, array(
354 'label' => __('Toggle','acf'),
355 'instructions' => __('Prepend an extra checkbox to toggle all choices','acf'),
356 'name' => 'toggle',
357 'type' => 'true_false',
358 'ui' => 1,
359 'conditions' => array(
360 array(
361 array(
362 'field' => 'field_type',
363 'operator' => '==',
364 'value' => 'checkbox',
365 ),
366 ),
367 )
368 ));
369
370 // Checkbox: other_choice
371 acf_render_field_setting($field, array(
372 'label' => __('Allow Custom','acf'),
373 'instructions' => __("Allow 'custom' values to be added", 'acf'),
374 'name' => 'allow_custom',
375 'type' => 'true_false',
376 'ui' => 1,
377 'conditions' => array(
378 array(
379 array(
380 'field' => 'field_type',
381 'operator' => '==',
382 'value' => 'checkbox',
383 ),
384 ),
385 )
386 ));
387
388
389 // Checkbox: save_other_choice
390 acf_render_field_setting($field, array(
391 'label' => __('Save Custom','acf'),
392 'instructions' => '',
393 'name' => 'save_custom',
394 'type' => 'true_false',
395 'ui' => 1,
396 'message' => __("Save 'custom' values to the field's choices", 'acf'),
397 'conditions' => array(
398 array(
399 array(
400 'field' => 'field_type',
401 'operator' => '==',
402 'value' => 'checkbox',
403 ),
404 array(
405 'field' => 'allow_custom',
406 'operator' => '==',
407 'value' => 1,
408 ),
409 ),
410 )
411 ));
412
413 }
414
415
416 /**
417 * update_field
418 *
419 * @param $field
420 *
421 * @return mixed
422 */
423 function update_field($field){
424
425 $field['default_value'] = acf_decode_choices($field['default_value'], true);
426
427 if($field['field_type'] === 'radio'){
428 $field['default_value'] = acfe_unarray($field['default_value']);
429 }
430
431 return $field;
432
433 }
434
435
436 /**
437 * prepare_field
438 *
439 * @param $field
440 *
441 * @return mixed
442 */
443 function prepare_field($field){
444
445 // field type
446 $type = $field['type'];
447 $field_type = $field['field_type'];
448
449 $field['type'] = $field_type;
450 $field['wrapper']['data-ftype'] = $type;
451
452 // choices
453 $field['choices'] = acfe_get_pretty_forms($field['forms']);
454
455 // allow custom
456 if($field['allow_custom']){
457
458 $value = acfe_get($field, 'value');
459 $value = acfe_as_array($value);
460
461 foreach($value as $v){
462
463 // append custom value to choices
464 if(!isset($field['choices'][ $v ])){
465 $field['choices'][ $v ] = $v;
466 $field['custom_choices'][ $v ] = $v;
467 }
468 }
469
470 }
471
472 // return
473 return $field;
474
475 }
476
477
478 /**
479 * load_value
480 *
481 * Handle old values which returned form id
482 * Should return form names now
483 *
484 * @param $value
485 * @param $post_id
486 * @param $field
487 *
488 * @return mixed
489 */
490 function load_value($value, $post_id, $field){
491
492 // bail early
493 if(empty($value)){
494 return $value;
495 }
496
497 // vars
498 $is_array = is_array($value);
499 $value = acfe_as_array($value);
500
501 // loop
502 foreach($value as &$v){
503
504 if(is_numeric($v)){
505
506 // get item
507 $item = acfe_get_module('form')->get_item($v);
508
509 // found item by ID
510 // return name
511 if($item){
512 $v = $item['name'];
513 }
514
515 }
516
517 }
518
519 // check array
520 if(!$is_array || $field['field_type'] === 'radio'){
521 $value = acfe_unarray($value);
522 }
523
524 return $value;
525
526 }
527
528
529 /**
530 * format_value
531 *
532 * @param $value
533 * @param $post_id
534 * @param $field
535 *
536 * @return array|false|mixed|string[]
537 */
538 function format_value($value, $post_id, $field){
539
540 // bail early
541 if(empty($value)){
542 return $value;
543 }
544
545 // vars
546 $is_array = is_array($value);
547 $value = acfe_as_array($value);
548
549 // loop
550 foreach($value as &$v){
551
552 // get object
553 $object = acfe_get_module('form')->get_item($v);
554
555 if(!$object || is_wp_error($object)) continue;
556
557 // return: name
558 if($field['return_format'] === 'id'){
559 $v = $object['ID'];
560 }
561
562 }
563
564 // check array
565 if(!$is_array){
566 $value = acfe_unarray($value);
567 }
568
569 // return
570 return $value;
571
572 }
573
574
575 /**
576 * validate_front_value
577 *
578 * @param $valid
579 * @param $value
580 * @param $field
581 * @param $input
582 * @param $form
583 *
584 * @return false
585 */
586 function validate_front_value($valid, $value, $field, $input, $form){
587
588 // bail early
589 if(!$this->pre_validate_front_value($valid, $value, $field, $form)){
590 return $valid;
591 }
592
593 // custom value allowed
594 if(!empty($field['allow_custom']) || !empty($field['other_choice'])){
595 return $valid;
596 }
597
598 // vars
599 $value = acfe_as_array($value);
600 $choices = acfe_as_array($field['forms']);
601
602 // empty choices
603 if(empty($choices)){
604 return $valid;
605 }
606
607 // check values against choices
608 if(!empty(array_diff($value, $choices))){
609 return false;
610 }
611
612 // return
613 return $valid;
614
615 }
616
617
618 /**
619 * translate_field
620 *
621 * @param $field
622 *
623 * @return mixed
624 */
625 function translate_field($field){
626
627 $field['placeholder'] = acf_translate($field['placeholder']);
628 $field['search_placeholder'] = acf_translate($field['search_placeholder']);
629
630 return $field;
631
632 }
633
634 }
635
636 // initialize
637 acf_register_field_type('acfe_field_forms');
638
639 endif;