PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.1.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.1.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 3.1.2, at includes/Core/Util/MetaBoxService.php

91 lines 2.6 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 $supportedFieldType = [
24 'select',
25 'select_advanced',
26 'checkbox_list',
27 'radio_list'
28 ];
29
30 $fileTypes = [
31 'image',
32 'image_upload',
33 'file_advanced',
34 'file_upload',
35 'single_image',
36 'file',
37 'image_advanced',
38 'video',
39 ];
40
41 $textFields = [];
42
43 $fileFields = [];
44
45 $metaBoxFields = rwmb_get_object_fields($postType);
46
47 foreach ($metaBoxFields as $index => $field) {
48 if (in_array($field['type'], $unsupportedTypes) && !in_array($field['field_type'], $supportedFieldType)) {
49 continue;
50 }
51
52 if ('group' === $field['type'] && isset($field['fields'])) {
53 $getFields = self::setMetaBoxSubFields($field, $textFields, $fileFields, $fileTypes);
54 $textFields = $getFields['text_fields'];
55 $fileFields = $getFields['file_fields'];
56 continue;
57 }
58
59 if (in_array($field['type'], $fileTypes)) {
60 $fileFields[$index]['name'] = $field['name'];
61 $fileFields[$index]['key'] = $field['id'];
62 $fileFields[$index]['required'] = $field['required'];
63 } else {
64 $textFields[$index]['name'] = $field['name'];
65 $textFields[$index]['key'] = $field['id'];
66 $textFields[$index]['required'] = $field['required'];
67 }
68 }
69
70 return ['text_fields'=> $textFields, 'file_fields'=> $fileFields];
71 }
72
73 private static function setMetaBoxSubFields($field, $textFields, $fileFields, $fileTypes)
74 {
75 foreach ($field['fields'] as $childIndex => $subField) {
76 if (in_array($subField['type'], $fileTypes)) {
77 $fileFields[$childIndex]['name'] = $subField['name'];
78 $fileFields[$childIndex]['type'] = $subField['type'];
79 $fileFields[$childIndex]['key'] = $field['id'] . '.' . $subField['id'];
80 $fileFields[$childIndex]['required'] = $subField['required'];
81 } else {
82 $textFields[$childIndex]['name'] = $field['name'] . '-' . $subField['name'];
83 $textFields[$childIndex]['key'] = $field['id'] . '.' . $subField['id'];
84 $textFields[$childIndex]['type'] = $subField['type'];
85 $textFields[$childIndex]['required'] = $subField['required'];
86 }
87 }
88 return ['text_fields'=>$textFields, 'file_fields'=> $fileFields];
89 }
90 }
91