PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.16.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.16.2
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / Core / Util / MetaBoxService.php

MetaBoxService.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.16.2, at includes/Core/Util/MetaBoxService.php

84 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Core\Util;
4
5 class MetaBoxService
6 {
7 public static function getMetaBoxFields($postType)
8 {
9 $unsupportedTypes = [
10 'file_input',
11 'tab',
12 'osm',
13 'heading',
14 'key_value',
15 'map',
16 'custom_html',
17 'background',
18 'fieldset_text',
19 'taxonomy',
20 'taxonomy_advanced',
21 ];
22
23 $fileTypes = [
24 'image',
25 'image_upload',
26 'file_advanced',
27 'file_upload',
28 'single_image',
29 'file',
30 'image_advanced',
31 'video',
32 ];
33
34 $textFields = [];
35
36 $fileFields = [];
37
38 $metaBoxFields = rwmb_get_object_fields($postType);
39
40 foreach ($metaBoxFields as $index => $field) {
41 if (in_array($field['type'], $unsupportedTypes)) {
42 continue;
43 }
44
45 if ('group' === $field['type'] && isset($field['fields'])) {
46 $getFields = self::setMetaBoxSubFields($field, $textFields, $fileFields, $fileTypes);
47 $textFields = $getFields['text_fields'];
48 $fileFields = $getFields['file_fields'];
49 continue;
50 }
51
52 if (in_array($field['type'], $fileTypes)) {
53 $fileFields[$index]['name'] = $field['name'];
54 $fileFields[$index]['key'] = $field['id'];
55 $fileFields[$index]['required'] = $field['required'];
56 } else {
57 $textFields[$index]['name'] = $field['name'];
58 $textFields[$index]['key'] = $field['id'];
59 $textFields[$index]['required'] = $field['required'];
60 }
61 }
62
63 return ['text_fields'=> $textFields, 'file_fields'=> $fileFields];
64 }
65
66 private static function setMetaBoxSubFields($field, $textFields, $fileFields, $fileTypes)
67 {
68 foreach ($field['fields'] as $childIndex => $subField) {
69 if (in_array($subField['type'], $fileTypes)) {
70 $fileFields[$childIndex]['name'] = $subField['name'];
71 $fileFields[$childIndex]['type'] = $subField['type'];
72 $fileFields[$childIndex]['key'] = $field['id'] . '.' . $subField['id'];
73 $fileFields[$childIndex]['required'] = $subField['required'];
74 } else {
75 $textFields[$childIndex]['name'] = $field['name'] . '-' . $subField['name'];
76 $textFields[$childIndex]['key'] = $field['id'] . '.' . $subField['id'];
77 $textFields[$childIndex]['type'] = $subField['type'];
78 $textFields[$childIndex]['required'] = $subField['required'];
79 }
80 }
81 return ['text_fields'=>$textFields, 'file_fields'=> $fileFields];
82 }
83 }
84