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/AdminFormHandler.php +149 -230 -3.0.12.15.3 View file →
@@ -26,9 +26,8 @@
26 26 use BitCode\BitForm\Core\Util\FileHandler;
27 27 use BitCode\BitForm\Core\Util\FormDuplicateHelper;
28 28 use BitCode\BitForm\Core\Util\HttpHelper;
29 29 use BitCode\BitForm\Core\Util\IpTool;
30 -use BitCode\BitForm\Core\Util\Log;
31 30 use BitCode\BitForm\Core\Util\Utilities;
32 31 use BitCode\BitForm\Core\WorkFlow\WorkFlow;
33 32 use BitCode\BitForm\Core\WorkFlow\WorkFlowHandler;
34 33 use WP_Error;
@@ -72,12 +71,14 @@
72 71 $this->createFormStylesDirIfNotExists();
73 72
74 73 if (
75 74 file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
76 - && wp_is_writable(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
75 + && is_writable(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
77 76 ) {
78 - $filePath = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . $sheetName;
79 - return FileHandler::writeFile($filePath, $styles);
77 + $createStyleFile = fopen(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . $sheetName, 'w');
78 + fwrite($createStyleFile, $styles);
79 + fclose($createStyleFile);
80 + return true;
80 81 }
81 82 return false;
82 83 }
83 84
@@ -153,12 +154,14 @@
153 154 $this->createFormStylesDirIfNotExists();
154 155
155 156 if (
156 157 file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
157 - && wp_is_writable(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
158 + && is_writable(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
158 159 ) {
159 - $filePath = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . $sheetName;
160 - return FileHandler::writeFile($filePath, $formStyle);
160 + $createStyleFile = fopen(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . $sheetName, 'w');
161 + fwrite($createStyleFile, $formStyle);
162 + fclose($createStyleFile);
163 + return true;
161 164 }
162 165 return false;
163 166 }
164 167
@@ -192,8 +195,17 @@
192 195 if ($formManager->isExist()) {
193 196 return new WP_Error('empty_form', __('Error Occurred, Please Reload', 'bit-form'));
194 197 }
195 198
199 + if (!class_exists('BitCode\\BitFormPro\\Plugin')) {
200 + if (!empty($workFlows) && count($workFlows) > 2) {
201 + return new WP_Error(
202 + 'free_limit',
203 + __('You are allowed to add maximum 2 workflows ', 'bit-form')
204 + );
205 + }
206 + }
207 +
196 208 if (isset($post->formStyle) && $post->formStyle) {
197 209 $sheetName = 'bitform-' . $post->form_id . '.css';
198 210 $this->saveStyleSheet($post->formStyle, $sheetName);
199 211 }
@@ -199,14 +211,13 @@
199 211 }
200 212
201 213 if (isset($post->layoutChanged) && $post->layoutChanged) {
202 214 $sheetName = 'bitform-layout-' . $post->form_id . '.css';
203 - $rowHeight = (int) $post->rowHeight;
215 + $rowHeight = (int)$post->rowHeight;
204 216 $this->saveLayoutStyleSheet($post->layout, $sheetName, $rowHeight);
205 217 }
206 218
207 219 $fields = wp_unslash($post->fields);
208 - $fields = Helpers::replaceFieldsDefaultErrorMsg($fields);
209 220 // $fields = $post->fields;
210 221 $layout = wp_unslash($post->layout);
211 222 $nestedLayout = isset($post->nestedLayouts) ? wp_unslash($post->nestedLayouts) : (object) [];
212 223 $formInfo = wp_unslash($post->formInfo);
@@ -308,11 +319,10 @@
308 319 return $save_status;
309 320 } elseif (!$save_status) {
310 321 return false;
311 322 } else {
312 - FileHandler::createIndexFile(BITFORMS_UPLOAD_DIR . "/$save_status");
323 + wp_mkdir_p(BITFORMS_UPLOAD_DIR . "/$save_status");
313 324 $formID = $save_status;
314 - do_action('bitform_admin_form_changed');
315 325 $integartionIDForWorkflow = [];
316 326 // Confiramtion Message [start]
317 327 if (!empty($formSettings->confirmation->type->successMsg)) {
318 328 $successMessages = $formSettings->confirmation->type->successMsg;
@@ -335,10 +345,10 @@
335 345 'builderSettings' => $builderSettings
336 346 ];
337 347 $update_status = static::$formModel->update(
338 348 [
339 - 'builder_helper_state' => \wp_json_encode($builder_helper_state),
340 - 'atomic_class_map' => $atomic_class_map,
349 + 'builder_helper_state' => \wp_json_encode($builder_helper_state),
350 + 'atomic_class_map' => $atomic_class_map,
341 351 ],
342 352 [
343 353 'id' => $formID,
344 354 ]
@@ -410,16 +420,8 @@
410 420 $integartionIDForWorkflow[$integrationType][$integIdx] = $savedID;
411 421 }
412 422 }
413 423 }
414 - if (isset($formSettings->formAbandonment)) {
415 - $formAbandonment = $formSettings->formAbandonment;
416 -
417 - $integrationName = 'formAbandonment';
418 - $integrationType = 'formAbandonment';
419 - $abandonmentIntegDetails = wp_json_encode($formAbandonment);
420 - $integrationHandler->saveIntegration($integrationName, $integrationType, $abandonmentIntegDetails, 'formAbandonment');
421 - }
422 424 if (!empty($integrations)) {
423 425 foreach ($integrations as $singleIntegrationKey => $singleIntegrationDetail) {
424 426 $integrationName = $singleIntegrationDetail->name;
425 427 unset($singleIntegrationDetail->name);
@@ -457,9 +459,9 @@
457 459 // }
458 460 }
459 461 //wrokFlows [end]
460 462 $details = [
461 - 'report_name' => __('All Entries', 'bit-form'),
463 + 'report_name' => 'All Entries',
462 464 'hiddenColumns' => ['__user_id', '__user_ip', '__referer', '__user_device', '__created_at', '__updated_at'],
463 465 'pageSize' => 10,
464 466 'sortBy' => [],
465 467 'filters' => [],
@@ -519,14 +521,13 @@
519 521 if (property_exists($post, 'builderSettings')) {
520 522 $builder_helper_state->builderSettings = $post->builderSettings;
521 523 }
522 524 if (property_exists($post, 'atomicClassMap')) {
523 - $atomic_class_map = \wp_json_encode((object) $post->atomicClassMap);
525 + $atomic_class_map = \wp_json_encode((object)$post->atomicClassMap);
524 526 }
525 527
526 528 if (property_exists($post, 'fields') && null !== $post->fields && property_exists($post, 'layout') && $post->layout) {
527 529 $fields = wp_unslash($post->fields);
528 - $fields = Helpers::replaceFieldsDefaultErrorMsg($fields);
529 530 $layout = wp_unslash($post->layout);
530 531 $nestedLayout = wp_unslash($post->nestedLayouts);
531 532 $formInfo = wp_unslash($post->formInfo);
532 533 $formID = wp_unslash($post->id);
@@ -546,8 +547,17 @@
546 547 if (empty($fields) || empty($layout) || is_null($formID)) {
547 548 return new WP_Error('empty_form', 'Can not update empty form.');
548 549 }
549 550
551 + if (!class_exists('BitCode\\BitFormPro\\Plugin')) {
552 + if (count($workFlows) > 2) {
553 + return new WP_Error(
554 + 'free_limit',
555 + __('You are allowed to add maximum 2 workflows ', 'bit-form')
556 + );
557 + }
558 + }
559 +
550 560 $form_content = [
551 561 'fields' => $fields,
552 562 'layout' => $layout,
553 563 'nestedLayout' => $nestedLayout,
@@ -741,12 +751,12 @@
741 751
742 752 $fieldNames['__user_id'] = __('User', 'bit-form');
743 753 $fieldNames['__user_ip'] = __('IP address', 'bit-form');
744 754 // $fieldNames['__user_location'] = __('');
745 - $fieldNames['__referer'] = __('Refer URL', 'bit-form');
746 - $fieldNames['__user_device'] = __('Device', 'bit-form');
747 - $fieldNames['__created_at'] = __('Created Time', 'bit-form');
748 - $fieldNames['__updated_at'] = __('Modified Time', 'bit-form');
755 + $fieldNames['__referer'] = __('Refer URL');
756 + $fieldNames['__user_device'] = __('Device');
757 + $fieldNames['__created_at'] = __('Created Time');
758 + $fieldNames['__updated_at'] = __('Modified Time');
749 759
750 760 $reportIsDefault = null;
751 761 if (isset($form_content['report_id'])) {
752 762 $validDateReport = $reportsModel->validateReportFields($reports, $fieldNames);
@@ -798,9 +808,9 @@
798 808 'form_name' => $form_name,
799 809 'form_content' => $form_content,
800 810 'user_id' => $user_details['id'],
801 811 'user_ip' => $user_details['ip'],
802 - 'builder_helper_state' => \wp_json_encode((object) $builder_helper_state),
812 + 'builder_helper_state' => \wp_json_encode((object)$builder_helper_state),
803 813 'generated_script_page_ids' => \wp_json_encode((object) []),
804 814 'user_device' => $user_details['device'],
805 815 'updated_at' => $user_details['time'],
806 816 ];
@@ -806,16 +816,15 @@
806 816 ];
807 817 if (isset($atomic_class_map)) {
808 818 $updateData['atomic_class_map'] = $atomic_class_map;
809 819 }
810 - $formUpdateVersion = get_option('bitform_form_update_version');
820 + $formUpdateVersion = get_option('bit-form_form_update_version');
811 821 if (!$formUpdateVersion) {
812 822 $formUpdateVersion = 1;
813 823 } else {
814 824 $formUpdateVersion = (int) $formUpdateVersion + 1;
815 825 }
816 - update_option('bitform_form_update_version', $formUpdateVersion);
817 - do_action('bitform_admin_form_changed');
826 + update_option('bit-form_form_update_version', $formUpdateVersion);
818 827
819 828 $update_status = static::$formModel->update(
820 829 $updateData,
821 830 [
@@ -861,9 +870,8 @@
861 870 if (2 === $newData['reports']) {
862 871 $errorIN .= empty($errorIN) ? 'reports' : ', reports';
863 872 }
864 873 if (!empty($errorIN)) {
865 - /* translators: %s: comma-separated list of areas where error occurred */
866 874 $updated_data['message'] = sprintf(__('Error Occured in saving %s', 'bit-form'), $errorIN);
867 875 return new WP_Error('Form update Error.', $updated_data);
868 876 }
869 877 if (null !== $reportIsDefault) {
@@ -868,9 +876,9 @@
868 876 }
869 877 if (null !== $reportIsDefault) {
870 878 $updated_data['form_content']['is_default'] = $reportIsDefault;
871 879 }
872 - $updated_data['message'] = __('Form updated successfully.', 'bit-form');
880 + $updated_data['message'] = __('Form updated successfully.', 'bitform');
873 881 return $updated_data;
874 882 }
875 883 }
876 884
@@ -875,23 +883,23 @@
875 883 }
876 884
877 885 public function setEmptyMetaValue($fieldkeys)
878 886 {
887 + $sqlEscaped = array_map(function ($fld) {
888 + return "'" . esc_sql($fld) . "'";
889 + }, $fieldkeys);
890 + $deletedFldKey = implode(',', $sqlEscaped);
879 891 global $wpdb;
880 - // Placeholders and arguments built dynamically from $fieldkeys; count matches at runtime.
881 - $placeholders = implode(',', array_fill(0, \count($fieldkeys), '%s'));
882 - $wpdb->query($wpdb->prepare(
883 - "UPDATE `{$wpdb->prefix}bitforms_form_entrymeta` SET meta_value = %s WHERE meta_key IN ($placeholders)",
884 - '',
885 - ...$fieldkeys
886 - ));
892 + $tablename = $wpdb->prefix . 'bitforms_form_entrymeta';
893 + $sql = $wpdb->prepare("UPDATE $tablename SET meta_value = %s WHERE meta_key IN ( " . $deletedFldKey . ')', '');
894 + $wpdb->query($sql);
887 895 }
888 896
889 897 public function changeFormStatus($Request, $post)
890 898 {
891 899 if (isset($Request['status']) && $Request['id']) {
892 - $status = sanitize_text_field(wp_unslash($Request['status']));
893 - $id = absint(wp_unslash($Request['id']));
900 + $status = wp_unslash($Request['status']);
901 + $id = wp_unslash($Request['id']);
894 902 } else {
895 903 $status = wp_unslash($post->status);
896 904 $id = wp_unslash($post->id);
897 905 }
@@ -925,10 +933,10 @@
925 933
926 934 public function changeBulkFormStatus($Request, $post)
927 935 {
928 936 if (isset($Request['status']) && $Request['formID']) {
929 - $status = sanitize_text_field(wp_unslash($Request['status']));
930 - $formID = array_map('absint', wp_unslash($Request['formID']));
937 + $status = wp_unslash($Request['status']);
938 + $formID = wp_unslash($Request['formID']);
931 939 } else {
932 940 $status = wp_unslash($post->status);
933 941 $formID = wp_unslash($post->formID);
934 942 }
@@ -963,13 +971,9 @@
963 971 public function getAllForm()
964 972 {
965 973 global $wpdb;
966 974
967 - // Direct query: table name interpolation only (no user input). $wpdb->prepare() cannot parameterize table names.
968 - $allForms = $wpdb->get_results("SELECT forms.id,forms.entries as fm_entries,forms.form_name,forms.status,forms.views,forms.created_at,COUNT(entries.id) as entries
969 - FROM `{$wpdb->prefix}bitforms_form` as forms
970 - LEFT JOIN `{$wpdb->prefix}bitforms_form_entries` as entries ON forms.id = entries.form_id
971 - GROUP BY forms.id");
975 + $allForms = $wpdb->get_results("SELECT forms.id,forms.entries as fm_entries,forms.form_name,forms.status,forms.views,forms.created_at,COUNT(entries.id) as entries FROM `{$wpdb->prefix}bitforms_form` as forms LEFT JOIN `{$wpdb->prefix}bitforms_form_entries` as entries ON forms.id = entries.form_id GROUP BY forms.id");
972 976
973 977 if (is_wp_error($allForms)) {
974 978 return $allForms;
975 979 } elseif (!$allForms) {
@@ -980,10 +984,10 @@
980 984 }
981 985
982 986 public function getAForm($Request, $post)
983 987 {
984 - if (!empty($Request['id'])) {
985 - $formID = absint(wp_unslash($Request['id']));
988 + if (isset($Request['id'])) {
989 + $formID = wp_unslash($Request['id']);
986 990 } else {
987 991 $formID = wp_unslash($post->id);
988 992 }
989 993 // return $post->fields;
@@ -1085,22 +1089,8 @@
1085 1089 );
1086 1090 }
1087 1091 }
1088 1092 }
1089 -
1090 - // get form abandonment integration if exist
1091 - $formAbandonmentInteg = $integrationHandler->getAllIntegration('formAbandonment', 'formAbandonment');
1092 - if (!is_wp_error($formAbandonmentInteg) && !empty($formAbandonmentInteg)) {
1093 - $formAbandonmentInteg = $formAbandonmentInteg[0];
1094 - if (!empty($formAbandonmentInteg->integration_details)) {
1095 - $formAbandonment = json_decode($formAbandonmentInteg->integration_details);
1096 - } else {
1097 - $formAbandonment = (object) [];
1098 - }
1099 - } else {
1100 - $formAbandonment = (object) [];
1101 - }
1102 -
1103 1093 $settingsContent = [
1104 1094 'formName' => $formManager->getFormName(),
1105 1095 'theme' => isset($form_content->theme) ? $form_content->theme : 'default',
1106 1096 'formPermissions' => isset($form_content->formPermissions) ? $form_content->formPermissions : (object) [],
@@ -1163,24 +1153,8 @@
1163 1153 'pdfTem' => [],
1164 1154 ]
1165 1155 );
1166 1156 }
1167 -
1168 - if (!empty($formAbandonment)) {
1169 - $settingsContent = array_merge(
1170 - $settingsContent,
1171 - [
1172 - 'formAbandonment' => $formAbandonment,
1173 - ]
1174 - );
1175 - } else {
1176 - $settingsContent = array_merge(
1177 - $settingsContent,
1178 - [
1179 - 'formAbandonment' => (object) [],
1180 - ]
1181 - );
1182 - }
1183 1157 $formSettings = [
1184 1158 'formSettings' => $settingsContent,
1185 1159 ];
1186 1160 $data = [
@@ -1195,9 +1169,8 @@
1195 1169 'additional' => empty($form_content->additional) ? [
1196 1170 'enabled' => [
1197 1171 'blocked_ip' => false,
1198 1172 'restrict_form' => false,
1199 - 'onePerIp' => false,
1200 1173 ],
1201 1174 'settings' => [
1202 1175 'restrict_form' => [
1203 1176 'day' => [],
@@ -1212,8 +1185,9 @@
1212 1185 ],
1213 1186 'entry_limit' => null,
1214 1187 'blocked_ip' => [],
1215 1188 ],
1189 + 'onePerIp' => false,
1216 1190 ] : $form_content->additional,
1217 1191 'created_at' => $formManager->getFormMetaData()['created_at'],
1218 1192 'views' => $formManager->getFormMetaData()['views'],
1219 1193 'entries' => $formManager->getFormMetaData()['entries'],
@@ -1254,9 +1228,9 @@
1254 1228 } else {
1255 1229 $returnedReportData[$reportKey]->details = [];
1256 1230 }
1257 1231 if ('1' === (string) $reportData->isDefault) {
1258 - $returnedReportData[$reportKey]->details->report_name = __('All Entries', 'bit-form');
1232 + $returnedReportData[$reportKey]->details->report_name = 'All Entries';
1259 1233 }
1260 1234 }
1261 1235 $reports = ['reports' => $returnedReportData];
1262 1236 $data = array_merge($data, $reports);
@@ -1270,10 +1244,10 @@
1270 1244 }
1271 1245
1272 1246 public function getAFormV1($Request, $post)
1273 1247 {
1274 - if (!empty($Request['id'])) {
1275 - $formID = absint(wp_unslash($Request['id']));
1248 + if (isset($Request['id'])) {
1249 + $formID = wp_unslash($Request['id']);
1276 1250 } else {
1277 1251 $formID = wp_unslash($post->id);
1278 1252 }
1279 1253 // return $post->fields;
@@ -1293,32 +1267,32 @@
1293 1267 'workFlowExist' => $form_content->workFlowExist,
1294 1268 'report_id' => isset($form_content->report_id) ? $form_content->report_id : null
1295 1269 ];
1296 1270 $successMessageHandler
1297 - = new SuccessMessageHandler($formID);
1271 + = new SuccessMessageHandler($formID);
1298 1272 $successMessages = $successMessageHandler->getAllMessage();
1299 1273 if (!is_wp_error($successMessages)) {
1300 1274 foreach ($successMessages as $sucessMessagekey => $sucessMessagevalue) {
1301 1275 $allConfirmation['type']['successMsg'][$sucessMessagekey] =
1302 - [
1303 - 'id' => $sucessMessagevalue->id,
1304 - 'title' => $sucessMessagevalue->message_title,
1305 - 'msg' => $sucessMessagevalue->message_content,
1306 - ];
1276 + [
1277 + 'id' => $sucessMessagevalue->id,
1278 + 'title' => $sucessMessagevalue->message_title,
1279 + 'msg' => $sucessMessagevalue->message_content,
1280 + ];
1307 1281 }
1308 1282 }
1309 1283 $emailTemplateHandler
1310 - = new EmailTemplateHandler($formID);
1284 + = new EmailTemplateHandler($formID);
1311 1285 $emailTemplates = $emailTemplateHandler->getAllTemplate();
1312 1286 if (!is_wp_error($emailTemplates)) {
1313 1287 foreach ($emailTemplates as $emailTemplatekey => $emailTemplatevalue) {
1314 1288 $mailTem[] =
1315 - [
1316 - 'id' => $emailTemplatevalue->id,
1317 - 'title' => $emailTemplatevalue->title,
1318 - 'sub' => $emailTemplatevalue->sub,
1319 - 'body' => $emailTemplatevalue->body,
1320 - ];
1289 + [
1290 + 'id' => $emailTemplatevalue->id,
1291 + 'title' => $emailTemplatevalue->title,
1292 + 'sub' => $emailTemplatevalue->sub,
1293 + 'body' => $emailTemplatevalue->body,
1294 + ];
1321 1295 }
1322 1296 }
1323 1297 $integrationHandler = new IntegrationHandler($formID);
1324 1298 $formIntegrations = $integrationHandler->getAllIntegration('form');
@@ -1339,9 +1313,9 @@
1339 1313 ];
1340 1314 $integrationData = array_merge($integrationData, $integration_details);
1341 1315 }
1342 1316 $allConfirmation['type'][$integrationValue->integration_type][]
1343 - = $integrationData;
1317 + = $integrationData;
1344 1318 } else {
1345 1319 $integrationData = [
1346 1320 'id' => $integrationValue->id,
1347 1321 'name' => $integrationValue->integration_name,
@@ -1349,10 +1323,10 @@
1349 1323 ];
1350 1324 $integrations[] = array_merge(
1351 1325 $integrationData,
1352 1326 is_string($integrationValue->integration_details) ?
1353 - (array) json_decode($integrationValue->integration_details) :
1354 - $integrationValue->integration_details
1327 + (array) json_decode($integrationValue->integration_details) :
1328 + $integrationValue->integration_details
1355 1329 );
1356 1330 }
1357 1331 }
1358 1332 }
@@ -1412,9 +1386,8 @@
1412 1386 'additional' => empty($form_content->additional) ? [
1413 1387 'enabled' => [
1414 1388 'blocked_ip' => false,
1415 1389 'restrict_form' => false,
1416 - 'onePerIp' => false,
1417 1390 ],
1418 1391 'settings' => [
1419 1392 'restrict_form' => [
1420 1393 'day' => [],
@@ -1429,8 +1402,9 @@
1429 1402 ],
1430 1403 'entry_limit' => null,
1431 1404 'blocked_ip' => [],
1432 1405 ],
1406 + 'onePerIp' => false,
1433 1407 ] : $form_content->additional,
1434 1408 'created_at' => $formManager->getFormMetaData()['created_at'],
1435 1409 'views' => $formManager->getFormMetaData()['views'],
1436 1410 'entries' => $formManager->getFormMetaData()['entries'],
@@ -1471,9 +1445,9 @@
1471 1445 } else {
1472 1446 $returnedReportData[$reportKey]->details = [];
1473 1447 }
1474 1448 if ('1' === (string) $reportData->isDefault) {
1475 - $returnedReportData[$reportKey]->details->report_name = __('All Entries', 'bit-form');
1449 + $returnedReportData[$reportKey]->details->report_name = 'All Entries';
1476 1450 }
1477 1451 }
1478 1452 $reports = ['reports' => $returnedReportData];
1479 1453 $data = array_merge($data, $reports);
@@ -1487,10 +1461,10 @@
1487 1461 }
1488 1462
1489 1463 public function deleteAForm($Request, $post)
1490 1464 {
1491 - if (!empty($Request['id'])) {
1492 - $formID = absint(wp_unslash($Request['id']));
1465 + if (isset($Request['id'])) {
1466 + $formID = wp_unslash($Request['id']);
1493 1467 } else {
1494 1468 $formID = wp_unslash($post->id);
1495 1469 }
1496 1470 if (is_null($formID)) {
@@ -1505,9 +1479,8 @@
1505 1479 [
1506 1480 'id' => $formID,
1507 1481 ]
1508 1482 );
1509 - do_action('bitform_admin_form_changed');
1510 1483
1511 1484 $successMessageModel = new SuccessMessageModel();
1512 1485 $deleteMsgStatus = $successMessageModel->delete(['form_id' => $formID]);
1513 1486
@@ -1563,10 +1536,10 @@
1563 1536 }
1564 1537
1565 1538 public function deleteBlukForm($Request, $post)
1566 1539 {
1567 - if (!empty($Request['formID'])) {
1568 - $formID = array_map('absint', wp_unslash($Request['formID']));
1540 + if (isset($Request['formID'])) {
1541 + $formID = wp_unslash($Request['formID']);
1569 1542 } else {
1570 1543 $formID = wp_unslash($post->formID);
1571 1544 }
1572 1545
@@ -1593,9 +1566,8 @@
1593 1566 [
1594 1567 'id' => $formID,
1595 1568 ]
1596 1569 );
1597 - do_action('bitform_admin_form_changed');
1598 1570
1599 1571 if (is_wp_error($delete_status)) {
1600 1572 wp_send_json_error($delete_status->get_error_message(), 400);
1601 1573 }
@@ -1642,14 +1614,8 @@
1642 1614 ]
1643 1615 );
1644 1616 }
1645 1617
1646 - // delete entry log and details; table name interpolation only — $wpdb->prepare() parameterizes the form_id value.
1647 - $wpdb->query($wpdb->prepare(
1648 - "DELETE em, e FROM `{$prefix}bitforms_form_log_details` AS em JOIN `{$prefix}bitforms_form_entry_log` AS e ON em.log_id = e.id WHERE e.form_id = %d",
1649 - $formID
1650 - ));
1651 -
1652 1618 $fileHandler = new FileHandler();
1653 1619 foreach ($formID as $fId) {
1654 1620 if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $fId)) {
1655 1621 $fileHandler->rmrf(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $fId);
@@ -1696,15 +1662,21 @@
1696 1662 if (!is_wp_error($duplicateResponse) || (is_wp_error($duplicateResponse) && 'result_empty' === $duplicateResponse->get_error_code())) {
1697 1663 // duplicate stylesheet
1698 1664 $style_dir = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR;
1699 1665 // layout style copy
1700 - $styleStr = FileHandler::readFile($style_dir . 'bitform-layout-' . $oldFormId . '.css');
1666 + $mainFormLayStyle = fopen($style_dir . 'bitform-layout-' . $oldFormId . '.css', 'r');
1667 + $styleStr = fread($mainFormLayStyle, filesize($style_dir . 'bitform-layout-' . $oldFormId . '.css'));
1701 1668 $newStyle = str_replace(".bf$oldFormId-", ".bf$newFormId-", $styleStr);
1702 - FileHandler::writeFile($style_dir . "bitform-layout-$newFormId.css", $newStyle);
1669 + $createStyleFile = fopen($style_dir . "bitform-layout-$newFormId.css", 'w');
1670 + fwrite($createStyleFile, $newStyle);
1671 + fclose($createStyleFile);
1703 1672 // style copy
1704 - $styleStr = FileHandler::readFile($style_dir . 'bitform-' . $oldFormId . '.css');
1673 + $mainFormStyle = fopen($style_dir . 'bitform-' . $oldFormId . '.css', 'r');
1674 + $styleStr = fread($mainFormStyle, filesize($style_dir . 'bitform-' . $oldFormId . '.css'));
1705 1675 $newStyle = str_replace("-$oldFormId", "-$newFormId", $styleStr);
1706 - FileHandler::writeFile($style_dir . "bitform-$newFormId.css", $newStyle);
1676 + $createStyleFile = fopen($style_dir . "bitform-$newFormId.css", 'w');
1677 + fwrite($createStyleFile, $newStyle);
1678 + fclose($createStyleFile);
1707 1679 $duplicatedForm = $this->getAForm(null, (object) ['id' => $newFormId]);
1708 1680 $duplicatedForm['message'] = __('Form duplicated successfully', 'bit-form');
1709 1681 return $duplicatedForm;
1710 1682 }
@@ -1717,15 +1689,15 @@
1717 1689 $newFormId = intval($post->newFormId);
1718 1690 if (!$oldFormId || empty($post->formDetail->fields) || empty($post->formDetail->layout)) {
1719 1691 return new WP_Error('invalid_form', __('Please import a valid json.', 'bit-form'));
1720 1692 }
1721 - $importtedForm = (array) $post->formDetail;
1693 + $importtedForm = (array)$post->formDetail;
1722 1694 $importtedForm['form_content']['fields'] = $importtedForm['fields'];
1723 1695 $importtedForm['form_content']['layout'] = $importtedForm['layout'];
1724 1696 $importtedForm['form_content']['nestedLayout'] = $importtedForm['nestedLayouts'];
1725 1697 $importtedForm['form_content']['formInfo'] = $importtedForm['formInfo'];
1726 1698 unset($importtedForm['fields'], $importtedForm['layout'], $importtedForm['nestedLayout'], $importtedForm['formInfo']);
1727 - $formData = FormDuplicateHelper::createReplica((array) $importtedForm, $oldFormId, $newFormId);
1699 + $formData = FormDuplicateHelper::createReplica((array)$importtedForm, $oldFormId, $newFormId);
1728 1700
1729 1701 if (!empty($importtedForm['rowHeight'])) {
1730 1702 $formData->rowHeight = $importtedForm['rowHeight'];
1731 1703 }
@@ -1812,9 +1784,9 @@
1812 1784 return new WP_Error('empty_form', __('Form does not exists.', 'bit-form'));
1813 1785 }
1814 1786
1815 1787 $newFormId = $oldFormId;
1816 - $duplicatedForm = $this->getAForm($Request, (object) ['id' => $oldFormId]);
1788 + $duplicatedForm = $this->getAForm($Request, (object)['id' => $oldFormId]);
1817 1789 $formData = FormDuplicateHelper::createReplica($duplicatedForm, $oldFormId, $newFormId);
1818 1790 // for custom css
1819 1791 $customCssPath = 'form-styles/bitform-custom-' . $newFormId . '.css';
1820 1792 $cssPath = Helpers::generatePathDirOrFile($customCssPath);
@@ -1834,10 +1806,10 @@
1834 1806 }
1835 1807
1836 1808 public function getFormEntryLabelAndCount($Request, $post)
1837 1809 {
1838 - if (!empty($Request['id'])) {
1839 - $id = absint(wp_unslash($Request['id']));
1810 + if (isset($Request['id'])) {
1811 + $id = wp_unslash($Request['id']);
1840 1812 } else {
1841 1813 $id = wp_unslash($post->id);
1842 1814 }
1843 1815 if (is_null($id)) {
@@ -1892,15 +1864,14 @@
1892 1864 }
1893 1865
1894 1866 public function getFormEntry($Request, $post)
1895 1867 {
1896 - if (!empty($Request['id'])) {
1897 - $id = absint(wp_unslash($Request['id']));
1868 + if (isset($Request['id'])) {
1869 + $id = wp_unslash($Request['id']);
1898 1870 $offset = isset($Request['offset']) ?
1899 1871 wp_unslash($Request['offset']) : 0;
1900 1872 $pageSize = isset($Request['pageSize']) ?
1901 1873 wp_unslash($Request['pageSize']) : 10;
1902 - $queryCondition = isset($Request['queryCondition']) ? wp_unslash($Request['queryCondition']) : ['form_id' => $id];
1903 1874 } else {
1904 1875 $id = wp_unslash($post->id);
1905 1876 $conditions = isset($post->conditions) ? wp_unslash($post->conditions) : [];
1906 1877 $dateBetweenFilter = isset($post->entriesFilterByDate) ? wp_unslash($post->entriesFilterByDate) : [];
@@ -1909,9 +1880,8 @@
1909 1880 $filters = isset($post->filters) ? wp_unslash($post->filters) : null;
1910 1881 $globalFilter = isset($post->globalFilter) ? wp_unslash($post->globalFilter) : null;
1911 1882 $pageSize = isset($post->pageSize) ?
1912 1883 wp_unslash($post->pageSize) : 10;
1913 - $queryCondition = isset($post->queryCondition) ? wp_unslash($post->queryCondition) : ['form_id' => $id];
1914 1884 }
1915 1885 if (is_null($id)) {
1916 1886 return new WP_Error('empty_form', __('Form id is empty.', 'bit-form'));
1917 1887 }
@@ -1918,12 +1888,15 @@
1918 1888 $formManager = new AdminFormManager($id);
1919 1889 if (!$formManager->isExist()) {
1920 1890 return new WP_Error('empty_form', __('Form does not exists', 'bit-form'));
1921 1891 }
1892 +
1922 1893 $formEntry = new FormEntryModel();
1923 1894 $entries = $formEntry->get(
1924 1895 'id',
1925 - $queryCondition,
1896 + [
1897 + 'form_id' => $id,
1898 + ],
1926 1899 null,
1927 1900 null,
1928 1901 'created_at',
1929 1902 'DESC'
@@ -1962,14 +1935,10 @@
1962 1935 $entryMeta = new FormEntryMetaModel();
1963 1936 // $formEntry = new FormEntryModel();
1964 1937
1965 1938 $entries = $entryMeta->getSingleEntryMeta($formFields, $entryId);
1939 + return $entries[0];
1966 1940
1967 - if (!is_wp_error($entries)) {
1968 - return $entries[0];
1969 - }
1970 - return new WP_Error('entry_not_fonud', __('Entry Not Found!', 'bit-form'));
1971 -
1972 1941 // $customFieldHandler = new CustomFieldHandler();
1973 1942 // $formEntries = $customFieldHandler->updatedEntries($formEntries, $fieldDetails);
1974 1943 // return $formEntries;
1975 1944 }
@@ -1975,10 +1944,10 @@
1975 1944 }
1976 1945
1977 1946 public function getEntriesForReport($Request, $post)
1978 1947 {
1979 - if (!empty($Request['id'])) {
1980 - $id = absint(wp_unslash($Request['id']));
1948 + if (isset($Request['id'])) {
1949 + $id = wp_unslash($Request['id']);
1981 1950 $offset = isset($Request['offset']) ?
1982 1951 wp_unslash($Request['offset']) : null;
1983 1952 $pageSize = isset($Request['pageSize']) ?
1984 1953 wp_unslash($Request['pageSize']) : null;
@@ -2039,9 +2008,8 @@
2039 2008 {
2040 2009 $formId = wp_unslash($post->formId);
2041 2010 $fileFormate = isset($post->fileFormate) ? wp_unslash($post->fileFormate) : null;
2042 2011 $limit = isset($post->limit) ? wp_unslash($post->limit) : null;
2043 - $entryCondition = isset($post->filter) ? wp_unslash($post->filter) : null;
2044 2012 $sortBy = isset($post->sort) ? wp_unslash($post->sort) : 'ASC';
2045 2013 $sortByField = isset($post->sortField) ? wp_unslash($post->sortField) : 'bitforms_form_entry_id';
2046 2014 $formFields = json_decode($post->selectedField);
2047 2015 if (is_null($formId)) {
@@ -2074,17 +2042,17 @@
2074 2042 return $entries;
2075 2043 }
2076 2044 $entryMeta = new FormEntryMetaModel();
2077 2045 $filter = [];
2078 - $formEntries = $entryMeta->getExportEntry($formFields, $entries, $formId, $fieldLabels, $limit, $sortBy, $sortByField, $offset, $entryCondition);
2046 + $formEntries = $entryMeta->getExportEntry($formFields, $entries, $formId, $fieldLabels, $limit, $sortBy, $sortByField);
2079 2047 return $formEntries;
2080 2048 }
2081 2049
2082 2050 public function deleteBlukFormEntries($Request, $post)
2083 2051 {
2084 - if (!empty($Request['formID'])) {
2085 - $formID = absint(wp_unslash($Request['formID']));
2086 - $entries = array_map('absint', wp_unslash($Request['entries']));
2052 + if (isset($Request['formID'])) {
2053 + $formID = wp_unslash($Request['formID']);
2054 + $entries = wp_unslash($Request['entries']);
2087 2055 } else {
2088 2056 $formID = wp_unslash($post->formID);
2089 2057 $entries = wp_unslash($post->entries);
2090 2058 }
@@ -2104,18 +2072,16 @@
2104 2072 if (!$formManager->isExist()) {
2105 2073 return new WP_Error('empty_form', __('Form does not exist.', 'bit-form'));
2106 2074 }
2107 2075 $workFlowRunHelper = new WorkFlow($formID);
2108 -
2109 2076 $workFlowreturnedOnDelete = $workFlowRunHelper->executeOnDelete(
2110 2077 $formManager,
2111 2078 $formID,
2112 2079 $entries
2113 2080 );
2114 -
2115 2081 if (isset($workFlowreturnedOnDelete['entries'])) {
2116 2082 if (0 === count($workFlowreturnedOnDelete['entries'])) {
2117 - return ['message' => __('Entry Deletetion prevented by workflow', 'bit-form')];
2083 + return ['message' => __('Entry Deletetion prevented by workflow', 'bit-form')];
2118 2084 } elseif (count($workFlowreturnedOnDelete['entries']) === count($entries)) {
2119 2085 $message = __('Entry Deleted successfully', 'bit-form');
2120 2086 } else {
2121 2087 $result['prevented'] = array_diff($entries, $workFlowreturnedOnDelete['entries']);
@@ -2136,9 +2102,9 @@
2136 2102 );
2137 2103 if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID)) {
2138 2104 $fileHandler = new FileHandler();
2139 2105 foreach ($entries as $enrtyKey => $entryID) {
2140 - $fileEntries = $fileHandler->getEntriesFileUploadDir($formID, $entryID);
2106 + $fileEntries = BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID . DIRECTORY_SEPARATOR . $entryID;
2141 2107 if (file_exists($fileEntries)) {
2142 2108 $fileHandler->rmrf($fileEntries);
2143 2109 }
2144 2110 }
@@ -2157,11 +2123,11 @@
2157 2123 }
2158 2124
2159 2125 public function duplicateFormEntry($Request, $post)
2160 2126 {
2161 - if (!empty($Request['formID'])) {
2162 - $formID = absint(wp_unslash($Request['formID']));
2163 - $entries = array_map('absint', wp_unslash($Request['entries']));
2127 + if (isset($Request['formID'])) {
2128 + $formID = wp_unslash($Request['formID']);
2129 + $entries = wp_unslash($Request['entries']);
2164 2130 } else {
2165 2131 $formID = wp_unslash($post->formID);
2166 2132 $entries = wp_unslash($post->entries);
2167 2133 }
@@ -2210,12 +2176,12 @@
2210 2176 );
2211 2177 if ($duplicate_status) {
2212 2178 $result['details'][$entryID] = $duplicatedEntryId;
2213 2179 $duplicate_count = $duplicate_count + 1;
2214 - if (file_exists(FileHandler::getEntriesFileUploadDir($formID, $entryID))) {
2180 + if (file_exists(BITFORMS_UPLOAD_DIR . "/$formID/$entryID")) {
2215 2181 $fileHandler->cpyr(
2216 - FileHandler::getEntriesFileUploadDir($formID, $entryID),
2217 - FileHandler::getEntriesFileUploadDir($formID, $duplicatedEntryId)
2182 + BITFORMS_UPLOAD_DIR . "/$formID/$entryID",
2183 + BITFORMS_UPLOAD_DIR . "/$formID/$duplicatedEntryId"
2218 2184 );
2219 2185 }
2220 2186 }
2221 2187 }
@@ -2232,11 +2198,11 @@
2232 2198 }
2233 2199
2234 2200 public function editFormEntry($Request, $post)
2235 2201 {
2236 - if (!empty($Request['formID'])) {
2237 - $formID = absint(wp_unslash($Request['formID']));
2238 - $entryID = absint(wp_unslash($Request['entryID']));
2202 + if (isset($Request['formID'])) {
2203 + $formID = wp_unslash($Request['formID']);
2204 + $entryID = wp_unslash($Request['entryID']);
2239 2205 } else {
2240 2206 $formID = wp_unslash($post->formID);
2241 2207 $entryID = wp_unslash($post->entryID);
2242 2208 }
@@ -2311,16 +2277,15 @@
2311 2277
2312 2278 public function updateFormEntry($Request, $post)
2313 2279 {
2314 2280 if (isset($Request['formID'], $Request['entryID'])) {
2315 - $formID = absint(wp_unslash($Request['formID']));
2316 - $entryID = absint(wp_unslash($Request['entryID']));
2281 + $formID = wp_unslash($Request['formID']);
2282 + $entryID = wp_unslash($Request['entryID']);
2317 2283 unset($Request['action'], $Request['formID'], $Request['entryID']);
2318 2284 }
2319 2285 $formManager = new AdminFormManager($formID);
2320 2286 $formManager->fieldNameReplaceOfPost();
2321 - // Called from AdminAjax handler; nonce already verified at AJAX entry before dispatch.
2322 - $updatedValue = is_array($post) ? $post : wp_unslash($_POST);
2287 + $updatedValue = wp_unslash($_POST);
2323 2288
2324 2289 if (is_null($updatedValue) || !is_array($updatedValue)) {
2325 2290 return new WP_Error('empty_data', __('Failed to update, Data is empty.', 'bit-form'));
2326 2291 }
@@ -2336,11 +2301,11 @@
2336 2301 }
2337 2302
2338 2303 public function getLogHistory($Request, $post)
2339 2304 {
2340 - if (!empty($Request['formID'])) {
2341 - $formID = absint(wp_unslash($Request['formID']));
2342 - $entryID = absint(wp_unslash($Request['entryID']));
2305 + if (isset($Request['formID'])) {
2306 + $formID = wp_unslash($Request['formID']);
2307 + $entryID = wp_unslash($Request['entryID']);
2343 2308 } else {
2344 2309 $formID = wp_unslash($post->formID);
2345 2310 $entryID = wp_unslash($post->entryID);
2346 2311 }
@@ -2360,10 +2325,10 @@
2360 2325 }
2361 2326
2362 2327 public function importDataStore($Request, $post)
2363 2328 {
2364 - if (!empty($Request['formID'])) {
2365 - $formID = absint(wp_unslash($Request['formID']));
2329 + if (isset($Request['formID'])) {
2330 + $formID = wp_unslash($Request['formID']);
2366 2331 } else {
2367 2332 $formID = wp_unslash($post->formID);
2368 2333 }
2369 2334 if (is_null($formID)) {
@@ -2375,14 +2340,10 @@
2375 2340 {
2376 2341 $pages = get_pages(['post_status' => 'publish', 'sort_column' => 'post_date', 'sort_order' => 'desc']);
2377 2342 $allPages = [];
2378 2343 foreach ($pages as $pageKey => $pageDetails) {
2379 - // $allPages[$pageKey]['title'] = $pageDetails->post_title;
2380 - // $allPages[$pageKey]['url'] = get_page_link($pageDetails->ID);
2381 - $allPages[] = (object) [
2382 - 'title' => $pageDetails->post_title,
2383 - 'url' => get_page_link($pageDetails->ID)
2384 - ];
2344 + $allPages[$pageKey]['title'] = $pageDetails->post_title;
2345 + $allPages[$pageKey]['url'] = get_page_link($pageDetails->ID);
2385 2346 }
2386 2347 return $allPages;
2387 2348 }
2388 2349
@@ -2387,11 +2348,11 @@
2387 2348 }
2388 2349
2389 2350 public function deleteAIntegration($Request, $post)
2390 2351 {
2391 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2392 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2393 - $id = absint(wp_unslash($Request['id']));
2352 + if (isset($Request['formID']) && $Request['id']) {
2353 + $formID = json_decode(wp_unslash($Request['formID']));
2354 + $id = wp_unslash($Request['id']);
2394 2355 } else {
2395 2356 $formID = wp_unslash($post->formID);
2396 2357 $id = wp_unslash($post->id);
2397 2358 }
@@ -2411,11 +2372,11 @@
2411 2372 }
2412 2373
2413 2374 public function deleteSuccessMessage($Request, $post)
2414 2375 {
2415 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2416 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2417 - $id = absint(wp_unslash($Request['id']));
2376 + if (isset($Request['formID']) && $Request['id']) {
2377 + $formID = json_decode(wp_unslash($Request['formID']));
2378 + $id = wp_unslash($Request['id']);
2418 2379 } else {
2419 2380 $formID = wp_unslash($post->formID);
2420 2381 $id = wp_unslash($post->id);
2421 2382 }
@@ -2434,11 +2395,11 @@
2434 2395 }
2435 2396
2436 2397 public function deleteAWorkflow($Request, $post)
2437 2398 {
2438 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2439 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2440 - $id = absint(wp_unslash($Request['id']));
2399 + if (isset($Request['formID']) && $Request['id']) {
2400 + $formID = json_decode(wp_unslash($Request['formID']));
2401 + $id = wp_unslash($Request['id']);
2441 2402 } else {
2442 2403 $formID = wp_unslash($post->formID);
2443 2404 $id = wp_unslash($post->id);
2444 2405 }
@@ -2456,11 +2417,11 @@
2456 2417 }
2457 2418
2458 2419 public function deleteAMailTemplate($Request, $post)
2459 2420 {
2460 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2461 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2462 - $id = absint(wp_unslash($Request['id']));
2421 + if (isset($Request['formID']) && $Request['id']) {
2422 + $formID = json_decode(wp_unslash($Request['formID']));
2423 + $id = wp_unslash($Request['id']);
2463 2424 } else {
2464 2425 $formID = wp_unslash($post->formID);
2465 2426 $id = wp_unslash($post->id);
2466 2427 }
@@ -2478,11 +2439,11 @@
2478 2439 }
2479 2440
2480 2441 public function duplicateAMailTemplate($Request, $post)
2481 2442 {
2482 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2483 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2484 - $id = absint(wp_unslash($Request['id']));
2443 + if (isset($Request['formID']) && $Request['id']) {
2444 + $formID = json_decode(wp_unslash($Request['formID']));
2445 + $id = wp_unslash($Request['id']);
2485 2446 } else {
2486 2447 $formID = wp_unslash($post->formID);
2487 2448 $id = wp_unslash($post->id);
2488 2449 }
@@ -2641,9 +2602,9 @@
2641 2602 $paySetting = json_decode($paySetting);
2642 2603 }
2643 2604
2644 2605 $canSave = null;
2645 - switch ($paySetting->type) {
2606 + switch($paySetting->type) {
2646 2607 case 'PayPal':
2647 2608 $canSave = $this->addWebhookToPaypal($paySetting);
2648 2609 break;
2649 2610 case 'Razorpay':
@@ -2744,16 +2705,15 @@
2744 2705 }
2745 2706 }
2746 2707
2747 2708 $data = [
2748 - 'enabled_events[]' => 'payment_intent.succeeded',
2749 - 'url' => $webhook_url,
2709 + 'enabled_events[]' => 'payment_intent.succeeded',
2710 + 'url' => $webhook_url,
2750 2711 ];
2751 2712
2752 2713 if (!$webhook_already_exist) {
2753 2714 $webhook_response = HttpHelper::post($create_webhook_url, $data, $headers);
2754 2715 if (is_wp_error($webhook_response) || (isset($webhook_response->error) && $webhook_response->error)) {
2755 - Log::debug_log(['Stripe webhook creation failed' => $webhook_response]);
2756 2716 return null;
2757 2717 }
2758 2718 }
2759 2719 return true;
@@ -2793,49 +2753,8 @@
2793 2753 } elseif (!$update_status) {
2794 2754 return new WP_Error('empty_form', __('Form update failed.', 'bit-form'));
2795 2755 } else {
2796 2756 return true;
2797 - }
2798 - }
2799 -
2800 - public function replaceAllFormsErrorMessagesByGlobalMessages()
2801 - {
2802 - try {
2803 - $formModel = new FormModel();
2804 - $allForms = $formModel->get(['id', 'form_content']);
2805 -
2806 - foreach ($allForms as $form) {
2807 - // Decode form_content JSON to stdClass
2808 - $formContent = \json_decode($form->form_content);
2809 - $fields = $formContent->fields ?? null;
2810 - // If decode fails, skip to next
2811 - if (!$fields) {
2812 - Log::debug_log("Form ID {$form->id}: invalid JSON in form_content");
2813 - continue;
2814 - }
2815 -
2816 - // Replace default error messages using your helper
2817 - $updatedFields = Helpers::replaceFieldsDefaultErrorMsg($fields);
2818 -
2819 - $formContent->fields = $updatedFields;
2820 - // Encode back to JSON
2821 - $updatedContent = \json_encode($formContent);
2822 -
2823 - if (false === $updatedContent) {
2824 - Log::debug_log("Form ID {$form->id}: JSON encoding failed");
2825 - continue;
2826 - }
2827 - // Update form content in DB
2828 - $formModel->update(
2829 - ['form_content' => $updatedContent], // data to update
2830 - ['id' => $form->id] // condition for update
2831 - );
2832 - }
2833 - } catch (\Exception $e) {
2834 - Log::debug_log([
2835 - 'message' => 'Error in updateAllFormsErrorMessagesWithGlobalMessages',
2836 - 'error' => $e->getMessage(),
2837 - ]);
2838 2757 }
2839 2758 }
2840 2759
2841 2760 public function updateSuccessMessageClassName($str, $msgIdx, $msgId)