PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.15.3
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.15.3
3.3.1 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 All 138 releases
← All changes | includes/Admin/Form/CustomFieldHandler.php +175 -187 1.92.15.3 View file →
@@ -8,218 +8,206 @@
8 8 namespace BitCode\BitForm\Admin\Form;
9 9
10 10 class CustomFieldHandler
11 11 {
12 - public function updatedEntries($formEntries, $fieldDetails)
13 - {
14 - foreach ($formEntries['entries'] as $index => $entry) {
15 - foreach ($fieldDetails as $field) {
16 - $fieldKey = $field['key'];
17 - if (isset($field['customType']) && !empty($entry->$fieldKey) && !empty($field['customType']->hiddenValue)) {
18 - $hiddenvalue = $field['customType']->hiddenValue;
19 - if ($field['customType']->fieldType == 'taxanomy_field') {
20 - $hiddenvalue = $field['customType']->hiddenValue;
21 - if (isset($field['mul'])) {
22 - $mul = $field['mul'];
23 - } else {
24 - $mul = '';
25 - }
26 -
27 - $value = $this->getTermFieldValue($field['type'], $entry->$fieldKey, $mul, $hiddenvalue);
28 - $formEntries['entries'][$index]->$fieldKey = $value;
29 - } else if ($field['customType']->fieldType == "user_field") {
30 - $hiddenvalue = $field['customType']->hiddenValue;
31 - if (isset($field['mul'])) {
32 - $mul = $field['mul'];
33 - } else {
34 - $mul = '';
35 - }
36 -
37 - $value = $this->getUserFieldValue($field['type'], $entry->$fieldKey, $mul, $hiddenvalue);
38 - $formEntries['entries'][$index]->$fieldKey = $value;
39 - } else if ($field['customType']->fieldType == "post_field") {
40 - $hiddenvalue = $field['customType']->hiddenValue;
41 - if (isset($field['mul'])) {
42 - $mul = $field['mul'];
43 - } else {
44 - $mul = '';
45 - }
46 -
47 - $value = $this->getPostFieldValue($field['type'], $entry->$fieldKey, $mul, $hiddenvalue);
48 - $formEntries['entries'][$index]->$fieldKey = $value;
49 - }
50 - }
12 + public function updatedEntries($formEntries, $fieldDetails)
13 + {
14 + foreach ($formEntries['entries'] as $index => $entry) {
15 + foreach ($fieldDetails as $field) {
16 + $fieldKey = $field['key'];
17 + if (isset($field['customType']) && !empty($entry->$fieldKey) && !empty($field['customType']->hiddenValue)) {
18 + $hiddenvalue = $field['customType']->hiddenValue;
19 + if ('taxanomy_field' === $field['customType']->fieldType) {
20 + $hiddenvalue = $field['customType']->hiddenValue;
21 + if (isset($field['mul'])) {
22 + $mul = $field['mul'];
23 + } else {
24 + $mul = '';
51 25 }
52 - }
53 - return $formEntries;
54 - }
55 26
56 - public function updatedData($form_fields, $toUpdateValues)
57 - {
58 - foreach ($form_fields as $field) {
59 - if (isset($field['customType']) && !empty($toUpdateValues[$field['key']])) {
60 - if (isset($field['customType']->hiddenValue)) {
61 - $hiddenvalue = $field['customType']->hiddenValue;
62 - if ($field['customType']->fieldType == 'taxanomy_field') {
63 - if (isset($field['mul'])) {
64 - $mul = $field['mul'];
65 - } else {
66 - $mul = '';
67 - }
68 -
69 - $value = $this->getTermFieldValue($field['type'], $toUpdateValues[$field['key']], $mul, $hiddenvalue);
70 - $toUpdateValues[$field['key']] = $value;
71 - } else if ($field['customType']->fieldType == "user_field") {
72 - if (isset($field['mul'])) {
73 - $mul = $field['mul'];
74 - } else {
75 - $mul = '';
76 - }
77 -
78 - $value = $this->getUserFieldValue($field['type'], $toUpdateValues[$field['key']], $mul, $hiddenvalue);
79 - $toUpdateValues[$field['key']] = $value;
80 - } else if ($field['customType']->fieldType == "post_field") {
81 - if (isset($field['mul'])) {
82 - $mul = $field['mul'];
83 - } else {
84 - $mul = '';
85 - }
86 -
87 - $value = $this->getPostFieldValue($field['type'], $toUpdateValues[$field['key']], $mul, $hiddenvalue);
88 - $toUpdateValues[$field['key']] = $value;
89 - }
90 - }
91 - }
92 - }
93 - return $toUpdateValues;
94 - }
95 -
96 - public function getPostFieldValue($type, $fieldValue, $mul, $hiddenvalue)
97 - {
98 - $value = '';
99 -
100 - if ($type == "select") {
101 -
102 - if ($mul == true) {
103 - $multipleValue = [];
104 - foreach (explode(',', $fieldValue) as $val) {
105 - $exists = get_post($val);
106 - if ($exists != false) {
107 - $multipleValue[] = $exists->$hiddenvalue;
108 - }
109 - }
110 - $value = implode(",", $multipleValue);
27 + $value = $this->getTermFieldValue($field['type'], $entry->$fieldKey, $mul, $hiddenvalue);
28 + $formEntries['entries'][$index]->$fieldKey = $value;
29 + } elseif ('user_field' === $field['customType']->fieldType) {
30 + $hiddenvalue = $field['customType']->hiddenValue;
31 + if (isset($field['mul'])) {
32 + $mul = $field['mul'];
111 33 } else {
112 - $exists = get_post($fieldValue);
113 - if ($exists != false) {
114 - $value = is_array($exists->$hiddenvalue) ? $exists->$hiddenvalue : (string) $exists->$hiddenvalue;
115 - }
34 + $mul = '';
116 35 }
117 36
118 - } else if ($type == "radio" || $type == "check") {
119 -
120 - if (is_array(json_decode($fieldValue))) {
121 - $multipleValues = [];
122 - foreach (json_decode($fieldValue) as $value) {
123 - $exists = get_post($value);
124 - if ($exists != false) {
125 - $multipleValues[] = $exists->$hiddenvalue;
126 - }
127 - }
128 - $value = json_encode($multipleValues);
37 + $value = $this->getUserFieldValue($field['type'], $entry->$fieldKey, $mul, $hiddenvalue);
38 + $formEntries['entries'][$index]->$fieldKey = $value;
39 + } elseif ('post_field' === $field['customType']->fieldType) {
40 + $hiddenvalue = $field['customType']->hiddenValue;
41 + if (isset($field['mul'])) {
42 + $mul = $field['mul'];
129 43 } else {
130 - $exists = get_post($fieldValue);
131 - if ($exists != false) {
132 - $value = $exists->$hiddenvalue;
133 - }
44 + $mul = '';
134 45 }
135 46
47 + $value = $this->getPostFieldValue($field['type'], $entry->$fieldKey, $mul, $hiddenvalue);
48 + $formEntries['entries'][$index]->$fieldKey = $value;
49 + }
136 50 }
137 - return $value;
51 + }
138 52 }
53 + return $formEntries;
54 + }
139 55
140 - public function getUserFieldValue($type, $fieldValue, $mul, $hiddenvalue)
141 - {
142 - $value = '';
143 - if ($type == "select") {
56 + public function updatedData($form_fields, $toUpdateValues)
57 + {
58 + foreach ($form_fields as $field) {
59 + if (isset($field['customType']) && !empty($toUpdateValues[$field['key']])) {
60 + if (isset($field['customType']->hiddenValue)) {
61 + $hiddenvalue = $field['customType']->hiddenValue;
62 + if ('taxanomy_field' === $field['customType']->fieldType) {
63 + if (isset($field['mul'])) {
64 + $mul = $field['mul'];
65 + } else {
66 + $mul = '';
67 + }
144 68
145 - if ($mul == true) {
146 - $multipleValue = [];
147 - foreach (explode(',', $fieldValue) as $val) {
148 - $exists = get_user_by('ID', $val);
149 - if ($exists != false) {
150 - $multipleValue[] = $exists->data->$hiddenvalue;
151 - }
152 - }
153 - $value = implode(",", $multipleValue);
69 + $value = $this->getTermFieldValue($field['type'], $toUpdateValues[$field['key']], $mul, $hiddenvalue);
70 + $toUpdateValues[$field['key']] = $value;
71 + } elseif ('user_field' === $field['customType']->fieldType) {
72 + if (isset($field['mul'])) {
73 + $mul = $field['mul'];
154 74 } else {
155 - $exists = get_user_by('ID', $fieldValue);
156 - if ($exists != false) {
157 - $value = is_array($exists->data->$hiddenvalue) ? $exists->data->$hiddenvalue : (string) $exists->data->$hiddenvalue;
158 - }
75 + $mul = '';
159 76 }
160 77
161 - } else if ($type == "radio" || $type == "check") {
162 -
163 - if (is_array(json_decode($fieldValue))) {
164 - $multipleValues = [];
165 - foreach (json_decode($fieldValue) as $value) {
166 - $exists = get_user_by('ID', $value);
167 - if ($exists != false) {
168 - $multipleValues[] = $exists->data->$hiddenvalue;
169 - }
170 - }
171 - $value = json_encode($multipleValues);
78 + $value = $this->getUserFieldValue($field['type'], $toUpdateValues[$field['key']], $mul, $hiddenvalue);
79 + $toUpdateValues[$field['key']] = $value;
80 + } elseif ('post_field' === $field['customType']->fieldType) {
81 + if (isset($field['mul'])) {
82 + $mul = $field['mul'];
172 83 } else {
173 - $exists = get_user_by('ID', $fieldValue);
174 - if ($exists != false) {
175 - $value = $exists->data->$hiddenvalue;
176 - }
84 + $mul = '';
177 85 }
178 86
87 + $value = $this->getPostFieldValue($field['type'], $toUpdateValues[$field['key']], $mul, $hiddenvalue);
88 + $toUpdateValues[$field['key']] = $value;
89 + }
179 90 }
180 - return $value;
91 + }
181 92 }
93 + return $toUpdateValues;
94 + }
182 95
183 - public function getTermFieldValue($type, $fieldValue, $mul, $hiddenvalue)
184 - {
185 - $value = '';
186 - if ($type == "select") {
96 + public function getPostFieldValue($type, $fieldValue, $mul, $hiddenvalue)
97 + {
98 + $value = '';
187 99
188 - if ($mul == true) {
189 - $multipleValue = [];
190 - foreach (explode(',', $fieldValue) as $val) {
191 - $exists = get_term_by('term_taxonomy_id', $val);
192 - if ($exists != false) {
193 - $multipleValue[] = $exists->$hiddenvalue;
194 - }
195 - }
196 - $value = implode(",", $multipleValue);
197 - } else {
198 - $exists = get_term_by('term_taxonomy_id', $fieldValue);
199 - if ($exists != false) {
200 - $value = is_array($exists->$hiddenvalue) ? $exists->$hiddenvalue : (string) $exists->$hiddenvalue;
201 - }
202 - }
100 + if ('select' === $type) {
101 + if (true === $mul) {
102 + $multipleValue = [];
103 + foreach (explode(',', $fieldValue) as $val) {
104 + $exists = get_post($val);
105 + if (false !== $exists) {
106 + $multipleValue[] = $exists->$hiddenvalue;
107 + }
108 + }
109 + $value = implode(',', $multipleValue);
110 + } else {
111 + $exists = get_post($fieldValue);
112 + if (false !== $exists) {
113 + $value = is_array($exists->$hiddenvalue) ? $exists->$hiddenvalue : (string) $exists->$hiddenvalue;
114 + }
115 + }
116 + } elseif ('radio' === $type || 'check' === $type) {
117 + if (is_array(json_decode($fieldValue))) {
118 + $multipleValues = [];
119 + foreach (json_decode($fieldValue) as $value) {
120 + $exists = get_post($value);
121 + if (false !== $exists) {
122 + $multipleValues[] = $exists->$hiddenvalue;
123 + }
124 + }
125 + $value = wp_json_encode($multipleValues);
126 + } else {
127 + $exists = get_post($fieldValue);
128 + if (false !== $exists) {
129 + $value = $exists->$hiddenvalue;
130 + }
131 + }
132 + }
133 + return $value;
134 + }
203 135
204 - } else if ($type == "radio" || $type == "check") {
136 + public function getUserFieldValue($type, $fieldValue, $mul, $hiddenvalue)
137 + {
138 + $value = '';
139 + if ('select' === $type) {
140 + if (true === $mul) {
141 + $multipleValue = [];
142 + foreach (explode(',', $fieldValue) as $val) {
143 + $exists = get_user_by('ID', $val);
144 + if (false !== $exists) {
145 + $multipleValue[] = $exists->data->$hiddenvalue;
146 + }
147 + }
148 + $value = implode(',', $multipleValue);
149 + } else {
150 + $exists = get_user_by('ID', $fieldValue);
151 + if (false !== $exists) {
152 + $value = is_array($exists->data->$hiddenvalue) ? $exists->data->$hiddenvalue : (string) $exists->data->$hiddenvalue;
153 + }
154 + }
155 + } elseif ('radio' === $type || 'check' === $type) {
156 + if (is_array(json_decode($fieldValue))) {
157 + $multipleValues = [];
158 + foreach (json_decode($fieldValue) as $value) {
159 + $exists = get_user_by('ID', $value);
160 + if (false !== $exists) {
161 + $multipleValues[] = $exists->data->$hiddenvalue;
162 + }
163 + }
164 + $value = wp_json_encode($multipleValues);
165 + } else {
166 + $exists = get_user_by('ID', $fieldValue);
167 + if (false !== $exists) {
168 + $value = $exists->data->$hiddenvalue;
169 + }
170 + }
171 + }
172 + return $value;
173 + }
205 174
206 - if (is_array(json_decode($fieldValue))) {
207 - $multipleValues = [];
208 - foreach (json_decode($fieldValue) as $value) {
209 - $exists = get_term_by('term_taxonomy_id', $value);
210 - if ($exists != false) {
211 - $multipleValues[] = $exists->$hiddenvalue;
212 - }
213 - }
214 - $value = json_encode($multipleValues);
215 - } else {
216 - $exists = get_term_by('term_taxonomy_id', $fieldValue);
217 - if ($exists != false) {
218 - $value = $exists->$hiddenvalue;
219 - }
220 - }
221 -
175 + public function getTermFieldValue($type, $fieldValue, $mul, $hiddenvalue)
176 + {
177 + $value = '';
178 + if ('select' === $type) {
179 + if (true === $mul) {
180 + $multipleValue = [];
181 + foreach (explode(',', $fieldValue) as $val) {
182 + $exists = get_term_by('term_taxonomy_id', $val);
183 + if (false !== $exists) {
184 + $multipleValue[] = $exists->$hiddenvalue;
185 + }
222 186 }
223 - return $value;
187 + $value = implode(',', $multipleValue);
188 + } else {
189 + $exists = get_term_by('term_taxonomy_id', $fieldValue);
190 + if (false !== $exists) {
191 + $value = is_array($exists->$hiddenvalue) ? $exists->$hiddenvalue : (string) $exists->$hiddenvalue;
192 + }
193 + }
194 + } elseif ('radio' === $type || 'check' === $type) {
195 + if (is_array(json_decode($fieldValue))) {
196 + $multipleValues = [];
197 + foreach (json_decode($fieldValue) as $value) {
198 + $exists = get_term_by('term_taxonomy_id', $value);
199 + if (false !== $exists) {
200 + $multipleValues[] = $exists->$hiddenvalue;
201 + }
202 + }
203 + $value = wp_json_encode($multipleValues);
204 + } else {
205 + $exists = get_term_by('term_taxonomy_id', $fieldValue);
206 + if (false !== $exists) {
207 + $value = $exists->$hiddenvalue;
208 + }
209 + }
224 210 }
211 + return $value;
212 + }
225 213 }