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 +186 -463 3.2.22.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,29 +624,18 @@
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 - $updated = $emailTemplateHandler->updateTemplate($templateDetail);
669 - if (is_wp_error($updated) && 'db_error' === $updated->get_error_code()) {
670 - $newData['mailTemplate'] = 2;
671 - } elseif (0 === $newData['mailTemplate']) {
672 - $newData['mailTemplate'] = 1;
673 - }
630 + $emailTemplateHandler->updateTemplate($templateDetail);
674 631 }
675 632 }
676 633 }
677 634 // return $formSettings;
678 635 // Email Template [end] */
679 - if (!empty($pdfTem) && class_exists('\BitCode\BitFormPro\Core\Messages\PdfTemplateHandler')) {
680 - $pdfTemplateHandler = new \BitCode\BitFormPro\Core\Messages\PdfTemplateHandler($formID);
636 + if (!empty($pdfTem)) {
637 + $pdfTemplateHandler = new PdfTemplateHandler($formID);
681 638
682 639 foreach ($pdfTem as $templateKey => $templateDetail) {
683 640 if (isset($templateDetail->setting->font->name)) {
684 641 $this->pdfFontDownload($templateDetail->setting->font->name);
@@ -698,15 +655,8 @@
698 655 if (!empty($formSettings->confirmation->type)) {
699 656 $allIntegrations = $formSettings->confirmation->type;
700 657 foreach ($allIntegrations as $integrationType => $integrationGroup) {
701 658 foreach ($integrationGroup as $singleIntegrationKey => $singleIntegrationDetail) {
702 - // Redirect (and webhook) enable/disable toggle persists to the integration status column.
703 - $integrationStatus = isset($singleIntegrationDetail->status) ? (int) $singleIntegrationDetail->status : 1;
704 - // Inline-CL temp ref for a brand-new redirect (reconciled to the real id for workflow rows).
705 - $clRef = isset($singleIntegrationDetail->clRef) ? $singleIntegrationDetail->clRef : null;
706 - if (is_object($singleIntegrationDetail)) {
707 - unset($singleIntegrationDetail->status, $singleIntegrationDetail->clRef);
708 - }
709 659 if (empty($singleIntegrationDetail->details)) {
710 660 $integrationName = $singleIntegrationDetail->title;
711 661 unset($singleIntegrationDetail->title);
712 662 $singleIntegrationDetailID = empty($singleIntegrationDetail->id) ? null : $singleIntegrationDetail->id;
@@ -720,16 +670,13 @@
720 670 $integrationDetails = !is_string($singleIntegrationDetail->details) ?
721 671 wp_json_encode($singleIntegrationDetail->details) : $singleIntegrationDetail->details;
722 672 }
723 673 if (empty($singleIntegrationDetailID)) {
724 - $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form', $integrationStatus);
674 + $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form');
725 675 $newData['settingConfiramation'] = 1;
726 676 $integartionIDForWorkflow[$integrationType][$singleIntegrationKey] = $savedID;
727 - if (!empty($clRef) && 'redirectPage' === $integrationType) {
728 - $integartionIDForWorkflow['redirectCLRef'][$clRef] = $savedID;
729 - }
730 677 } else {
731 - $integrationHandler->updateIntegration($singleIntegrationDetailID, $integrationName, $integrationType, $integrationDetails, 'form', $integrationStatus);
678 + $integrationHandler->updateIntegration($singleIntegrationDetailID, $integrationName, $integrationType, $integrationDetails, 'form');
732 679 }
733 680 }
734 681 }
735 682 }
@@ -740,11 +687,8 @@
740 687 $integrationType = $singleIntegrationDetail->type;
741 688 unset($singleIntegrationDetail->type);
742 689 $singleIntegrationDetailID = empty($singleIntegrationDetail->id) ? null : $singleIntegrationDetail->id;
743 690 unset($singleIntegrationDetail->id);
744 - // Inline-CL temp ref for a brand-new integration (reconciled to the real id for workflow rows).
745 - $clRef = isset($singleIntegrationDetail->__bf_cl_ref) ? $singleIntegrationDetail->__bf_cl_ref : null;
746 - unset($singleIntegrationDetail->__bf_cl_ref);
747 691 if (empty($singleIntegrationDetail->details)) {
748 692 $integrationDetails = !is_string($singleIntegrationDetail) ?
749 693 wp_json_encode($singleIntegrationDetail) : $singleIntegrationDetail;
750 694 } else {
@@ -753,11 +697,8 @@
753 697 }
754 698 if (empty($singleIntegrationDetailID)) {
755 699 $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form');
756 700 $integartionIDForWorkflow[$integrationType][$singleIntegrationKey] = $savedID;
757 - if (!empty($clRef) && !is_wp_error($savedID)) {
758 - $integartionIDForWorkflow['integrationCLRef'][$clRef] = $savedID;
759 - }
760 701 if (is_wp_error($savedID) && 'result_empty' !== $savedID->get_error_code()) {
761 702 $newData['integation'] = 2;
762 703 } else {
763 704 $newData['integation'] = 1;
@@ -810,19 +751,15 @@
810 751
811 752 $fieldNames['__user_id'] = __('User', 'bit-form');
812 753 $fieldNames['__user_ip'] = __('IP address', 'bit-form');
813 754 // $fieldNames['__user_location'] = __('');
814 - $fieldNames['__referer'] = __('Refer URL', 'bit-form');
815 - $fieldNames['__user_device'] = __('Device', 'bit-form');
816 - $fieldNames['__created_at'] = __('Created Time', 'bit-form');
817 - $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');
818 759
819 760 $reportIsDefault = null;
820 - // The client posts currentReport as {} whenever its report atom has not resolved yet. That
821 - // is an empty stdClass, which empty() above treats as non-empty, so we reach here with
822 - // nothing to save — and writing the validated result would replace the stored report's
823 - // column order, hidden columns, page size and name with an empty list. Leave the row alone.
824 - if (isset($form_content['report_id']) && ReportsModel::isValidatableReport($reports)) {
761 + if (isset($form_content['report_id'])) {
825 762 $validDateReport = $reportsModel->validateReportFields($reports, $fieldNames);
826 763 if (isset($reports->isDefault)) {
827 764 $reportIsDefault = $reports->isDefault;
828 765 } else {
@@ -871,9 +808,9 @@
871 808 'form_name' => $form_name,
872 809 'form_content' => $form_content,
873 810 'user_id' => $user_details['id'],
874 811 'user_ip' => $user_details['ip'],
875 - 'builder_helper_state' => \wp_json_encode((object) $builder_helper_state),
812 + 'builder_helper_state' => \wp_json_encode((object)$builder_helper_state),
876 813 'generated_script_page_ids' => \wp_json_encode((object) []),
877 814 'user_device' => $user_details['device'],
878 815 'updated_at' => $user_details['time'],
879 816 ];
@@ -879,16 +816,15 @@
879 816 ];
880 817 if (isset($atomic_class_map)) {
881 818 $updateData['atomic_class_map'] = $atomic_class_map;
882 819 }
883 - $formUpdateVersion = get_option('bitform_form_update_version');
820 + $formUpdateVersion = get_option('bit-form_form_update_version');
884 821 if (!$formUpdateVersion) {
885 822 $formUpdateVersion = 1;
886 823 } else {
887 824 $formUpdateVersion = (int) $formUpdateVersion + 1;
888 825 }
889 - update_option('bitform_form_update_version', $formUpdateVersion);
890 - do_action('bitform_admin_form_changed');
826 + update_option('bit-form_form_update_version', $formUpdateVersion);
891 827
892 828 $update_status = static::$formModel->update(
893 829 $updateData,
894 830 [
@@ -934,9 +870,8 @@
934 870 if (2 === $newData['reports']) {
935 871 $errorIN .= empty($errorIN) ? 'reports' : ', reports';
936 872 }
937 873 if (!empty($errorIN)) {
938 - /* translators: %s: comma-separated list of areas where error occurred */
939 874 $updated_data['message'] = sprintf(__('Error Occured in saving %s', 'bit-form'), $errorIN);
940 875 return new WP_Error('Form update Error.', $updated_data);
941 876 }
942 877 if (null !== $reportIsDefault) {
@@ -941,76 +876,30 @@
941 876 }
942 877 if (null !== $reportIsDefault) {
943 878 $updated_data['form_content']['is_default'] = $reportIsDefault;
944 879 }
945 - $updated_data['message'] = __('Form updated successfully.', 'bit-form');
880 + $updated_data['message'] = __('Form updated successfully.', 'bitform');
946 881 return $updated_data;
947 882 }
948 883 }
949 884
950 - /**
951 - * Drop orphan fields (present in `fields` but in no layout) from form_content
952 - * before persisting, and remove now-childless nestedLayout entries.
953 - *
954 - * Entry meta is NEVER touched here — only explicit user deletes clear meta
955 - * (see setEmptyMetaValue). Fail closed: an unusable/partial layout, or a
956 - * client that flagged a failed pre-save layout sync (->skipOrphanPrune),
957 - * prunes nothing. Pruned keys are logged, never silently dropped.
958 - *
959 - * @param object|array $fields by ref; orphan keys removed
960 - * @param object|null $nestedLayout by ref; stale container entries removed
961 - * @param array|object $layout raw layout (single or multi-step)
962 - * @param int|string|null $formID for logging ('new' when absent)
963 - * @param object $post raw request; honors ->skipOrphanPrune
964 - */
965 - private function pruneOrphanFields(&$fields, &$nestedLayout, $layout, $formID, $post)
966 - {
967 - $formLabel = $formID ? $formID : 'new';
968 - if (isset($post->skipOrphanPrune) && $post->skipOrphanPrune) {
969 - Log::debug_log('Bit Form: orphan prune skipped (client reported failed layout sync). FormID=' . $formLabel);
970 - return;
971 - }
972 - $orphanFldKeys = FormManager::computeOrphanFieldKeys($layout, $nestedLayout, $fields);
973 - // null = unusable/partial layout (fail closed); [] = nothing to prune
974 - if (!is_array($orphanFldKeys) || empty($orphanFldKeys)) {
975 - return;
976 - }
977 - Log::debug_log('Bit Form: pruning orphan fields (absent from every layout). FormID=' . $formLabel . ' keys=' . implode(',', $orphanFldKeys));
978 - foreach ($orphanFldKeys as $orphanKey) {
979 - if (is_object($fields)) {
980 - unset($fields->{$orphanKey});
981 - } elseif (is_array($fields)) {
982 - unset($fields[$orphanKey]);
983 - }
984 - }
985 - // prune stale nestedLayout entries — containers that no longer exist in fields
986 - if (is_object($nestedLayout)) {
987 - foreach (array_keys(get_object_vars($nestedLayout)) as $nKey) {
988 - $parentExists = is_object($fields) ? isset($fields->{$nKey}) : isset($fields[$nKey]);
989 - if (!$parentExists) {
990 - unset($nestedLayout->{$nKey});
991 - }
992 - }
993 - }
994 - }
995 -
996 885 public function setEmptyMetaValue($fieldkeys)
997 886 {
887 + $sqlEscaped = array_map(function ($fld) {
888 + return "'" . esc_sql($fld) . "'";
889 + }, $fieldkeys);
890 + $deletedFldKey = implode(',', $sqlEscaped);
998 891 global $wpdb;
999 - // Placeholders and arguments built dynamically from $fieldkeys; count matches at runtime.
1000 - $placeholders = implode(',', array_fill(0, \count($fieldkeys), '%s'));
1001 - $wpdb->query($wpdb->prepare(
1002 - "UPDATE `{$wpdb->prefix}bitforms_form_entrymeta` SET meta_value = %s WHERE meta_key IN ($placeholders)",
1003 - '',
1004 - ...$fieldkeys
1005 - ));
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);
1006 895 }
1007 896
1008 897 public function changeFormStatus($Request, $post)
1009 898 {
1010 899 if (isset($Request['status']) && $Request['id']) {
1011 - $status = sanitize_text_field(wp_unslash($Request['status']));
1012 - $id = absint(wp_unslash($Request['id']));
900 + $status = wp_unslash($Request['status']);
901 + $id = wp_unslash($Request['id']);
1013 902 } else {
1014 903 $status = wp_unslash($post->status);
1015 904 $id = wp_unslash($post->id);
1016 905 }
@@ -1044,10 +933,10 @@
1044 933
1045 934 public function changeBulkFormStatus($Request, $post)
1046 935 {
1047 936 if (isset($Request['status']) && $Request['formID']) {
1048 - $status = sanitize_text_field(wp_unslash($Request['status']));
1049 - $formID = array_map('absint', wp_unslash($Request['formID']));
937 + $status = wp_unslash($Request['status']);
938 + $formID = wp_unslash($Request['formID']);
1050 939 } else {
1051 940 $status = wp_unslash($post->status);
1052 941 $formID = wp_unslash($post->formID);
1053 942 }
@@ -1082,13 +971,9 @@
1082 971 public function getAllForm()
1083 972 {
1084 973 global $wpdb;
1085 974
1086 - // Direct query: table name interpolation only (no user input). $wpdb->prepare() cannot parameterize table names.
1087 - $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
1088 - FROM `{$wpdb->prefix}bitforms_form` as forms
1089 - LEFT JOIN `{$wpdb->prefix}bitforms_form_entries` as entries ON forms.id = entries.form_id
1090 - 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");
1091 976
1092 977 if (is_wp_error($allForms)) {
1093 978 return $allForms;
1094 979 } elseif (!$allForms) {
@@ -1099,10 +984,10 @@
1099 984 }
1100 985
1101 986 public function getAForm($Request, $post)
1102 987 {
1103 - if (!empty($Request['id'])) {
1104 - $formID = absint(wp_unslash($Request['id']));
988 + if (isset($Request['id'])) {
989 + $formID = wp_unslash($Request['id']);
1105 990 } else {
1106 991 $formID = wp_unslash($post->id);
1107 992 }
1108 993 // return $post->fields;
@@ -1121,9 +1006,9 @@
1121 1006 'nestedLayout' => !empty($form_content->nestedLayout) ? $form_content->nestedLayout : (object) [],
1122 1007 'formInfo' => !empty($form_content->formInfo) ? $form_content->formInfo : (object) ['formName' => $formManager->getFormName()],
1123 1008 'fields' => $form_content->fields,
1124 1009 'form_name' => $formManager->getFormName(),
1125 - 'workFlowExist' => isset($form_content->workFlowExist) ? $form_content->workFlowExist : [],
1010 + 'workFlowExist' => $form_content->workFlowExist,
1126 1011 'report_id' => isset($form_content->report_id) ? $form_content->report_id : null
1127 1012 ];
1128 1013 $successMessageHandler
1129 1014 = new SuccessMessageHandler($formID);
@@ -1146,37 +1031,28 @@
1146 1031 if (!is_wp_error($emailTemplates)) {
1147 1032 foreach ($emailTemplates as $emailTemplatekey => $emailTemplatevalue) {
1148 1033 $mailTem[] =
1149 1034 [
1150 - 'id' => $emailTemplatevalue->id,
1151 - 'title' => $emailTemplatevalue->title,
1152 - 'sub' => $emailTemplatevalue->sub,
1153 - 'body' => $emailTemplatevalue->body,
1154 - 'status' => isset($emailTemplatevalue->status) ? (int) $emailTemplatevalue->status : 1,
1155 - '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,
1156 1039 ];
1157 1040 }
1158 1041 }
1159 1042 // get all pdf template
1160 - if (class_exists('\BitCode\BitFormPro\Core\Messages\PdfTemplateHandler')) {
1161 - $pdfTemplateHandler = new \BitCode\BitFormPro\Core\Messages\PdfTemplateHandler($formID);
1162 - $pdfTemplates = $pdfTemplateHandler->getAll();
1043 + $pdfTemplateHandler = new PdfTemplateHandler($formID);
1044 + $pdfTemplates = $pdfTemplateHandler->getAll();
1163 1045
1164 - if (!is_wp_error($pdfTemplates)) {
1165 - foreach ($pdfTemplates as $value) {
1166 - $pdfTem[] =
1167 - [
1168 - 'id' => $value->id,
1169 - 'title' => $value->title,
1170 - 'setting' => json_decode($value->setting),
1171 - 'pdf_config' => !empty($value->pdf_config) ? json_decode($value->pdf_config) : (object) [
1172 - 'status' => 1,
1173 - 'header' => '',
1174 - 'footer' => '',
1175 - ],
1176 - 'body' => $value->body,
1177 - ];
1178 - }
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 + ];
1179 1055 }
1180 1056 }
1181 1057
1182 1058 $integrationHandler = new IntegrationHandler($formID);
@@ -1184,11 +1060,10 @@
1184 1060 if (!is_wp_error($formIntegrations)) {
1185 1061 foreach ($formIntegrations as $integrationkey => $integrationValue) {
1186 1062 if ('redirectPage' === $integrationValue->integration_type || 'webHooks' === $integrationValue->integration_type) {
1187 1063 $integrationData = [
1188 - 'id' => $integrationValue->id,
1189 - 'title' => $integrationValue->integration_name,
1190 - 'status' => isset($integrationValue->status) ? (int) $integrationValue->status : 1,
1064 + 'id' => $integrationValue->id,
1065 + 'title' => $integrationValue->integration_name,
1191 1066 ];
1192 1067 if (!empty($integrationValue->integration_details)) {
1193 1068 $integration_details = (array) json_decode($integrationValue->integration_details);
1194 1069 $integrationData = array_merge($integration_details, $integrationData);
@@ -1214,22 +1089,8 @@
1214 1089 );
1215 1090 }
1216 1091 }
1217 1092 }
1218 -
1219 - // get form abandonment integration if exist
1220 - $formAbandonmentInteg = $integrationHandler->getAllIntegration('formAbandonment', 'formAbandonment');
1221 - if (!is_wp_error($formAbandonmentInteg) && !empty($formAbandonmentInteg)) {
1222 - $formAbandonmentInteg = $formAbandonmentInteg[0];
1223 - if (!empty($formAbandonmentInteg->integration_details)) {
1224 - $formAbandonment = json_decode($formAbandonmentInteg->integration_details);
1225 - } else {
1226 - $formAbandonment = (object) [];
1227 - }
1228 - } else {
1229 - $formAbandonment = (object) [];
1230 - }
1231 -
1232 1093 $settingsContent = [
1233 1094 'formName' => $formManager->getFormName(),
1234 1095 'theme' => isset($form_content->theme) ? $form_content->theme : 'default',
1235 1096 'formPermissions' => isset($form_content->formPermissions) ? $form_content->formPermissions : (object) [],
@@ -1292,24 +1153,8 @@
1292 1153 'pdfTem' => [],
1293 1154 ]
1294 1155 );
1295 1156 }
1296 -
1297 - if (!empty($formAbandonment)) {
1298 - $settingsContent = array_merge(
1299 - $settingsContent,
1300 - [
1301 - 'formAbandonment' => $formAbandonment,
1302 - ]
1303 - );
1304 - } else {
1305 - $settingsContent = array_merge(
1306 - $settingsContent,
1307 - [
1308 - 'formAbandonment' => (object) [],
1309 - ]
1310 - );
1311 - }
1312 1157 $formSettings = [
1313 1158 'formSettings' => $settingsContent,
1314 1159 ];
1315 1160 $data = [
@@ -1320,14 +1165,12 @@
1320 1165 'style' => $helper_states->style,
1321 1166 'themeVars' => $helper_states->themeVars,
1322 1167 'themeColors' => $helper_states->themeColors,
1323 1168 'builderSettings' => $helper_states->builderSettings,
1324 - 'customCode' => FrontEndScriptGenerator::getCustomCodes($formID),
1325 1169 'additional' => empty($form_content->additional) ? [
1326 1170 'enabled' => [
1327 1171 'blocked_ip' => false,
1328 1172 'restrict_form' => false,
1329 - 'onePerIp' => false,
1330 1173 ],
1331 1174 'settings' => [
1332 1175 'restrict_form' => [
1333 1176 'day' => [],
@@ -1342,8 +1185,9 @@
1342 1185 ],
1343 1186 'entry_limit' => null,
1344 1187 'blocked_ip' => [],
1345 1188 ],
1189 + 'onePerIp' => false,
1346 1190 ] : $form_content->additional,
1347 1191 'created_at' => $formManager->getFormMetaData()['created_at'],
1348 1192 'views' => $formManager->getFormMetaData()['views'],
1349 1193 'entries' => $formManager->getFormMetaData()['entries'],
@@ -1384,9 +1228,9 @@
1384 1228 } else {
1385 1229 $returnedReportData[$reportKey]->details = [];
1386 1230 }
1387 1231 if ('1' === (string) $reportData->isDefault) {
1388 - $returnedReportData[$reportKey]->details->report_name = __('All Entries', 'bit-form');
1232 + $returnedReportData[$reportKey]->details->report_name = 'All Entries';
1389 1233 }
1390 1234 }
1391 1235 $reports = ['reports' => $returnedReportData];
1392 1236 $data = array_merge($data, $reports);
@@ -1400,10 +1244,10 @@
1400 1244 }
1401 1245
1402 1246 public function getAFormV1($Request, $post)
1403 1247 {
1404 - if (!empty($Request['id'])) {
1405 - $formID = absint(wp_unslash($Request['id']));
1248 + if (isset($Request['id'])) {
1249 + $formID = wp_unslash($Request['id']);
1406 1250 } else {
1407 1251 $formID = wp_unslash($post->id);
1408 1252 }
1409 1253 // return $post->fields;
@@ -1419,39 +1263,36 @@
1419 1263 $form_content_arr = [
1420 1264 'layout' => $form_content->layout,
1421 1265 'fields' => $form_content->fields,
1422 1266 'form_name' => $formManager->getFormName(),
1423 - 'workFlowExist' => isset($form_content->workFlowExist) ? $form_content->workFlowExist : [],
1267 + 'workFlowExist' => $form_content->workFlowExist,
1424 1268 'report_id' => isset($form_content->report_id) ? $form_content->report_id : null
1425 1269 ];
1426 1270 $successMessageHandler
1427 - = new SuccessMessageHandler($formID);
1271 + = new SuccessMessageHandler($formID);
1428 1272 $successMessages = $successMessageHandler->getAllMessage();
1429 1273 if (!is_wp_error($successMessages)) {
1430 1274 foreach ($successMessages as $sucessMessagekey => $sucessMessagevalue) {
1431 1275 $allConfirmation['type']['successMsg'][$sucessMessagekey] =
1432 - [
1433 - 'id' => $sucessMessagevalue->id,
1434 - 'title' => $sucessMessagevalue->message_title,
1435 - 'msg' => $sucessMessagevalue->message_content,
1436 - 'config' => !empty($sucessMessagevalue->message_config) ? json_decode($sucessMessagevalue->message_config) : (object) [],
1437 - ];
1276 + [
1277 + 'id' => $sucessMessagevalue->id,
1278 + 'title' => $sucessMessagevalue->message_title,
1279 + 'msg' => $sucessMessagevalue->message_content,
1280 + ];
1438 1281 }
1439 1282 }
1440 1283 $emailTemplateHandler
1441 - = new EmailTemplateHandler($formID);
1284 + = new EmailTemplateHandler($formID);
1442 1285 $emailTemplates = $emailTemplateHandler->getAllTemplate();
1443 1286 if (!is_wp_error($emailTemplates)) {
1444 1287 foreach ($emailTemplates as $emailTemplatekey => $emailTemplatevalue) {
1445 1288 $mailTem[] =
1446 - [
1447 - 'id' => $emailTemplatevalue->id,
1448 - 'title' => $emailTemplatevalue->title,
1449 - 'sub' => $emailTemplatevalue->sub,
1450 - 'body' => $emailTemplatevalue->body,
1451 - 'status' => isset($emailTemplatevalue->status) ? (int) $emailTemplatevalue->status : 1,
1452 - 'config' => !empty($emailTemplatevalue->config) ? json_decode($emailTemplatevalue->config) : (object) [],
1453 - ];
1289 + [
1290 + 'id' => $emailTemplatevalue->id,
1291 + 'title' => $emailTemplatevalue->title,
1292 + 'sub' => $emailTemplatevalue->sub,
1293 + 'body' => $emailTemplatevalue->body,
1294 + ];
1454 1295 }
1455 1296 }
1456 1297 $integrationHandler = new IntegrationHandler($formID);
1457 1298 $formIntegrations = $integrationHandler->getAllIntegration('form');
@@ -1458,11 +1299,10 @@
1458 1299 if (!is_wp_error($formIntegrations)) {
1459 1300 foreach ($formIntegrations as $integrationkey => $integrationValue) {
1460 1301 if ('redirectPage' === $integrationValue->integration_type || 'webHooks' === $integrationValue->integration_type) {
1461 1302 $integrationData = [
1462 - 'id' => $integrationValue->id,
1463 - 'title' => $integrationValue->integration_name,
1464 - 'status' => isset($integrationValue->status) ? (int) $integrationValue->status : 1,
1303 + 'id' => $integrationValue->id,
1304 + 'title' => $integrationValue->integration_name,
1465 1305 ];
1466 1306 if (!empty($integrationValue->integration_details)) {
1467 1307 // var_dump(json_decode($integrationValue->integration_details));
1468 1308 $integration_details = (array) json_decode($integrationValue->integration_details);
@@ -1473,9 +1313,9 @@
1473 1313 ];
1474 1314 $integrationData = array_merge($integrationData, $integration_details);
1475 1315 }
1476 1316 $allConfirmation['type'][$integrationValue->integration_type][]
1477 - = $integrationData;
1317 + = $integrationData;
1478 1318 } else {
1479 1319 $integrationData = [
1480 1320 'id' => $integrationValue->id,
1481 1321 'name' => $integrationValue->integration_name,
@@ -1483,10 +1323,10 @@
1483 1323 ];
1484 1324 $integrations[] = array_merge(
1485 1325 $integrationData,
1486 1326 is_string($integrationValue->integration_details) ?
1487 - (array) json_decode($integrationValue->integration_details) :
1488 - $integrationValue->integration_details
1327 + (array) json_decode($integrationValue->integration_details) :
1328 + $integrationValue->integration_details
1489 1329 );
1490 1330 }
1491 1331 }
1492 1332 }
@@ -1546,9 +1386,8 @@
1546 1386 'additional' => empty($form_content->additional) ? [
1547 1387 'enabled' => [
1548 1388 'blocked_ip' => false,
1549 1389 'restrict_form' => false,
1550 - 'onePerIp' => false,
1551 1390 ],
1552 1391 'settings' => [
1553 1392 'restrict_form' => [
1554 1393 'day' => [],
@@ -1563,8 +1402,9 @@
1563 1402 ],
1564 1403 'entry_limit' => null,
1565 1404 'blocked_ip' => [],
1566 1405 ],
1406 + 'onePerIp' => false,
1567 1407 ] : $form_content->additional,
1568 1408 'created_at' => $formManager->getFormMetaData()['created_at'],
1569 1409 'views' => $formManager->getFormMetaData()['views'],
1570 1410 'entries' => $formManager->getFormMetaData()['entries'],
@@ -1605,9 +1445,9 @@
1605 1445 } else {
1606 1446 $returnedReportData[$reportKey]->details = [];
1607 1447 }
1608 1448 if ('1' === (string) $reportData->isDefault) {
1609 - $returnedReportData[$reportKey]->details->report_name = __('All Entries', 'bit-form');
1449 + $returnedReportData[$reportKey]->details->report_name = 'All Entries';
1610 1450 }
1611 1451 }
1612 1452 $reports = ['reports' => $returnedReportData];
1613 1453 $data = array_merge($data, $reports);
@@ -1621,10 +1461,10 @@
1621 1461 }
1622 1462
1623 1463 public function deleteAForm($Request, $post)
1624 1464 {
1625 - if (!empty($Request['id'])) {
1626 - $formID = absint(wp_unslash($Request['id']));
1465 + if (isset($Request['id'])) {
1466 + $formID = wp_unslash($Request['id']);
1627 1467 } else {
1628 1468 $formID = wp_unslash($post->id);
1629 1469 }
1630 1470 if (is_null($formID)) {
@@ -1639,9 +1479,8 @@
1639 1479 [
1640 1480 'id' => $formID,
1641 1481 ]
1642 1482 );
1643 - do_action('bitform_admin_form_changed');
1644 1483
1645 1484 $successMessageModel = new SuccessMessageModel();
1646 1485 $deleteMsgStatus = $successMessageModel->delete(['form_id' => $formID]);
1647 1486
@@ -1647,12 +1486,10 @@
1647 1486
1648 1487 $emailTemplateModel = new EmailTemplateModel();
1649 1488 $deleteTemplateStatus = $emailTemplateModel->delete(['form_id' => $formID]);
1650 1489
1651 - if (class_exists('\BitCode\BitFormPro\Core\Database\PdfTemplateModel')) {
1652 - $pdfTemplateModel = new \BitCode\BitFormPro\Core\Database\PdfTemplateModel();
1653 - $deletePdfTemplateStatus = $pdfTemplateModel->delete(['form_id' => $formID]);
1654 - }
1490 + $pdfTemplateModel = new PdfTemplateModel();
1491 + $deletePdfTemplateStatus = $pdfTemplateModel->delete(['form_id' => $formID]);
1655 1492
1656 1493 $integrationModel = new IntegrationModel();
1657 1494 $deleteIntegrationStatus = $integrationModel->delete(['form_id' => $formID]);
1658 1495
@@ -1699,10 +1536,10 @@
1699 1536 }
1700 1537
1701 1538 public function deleteBlukForm($Request, $post)
1702 1539 {
1703 - if (!empty($Request['formID'])) {
1704 - $formID = array_map('absint', wp_unslash($Request['formID']));
1540 + if (isset($Request['formID'])) {
1541 + $formID = wp_unslash($Request['formID']);
1705 1542 } else {
1706 1543 $formID = wp_unslash($post->formID);
1707 1544 }
1708 1545
@@ -1729,9 +1566,8 @@
1729 1566 [
1730 1567 'id' => $formID,
1731 1568 ]
1732 1569 );
1733 - do_action('bitform_admin_form_changed');
1734 1570
1735 1571 if (is_wp_error($delete_status)) {
1736 1572 wp_send_json_error($delete_status->get_error_message(), 400);
1737 1573 }
@@ -1742,12 +1578,10 @@
1742 1578
1743 1579 $emailTemplateModel = new EmailTemplateModel();
1744 1580 $deleteTemplateStatus = $emailTemplateModel->bulkDelete(['form_id' => $formID]);
1745 1581
1746 - if (class_exists('\BitCode\BitFormPro\Core\Database\PdfTemplateModel')) {
1747 - $pdfTemplateModel = new \BitCode\BitFormPro\Core\Database\PdfTemplateModel();
1748 - $deletePdfTemplateStatus = $pdfTemplateModel->bulkDelete(['form_id' => $formID]);
1749 - }
1582 + $pdfTemplateModel = new PdfTemplateModel();
1583 + $deletePdfTemplateStatus = $pdfTemplateModel->bulkDelete(['form_id' => $formID]);
1750 1584
1751 1585 $integrationModel = new IntegrationModel();
1752 1586 $deleteIntegrationStatus = $integrationModel->bulkDelete(['form_id' => $formID]);
1753 1587
@@ -1780,14 +1614,8 @@
1780 1614 ]
1781 1615 );
1782 1616 }
1783 1617
1784 - // delete entry log and details; table name interpolation only — $wpdb->prepare() parameterizes the form_id value.
1785 - $wpdb->query($wpdb->prepare(
1786 - "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",
1787 - $formID
1788 - ));
1789 -
1790 1618 $fileHandler = new FileHandler();
1791 1619 foreach ($formID as $fId) {
1792 1620 if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $fId)) {
1793 1621 $fileHandler->rmrf(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $fId);
@@ -1834,15 +1662,21 @@
1834 1662 if (!is_wp_error($duplicateResponse) || (is_wp_error($duplicateResponse) && 'result_empty' === $duplicateResponse->get_error_code())) {
1835 1663 // duplicate stylesheet
1836 1664 $style_dir = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR;
1837 1665 // layout style copy
1838 - $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'));
1839 1668 $newStyle = str_replace(".bf$oldFormId-", ".bf$newFormId-", $styleStr);
1840 - 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);
1841 1672 // style copy
1842 - $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'));
1843 1675 $newStyle = str_replace("-$oldFormId", "-$newFormId", $styleStr);
1844 - FileHandler::writeFile($style_dir . "bitform-$newFormId.css", $newStyle);
1676 + $createStyleFile = fopen($style_dir . "bitform-$newFormId.css", 'w');
1677 + fwrite($createStyleFile, $newStyle);
1678 + fclose($createStyleFile);
1845 1679 $duplicatedForm = $this->getAForm(null, (object) ['id' => $newFormId]);
1846 1680 $duplicatedForm['message'] = __('Form duplicated successfully', 'bit-form');
1847 1681 return $duplicatedForm;
1848 1682 }
@@ -1855,15 +1689,15 @@
1855 1689 $newFormId = intval($post->newFormId);
1856 1690 if (!$oldFormId || empty($post->formDetail->fields) || empty($post->formDetail->layout)) {
1857 1691 return new WP_Error('invalid_form', __('Please import a valid json.', 'bit-form'));
1858 1692 }
1859 - $importtedForm = (array) $post->formDetail;
1693 + $importtedForm = (array)$post->formDetail;
1860 1694 $importtedForm['form_content']['fields'] = $importtedForm['fields'];
1861 1695 $importtedForm['form_content']['layout'] = $importtedForm['layout'];
1862 1696 $importtedForm['form_content']['nestedLayout'] = $importtedForm['nestedLayouts'];
1863 1697 $importtedForm['form_content']['formInfo'] = $importtedForm['formInfo'];
1864 1698 unset($importtedForm['fields'], $importtedForm['layout'], $importtedForm['nestedLayout'], $importtedForm['formInfo']);
1865 - $formData = FormDuplicateHelper::createReplica((array) $importtedForm, $oldFormId, $newFormId);
1699 + $formData = FormDuplicateHelper::createReplica((array)$importtedForm, $oldFormId, $newFormId);
1866 1700
1867 1701 if (!empty($importtedForm['rowHeight'])) {
1868 1702 $formData->rowHeight = $importtedForm['rowHeight'];
1869 1703 }
@@ -1950,9 +1784,9 @@
1950 1784 return new WP_Error('empty_form', __('Form does not exists.', 'bit-form'));
1951 1785 }
1952 1786
1953 1787 $newFormId = $oldFormId;
1954 - $duplicatedForm = $this->getAForm($Request, (object) ['id' => $oldFormId]);
1788 + $duplicatedForm = $this->getAForm($Request, (object)['id' => $oldFormId]);
1955 1789 $formData = FormDuplicateHelper::createReplica($duplicatedForm, $oldFormId, $newFormId);
1956 1790 // for custom css
1957 1791 $customCssPath = 'form-styles/bitform-custom-' . $newFormId . '.css';
1958 1792 $cssPath = Helpers::generatePathDirOrFile($customCssPath);
@@ -1972,10 +1806,10 @@
1972 1806 }
1973 1807
1974 1808 public function getFormEntryLabelAndCount($Request, $post)
1975 1809 {
1976 - if (!empty($Request['id'])) {
1977 - $id = absint(wp_unslash($Request['id']));
1810 + if (isset($Request['id'])) {
1811 + $id = wp_unslash($Request['id']);
1978 1812 } else {
1979 1813 $id = wp_unslash($post->id);
1980 1814 }
1981 1815 if (is_null($id)) {
@@ -2028,74 +1862,16 @@
2028 1862 $response['fieldDetails'] = $labels;
2029 1863 return $response;
2030 1864 }
2031 1865
2032 - /**
2033 - * Sanitize a request-supplied entry query condition before it reaches the Model
2034 - * layer. Only known entry-table columns are allowed as condition keys, operators
2035 - * are restricted to a safe allow-list ['form_id' => $id] when nothing valid remains.
2036 - *
2037 - * @param mixed $queryCondition
2038 - * @param int $id
2039 - * @return array
2040 - */
2041 - private function sanitizeEntryQueryCondition($queryCondition, $id)
2042 - {
2043 - $allowedColumns = [
2044 - 'id', 'form_id', 'status', 'created_at', 'updated_at',
2045 - 'user_id', 'user_ip', 'user_device', 'user_location', 'referer',
2046 - ];
2047 - $allowedOperators = ['=', '!=', '<>', '<', '>', '<=', '>=', 'LIKE', 'IN'];
2048 -
2049 - if (!is_array($queryCondition)) {
2050 - return ['form_id' => $id];
2051 - }
2052 -
2053 - $safe = [];
2054 - foreach ($queryCondition as $key => $value) {
2055 - if (!in_array($key, $allowedColumns, true)) {
2056 - continue;
2057 - }
2058 -
2059 - if (is_array($value)) {
2060 - // Never honour a request-supplied raw SQL fragment.
2061 - unset($value['raw']);
2062 -
2063 - if (array_key_exists('operator', $value) || array_key_exists('value', $value)) {
2064 - $operator = isset($value['operator']) && is_string($value['operator'])
2065 - ? strtoupper(trim($value['operator']))
2066 - : '=';
2067 - if (!in_array($operator, $allowedOperators, true)) {
2068 - $operator = '=';
2069 - }
2070 - $condValue = isset($value['value']) ? $value['value'] : '';
2071 - if (is_scalar($condValue)) {
2072 - $safe[$key] = ['operator' => $operator, 'value' => $condValue];
2073 - }
2074 - } else {
2075 - // IN-style list: keep scalar members only (bound by the Model).
2076 - $list = array_values(array_filter($value, 'is_scalar'));
2077 - if (!empty($list)) {
2078 - $safe[$key] = $list;
2079 - }
2080 - }
2081 - } elseif (is_scalar($value)) {
2082 - $safe[$key] = $value;
2083 - }
2084 - }
2085 -
2086 - return empty($safe) ? ['form_id' => $id] : $safe;
2087 - }
2088 -
2089 1866 public function getFormEntry($Request, $post)
2090 1867 {
2091 - if (!empty($Request['id'])) {
2092 - $id = absint(wp_unslash($Request['id']));
1868 + if (isset($Request['id'])) {
1869 + $id = wp_unslash($Request['id']);
2093 1870 $offset = isset($Request['offset']) ?
2094 1871 wp_unslash($Request['offset']) : 0;
2095 1872 $pageSize = isset($Request['pageSize']) ?
2096 1873 wp_unslash($Request['pageSize']) : 10;
2097 - $queryCondition = isset($Request['queryCondition']) ? wp_unslash($Request['queryCondition']) : ['form_id' => $id];
2098 1874 } else {
2099 1875 $id = wp_unslash($post->id);
2100 1876 $conditions = isset($post->conditions) ? wp_unslash($post->conditions) : [];
2101 1877 $dateBetweenFilter = isset($post->entriesFilterByDate) ? wp_unslash($post->entriesFilterByDate) : [];
@@ -2104,11 +1880,9 @@
2104 1880 $filters = isset($post->filters) ? wp_unslash($post->filters) : null;
2105 1881 $globalFilter = isset($post->globalFilter) ? wp_unslash($post->globalFilter) : null;
2106 1882 $pageSize = isset($post->pageSize) ?
2107 1883 wp_unslash($post->pageSize) : 10;
2108 - $queryCondition = isset($post->queryCondition) ? wp_unslash($post->queryCondition) : ['form_id' => $id];
2109 1884 }
2110 - $queryCondition = $this->sanitizeEntryQueryCondition($queryCondition, $id);
2111 1885 if (is_null($id)) {
2112 1886 return new WP_Error('empty_form', __('Form id is empty.', 'bit-form'));
2113 1887 }
2114 1888 $formManager = new AdminFormManager($id);
@@ -2114,12 +1888,15 @@
2114 1888 $formManager = new AdminFormManager($id);
2115 1889 if (!$formManager->isExist()) {
2116 1890 return new WP_Error('empty_form', __('Form does not exists', 'bit-form'));
2117 1891 }
1892 +
2118 1893 $formEntry = new FormEntryModel();
2119 1894 $entries = $formEntry->get(
2120 1895 'id',
2121 - $queryCondition,
1896 + [
1897 + 'form_id' => $id,
1898 + ],
2122 1899 null,
2123 1900 null,
2124 1901 'created_at',
2125 1902 'DESC'
@@ -2158,14 +1935,10 @@
2158 1935 $entryMeta = new FormEntryMetaModel();
2159 1936 // $formEntry = new FormEntryModel();
2160 1937
2161 1938 $entries = $entryMeta->getSingleEntryMeta($formFields, $entryId);
1939 + return $entries[0];
2162 1940
2163 - if (!is_wp_error($entries)) {
2164 - return $entries[0];
2165 - }
2166 - return new WP_Error('entry_not_fonud', __('Entry Not Found!', 'bit-form'));
2167 -
2168 1941 // $customFieldHandler = new CustomFieldHandler();
2169 1942 // $formEntries = $customFieldHandler->updatedEntries($formEntries, $fieldDetails);
2170 1943 // return $formEntries;
2171 1944 }
@@ -2171,10 +1944,10 @@
2171 1944 }
2172 1945
2173 1946 public function getEntriesForReport($Request, $post)
2174 1947 {
2175 - if (!empty($Request['id'])) {
2176 - $id = absint(wp_unslash($Request['id']));
1948 + if (isset($Request['id'])) {
1949 + $id = wp_unslash($Request['id']);
2177 1950 $offset = isset($Request['offset']) ?
2178 1951 wp_unslash($Request['offset']) : null;
2179 1952 $pageSize = isset($Request['pageSize']) ?
2180 1953 wp_unslash($Request['pageSize']) : null;
@@ -2235,9 +2008,8 @@
2235 2008 {
2236 2009 $formId = wp_unslash($post->formId);
2237 2010 $fileFormate = isset($post->fileFormate) ? wp_unslash($post->fileFormate) : null;
2238 2011 $limit = isset($post->limit) ? wp_unslash($post->limit) : null;
2239 - $entryCondition = isset($post->filter) ? wp_unslash($post->filter) : null;
2240 2012 $sortBy = isset($post->sort) ? wp_unslash($post->sort) : 'ASC';
2241 2013 $sortByField = isset($post->sortField) ? wp_unslash($post->sortField) : 'bitforms_form_entry_id';
2242 2014 $formFields = json_decode($post->selectedField);
2243 2015 if (is_null($formId)) {
@@ -2270,17 +2042,17 @@
2270 2042 return $entries;
2271 2043 }
2272 2044 $entryMeta = new FormEntryMetaModel();
2273 2045 $filter = [];
2274 - $formEntries = $entryMeta->getExportEntry($formFields, $entries, $formId, $fieldLabels, $limit, $sortBy, $sortByField, $offset, $entryCondition);
2046 + $formEntries = $entryMeta->getExportEntry($formFields, $entries, $formId, $fieldLabels, $limit, $sortBy, $sortByField);
2275 2047 return $formEntries;
2276 2048 }
2277 2049
2278 2050 public function deleteBlukFormEntries($Request, $post)
2279 2051 {
2280 - if (!empty($Request['formID'])) {
2281 - $formID = absint(wp_unslash($Request['formID']));
2282 - $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']);
2283 2055 } else {
2284 2056 $formID = wp_unslash($post->formID);
2285 2057 $entries = wp_unslash($post->entries);
2286 2058 }
@@ -2300,18 +2072,16 @@
2300 2072 if (!$formManager->isExist()) {
2301 2073 return new WP_Error('empty_form', __('Form does not exist.', 'bit-form'));
2302 2074 }
2303 2075 $workFlowRunHelper = new WorkFlow($formID);
2304 -
2305 2076 $workFlowreturnedOnDelete = $workFlowRunHelper->executeOnDelete(
2306 2077 $formManager,
2307 2078 $formID,
2308 2079 $entries
2309 2080 );
2310 -
2311 2081 if (isset($workFlowreturnedOnDelete['entries'])) {
2312 2082 if (0 === count($workFlowreturnedOnDelete['entries'])) {
2313 - return ['message' => __('Entry Deletetion prevented by workflow', 'bit-form')];
2083 + return ['message' => __('Entry Deletetion prevented by workflow', 'bit-form')];
2314 2084 } elseif (count($workFlowreturnedOnDelete['entries']) === count($entries)) {
2315 2085 $message = __('Entry Deleted successfully', 'bit-form');
2316 2086 } else {
2317 2087 $result['prevented'] = array_diff($entries, $workFlowreturnedOnDelete['entries']);
@@ -2332,9 +2102,9 @@
2332 2102 );
2333 2103 if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID)) {
2334 2104 $fileHandler = new FileHandler();
2335 2105 foreach ($entries as $enrtyKey => $entryID) {
2336 - $fileEntries = $fileHandler->getEntriesFileUploadDir($formID, $entryID);
2106 + $fileEntries = BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID . DIRECTORY_SEPARATOR . $entryID;
2337 2107 if (file_exists($fileEntries)) {
2338 2108 $fileHandler->rmrf($fileEntries);
2339 2109 }
2340 2110 }
@@ -2353,11 +2123,11 @@
2353 2123 }
2354 2124
2355 2125 public function duplicateFormEntry($Request, $post)
2356 2126 {
2357 - if (!empty($Request['formID'])) {
2358 - $formID = absint(wp_unslash($Request['formID']));
2359 - $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']);
2360 2130 } else {
2361 2131 $formID = wp_unslash($post->formID);
2362 2132 $entries = wp_unslash($post->entries);
2363 2133 }
@@ -2406,12 +2176,12 @@
2406 2176 );
2407 2177 if ($duplicate_status) {
2408 2178 $result['details'][$entryID] = $duplicatedEntryId;
2409 2179 $duplicate_count = $duplicate_count + 1;
2410 - if (file_exists(FileHandler::getEntriesFileUploadDir($formID, $entryID))) {
2180 + if (file_exists(BITFORMS_UPLOAD_DIR . "/$formID/$entryID")) {
2411 2181 $fileHandler->cpyr(
2412 - FileHandler::getEntriesFileUploadDir($formID, $entryID),
2413 - FileHandler::getEntriesFileUploadDir($formID, $duplicatedEntryId)
2182 + BITFORMS_UPLOAD_DIR . "/$formID/$entryID",
2183 + BITFORMS_UPLOAD_DIR . "/$formID/$duplicatedEntryId"
2414 2184 );
2415 2185 }
2416 2186 }
2417 2187 }
@@ -2428,11 +2198,11 @@
2428 2198 }
2429 2199
2430 2200 public function editFormEntry($Request, $post)
2431 2201 {
2432 - if (!empty($Request['formID'])) {
2433 - $formID = absint(wp_unslash($Request['formID']));
2434 - $entryID = absint(wp_unslash($Request['entryID']));
2202 + if (isset($Request['formID'])) {
2203 + $formID = wp_unslash($Request['formID']);
2204 + $entryID = wp_unslash($Request['entryID']);
2435 2205 } else {
2436 2206 $formID = wp_unslash($post->formID);
2437 2207 $entryID = wp_unslash($post->entryID);
2438 2208 }
@@ -2507,16 +2277,15 @@
2507 2277
2508 2278 public function updateFormEntry($Request, $post)
2509 2279 {
2510 2280 if (isset($Request['formID'], $Request['entryID'])) {
2511 - $formID = absint(wp_unslash($Request['formID']));
2512 - $entryID = absint(wp_unslash($Request['entryID']));
2281 + $formID = wp_unslash($Request['formID']);
2282 + $entryID = wp_unslash($Request['entryID']);
2513 2283 unset($Request['action'], $Request['formID'], $Request['entryID']);
2514 2284 }
2515 2285 $formManager = new AdminFormManager($formID);
2516 2286 $formManager->fieldNameReplaceOfPost();
2517 - // Called from AdminAjax handler; nonce already verified at AJAX entry before dispatch.
2518 - $updatedValue = is_array($post) ? $post : wp_unslash($_POST);
2287 + $updatedValue = wp_unslash($_POST);
2519 2288
2520 2289 if (is_null($updatedValue) || !is_array($updatedValue)) {
2521 2290 return new WP_Error('empty_data', __('Failed to update, Data is empty.', 'bit-form'));
2522 2291 }
@@ -2532,11 +2301,11 @@
2532 2301 }
2533 2302
2534 2303 public function getLogHistory($Request, $post)
2535 2304 {
2536 - if (!empty($Request['formID'])) {
2537 - $formID = absint(wp_unslash($Request['formID']));
2538 - $entryID = absint(wp_unslash($Request['entryID']));
2305 + if (isset($Request['formID'])) {
2306 + $formID = wp_unslash($Request['formID']);
2307 + $entryID = wp_unslash($Request['entryID']);
2539 2308 } else {
2540 2309 $formID = wp_unslash($post->formID);
2541 2310 $entryID = wp_unslash($post->entryID);
2542 2311 }
@@ -2556,10 +2325,10 @@
2556 2325 }
2557 2326
2558 2327 public function importDataStore($Request, $post)
2559 2328 {
2560 - if (!empty($Request['formID'])) {
2561 - $formID = absint(wp_unslash($Request['formID']));
2329 + if (isset($Request['formID'])) {
2330 + $formID = wp_unslash($Request['formID']);
2562 2331 } else {
2563 2332 $formID = wp_unslash($post->formID);
2564 2333 }
2565 2334 if (is_null($formID)) {
@@ -2571,14 +2340,10 @@
2571 2340 {
2572 2341 $pages = get_pages(['post_status' => 'publish', 'sort_column' => 'post_date', 'sort_order' => 'desc']);
2573 2342 $allPages = [];
2574 2343 foreach ($pages as $pageKey => $pageDetails) {
2575 - // $allPages[$pageKey]['title'] = $pageDetails->post_title;
2576 - // $allPages[$pageKey]['url'] = get_page_link($pageDetails->ID);
2577 - $allPages[] = (object) [
2578 - 'title' => $pageDetails->post_title,
2579 - 'url' => get_page_link($pageDetails->ID)
2580 - ];
2344 + $allPages[$pageKey]['title'] = $pageDetails->post_title;
2345 + $allPages[$pageKey]['url'] = get_page_link($pageDetails->ID);
2581 2346 }
2582 2347 return $allPages;
2583 2348 }
2584 2349
@@ -2583,11 +2348,11 @@
2583 2348 }
2584 2349
2585 2350 public function deleteAIntegration($Request, $post)
2586 2351 {
2587 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2588 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2589 - $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']);
2590 2355 } else {
2591 2356 $formID = wp_unslash($post->formID);
2592 2357 $id = wp_unslash($post->id);
2593 2358 }
@@ -2607,11 +2372,11 @@
2607 2372 }
2608 2373
2609 2374 public function deleteSuccessMessage($Request, $post)
2610 2375 {
2611 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2612 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2613 - $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']);
2614 2379 } else {
2615 2380 $formID = wp_unslash($post->formID);
2616 2381 $id = wp_unslash($post->id);
2617 2382 }
@@ -2630,11 +2395,11 @@
2630 2395 }
2631 2396
2632 2397 public function deleteAWorkflow($Request, $post)
2633 2398 {
2634 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2635 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2636 - $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']);
2637 2402 } else {
2638 2403 $formID = wp_unslash($post->formID);
2639 2404 $id = wp_unslash($post->id);
2640 2405 }
@@ -2652,11 +2417,11 @@
2652 2417 }
2653 2418
2654 2419 public function deleteAMailTemplate($Request, $post)
2655 2420 {
2656 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2657 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2658 - $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']);
2659 2424 } else {
2660 2425 $formID = wp_unslash($post->formID);
2661 2426 $id = wp_unslash($post->id);
2662 2427 }
@@ -2674,11 +2439,11 @@
2674 2439 }
2675 2440
2676 2441 public function duplicateAMailTemplate($Request, $post)
2677 2442 {
2678 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2679 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2680 - $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']);
2681 2446 } else {
2682 2447 $formID = wp_unslash($post->formID);
2683 2448 $id = wp_unslash($post->id);
2684 2449 }
@@ -2837,9 +2602,9 @@
2837 2602 $paySetting = json_decode($paySetting);
2838 2603 }
2839 2604
2840 2605 $canSave = null;
2841 - switch ($paySetting->type) {
2606 + switch($paySetting->type) {
2842 2607 case 'PayPal':
2843 2608 $canSave = $this->addWebhookToPaypal($paySetting);
2844 2609 break;
2845 2610 case 'Razorpay':
@@ -2940,16 +2705,15 @@
2940 2705 }
2941 2706 }
2942 2707
2943 2708 $data = [
2944 - 'enabled_events[]' => 'payment_intent.succeeded',
2945 - 'url' => $webhook_url,
2709 + 'enabled_events[]' => 'payment_intent.succeeded',
2710 + 'url' => $webhook_url,
2946 2711 ];
2947 2712
2948 2713 if (!$webhook_already_exist) {
2949 2714 $webhook_response = HttpHelper::post($create_webhook_url, $data, $headers);
2950 2715 if (is_wp_error($webhook_response) || (isset($webhook_response->error) && $webhook_response->error)) {
2951 - Log::debug_log(['Stripe webhook creation failed' => $webhook_response]);
2952 2716 return null;
2953 2717 }
2954 2718 }
2955 2719 return true;
@@ -2989,49 +2753,8 @@
2989 2753 } elseif (!$update_status) {
2990 2754 return new WP_Error('empty_form', __('Form update failed.', 'bit-form'));
2991 2755 } else {
2992 2756 return true;
2993 - }
2994 - }
2995 -
2996 - public function replaceAllFormsErrorMessagesByGlobalMessages()
2997 - {
2998 - try {
2999 - $formModel = new FormModel();
3000 - $allForms = $formModel->get(['id', 'form_content']);
3001 -
3002 - foreach ($allForms as $form) {
3003 - // Decode form_content JSON to stdClass
3004 - $formContent = \json_decode($form->form_content);
3005 - $fields = $formContent->fields ?? null;
3006 - // If decode fails, skip to next
3007 - if (!$fields) {
3008 - Log::debug_log("Form ID {$form->id}: invalid JSON in form_content");
3009 - continue;
3010 - }
3011 -
3012 - // Replace default error messages using your helper
3013 - $updatedFields = Helpers::replaceFieldsDefaultErrorMsg($fields);
3014 -
3015 - $formContent->fields = $updatedFields;
3016 - // Encode back to JSON
3017 - $updatedContent = \json_encode($formContent);
3018 -
3019 - if (false === $updatedContent) {
3020 - Log::debug_log("Form ID {$form->id}: JSON encoding failed");
3021 - continue;
3022 - }
3023 - // Update form content in DB
3024 - $formModel->update(
3025 - ['form_content' => $updatedContent], // data to update
3026 - ['id' => $form->id] // condition for update
3027 - );
3028 - }
3029 - } catch (\Exception $e) {
3030 - Log::debug_log([
3031 - 'message' => 'Error in updateAllFormsErrorMessagesWithGlobalMessages',
3032 - 'error' => $e->getMessage(),
3033 - ]);
3034 2757 }
3035 2758 }
3036 2759
3037 2760 public function updateSuccessMessageClassName($str, $msgIdx, $msgId)