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
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
← All changes | includes/Admin/Form/AdminFormHandler.php +182 -392 3.2.02.15.3 View file →
@@ -13,14 +13,15 @@
13 13 use BitCode\BitForm\Core\Database\FormEntryMetaModel;
14 14 use BitCode\BitForm\Core\Database\FormEntryModel;
15 15 use BitCode\BitForm\Core\Database\FormModel;
16 16 use BitCode\BitForm\Core\Database\IntegrationModel;
17 +use BitCode\BitForm\Core\Database\PdfTemplateModel;
17 18 use BitCode\BitForm\Core\Database\ReportsModel;
18 19 use BitCode\BitForm\Core\Database\SuccessMessageModel;
19 20 use BitCode\BitForm\Core\Database\WorkFlowModel;
20 -use BitCode\BitForm\Core\Form\FormManager;
21 21 use BitCode\BitForm\Core\Integration\IntegrationHandler;
22 22 use BitCode\BitForm\Core\Messages\EmailTemplateHandler;
23 +use BitCode\BitForm\Core\Messages\PdfTemplateHandler;
23 24 use BitCode\BitForm\Core\Messages\SuccessMessageHandler;
24 25 use BitCode\BitForm\Core\Migration\MigrationHelper;
25 26 use BitCode\BitForm\Core\Util\FileHandler;
26 27 use BitCode\BitForm\Core\Util\FormDuplicateHelper;
@@ -25,9 +26,8 @@
25 26 use BitCode\BitForm\Core\Util\FileHandler;
26 27 use BitCode\BitForm\Core\Util\FormDuplicateHelper;
27 28 use BitCode\BitForm\Core\Util\HttpHelper;
28 29 use BitCode\BitForm\Core\Util\IpTool;
29 -use BitCode\BitForm\Core\Util\Log;
30 30 use BitCode\BitForm\Core\Util\Utilities;
31 31 use BitCode\BitForm\Core\WorkFlow\WorkFlow;
32 32 use BitCode\BitForm\Core\WorkFlow\WorkFlowHandler;
33 33 use WP_Error;
@@ -71,12 +71,14 @@
71 71 $this->createFormStylesDirIfNotExists();
72 72
73 73 if (
74 74 file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
75 - && wp_is_writable(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
75 + && is_writable(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
76 76 ) {
77 - $filePath = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . $sheetName;
78 - 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;
79 81 }
80 82 return false;
81 83 }
82 84
@@ -86,9 +88,9 @@
86 88 $sm_width = 400;
87 89 $lg_styles = '';
88 90 $md_styles = '';
89 91 $sm_styles = '';
90 - for ($i = 0; $i < count($layout->lg ?? []); $i++) {
92 + for ($i = 0; $i < count($layout->lg); $i++) {
91 93 $fld = $layout->lg[$i];
92 94
93 95 if ($fld->w < 10) {
94 96 $lay_row_height = 43;
@@ -152,12 +154,14 @@
152 154 $this->createFormStylesDirIfNotExists();
153 155
154 156 if (
155 157 file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
156 - && wp_is_writable(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
158 + && is_writable(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
157 159 ) {
158 - $filePath = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . $sheetName;
159 - 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;
160 164 }
161 165 return false;
162 166 }
163 167
@@ -191,8 +195,17 @@
191 195 if ($formManager->isExist()) {
192 196 return new WP_Error('empty_form', __('Error Occurred, Please Reload', 'bit-form'));
193 197 }
194 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 +
195 208 if (isset($post->formStyle) && $post->formStyle) {
196 209 $sheetName = 'bitform-' . $post->form_id . '.css';
197 210 $this->saveStyleSheet($post->formStyle, $sheetName);
198 211 }
@@ -198,14 +211,13 @@
198 211 }
199 212
200 213 if (isset($post->layoutChanged) && $post->layoutChanged) {
201 214 $sheetName = 'bitform-layout-' . $post->form_id . '.css';
202 - $rowHeight = (int) $post->rowHeight;
215 + $rowHeight = (int)$post->rowHeight;
203 216 $this->saveLayoutStyleSheet($post->layout, $sheetName, $rowHeight);
204 217 }
205 218
206 219 $fields = wp_unslash($post->fields);
207 - $fields = Helpers::replaceFieldsDefaultErrorMsg($fields);
208 220 // $fields = $post->fields;
209 221 $layout = wp_unslash($post->layout);
210 222 $nestedLayout = isset($post->nestedLayouts) ? wp_unslash($post->nestedLayouts) : (object) [];
211 223 $formInfo = wp_unslash($post->formInfo);
@@ -240,12 +252,8 @@
240 252 'empty_form',
241 253 __('Form Name Should Be Within 50 Characters', 'bit-form')
242 254 );
243 255 }
244 - // Guard: never persist orphan fields (in fields but in no layout) — they
245 - // render nothing yet their validation rules block submission. Covers old
246 - // clients and hand-edited imports (importAForm funnels through here).
247 - $this->pruneOrphanFields($fields, $nestedLayout, $layout, null, $post);
248 256 $form_content = [
249 257 'fields' => $fields,
250 258 'layout' => $layout,
251 259 'nestedLayout' => $nestedLayout,
@@ -311,11 +319,10 @@
311 319 return $save_status;
312 320 } elseif (!$save_status) {
313 321 return false;
314 322 } else {
315 - FileHandler::createIndexFile(BITFORMS_UPLOAD_DIR . "/$save_status");
323 + wp_mkdir_p(BITFORMS_UPLOAD_DIR . "/$save_status");
316 324 $formID = $save_status;
317 - do_action('bitform_admin_form_changed');
318 325 $integartionIDForWorkflow = [];
319 326 // Confiramtion Message [start]
320 327 if (!empty($formSettings->confirmation->type->successMsg)) {
321 328 $successMessages = $formSettings->confirmation->type->successMsg;
@@ -324,11 +331,8 @@
324 331 $savedID = $successMessageHandler->saveMessage($messageDetail);
325 332 if ($savedID) {
326 333 $msgIdx = empty($messageDetail->id) ? $messageKey : wp_json_encode(['id' => $messageDetail->id]);
327 334 $integartionIDForWorkflow['successMsg'][$msgIdx] = $savedID;
328 - if (!empty($messageDetail->clRef)) {
329 - $integartionIDForWorkflow['confirmationCLRef'][$messageDetail->clRef] = $savedID;
330 - }
331 335 $messageDetail->id = $savedID;
332 336 $style = $this->updateSuccessMessageClassName($style, $messageKey, $savedID);
333 337 $atomic_class_map = $this->updateSuccessMessageClassName($atomic_class_map, $messageKey, $savedID);
334 338 }
@@ -341,10 +345,10 @@
341 345 'builderSettings' => $builderSettings
342 346 ];
343 347 $update_status = static::$formModel->update(
344 348 [
345 - 'builder_helper_state' => \wp_json_encode($builder_helper_state),
346 - 'atomic_class_map' => $atomic_class_map,
349 + 'builder_helper_state' => \wp_json_encode($builder_helper_state),
350 + 'atomic_class_map' => $atomic_class_map,
347 351 ],
348 352 [
349 353 'id' => $formID,
350 354 ]
@@ -361,17 +365,11 @@
361 365 $emailTemplateHandler
362 366 = new EmailTemplateHandler($formID, $user_details);
363 367 foreach ($mailTem as $templateKey => $templateDetail) {
364 368 $savedID = $emailTemplateHandler->saveTemplate($templateDetail);
365 - if ($savedID && !is_wp_error($savedID)) {
369 + if ($savedID) {
366 370 $tempIdx = empty($templateDetail->id) ? $templateKey : wp_json_encode(['id' => $templateDetail->id]);
367 371 $integartionIDForWorkflow['mailNotify'][$tempIdx] = $savedID;
368 - if (!empty($templateDetail->clRef)) {
369 - $integartionIDForWorkflow['emailCLRef'][$templateDetail->clRef] = $savedID;
370 - }
371 - // return the new id (and drop the temp ref) so the frontend reconciles the template
372 - $templateDetail->id = $savedID;
373 - unset($templateDetail->clRef);
374 372 }
375 373 }
376 374 }
377 375 // Email Template [end] */
@@ -376,10 +374,10 @@
376 374 }
377 375 // Email Template [end] */
378 376
379 377 // PDF Template [start]
380 - if (!empty($pdfTem) && class_exists('\BitCode\BitFormPro\Core\Messages\PdfTemplateHandler')) {
381 - $pdfTemplateHandler = new \BitCode\BitFormPro\Core\Messages\PdfTemplateHandler($formID);
378 + if (!empty($pdfTem)) {
379 + $pdfTemplateHandler = new PdfTemplateHandler($formID);
382 380 $workFlowString = '';
383 381 if (!empty($workFlows)) {
384 382 $workFlowString = wp_json_encode($workFlows);
385 383 }
@@ -392,17 +390,8 @@
392 390 $this->pdfFontDownload($pdfSetting->font->name);
393 391 }
394 392 if (!empty($workFlowString)) {
395 393 $workFlowString = str_replace('"pdfId":"{\"id\":\"' . $templateDetail->id . '\"}"', '"pdfId":"{\"id\":\"' . $savedID . '\"}"', $workFlowString);
396 - // Multi-PDF: remap ids inside "pdfIds":[...] segments only — email-template ids use
397 - // the same {\"id\":N} token shape, so a global replace would corrupt them.
398 - $workFlowString = preg_replace_callback(
399 - '/"pdfIds":\[[^\]]*\]/',
400 - function ($matches) use ($templateDetail, $savedID) {
401 - return str_replace('{\"id\":\"' . $templateDetail->id . '\"}', '{\"id\":\"' . $savedID . '\"}', $matches[0]);
402 - },
403 - $workFlowString
404 - );
405 394 }
406 395 }
407 396 if (!empty($workFlowString) && !empty($workFlows)) {
408 397 $workFlows = json_decode($workFlowString);
@@ -414,14 +403,8 @@
414 403 if (!empty($formSettings->confirmation->type)) {
415 404 $allIntegrations = $formSettings->confirmation->type;
416 405 foreach ($allIntegrations as $integrationType => $integrationGroup) {
417 406 foreach ($integrationGroup as $singleIntegrationKey => $singleIntegrationDetail) {
418 - $integrationStatus = isset($singleIntegrationDetail->status) ? (int) $singleIntegrationDetail->status : 1;
419 - // Inline-CL temp ref for a brand-new redirect (reconciled to the real id for workflow rows).
420 - $clRef = isset($singleIntegrationDetail->clRef) ? $singleIntegrationDetail->clRef : null;
421 - if (is_object($singleIntegrationDetail)) {
422 - unset($singleIntegrationDetail->status, $singleIntegrationDetail->clRef);
423 - }
424 407 if (empty($singleIntegrationDetail->details)) {
425 408 $integrationName = $singleIntegrationDetail->title;
426 409 unset($singleIntegrationDetail->title, $singleIntegrationDetail->id);
427 410
@@ -431,25 +414,14 @@
431 414 $integrationName = $singleIntegrationDetail->title;
432 415 $integrationDetails = !is_string($singleIntegrationDetail->details) ?
433 416 wp_json_encode($singleIntegrationDetail->details) : $singleIntegrationDetail->details;
434 417 }
435 - $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form', $integrationStatus);
418 + $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form');
436 419 $integIdx = empty($singleIntegrationDetail->id) ? $savedID : wp_json_encode(['id' => $singleIntegrationDetail->id]);
437 420 $integartionIDForWorkflow[$integrationType][$integIdx] = $savedID;
438 - if (!empty($clRef) && 'redirectPage' === $integrationType) {
439 - $integartionIDForWorkflow['redirectCLRef'][$clRef] = $savedID;
440 - }
441 421 }
442 422 }
443 423 }
444 - if (isset($formSettings->formAbandonment)) {
445 - $formAbandonment = $formSettings->formAbandonment;
446 -
447 - $integrationName = 'formAbandonment';
448 - $integrationType = 'formAbandonment';
449 - $abandonmentIntegDetails = wp_json_encode($formAbandonment);
450 - $integrationHandler->saveIntegration($integrationName, $integrationType, $abandonmentIntegDetails, 'formAbandonment');
451 - }
452 424 if (!empty($integrations)) {
453 425 foreach ($integrations as $singleIntegrationKey => $singleIntegrationDetail) {
454 426 $integrationName = $singleIntegrationDetail->name;
455 427 unset($singleIntegrationDetail->name);
@@ -456,11 +428,8 @@
456 428 $integrationType = $singleIntegrationDetail->type;
457 429 unset($singleIntegrationDetail->type);
458 430 $singleIntegrationDetailID = empty($singleIntegrationDetail->id) ? null : $singleIntegrationDetail->id;
459 431 unset($singleIntegrationDetail->id);
460 - // Inline-CL temp ref for a brand-new integration (reconciled to the real id for workflow rows).
461 - $clRef = isset($singleIntegrationDetail->__bf_cl_ref) ? $singleIntegrationDetail->__bf_cl_ref : null;
462 - unset($singleIntegrationDetail->__bf_cl_ref);
463 432 if (empty($singleIntegrationDetail->details)) {
464 433 $integrationDetails = !is_string($singleIntegrationDetail) ?
465 434 wp_json_encode($singleIntegrationDetail) : $singleIntegrationDetail;
466 435 } else {
@@ -469,11 +438,8 @@
469 438 }
470 439 $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form');
471 440 $integIdx = empty($singleIntegrationDetailID) ? $singleIntegrationKey : wp_json_encode(['id' => $singleIntegrationDetailID]);
472 441 $integartionIDForWorkflow['integ'][$integIdx] = $savedID;
473 - if (!empty($clRef) && !is_wp_error($savedID)) {
474 - $integartionIDForWorkflow['integrationCLRef'][$clRef] = $savedID;
475 - }
476 442 }
477 443 }
478 444 //Integrations [end]
479 445 //wrokFlows [start]
@@ -493,9 +459,9 @@
493 459 // }
494 460 }
495 461 //wrokFlows [end]
496 462 $details = [
497 - 'report_name' => __('All Entries', 'bit-form'),
463 + 'report_name' => 'All Entries',
498 464 'hiddenColumns' => ['__user_id', '__user_ip', '__referer', '__user_device', '__created_at', '__updated_at'],
499 465 'pageSize' => 10,
500 466 'sortBy' => [],
501 467 'filters' => [],
@@ -555,14 +521,13 @@
555 521 if (property_exists($post, 'builderSettings')) {
556 522 $builder_helper_state->builderSettings = $post->builderSettings;
557 523 }
558 524 if (property_exists($post, 'atomicClassMap')) {
559 - $atomic_class_map = \wp_json_encode((object) $post->atomicClassMap);
525 + $atomic_class_map = \wp_json_encode((object)$post->atomicClassMap);
560 526 }
561 527
562 528 if (property_exists($post, 'fields') && null !== $post->fields && property_exists($post, 'layout') && $post->layout) {
563 529 $fields = wp_unslash($post->fields);
564 - $fields = Helpers::replaceFieldsDefaultErrorMsg($fields);
565 530 $layout = wp_unslash($post->layout);
566 531 $nestedLayout = wp_unslash($post->nestedLayouts);
567 532 $formInfo = wp_unslash($post->formInfo);
568 533 $formID = wp_unslash($post->id);
@@ -582,10 +547,16 @@
582 547 if (empty($fields) || empty($layout) || is_null($formID)) {
583 548 return new WP_Error('empty_form', 'Can not update empty form.');
584 549 }
585 550
586 - // Guard: never persist orphan fields (see createNewForm). Fail closed.
587 - $this->pruneOrphanFields($fields, $nestedLayout, $layout, $formID, $post);
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 + }
588 559
589 560 $form_content = [
590 561 'fields' => $fields,
591 562 'layout' => $layout,
@@ -627,11 +598,8 @@
627 598 $savedID = $successMessageHandler->saveMessage($messageDetail);
628 599 if ($savedID) {
629 600 $newData['settingConfiramation'] = 1;
630 601 $integartionIDForWorkflow['successMsg'][$messageKey] = $savedID;
631 - if (!empty($messageDetail->clRef)) {
632 - $integartionIDForWorkflow['confirmationCLRef'][$messageDetail->clRef] = $savedID;
633 - }
634 602 $messageDetail->id = $savedID;
635 603 $builder_helper_state->style = $this->updateSuccessMessageClassName($builder_helper_state->style, $messageKey, $savedID);
636 604 if (isset($atomic_class_map)) {
637 605 $atomic_class_map = $this->updateSuccessMessageClassName($atomic_class_map, $messageKey, $savedID);
@@ -656,14 +624,8 @@
656 624 $newData['mailTemplate'] = 2;
657 625 } else {
658 626 $newData['mailTemplate'] = 1;
659 627 $integartionIDForWorkflow['mailTem'][$templateKey] = $savedID;
660 - if (!empty($templateDetail->clRef)) {
661 - $integartionIDForWorkflow['emailCLRef'][$templateDetail->clRef] = $savedID;
662 - }
663 - // return the new id (and drop the temp ref) so the frontend reconciles the template
664 - $templateDetail->id = $savedID;
665 - unset($templateDetail->clRef);
666 628 }
667 629 } else {
668 630 $emailTemplateHandler->updateTemplate($templateDetail);
669 631 }
@@ -670,10 +632,10 @@
670 632 }
671 633 }
672 634 // return $formSettings;
673 635 // Email Template [end] */
674 - if (!empty($pdfTem) && class_exists('\BitCode\BitFormPro\Core\Messages\PdfTemplateHandler')) {
675 - $pdfTemplateHandler = new \BitCode\BitFormPro\Core\Messages\PdfTemplateHandler($formID);
636 + if (!empty($pdfTem)) {
637 + $pdfTemplateHandler = new PdfTemplateHandler($formID);
676 638
677 639 foreach ($pdfTem as $templateKey => $templateDetail) {
678 640 if (isset($templateDetail->setting->font->name)) {
679 641 $this->pdfFontDownload($templateDetail->setting->font->name);
@@ -693,15 +655,8 @@
693 655 if (!empty($formSettings->confirmation->type)) {
694 656 $allIntegrations = $formSettings->confirmation->type;
695 657 foreach ($allIntegrations as $integrationType => $integrationGroup) {
696 658 foreach ($integrationGroup as $singleIntegrationKey => $singleIntegrationDetail) {
697 - // Redirect (and webhook) enable/disable toggle persists to the integration status column.
698 - $integrationStatus = isset($singleIntegrationDetail->status) ? (int) $singleIntegrationDetail->status : 1;
699 - // Inline-CL temp ref for a brand-new redirect (reconciled to the real id for workflow rows).
700 - $clRef = isset($singleIntegrationDetail->clRef) ? $singleIntegrationDetail->clRef : null;
701 - if (is_object($singleIntegrationDetail)) {
702 - unset($singleIntegrationDetail->status, $singleIntegrationDetail->clRef);
703 - }
704 659 if (empty($singleIntegrationDetail->details)) {
705 660 $integrationName = $singleIntegrationDetail->title;
706 661 unset($singleIntegrationDetail->title);
707 662 $singleIntegrationDetailID = empty($singleIntegrationDetail->id) ? null : $singleIntegrationDetail->id;
@@ -715,16 +670,13 @@
715 670 $integrationDetails = !is_string($singleIntegrationDetail->details) ?
716 671 wp_json_encode($singleIntegrationDetail->details) : $singleIntegrationDetail->details;
717 672 }
718 673 if (empty($singleIntegrationDetailID)) {
719 - $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form', $integrationStatus);
674 + $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form');
720 675 $newData['settingConfiramation'] = 1;
721 676 $integartionIDForWorkflow[$integrationType][$singleIntegrationKey] = $savedID;
722 - if (!empty($clRef) && 'redirectPage' === $integrationType) {
723 - $integartionIDForWorkflow['redirectCLRef'][$clRef] = $savedID;
724 - }
725 677 } else {
726 - $integrationHandler->updateIntegration($singleIntegrationDetailID, $integrationName, $integrationType, $integrationDetails, 'form', $integrationStatus);
678 + $integrationHandler->updateIntegration($singleIntegrationDetailID, $integrationName, $integrationType, $integrationDetails, 'form');
727 679 }
728 680 }
729 681 }
730 682 }
@@ -735,11 +687,8 @@
735 687 $integrationType = $singleIntegrationDetail->type;
736 688 unset($singleIntegrationDetail->type);
737 689 $singleIntegrationDetailID = empty($singleIntegrationDetail->id) ? null : $singleIntegrationDetail->id;
738 690 unset($singleIntegrationDetail->id);
739 - // Inline-CL temp ref for a brand-new integration (reconciled to the real id for workflow rows).
740 - $clRef = isset($singleIntegrationDetail->__bf_cl_ref) ? $singleIntegrationDetail->__bf_cl_ref : null;
741 - unset($singleIntegrationDetail->__bf_cl_ref);
742 691 if (empty($singleIntegrationDetail->details)) {
743 692 $integrationDetails = !is_string($singleIntegrationDetail) ?
744 693 wp_json_encode($singleIntegrationDetail) : $singleIntegrationDetail;
745 694 } else {
@@ -748,11 +697,8 @@
748 697 }
749 698 if (empty($singleIntegrationDetailID)) {
750 699 $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form');
751 700 $integartionIDForWorkflow[$integrationType][$singleIntegrationKey] = $savedID;
752 - if (!empty($clRef) && !is_wp_error($savedID)) {
753 - $integartionIDForWorkflow['integrationCLRef'][$clRef] = $savedID;
754 - }
755 701 if (is_wp_error($savedID) && 'result_empty' !== $savedID->get_error_code()) {
756 702 $newData['integation'] = 2;
757 703 } else {
758 704 $newData['integation'] = 1;
@@ -805,12 +751,12 @@
805 751
806 752 $fieldNames['__user_id'] = __('User', 'bit-form');
807 753 $fieldNames['__user_ip'] = __('IP address', 'bit-form');
808 754 // $fieldNames['__user_location'] = __('');
809 - $fieldNames['__referer'] = __('Refer URL', 'bit-form');
810 - $fieldNames['__user_device'] = __('Device', 'bit-form');
811 - $fieldNames['__created_at'] = __('Created Time', 'bit-form');
812 - $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');
813 759
814 760 $reportIsDefault = null;
815 761 if (isset($form_content['report_id'])) {
816 762 $validDateReport = $reportsModel->validateReportFields($reports, $fieldNames);
@@ -862,9 +808,9 @@
862 808 'form_name' => $form_name,
863 809 'form_content' => $form_content,
864 810 'user_id' => $user_details['id'],
865 811 'user_ip' => $user_details['ip'],
866 - 'builder_helper_state' => \wp_json_encode((object) $builder_helper_state),
812 + 'builder_helper_state' => \wp_json_encode((object)$builder_helper_state),
867 813 'generated_script_page_ids' => \wp_json_encode((object) []),
868 814 'user_device' => $user_details['device'],
869 815 'updated_at' => $user_details['time'],
870 816 ];
@@ -870,16 +816,15 @@
870 816 ];
871 817 if (isset($atomic_class_map)) {
872 818 $updateData['atomic_class_map'] = $atomic_class_map;
873 819 }
874 - $formUpdateVersion = get_option('bitform_form_update_version');
820 + $formUpdateVersion = get_option('bit-form_form_update_version');
875 821 if (!$formUpdateVersion) {
876 822 $formUpdateVersion = 1;
877 823 } else {
878 824 $formUpdateVersion = (int) $formUpdateVersion + 1;
879 825 }
880 - update_option('bitform_form_update_version', $formUpdateVersion);
881 - do_action('bitform_admin_form_changed');
826 + update_option('bit-form_form_update_version', $formUpdateVersion);
882 827
883 828 $update_status = static::$formModel->update(
884 829 $updateData,
885 830 [
@@ -925,9 +870,8 @@
925 870 if (2 === $newData['reports']) {
926 871 $errorIN .= empty($errorIN) ? 'reports' : ', reports';
927 872 }
928 873 if (!empty($errorIN)) {
929 - /* translators: %s: comma-separated list of areas where error occurred */
930 874 $updated_data['message'] = sprintf(__('Error Occured in saving %s', 'bit-form'), $errorIN);
931 875 return new WP_Error('Form update Error.', $updated_data);
932 876 }
933 877 if (null !== $reportIsDefault) {
@@ -932,76 +876,30 @@
932 876 }
933 877 if (null !== $reportIsDefault) {
934 878 $updated_data['form_content']['is_default'] = $reportIsDefault;
935 879 }
936 - $updated_data['message'] = __('Form updated successfully.', 'bit-form');
880 + $updated_data['message'] = __('Form updated successfully.', 'bitform');
937 881 return $updated_data;
938 882 }
939 883 }
940 884
941 - /**
942 - * Drop orphan fields (present in `fields` but in no layout) from form_content
943 - * before persisting, and remove now-childless nestedLayout entries.
944 - *
945 - * Entry meta is NEVER touched here — only explicit user deletes clear meta
946 - * (see setEmptyMetaValue). Fail closed: an unusable/partial layout, or a
947 - * client that flagged a failed pre-save layout sync (->skipOrphanPrune),
948 - * prunes nothing. Pruned keys are logged, never silently dropped.
949 - *
950 - * @param object|array $fields by ref; orphan keys removed
951 - * @param object|null $nestedLayout by ref; stale container entries removed
952 - * @param array|object $layout raw layout (single or multi-step)
953 - * @param int|string|null $formID for logging ('new' when absent)
954 - * @param object $post raw request; honors ->skipOrphanPrune
955 - */
956 - private function pruneOrphanFields(&$fields, &$nestedLayout, $layout, $formID, $post)
957 - {
958 - $formLabel = $formID ? $formID : 'new';
959 - if (isset($post->skipOrphanPrune) && $post->skipOrphanPrune) {
960 - Log::debug_log('Bit Form: orphan prune skipped (client reported failed layout sync). FormID=' . $formLabel);
961 - return;
962 - }
963 - $orphanFldKeys = FormManager::computeOrphanFieldKeys($layout, $nestedLayout, $fields);
964 - // null = unusable/partial layout (fail closed); [] = nothing to prune
965 - if (!is_array($orphanFldKeys) || empty($orphanFldKeys)) {
966 - return;
967 - }
968 - Log::debug_log('Bit Form: pruning orphan fields (absent from every layout). FormID=' . $formLabel . ' keys=' . implode(',', $orphanFldKeys));
969 - foreach ($orphanFldKeys as $orphanKey) {
970 - if (is_object($fields)) {
971 - unset($fields->{$orphanKey});
972 - } elseif (is_array($fields)) {
973 - unset($fields[$orphanKey]);
974 - }
975 - }
976 - // prune stale nestedLayout entries — containers that no longer exist in fields
977 - if (is_object($nestedLayout)) {
978 - foreach (array_keys(get_object_vars($nestedLayout)) as $nKey) {
979 - $parentExists = is_object($fields) ? isset($fields->{$nKey}) : isset($fields[$nKey]);
980 - if (!$parentExists) {
981 - unset($nestedLayout->{$nKey});
982 - }
983 - }
984 - }
985 - }
986 -
987 885 public function setEmptyMetaValue($fieldkeys)
988 886 {
887 + $sqlEscaped = array_map(function ($fld) {
888 + return "'" . esc_sql($fld) . "'";
889 + }, $fieldkeys);
890 + $deletedFldKey = implode(',', $sqlEscaped);
989 891 global $wpdb;
990 - // Placeholders and arguments built dynamically from $fieldkeys; count matches at runtime.
991 - $placeholders = implode(',', array_fill(0, \count($fieldkeys), '%s'));
992 - $wpdb->query($wpdb->prepare(
993 - "UPDATE `{$wpdb->prefix}bitforms_form_entrymeta` SET meta_value = %s WHERE meta_key IN ($placeholders)",
994 - '',
995 - ...$fieldkeys
996 - ));
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);
997 895 }
998 896
999 897 public function changeFormStatus($Request, $post)
1000 898 {
1001 899 if (isset($Request['status']) && $Request['id']) {
1002 - $status = sanitize_text_field(wp_unslash($Request['status']));
1003 - $id = absint(wp_unslash($Request['id']));
900 + $status = wp_unslash($Request['status']);
901 + $id = wp_unslash($Request['id']);
1004 902 } else {
1005 903 $status = wp_unslash($post->status);
1006 904 $id = wp_unslash($post->id);
1007 905 }
@@ -1035,10 +933,10 @@
1035 933
1036 934 public function changeBulkFormStatus($Request, $post)
1037 935 {
1038 936 if (isset($Request['status']) && $Request['formID']) {
1039 - $status = sanitize_text_field(wp_unslash($Request['status']));
1040 - $formID = array_map('absint', wp_unslash($Request['formID']));
937 + $status = wp_unslash($Request['status']);
938 + $formID = wp_unslash($Request['formID']);
1041 939 } else {
1042 940 $status = wp_unslash($post->status);
1043 941 $formID = wp_unslash($post->formID);
1044 942 }
@@ -1073,13 +971,9 @@
1073 971 public function getAllForm()
1074 972 {
1075 973 global $wpdb;
1076 974
1077 - // Direct query: table name interpolation only (no user input). $wpdb->prepare() cannot parameterize table names.
1078 - $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
1079 - FROM `{$wpdb->prefix}bitforms_form` as forms
1080 - LEFT JOIN `{$wpdb->prefix}bitforms_form_entries` as entries ON forms.id = entries.form_id
1081 - 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");
1082 976
1083 977 if (is_wp_error($allForms)) {
1084 978 return $allForms;
1085 979 } elseif (!$allForms) {
@@ -1090,10 +984,10 @@
1090 984 }
1091 985
1092 986 public function getAForm($Request, $post)
1093 987 {
1094 - if (!empty($Request['id'])) {
1095 - $formID = absint(wp_unslash($Request['id']));
988 + if (isset($Request['id'])) {
989 + $formID = wp_unslash($Request['id']);
1096 990 } else {
1097 991 $formID = wp_unslash($post->id);
1098 992 }
1099 993 // return $post->fields;
@@ -1137,37 +1031,28 @@
1137 1031 if (!is_wp_error($emailTemplates)) {
1138 1032 foreach ($emailTemplates as $emailTemplatekey => $emailTemplatevalue) {
1139 1033 $mailTem[] =
1140 1034 [
1141 - 'id' => $emailTemplatevalue->id,
1142 - 'title' => $emailTemplatevalue->title,
1143 - 'sub' => $emailTemplatevalue->sub,
1144 - 'body' => $emailTemplatevalue->body,
1145 - 'status' => isset($emailTemplatevalue->status) ? (int) $emailTemplatevalue->status : 1,
1146 - 'config' => !empty($emailTemplatevalue->config) ? json_decode($emailTemplatevalue->config) : (object) [],
1035 + 'id' => $emailTemplatevalue->id,
1036 + 'title' => $emailTemplatevalue->title,
1037 + 'sub' => $emailTemplatevalue->sub,
1038 + 'body' => $emailTemplatevalue->body,
1147 1039 ];
1148 1040 }
1149 1041 }
1150 1042 // get all pdf template
1151 - if (class_exists('\BitCode\BitFormPro\Core\Messages\PdfTemplateHandler')) {
1152 - $pdfTemplateHandler = new \BitCode\BitFormPro\Core\Messages\PdfTemplateHandler($formID);
1153 - $pdfTemplates = $pdfTemplateHandler->getAll();
1043 + $pdfTemplateHandler = new PdfTemplateHandler($formID);
1044 + $pdfTemplates = $pdfTemplateHandler->getAll();
1154 1045
1155 - if (!is_wp_error($pdfTemplates)) {
1156 - foreach ($pdfTemplates as $value) {
1157 - $pdfTem[] =
1158 - [
1159 - 'id' => $value->id,
1160 - 'title' => $value->title,
1161 - 'setting' => json_decode($value->setting),
1162 - 'pdf_config' => !empty($value->pdf_config) ? json_decode($value->pdf_config) : (object) [
1163 - 'status' => 1,
1164 - 'header' => '',
1165 - 'footer' => '',
1166 - ],
1167 - 'body' => $value->body,
1168 - ];
1169 - }
1046 + if (!is_wp_error($pdfTemplates)) {
1047 + foreach ($pdfTemplates as $value) {
1048 + $pdfTem[] =
1049 + [
1050 + 'id' => $value->id,
1051 + 'title' => $value->title,
1052 + 'setting' => json_decode($value->setting),
1053 + 'body' => $value->body,
1054 + ];
1170 1055 }
1171 1056 }
1172 1057
1173 1058 $integrationHandler = new IntegrationHandler($formID);
@@ -1175,11 +1060,10 @@
1175 1060 if (!is_wp_error($formIntegrations)) {
1176 1061 foreach ($formIntegrations as $integrationkey => $integrationValue) {
1177 1062 if ('redirectPage' === $integrationValue->integration_type || 'webHooks' === $integrationValue->integration_type) {
1178 1063 $integrationData = [
1179 - 'id' => $integrationValue->id,
1180 - 'title' => $integrationValue->integration_name,
1181 - 'status' => isset($integrationValue->status) ? (int) $integrationValue->status : 1,
1064 + 'id' => $integrationValue->id,
1065 + 'title' => $integrationValue->integration_name,
1182 1066 ];
1183 1067 if (!empty($integrationValue->integration_details)) {
1184 1068 $integration_details = (array) json_decode($integrationValue->integration_details);
1185 1069 $integrationData = array_merge($integration_details, $integrationData);
@@ -1205,22 +1089,8 @@
1205 1089 );
1206 1090 }
1207 1091 }
1208 1092 }
1209 -
1210 - // get form abandonment integration if exist
1211 - $formAbandonmentInteg = $integrationHandler->getAllIntegration('formAbandonment', 'formAbandonment');
1212 - if (!is_wp_error($formAbandonmentInteg) && !empty($formAbandonmentInteg)) {
1213 - $formAbandonmentInteg = $formAbandonmentInteg[0];
1214 - if (!empty($formAbandonmentInteg->integration_details)) {
1215 - $formAbandonment = json_decode($formAbandonmentInteg->integration_details);
1216 - } else {
1217 - $formAbandonment = (object) [];
1218 - }
1219 - } else {
1220 - $formAbandonment = (object) [];
1221 - }
1222 -
1223 1093 $settingsContent = [
1224 1094 'formName' => $formManager->getFormName(),
1225 1095 'theme' => isset($form_content->theme) ? $form_content->theme : 'default',
1226 1096 'formPermissions' => isset($form_content->formPermissions) ? $form_content->formPermissions : (object) [],
@@ -1283,24 +1153,8 @@
1283 1153 'pdfTem' => [],
1284 1154 ]
1285 1155 );
1286 1156 }
1287 -
1288 - if (!empty($formAbandonment)) {
1289 - $settingsContent = array_merge(
1290 - $settingsContent,
1291 - [
1292 - 'formAbandonment' => $formAbandonment,
1293 - ]
1294 - );
1295 - } else {
1296 - $settingsContent = array_merge(
1297 - $settingsContent,
1298 - [
1299 - 'formAbandonment' => (object) [],
1300 - ]
1301 - );
1302 - }
1303 1157 $formSettings = [
1304 1158 'formSettings' => $settingsContent,
1305 1159 ];
1306 1160 $data = [
@@ -1311,14 +1165,12 @@
1311 1165 'style' => $helper_states->style,
1312 1166 'themeVars' => $helper_states->themeVars,
1313 1167 'themeColors' => $helper_states->themeColors,
1314 1168 'builderSettings' => $helper_states->builderSettings,
1315 - 'customCode' => FrontEndScriptGenerator::getCustomCodes($formID),
1316 1169 'additional' => empty($form_content->additional) ? [
1317 1170 'enabled' => [
1318 1171 'blocked_ip' => false,
1319 1172 'restrict_form' => false,
1320 - 'onePerIp' => false,
1321 1173 ],
1322 1174 'settings' => [
1323 1175 'restrict_form' => [
1324 1176 'day' => [],
@@ -1333,8 +1185,9 @@
1333 1185 ],
1334 1186 'entry_limit' => null,
1335 1187 'blocked_ip' => [],
1336 1188 ],
1189 + 'onePerIp' => false,
1337 1190 ] : $form_content->additional,
1338 1191 'created_at' => $formManager->getFormMetaData()['created_at'],
1339 1192 'views' => $formManager->getFormMetaData()['views'],
1340 1193 'entries' => $formManager->getFormMetaData()['entries'],
@@ -1375,9 +1228,9 @@
1375 1228 } else {
1376 1229 $returnedReportData[$reportKey]->details = [];
1377 1230 }
1378 1231 if ('1' === (string) $reportData->isDefault) {
1379 - $returnedReportData[$reportKey]->details->report_name = __('All Entries', 'bit-form');
1232 + $returnedReportData[$reportKey]->details->report_name = 'All Entries';
1380 1233 }
1381 1234 }
1382 1235 $reports = ['reports' => $returnedReportData];
1383 1236 $data = array_merge($data, $reports);
@@ -1391,10 +1244,10 @@
1391 1244 }
1392 1245
1393 1246 public function getAFormV1($Request, $post)
1394 1247 {
1395 - if (!empty($Request['id'])) {
1396 - $formID = absint(wp_unslash($Request['id']));
1248 + if (isset($Request['id'])) {
1249 + $formID = wp_unslash($Request['id']);
1397 1250 } else {
1398 1251 $formID = wp_unslash($post->id);
1399 1252 }
1400 1253 // return $post->fields;
@@ -1414,35 +1267,32 @@
1414 1267 'workFlowExist' => $form_content->workFlowExist,
1415 1268 'report_id' => isset($form_content->report_id) ? $form_content->report_id : null
1416 1269 ];
1417 1270 $successMessageHandler
1418 - = new SuccessMessageHandler($formID);
1271 + = new SuccessMessageHandler($formID);
1419 1272 $successMessages = $successMessageHandler->getAllMessage();
1420 1273 if (!is_wp_error($successMessages)) {
1421 1274 foreach ($successMessages as $sucessMessagekey => $sucessMessagevalue) {
1422 1275 $allConfirmation['type']['successMsg'][$sucessMessagekey] =
1423 - [
1424 - 'id' => $sucessMessagevalue->id,
1425 - 'title' => $sucessMessagevalue->message_title,
1426 - 'msg' => $sucessMessagevalue->message_content,
1427 - 'config' => !empty($sucessMessagevalue->message_config) ? json_decode($sucessMessagevalue->message_config) : (object) [],
1428 - ];
1276 + [
1277 + 'id' => $sucessMessagevalue->id,
1278 + 'title' => $sucessMessagevalue->message_title,
1279 + 'msg' => $sucessMessagevalue->message_content,
1280 + ];
1429 1281 }
1430 1282 }
1431 1283 $emailTemplateHandler
1432 - = new EmailTemplateHandler($formID);
1284 + = new EmailTemplateHandler($formID);
1433 1285 $emailTemplates = $emailTemplateHandler->getAllTemplate();
1434 1286 if (!is_wp_error($emailTemplates)) {
1435 1287 foreach ($emailTemplates as $emailTemplatekey => $emailTemplatevalue) {
1436 1288 $mailTem[] =
1437 - [
1438 - 'id' => $emailTemplatevalue->id,
1439 - 'title' => $emailTemplatevalue->title,
1440 - 'sub' => $emailTemplatevalue->sub,
1441 - 'body' => $emailTemplatevalue->body,
1442 - 'status' => isset($emailTemplatevalue->status) ? (int) $emailTemplatevalue->status : 1,
1443 - 'config' => !empty($emailTemplatevalue->config) ? json_decode($emailTemplatevalue->config) : (object) [],
1444 - ];
1289 + [
1290 + 'id' => $emailTemplatevalue->id,
1291 + 'title' => $emailTemplatevalue->title,
1292 + 'sub' => $emailTemplatevalue->sub,
1293 + 'body' => $emailTemplatevalue->body,
1294 + ];
1445 1295 }
1446 1296 }
1447 1297 $integrationHandler = new IntegrationHandler($formID);
1448 1298 $formIntegrations = $integrationHandler->getAllIntegration('form');
@@ -1449,11 +1299,10 @@
1449 1299 if (!is_wp_error($formIntegrations)) {
1450 1300 foreach ($formIntegrations as $integrationkey => $integrationValue) {
1451 1301 if ('redirectPage' === $integrationValue->integration_type || 'webHooks' === $integrationValue->integration_type) {
1452 1302 $integrationData = [
1453 - 'id' => $integrationValue->id,
1454 - 'title' => $integrationValue->integration_name,
1455 - 'status' => isset($integrationValue->status) ? (int) $integrationValue->status : 1,
1303 + 'id' => $integrationValue->id,
1304 + 'title' => $integrationValue->integration_name,
1456 1305 ];
1457 1306 if (!empty($integrationValue->integration_details)) {
1458 1307 // var_dump(json_decode($integrationValue->integration_details));
1459 1308 $integration_details = (array) json_decode($integrationValue->integration_details);
@@ -1464,9 +1313,9 @@
1464 1313 ];
1465 1314 $integrationData = array_merge($integrationData, $integration_details);
1466 1315 }
1467 1316 $allConfirmation['type'][$integrationValue->integration_type][]
1468 - = $integrationData;
1317 + = $integrationData;
1469 1318 } else {
1470 1319 $integrationData = [
1471 1320 'id' => $integrationValue->id,
1472 1321 'name' => $integrationValue->integration_name,
@@ -1474,10 +1323,10 @@
1474 1323 ];
1475 1324 $integrations[] = array_merge(
1476 1325 $integrationData,
1477 1326 is_string($integrationValue->integration_details) ?
1478 - (array) json_decode($integrationValue->integration_details) :
1479 - $integrationValue->integration_details
1327 + (array) json_decode($integrationValue->integration_details) :
1328 + $integrationValue->integration_details
1480 1329 );
1481 1330 }
1482 1331 }
1483 1332 }
@@ -1537,9 +1386,8 @@
1537 1386 'additional' => empty($form_content->additional) ? [
1538 1387 'enabled' => [
1539 1388 'blocked_ip' => false,
1540 1389 'restrict_form' => false,
1541 - 'onePerIp' => false,
1542 1390 ],
1543 1391 'settings' => [
1544 1392 'restrict_form' => [
1545 1393 'day' => [],
@@ -1554,8 +1402,9 @@
1554 1402 ],
1555 1403 'entry_limit' => null,
1556 1404 'blocked_ip' => [],
1557 1405 ],
1406 + 'onePerIp' => false,
1558 1407 ] : $form_content->additional,
1559 1408 'created_at' => $formManager->getFormMetaData()['created_at'],
1560 1409 'views' => $formManager->getFormMetaData()['views'],
1561 1410 'entries' => $formManager->getFormMetaData()['entries'],
@@ -1596,9 +1445,9 @@
1596 1445 } else {
1597 1446 $returnedReportData[$reportKey]->details = [];
1598 1447 }
1599 1448 if ('1' === (string) $reportData->isDefault) {
1600 - $returnedReportData[$reportKey]->details->report_name = __('All Entries', 'bit-form');
1449 + $returnedReportData[$reportKey]->details->report_name = 'All Entries';
1601 1450 }
1602 1451 }
1603 1452 $reports = ['reports' => $returnedReportData];
1604 1453 $data = array_merge($data, $reports);
@@ -1612,10 +1461,10 @@
1612 1461 }
1613 1462
1614 1463 public function deleteAForm($Request, $post)
1615 1464 {
1616 - if (!empty($Request['id'])) {
1617 - $formID = absint(wp_unslash($Request['id']));
1465 + if (isset($Request['id'])) {
1466 + $formID = wp_unslash($Request['id']);
1618 1467 } else {
1619 1468 $formID = wp_unslash($post->id);
1620 1469 }
1621 1470 if (is_null($formID)) {
@@ -1630,9 +1479,8 @@
1630 1479 [
1631 1480 'id' => $formID,
1632 1481 ]
1633 1482 );
1634 - do_action('bitform_admin_form_changed');
1635 1483
1636 1484 $successMessageModel = new SuccessMessageModel();
1637 1485 $deleteMsgStatus = $successMessageModel->delete(['form_id' => $formID]);
1638 1486
@@ -1638,12 +1486,10 @@
1638 1486
1639 1487 $emailTemplateModel = new EmailTemplateModel();
1640 1488 $deleteTemplateStatus = $emailTemplateModel->delete(['form_id' => $formID]);
1641 1489
1642 - if (class_exists('\BitCode\BitFormPro\Core\Database\PdfTemplateModel')) {
1643 - $pdfTemplateModel = new \BitCode\BitFormPro\Core\Database\PdfTemplateModel();
1644 - $deletePdfTemplateStatus = $pdfTemplateModel->delete(['form_id' => $formID]);
1645 - }
1490 + $pdfTemplateModel = new PdfTemplateModel();
1491 + $deletePdfTemplateStatus = $pdfTemplateModel->delete(['form_id' => $formID]);
1646 1492
1647 1493 $integrationModel = new IntegrationModel();
1648 1494 $deleteIntegrationStatus = $integrationModel->delete(['form_id' => $formID]);
1649 1495
@@ -1690,10 +1536,10 @@
1690 1536 }
1691 1537
1692 1538 public function deleteBlukForm($Request, $post)
1693 1539 {
1694 - if (!empty($Request['formID'])) {
1695 - $formID = array_map('absint', wp_unslash($Request['formID']));
1540 + if (isset($Request['formID'])) {
1541 + $formID = wp_unslash($Request['formID']);
1696 1542 } else {
1697 1543 $formID = wp_unslash($post->formID);
1698 1544 }
1699 1545
@@ -1720,9 +1566,8 @@
1720 1566 [
1721 1567 'id' => $formID,
1722 1568 ]
1723 1569 );
1724 - do_action('bitform_admin_form_changed');
1725 1570
1726 1571 if (is_wp_error($delete_status)) {
1727 1572 wp_send_json_error($delete_status->get_error_message(), 400);
1728 1573 }
@@ -1733,12 +1578,10 @@
1733 1578
1734 1579 $emailTemplateModel = new EmailTemplateModel();
1735 1580 $deleteTemplateStatus = $emailTemplateModel->bulkDelete(['form_id' => $formID]);
1736 1581
1737 - if (class_exists('\BitCode\BitFormPro\Core\Database\PdfTemplateModel')) {
1738 - $pdfTemplateModel = new \BitCode\BitFormPro\Core\Database\PdfTemplateModel();
1739 - $deletePdfTemplateStatus = $pdfTemplateModel->bulkDelete(['form_id' => $formID]);
1740 - }
1582 + $pdfTemplateModel = new PdfTemplateModel();
1583 + $deletePdfTemplateStatus = $pdfTemplateModel->bulkDelete(['form_id' => $formID]);
1741 1584
1742 1585 $integrationModel = new IntegrationModel();
1743 1586 $deleteIntegrationStatus = $integrationModel->bulkDelete(['form_id' => $formID]);
1744 1587
@@ -1771,14 +1614,8 @@
1771 1614 ]
1772 1615 );
1773 1616 }
1774 1617
1775 - // delete entry log and details; table name interpolation only — $wpdb->prepare() parameterizes the form_id value.
1776 - $wpdb->query($wpdb->prepare(
1777 - "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",
1778 - $formID
1779 - ));
1780 -
1781 1618 $fileHandler = new FileHandler();
1782 1619 foreach ($formID as $fId) {
1783 1620 if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $fId)) {
1784 1621 $fileHandler->rmrf(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $fId);
@@ -1825,15 +1662,21 @@
1825 1662 if (!is_wp_error($duplicateResponse) || (is_wp_error($duplicateResponse) && 'result_empty' === $duplicateResponse->get_error_code())) {
1826 1663 // duplicate stylesheet
1827 1664 $style_dir = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR;
1828 1665 // layout style copy
1829 - $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'));
1830 1668 $newStyle = str_replace(".bf$oldFormId-", ".bf$newFormId-", $styleStr);
1831 - 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);
1832 1672 // style copy
1833 - $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'));
1834 1675 $newStyle = str_replace("-$oldFormId", "-$newFormId", $styleStr);
1835 - FileHandler::writeFile($style_dir . "bitform-$newFormId.css", $newStyle);
1676 + $createStyleFile = fopen($style_dir . "bitform-$newFormId.css", 'w');
1677 + fwrite($createStyleFile, $newStyle);
1678 + fclose($createStyleFile);
1836 1679 $duplicatedForm = $this->getAForm(null, (object) ['id' => $newFormId]);
1837 1680 $duplicatedForm['message'] = __('Form duplicated successfully', 'bit-form');
1838 1681 return $duplicatedForm;
1839 1682 }
@@ -1846,15 +1689,15 @@
1846 1689 $newFormId = intval($post->newFormId);
1847 1690 if (!$oldFormId || empty($post->formDetail->fields) || empty($post->formDetail->layout)) {
1848 1691 return new WP_Error('invalid_form', __('Please import a valid json.', 'bit-form'));
1849 1692 }
1850 - $importtedForm = (array) $post->formDetail;
1693 + $importtedForm = (array)$post->formDetail;
1851 1694 $importtedForm['form_content']['fields'] = $importtedForm['fields'];
1852 1695 $importtedForm['form_content']['layout'] = $importtedForm['layout'];
1853 1696 $importtedForm['form_content']['nestedLayout'] = $importtedForm['nestedLayouts'];
1854 1697 $importtedForm['form_content']['formInfo'] = $importtedForm['formInfo'];
1855 1698 unset($importtedForm['fields'], $importtedForm['layout'], $importtedForm['nestedLayout'], $importtedForm['formInfo']);
1856 - $formData = FormDuplicateHelper::createReplica((array) $importtedForm, $oldFormId, $newFormId);
1699 + $formData = FormDuplicateHelper::createReplica((array)$importtedForm, $oldFormId, $newFormId);
1857 1700
1858 1701 if (!empty($importtedForm['rowHeight'])) {
1859 1702 $formData->rowHeight = $importtedForm['rowHeight'];
1860 1703 }
@@ -1941,9 +1784,9 @@
1941 1784 return new WP_Error('empty_form', __('Form does not exists.', 'bit-form'));
1942 1785 }
1943 1786
1944 1787 $newFormId = $oldFormId;
1945 - $duplicatedForm = $this->getAForm($Request, (object) ['id' => $oldFormId]);
1788 + $duplicatedForm = $this->getAForm($Request, (object)['id' => $oldFormId]);
1946 1789 $formData = FormDuplicateHelper::createReplica($duplicatedForm, $oldFormId, $newFormId);
1947 1790 // for custom css
1948 1791 $customCssPath = 'form-styles/bitform-custom-' . $newFormId . '.css';
1949 1792 $cssPath = Helpers::generatePathDirOrFile($customCssPath);
@@ -1963,10 +1806,10 @@
1963 1806 }
1964 1807
1965 1808 public function getFormEntryLabelAndCount($Request, $post)
1966 1809 {
1967 - if (!empty($Request['id'])) {
1968 - $id = absint(wp_unslash($Request['id']));
1810 + if (isset($Request['id'])) {
1811 + $id = wp_unslash($Request['id']);
1969 1812 } else {
1970 1813 $id = wp_unslash($post->id);
1971 1814 }
1972 1815 if (is_null($id)) {
@@ -2021,15 +1864,14 @@
2021 1864 }
2022 1865
2023 1866 public function getFormEntry($Request, $post)
2024 1867 {
2025 - if (!empty($Request['id'])) {
2026 - $id = absint(wp_unslash($Request['id']));
1868 + if (isset($Request['id'])) {
1869 + $id = wp_unslash($Request['id']);
2027 1870 $offset = isset($Request['offset']) ?
2028 1871 wp_unslash($Request['offset']) : 0;
2029 1872 $pageSize = isset($Request['pageSize']) ?
2030 1873 wp_unslash($Request['pageSize']) : 10;
2031 - $queryCondition = isset($Request['queryCondition']) ? wp_unslash($Request['queryCondition']) : ['form_id' => $id];
2032 1874 } else {
2033 1875 $id = wp_unslash($post->id);
2034 1876 $conditions = isset($post->conditions) ? wp_unslash($post->conditions) : [];
2035 1877 $dateBetweenFilter = isset($post->entriesFilterByDate) ? wp_unslash($post->entriesFilterByDate) : [];
@@ -2038,9 +1880,8 @@
2038 1880 $filters = isset($post->filters) ? wp_unslash($post->filters) : null;
2039 1881 $globalFilter = isset($post->globalFilter) ? wp_unslash($post->globalFilter) : null;
2040 1882 $pageSize = isset($post->pageSize) ?
2041 1883 wp_unslash($post->pageSize) : 10;
2042 - $queryCondition = isset($post->queryCondition) ? wp_unslash($post->queryCondition) : ['form_id' => $id];
2043 1884 }
2044 1885 if (is_null($id)) {
2045 1886 return new WP_Error('empty_form', __('Form id is empty.', 'bit-form'));
2046 1887 }
@@ -2047,12 +1888,15 @@
2047 1888 $formManager = new AdminFormManager($id);
2048 1889 if (!$formManager->isExist()) {
2049 1890 return new WP_Error('empty_form', __('Form does not exists', 'bit-form'));
2050 1891 }
1892 +
2051 1893 $formEntry = new FormEntryModel();
2052 1894 $entries = $formEntry->get(
2053 1895 'id',
2054 - $queryCondition,
1896 + [
1897 + 'form_id' => $id,
1898 + ],
2055 1899 null,
2056 1900 null,
2057 1901 'created_at',
2058 1902 'DESC'
@@ -2091,14 +1935,10 @@
2091 1935 $entryMeta = new FormEntryMetaModel();
2092 1936 // $formEntry = new FormEntryModel();
2093 1937
2094 1938 $entries = $entryMeta->getSingleEntryMeta($formFields, $entryId);
1939 + return $entries[0];
2095 1940
2096 - if (!is_wp_error($entries)) {
2097 - return $entries[0];
2098 - }
2099 - return new WP_Error('entry_not_fonud', __('Entry Not Found!', 'bit-form'));
2100 -
2101 1941 // $customFieldHandler = new CustomFieldHandler();
2102 1942 // $formEntries = $customFieldHandler->updatedEntries($formEntries, $fieldDetails);
2103 1943 // return $formEntries;
2104 1944 }
@@ -2104,10 +1944,10 @@
2104 1944 }
2105 1945
2106 1946 public function getEntriesForReport($Request, $post)
2107 1947 {
2108 - if (!empty($Request['id'])) {
2109 - $id = absint(wp_unslash($Request['id']));
1948 + if (isset($Request['id'])) {
1949 + $id = wp_unslash($Request['id']);
2110 1950 $offset = isset($Request['offset']) ?
2111 1951 wp_unslash($Request['offset']) : null;
2112 1952 $pageSize = isset($Request['pageSize']) ?
2113 1953 wp_unslash($Request['pageSize']) : null;
@@ -2168,9 +2008,8 @@
2168 2008 {
2169 2009 $formId = wp_unslash($post->formId);
2170 2010 $fileFormate = isset($post->fileFormate) ? wp_unslash($post->fileFormate) : null;
2171 2011 $limit = isset($post->limit) ? wp_unslash($post->limit) : null;
2172 - $entryCondition = isset($post->filter) ? wp_unslash($post->filter) : null;
2173 2012 $sortBy = isset($post->sort) ? wp_unslash($post->sort) : 'ASC';
2174 2013 $sortByField = isset($post->sortField) ? wp_unslash($post->sortField) : 'bitforms_form_entry_id';
2175 2014 $formFields = json_decode($post->selectedField);
2176 2015 if (is_null($formId)) {
@@ -2203,17 +2042,17 @@
2203 2042 return $entries;
2204 2043 }
2205 2044 $entryMeta = new FormEntryMetaModel();
2206 2045 $filter = [];
2207 - $formEntries = $entryMeta->getExportEntry($formFields, $entries, $formId, $fieldLabels, $limit, $sortBy, $sortByField, $offset, $entryCondition);
2046 + $formEntries = $entryMeta->getExportEntry($formFields, $entries, $formId, $fieldLabels, $limit, $sortBy, $sortByField);
2208 2047 return $formEntries;
2209 2048 }
2210 2049
2211 2050 public function deleteBlukFormEntries($Request, $post)
2212 2051 {
2213 - if (!empty($Request['formID'])) {
2214 - $formID = absint(wp_unslash($Request['formID']));
2215 - $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']);
2216 2055 } else {
2217 2056 $formID = wp_unslash($post->formID);
2218 2057 $entries = wp_unslash($post->entries);
2219 2058 }
@@ -2233,18 +2072,16 @@
2233 2072 if (!$formManager->isExist()) {
2234 2073 return new WP_Error('empty_form', __('Form does not exist.', 'bit-form'));
2235 2074 }
2236 2075 $workFlowRunHelper = new WorkFlow($formID);
2237 -
2238 2076 $workFlowreturnedOnDelete = $workFlowRunHelper->executeOnDelete(
2239 2077 $formManager,
2240 2078 $formID,
2241 2079 $entries
2242 2080 );
2243 -
2244 2081 if (isset($workFlowreturnedOnDelete['entries'])) {
2245 2082 if (0 === count($workFlowreturnedOnDelete['entries'])) {
2246 - return ['message' => __('Entry Deletetion prevented by workflow', 'bit-form')];
2083 + return ['message' => __('Entry Deletetion prevented by workflow', 'bit-form')];
2247 2084 } elseif (count($workFlowreturnedOnDelete['entries']) === count($entries)) {
2248 2085 $message = __('Entry Deleted successfully', 'bit-form');
2249 2086 } else {
2250 2087 $result['prevented'] = array_diff($entries, $workFlowreturnedOnDelete['entries']);
@@ -2265,9 +2102,9 @@
2265 2102 );
2266 2103 if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID)) {
2267 2104 $fileHandler = new FileHandler();
2268 2105 foreach ($entries as $enrtyKey => $entryID) {
2269 - $fileEntries = $fileHandler->getEntriesFileUploadDir($formID, $entryID);
2106 + $fileEntries = BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID . DIRECTORY_SEPARATOR . $entryID;
2270 2107 if (file_exists($fileEntries)) {
2271 2108 $fileHandler->rmrf($fileEntries);
2272 2109 }
2273 2110 }
@@ -2286,11 +2123,11 @@
2286 2123 }
2287 2124
2288 2125 public function duplicateFormEntry($Request, $post)
2289 2126 {
2290 - if (!empty($Request['formID'])) {
2291 - $formID = absint(wp_unslash($Request['formID']));
2292 - $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']);
2293 2130 } else {
2294 2131 $formID = wp_unslash($post->formID);
2295 2132 $entries = wp_unslash($post->entries);
2296 2133 }
@@ -2339,12 +2176,12 @@
2339 2176 );
2340 2177 if ($duplicate_status) {
2341 2178 $result['details'][$entryID] = $duplicatedEntryId;
2342 2179 $duplicate_count = $duplicate_count + 1;
2343 - if (file_exists(FileHandler::getEntriesFileUploadDir($formID, $entryID))) {
2180 + if (file_exists(BITFORMS_UPLOAD_DIR . "/$formID/$entryID")) {
2344 2181 $fileHandler->cpyr(
2345 - FileHandler::getEntriesFileUploadDir($formID, $entryID),
2346 - FileHandler::getEntriesFileUploadDir($formID, $duplicatedEntryId)
2182 + BITFORMS_UPLOAD_DIR . "/$formID/$entryID",
2183 + BITFORMS_UPLOAD_DIR . "/$formID/$duplicatedEntryId"
2347 2184 );
2348 2185 }
2349 2186 }
2350 2187 }
@@ -2361,11 +2198,11 @@
2361 2198 }
2362 2199
2363 2200 public function editFormEntry($Request, $post)
2364 2201 {
2365 - if (!empty($Request['formID'])) {
2366 - $formID = absint(wp_unslash($Request['formID']));
2367 - $entryID = absint(wp_unslash($Request['entryID']));
2202 + if (isset($Request['formID'])) {
2203 + $formID = wp_unslash($Request['formID']);
2204 + $entryID = wp_unslash($Request['entryID']);
2368 2205 } else {
2369 2206 $formID = wp_unslash($post->formID);
2370 2207 $entryID = wp_unslash($post->entryID);
2371 2208 }
@@ -2440,16 +2277,15 @@
2440 2277
2441 2278 public function updateFormEntry($Request, $post)
2442 2279 {
2443 2280 if (isset($Request['formID'], $Request['entryID'])) {
2444 - $formID = absint(wp_unslash($Request['formID']));
2445 - $entryID = absint(wp_unslash($Request['entryID']));
2281 + $formID = wp_unslash($Request['formID']);
2282 + $entryID = wp_unslash($Request['entryID']);
2446 2283 unset($Request['action'], $Request['formID'], $Request['entryID']);
2447 2284 }
2448 2285 $formManager = new AdminFormManager($formID);
2449 2286 $formManager->fieldNameReplaceOfPost();
2450 - // Called from AdminAjax handler; nonce already verified at AJAX entry before dispatch.
2451 - $updatedValue = is_array($post) ? $post : wp_unslash($_POST);
2287 + $updatedValue = wp_unslash($_POST);
2452 2288
2453 2289 if (is_null($updatedValue) || !is_array($updatedValue)) {
2454 2290 return new WP_Error('empty_data', __('Failed to update, Data is empty.', 'bit-form'));
2455 2291 }
@@ -2465,11 +2301,11 @@
2465 2301 }
2466 2302
2467 2303 public function getLogHistory($Request, $post)
2468 2304 {
2469 - if (!empty($Request['formID'])) {
2470 - $formID = absint(wp_unslash($Request['formID']));
2471 - $entryID = absint(wp_unslash($Request['entryID']));
2305 + if (isset($Request['formID'])) {
2306 + $formID = wp_unslash($Request['formID']);
2307 + $entryID = wp_unslash($Request['entryID']);
2472 2308 } else {
2473 2309 $formID = wp_unslash($post->formID);
2474 2310 $entryID = wp_unslash($post->entryID);
2475 2311 }
@@ -2489,10 +2325,10 @@
2489 2325 }
2490 2326
2491 2327 public function importDataStore($Request, $post)
2492 2328 {
2493 - if (!empty($Request['formID'])) {
2494 - $formID = absint(wp_unslash($Request['formID']));
2329 + if (isset($Request['formID'])) {
2330 + $formID = wp_unslash($Request['formID']);
2495 2331 } else {
2496 2332 $formID = wp_unslash($post->formID);
2497 2333 }
2498 2334 if (is_null($formID)) {
@@ -2504,14 +2340,10 @@
2504 2340 {
2505 2341 $pages = get_pages(['post_status' => 'publish', 'sort_column' => 'post_date', 'sort_order' => 'desc']);
2506 2342 $allPages = [];
2507 2343 foreach ($pages as $pageKey => $pageDetails) {
2508 - // $allPages[$pageKey]['title'] = $pageDetails->post_title;
2509 - // $allPages[$pageKey]['url'] = get_page_link($pageDetails->ID);
2510 - $allPages[] = (object) [
2511 - 'title' => $pageDetails->post_title,
2512 - 'url' => get_page_link($pageDetails->ID)
2513 - ];
2344 + $allPages[$pageKey]['title'] = $pageDetails->post_title;
2345 + $allPages[$pageKey]['url'] = get_page_link($pageDetails->ID);
2514 2346 }
2515 2347 return $allPages;
2516 2348 }
2517 2349
@@ -2516,11 +2348,11 @@
2516 2348 }
2517 2349
2518 2350 public function deleteAIntegration($Request, $post)
2519 2351 {
2520 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2521 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2522 - $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']);
2523 2355 } else {
2524 2356 $formID = wp_unslash($post->formID);
2525 2357 $id = wp_unslash($post->id);
2526 2358 }
@@ -2540,11 +2372,11 @@
2540 2372 }
2541 2373
2542 2374 public function deleteSuccessMessage($Request, $post)
2543 2375 {
2544 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2545 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2546 - $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']);
2547 2379 } else {
2548 2380 $formID = wp_unslash($post->formID);
2549 2381 $id = wp_unslash($post->id);
2550 2382 }
@@ -2563,11 +2395,11 @@
2563 2395 }
2564 2396
2565 2397 public function deleteAWorkflow($Request, $post)
2566 2398 {
2567 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2568 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2569 - $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']);
2570 2402 } else {
2571 2403 $formID = wp_unslash($post->formID);
2572 2404 $id = wp_unslash($post->id);
2573 2405 }
@@ -2585,11 +2417,11 @@
2585 2417 }
2586 2418
2587 2419 public function deleteAMailTemplate($Request, $post)
2588 2420 {
2589 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2590 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2591 - $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']);
2592 2424 } else {
2593 2425 $formID = wp_unslash($post->formID);
2594 2426 $id = wp_unslash($post->id);
2595 2427 }
@@ -2607,11 +2439,11 @@
2607 2439 }
2608 2440
2609 2441 public function duplicateAMailTemplate($Request, $post)
2610 2442 {
2611 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2612 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2613 - $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']);
2614 2446 } else {
2615 2447 $formID = wp_unslash($post->formID);
2616 2448 $id = wp_unslash($post->id);
2617 2449 }
@@ -2770,9 +2602,9 @@
2770 2602 $paySetting = json_decode($paySetting);
2771 2603 }
2772 2604
2773 2605 $canSave = null;
2774 - switch ($paySetting->type) {
2606 + switch($paySetting->type) {
2775 2607 case 'PayPal':
2776 2608 $canSave = $this->addWebhookToPaypal($paySetting);
2777 2609 break;
2778 2610 case 'Razorpay':
@@ -2873,16 +2705,15 @@
2873 2705 }
2874 2706 }
2875 2707
2876 2708 $data = [
2877 - 'enabled_events[]' => 'payment_intent.succeeded',
2878 - 'url' => $webhook_url,
2709 + 'enabled_events[]' => 'payment_intent.succeeded',
2710 + 'url' => $webhook_url,
2879 2711 ];
2880 2712
2881 2713 if (!$webhook_already_exist) {
2882 2714 $webhook_response = HttpHelper::post($create_webhook_url, $data, $headers);
2883 2715 if (is_wp_error($webhook_response) || (isset($webhook_response->error) && $webhook_response->error)) {
2884 - Log::debug_log(['Stripe webhook creation failed' => $webhook_response]);
2885 2716 return null;
2886 2717 }
2887 2718 }
2888 2719 return true;
@@ -2922,49 +2753,8 @@
2922 2753 } elseif (!$update_status) {
2923 2754 return new WP_Error('empty_form', __('Form update failed.', 'bit-form'));
2924 2755 } else {
2925 2756 return true;
2926 - }
2927 - }
2928 -
2929 - public function replaceAllFormsErrorMessagesByGlobalMessages()
2930 - {
2931 - try {
2932 - $formModel = new FormModel();
2933 - $allForms = $formModel->get(['id', 'form_content']);
2934 -
2935 - foreach ($allForms as $form) {
2936 - // Decode form_content JSON to stdClass
2937 - $formContent = \json_decode($form->form_content);
2938 - $fields = $formContent->fields ?? null;
2939 - // If decode fails, skip to next
2940 - if (!$fields) {
2941 - Log::debug_log("Form ID {$form->id}: invalid JSON in form_content");
2942 - continue;
2943 - }
2944 -
2945 - // Replace default error messages using your helper
2946 - $updatedFields = Helpers::replaceFieldsDefaultErrorMsg($fields);
2947 -
2948 - $formContent->fields = $updatedFields;
2949 - // Encode back to JSON
2950 - $updatedContent = \json_encode($formContent);
2951 -
2952 - if (false === $updatedContent) {
2953 - Log::debug_log("Form ID {$form->id}: JSON encoding failed");
2954 - continue;
2955 - }
2956 - // Update form content in DB
2957 - $formModel->update(
2958 - ['form_content' => $updatedContent], // data to update
2959 - ['id' => $form->id] // condition for update
2960 - );
2961 - }
2962 - } catch (\Exception $e) {
2963 - Log::debug_log([
2964 - 'message' => 'Error in updateAllFormsErrorMessagesWithGlobalMessages',
2965 - 'error' => $e->getMessage(),
2966 - ]);
2967 2757 }
2968 2758 }
2969 2759
2970 2760 public function updateSuccessMessageClassName($str, $msgIdx, $msgId)