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 -475 3.3.12.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' => [],
@@ -524,12 +490,8 @@
524 490 $updated_data['form_content']['is_default'] = 1;
525 491 }
526 492 $updated_data['message'] = __('Form Saved successfully', 'bit-form');
527 493
528 - // Form and dependent rows are persisted; multilingual providers register
529 - // the form's translatable strings here.
530 - do_action('bitform_form_saved', $save_status);
531 -
532 494 return $updated_data;
533 495 }
534 496 }
535 497
@@ -559,14 +521,13 @@
559 521 if (property_exists($post, 'builderSettings')) {
560 522 $builder_helper_state->builderSettings = $post->builderSettings;
561 523 }
562 524 if (property_exists($post, 'atomicClassMap')) {
563 - $atomic_class_map = \wp_json_encode((object) $post->atomicClassMap);
525 + $atomic_class_map = \wp_json_encode((object)$post->atomicClassMap);
564 526 }
565 527
566 528 if (property_exists($post, 'fields') && null !== $post->fields && property_exists($post, 'layout') && $post->layout) {
567 529 $fields = wp_unslash($post->fields);
568 - $fields = Helpers::replaceFieldsDefaultErrorMsg($fields);
569 530 $layout = wp_unslash($post->layout);
570 531 $nestedLayout = wp_unslash($post->nestedLayouts);
571 532 $formInfo = wp_unslash($post->formInfo);
572 533 $formID = wp_unslash($post->id);
@@ -586,10 +547,16 @@
586 547 if (empty($fields) || empty($layout) || is_null($formID)) {
587 548 return new WP_Error('empty_form', 'Can not update empty form.');
588 549 }
589 550
590 - // Guard: never persist orphan fields (see createNewForm). Fail closed.
591 - $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 + }
592 559
593 560 $form_content = [
594 561 'fields' => $fields,
595 562 'layout' => $layout,
@@ -631,11 +598,8 @@
631 598 $savedID = $successMessageHandler->saveMessage($messageDetail);
632 599 if ($savedID) {
633 600 $newData['settingConfiramation'] = 1;
634 601 $integartionIDForWorkflow['successMsg'][$messageKey] = $savedID;
635 - if (!empty($messageDetail->clRef)) {
636 - $integartionIDForWorkflow['confirmationCLRef'][$messageDetail->clRef] = $savedID;
637 - }
638 602 $messageDetail->id = $savedID;
639 603 $builder_helper_state->style = $this->updateSuccessMessageClassName($builder_helper_state->style, $messageKey, $savedID);
640 604 if (isset($atomic_class_map)) {
641 605 $atomic_class_map = $this->updateSuccessMessageClassName($atomic_class_map, $messageKey, $savedID);
@@ -660,29 +624,18 @@
660 624 $newData['mailTemplate'] = 2;
661 625 } else {
662 626 $newData['mailTemplate'] = 1;
663 627 $integartionIDForWorkflow['mailTem'][$templateKey] = $savedID;
664 - if (!empty($templateDetail->clRef)) {
665 - $integartionIDForWorkflow['emailCLRef'][$templateDetail->clRef] = $savedID;
666 - }
667 - // return the new id (and drop the temp ref) so the frontend reconciles the template
668 - $templateDetail->id = $savedID;
669 - unset($templateDetail->clRef);
670 628 }
671 629 } else {
672 - $updated = $emailTemplateHandler->updateTemplate($templateDetail);
673 - if (is_wp_error($updated) && 'db_error' === $updated->get_error_code()) {
674 - $newData['mailTemplate'] = 2;
675 - } elseif (0 === $newData['mailTemplate']) {
676 - $newData['mailTemplate'] = 1;
677 - }
630 + $emailTemplateHandler->updateTemplate($templateDetail);
678 631 }
679 632 }
680 633 }
681 634 // return $formSettings;
682 635 // Email Template [end] */
683 - if (!empty($pdfTem) && class_exists('\BitCode\BitFormPro\Core\Messages\PdfTemplateHandler')) {
684 - $pdfTemplateHandler = new \BitCode\BitFormPro\Core\Messages\PdfTemplateHandler($formID);
636 + if (!empty($pdfTem)) {
637 + $pdfTemplateHandler = new PdfTemplateHandler($formID);
685 638
686 639 foreach ($pdfTem as $templateKey => $templateDetail) {
687 640 if (isset($templateDetail->setting->font->name)) {
688 641 $this->pdfFontDownload($templateDetail->setting->font->name);
@@ -702,15 +655,8 @@
702 655 if (!empty($formSettings->confirmation->type)) {
703 656 $allIntegrations = $formSettings->confirmation->type;
704 657 foreach ($allIntegrations as $integrationType => $integrationGroup) {
705 658 foreach ($integrationGroup as $singleIntegrationKey => $singleIntegrationDetail) {
706 - // Redirect (and webhook) enable/disable toggle persists to the integration status column.
707 - $integrationStatus = isset($singleIntegrationDetail->status) ? (int) $singleIntegrationDetail->status : 1;
708 - // Inline-CL temp ref for a brand-new redirect (reconciled to the real id for workflow rows).
709 - $clRef = isset($singleIntegrationDetail->clRef) ? $singleIntegrationDetail->clRef : null;
710 - if (is_object($singleIntegrationDetail)) {
711 - unset($singleIntegrationDetail->status, $singleIntegrationDetail->clRef);
712 - }
713 659 if (empty($singleIntegrationDetail->details)) {
714 660 $integrationName = $singleIntegrationDetail->title;
715 661 unset($singleIntegrationDetail->title);
716 662 $singleIntegrationDetailID = empty($singleIntegrationDetail->id) ? null : $singleIntegrationDetail->id;
@@ -724,16 +670,13 @@
724 670 $integrationDetails = !is_string($singleIntegrationDetail->details) ?
725 671 wp_json_encode($singleIntegrationDetail->details) : $singleIntegrationDetail->details;
726 672 }
727 673 if (empty($singleIntegrationDetailID)) {
728 - $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form', $integrationStatus);
674 + $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form');
729 675 $newData['settingConfiramation'] = 1;
730 676 $integartionIDForWorkflow[$integrationType][$singleIntegrationKey] = $savedID;
731 - if (!empty($clRef) && 'redirectPage' === $integrationType) {
732 - $integartionIDForWorkflow['redirectCLRef'][$clRef] = $savedID;
733 - }
734 677 } else {
735 - $integrationHandler->updateIntegration($singleIntegrationDetailID, $integrationName, $integrationType, $integrationDetails, 'form', $integrationStatus);
678 + $integrationHandler->updateIntegration($singleIntegrationDetailID, $integrationName, $integrationType, $integrationDetails, 'form');
736 679 }
737 680 }
738 681 }
739 682 }
@@ -744,11 +687,8 @@
744 687 $integrationType = $singleIntegrationDetail->type;
745 688 unset($singleIntegrationDetail->type);
746 689 $singleIntegrationDetailID = empty($singleIntegrationDetail->id) ? null : $singleIntegrationDetail->id;
747 690 unset($singleIntegrationDetail->id);
748 - // Inline-CL temp ref for a brand-new integration (reconciled to the real id for workflow rows).
749 - $clRef = isset($singleIntegrationDetail->__bf_cl_ref) ? $singleIntegrationDetail->__bf_cl_ref : null;
750 - unset($singleIntegrationDetail->__bf_cl_ref);
751 691 if (empty($singleIntegrationDetail->details)) {
752 692 $integrationDetails = !is_string($singleIntegrationDetail) ?
753 693 wp_json_encode($singleIntegrationDetail) : $singleIntegrationDetail;
754 694 } else {
@@ -757,11 +697,8 @@
757 697 }
758 698 if (empty($singleIntegrationDetailID)) {
759 699 $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form');
760 700 $integartionIDForWorkflow[$integrationType][$singleIntegrationKey] = $savedID;
761 - if (!empty($clRef) && !is_wp_error($savedID)) {
762 - $integartionIDForWorkflow['integrationCLRef'][$clRef] = $savedID;
763 - }
764 701 if (is_wp_error($savedID) && 'result_empty' !== $savedID->get_error_code()) {
765 702 $newData['integation'] = 2;
766 703 } else {
767 704 $newData['integation'] = 1;
@@ -801,11 +738,8 @@
801 738 }
802 739 $form_content = array_merge($form_content, ['workFlowExist' => $workFlowExist]);
803 740 //wrokFlows [end]
804 741 //reports [start] */
805 - // read unconditionally after the reports block; a save without currentReport
806 - // must not trip an undefined-variable warning
807 - $reportIsDefault = null;
808 742 if (!empty($reports)) {
809 743 $reportsModel = new ReportsModel();
810 744 $fieldNames = [];
811 745 foreach ($fields as $key => $field) {
@@ -817,19 +751,15 @@
817 751
818 752 $fieldNames['__user_id'] = __('User', 'bit-form');
819 753 $fieldNames['__user_ip'] = __('IP address', 'bit-form');
820 754 // $fieldNames['__user_location'] = __('');
821 - $fieldNames['__referer'] = __('Refer URL', 'bit-form');
822 - $fieldNames['__user_device'] = __('Device', 'bit-form');
823 - $fieldNames['__created_at'] = __('Created Time', 'bit-form');
824 - $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');
825 759
826 760 $reportIsDefault = null;
827 - // The client posts currentReport as {} whenever its report atom has not resolved yet. That
828 - // is an empty stdClass, which empty() above treats as non-empty, so we reach here with
829 - // nothing to save — and writing the validated result would replace the stored report's
830 - // column order, hidden columns, page size and name with an empty list. Leave the row alone.
831 - if (isset($form_content['report_id']) && ReportsModel::isValidatableReport($reports)) {
761 + if (isset($form_content['report_id'])) {
832 762 $validDateReport = $reportsModel->validateReportFields($reports, $fieldNames);
833 763 if (isset($reports->isDefault)) {
834 764 $reportIsDefault = $reports->isDefault;
835 765 } else {
@@ -878,9 +808,9 @@
878 808 'form_name' => $form_name,
879 809 'form_content' => $form_content,
880 810 'user_id' => $user_details['id'],
881 811 'user_ip' => $user_details['ip'],
882 - 'builder_helper_state' => \wp_json_encode((object) $builder_helper_state),
812 + 'builder_helper_state' => \wp_json_encode((object)$builder_helper_state),
883 813 'generated_script_page_ids' => \wp_json_encode((object) []),
884 814 'user_device' => $user_details['device'],
885 815 'updated_at' => $user_details['time'],
886 816 ];
@@ -886,16 +816,15 @@
886 816 ];
887 817 if (isset($atomic_class_map)) {
888 818 $updateData['atomic_class_map'] = $atomic_class_map;
889 819 }
890 - $formUpdateVersion = get_option('bitform_form_update_version');
820 + $formUpdateVersion = get_option('bit-form_form_update_version');
891 821 if (!$formUpdateVersion) {
892 822 $formUpdateVersion = 1;
893 823 } else {
894 824 $formUpdateVersion = (int) $formUpdateVersion + 1;
895 825 }
896 - update_option('bitform_form_update_version', $formUpdateVersion);
897 - do_action('bitform_admin_form_changed');
826 + update_option('bit-form_form_update_version', $formUpdateVersion);
898 827
899 828 $update_status = static::$formModel->update(
900 829 $updateData,
901 830 [
@@ -940,14 +869,9 @@
940 869 }
941 870 if (2 === $newData['reports']) {
942 871 $errorIN .= empty($errorIN) ? 'reports' : ', reports';
943 872 }
944 - // See createNewForm(). Fired before the partial-failure return: the rows
945 - // that did save are already persisted, so their strings still need registering.
946 - do_action('bitform_form_saved', $formId);
947 -
948 873 if (!empty($errorIN)) {
949 - /* translators: %s: comma-separated list of areas where error occurred */
950 874 $updated_data['message'] = sprintf(__('Error Occured in saving %s', 'bit-form'), $errorIN);
951 875 return new WP_Error('Form update Error.', $updated_data);
952 876 }
953 877 if (null !== $reportIsDefault) {
@@ -952,77 +876,30 @@
952 876 }
953 877 if (null !== $reportIsDefault) {
954 878 $updated_data['form_content']['is_default'] = $reportIsDefault;
955 879 }
956 - $updated_data['message'] = __('Form updated successfully.', 'bit-form');
957 -
880 + $updated_data['message'] = __('Form updated successfully.', 'bitform');
958 881 return $updated_data;
959 882 }
960 883 }
961 884
962 - /**
963 - * Drop orphan fields (present in `fields` but in no layout) from form_content
964 - * before persisting, and remove now-childless nestedLayout entries.
965 - *
966 - * Entry meta is NEVER touched here — only explicit user deletes clear meta
967 - * (see setEmptyMetaValue). Fail closed: an unusable/partial layout, or a
968 - * client that flagged a failed pre-save layout sync (->skipOrphanPrune),
969 - * prunes nothing. Pruned keys are logged, never silently dropped.
970 - *
971 - * @param object|array $fields by ref; orphan keys removed
972 - * @param object|null $nestedLayout by ref; stale container entries removed
973 - * @param array|object $layout raw layout (single or multi-step)
974 - * @param int|string|null $formID for logging ('new' when absent)
975 - * @param object $post raw request; honors ->skipOrphanPrune
976 - */
977 - private function pruneOrphanFields(&$fields, &$nestedLayout, $layout, $formID, $post)
978 - {
979 - $formLabel = $formID ? $formID : 'new';
980 - if (isset($post->skipOrphanPrune) && $post->skipOrphanPrune) {
981 - Log::debug_log('Bit Form: orphan prune skipped (client reported failed layout sync). FormID=' . $formLabel);
982 - return;
983 - }
984 - $orphanFldKeys = FormManager::computeOrphanFieldKeys($layout, $nestedLayout, $fields);
985 - // null = unusable/partial layout (fail closed); [] = nothing to prune
986 - if (!is_array($orphanFldKeys) || empty($orphanFldKeys)) {
987 - return;
988 - }
989 - Log::debug_log('Bit Form: pruning orphan fields (absent from every layout). FormID=' . $formLabel . ' keys=' . implode(',', $orphanFldKeys));
990 - foreach ($orphanFldKeys as $orphanKey) {
991 - if (is_object($fields)) {
992 - unset($fields->{$orphanKey});
993 - } elseif (is_array($fields)) {
994 - unset($fields[$orphanKey]);
995 - }
996 - }
997 - // prune stale nestedLayout entries — containers that no longer exist in fields
998 - if (is_object($nestedLayout)) {
999 - foreach (array_keys(get_object_vars($nestedLayout)) as $nKey) {
1000 - $parentExists = is_object($fields) ? isset($fields->{$nKey}) : isset($fields[$nKey]);
1001 - if (!$parentExists) {
1002 - unset($nestedLayout->{$nKey});
1003 - }
1004 - }
1005 - }
1006 - }
1007 -
1008 885 public function setEmptyMetaValue($fieldkeys)
1009 886 {
887 + $sqlEscaped = array_map(function ($fld) {
888 + return "'" . esc_sql($fld) . "'";
889 + }, $fieldkeys);
890 + $deletedFldKey = implode(',', $sqlEscaped);
1010 891 global $wpdb;
1011 - // Placeholders and arguments built dynamically from $fieldkeys; count matches at runtime.
1012 - $placeholders = implode(',', array_fill(0, \count($fieldkeys), '%s'));
1013 - $wpdb->query($wpdb->prepare(
1014 - "UPDATE `{$wpdb->prefix}bitforms_form_entrymeta` SET meta_value = %s WHERE meta_key IN ($placeholders)",
1015 - '',
1016 - ...$fieldkeys
1017 - ));
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);
1018 895 }
1019 896
1020 897 public function changeFormStatus($Request, $post)
1021 898 {
1022 899 if (isset($Request['status']) && $Request['id']) {
1023 - $status = sanitize_text_field(wp_unslash($Request['status']));
1024 - $id = absint(wp_unslash($Request['id']));
900 + $status = wp_unslash($Request['status']);
901 + $id = wp_unslash($Request['id']);
1025 902 } else {
1026 903 $status = wp_unslash($post->status);
1027 904 $id = wp_unslash($post->id);
1028 905 }
@@ -1056,10 +933,10 @@
1056 933
1057 934 public function changeBulkFormStatus($Request, $post)
1058 935 {
1059 936 if (isset($Request['status']) && $Request['formID']) {
1060 - $status = sanitize_text_field(wp_unslash($Request['status']));
1061 - $formID = array_map('absint', wp_unslash($Request['formID']));
937 + $status = wp_unslash($Request['status']);
938 + $formID = wp_unslash($Request['formID']);
1062 939 } else {
1063 940 $status = wp_unslash($post->status);
1064 941 $formID = wp_unslash($post->formID);
1065 942 }
@@ -1094,13 +971,9 @@
1094 971 public function getAllForm()
1095 972 {
1096 973 global $wpdb;
1097 974
1098 - // Direct query: table name interpolation only (no user input). $wpdb->prepare() cannot parameterize table names.
1099 - $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
1100 - FROM `{$wpdb->prefix}bitforms_form` as forms
1101 - LEFT JOIN `{$wpdb->prefix}bitforms_form_entries` as entries ON forms.id = entries.form_id
1102 - 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");
1103 976
1104 977 if (is_wp_error($allForms)) {
1105 978 return $allForms;
1106 979 } elseif (!$allForms) {
@@ -1111,10 +984,10 @@
1111 984 }
1112 985
1113 986 public function getAForm($Request, $post)
1114 987 {
1115 - if (!empty($Request['id'])) {
1116 - $formID = absint(wp_unslash($Request['id']));
988 + if (isset($Request['id'])) {
989 + $formID = wp_unslash($Request['id']);
1117 990 } else {
1118 991 $formID = wp_unslash($post->id);
1119 992 }
1120 993 // return $post->fields;
@@ -1133,9 +1006,9 @@
1133 1006 'nestedLayout' => !empty($form_content->nestedLayout) ? $form_content->nestedLayout : (object) [],
1134 1007 'formInfo' => !empty($form_content->formInfo) ? $form_content->formInfo : (object) ['formName' => $formManager->getFormName()],
1135 1008 'fields' => $form_content->fields,
1136 1009 'form_name' => $formManager->getFormName(),
1137 - 'workFlowExist' => isset($form_content->workFlowExist) ? $form_content->workFlowExist : [],
1010 + 'workFlowExist' => $form_content->workFlowExist,
1138 1011 'report_id' => isset($form_content->report_id) ? $form_content->report_id : null
1139 1012 ];
1140 1013 $successMessageHandler
1141 1014 = new SuccessMessageHandler($formID);
@@ -1158,37 +1031,28 @@
1158 1031 if (!is_wp_error($emailTemplates)) {
1159 1032 foreach ($emailTemplates as $emailTemplatekey => $emailTemplatevalue) {
1160 1033 $mailTem[] =
1161 1034 [
1162 - 'id' => $emailTemplatevalue->id,
1163 - 'title' => $emailTemplatevalue->title,
1164 - 'sub' => $emailTemplatevalue->sub,
1165 - 'body' => $emailTemplatevalue->body,
1166 - 'status' => isset($emailTemplatevalue->status) ? (int) $emailTemplatevalue->status : 1,
1167 - 'config' => EmailTemplateHandler::normalizeConfig($emailTemplatevalue->config ?? null),
1035 + 'id' => $emailTemplatevalue->id,
1036 + 'title' => $emailTemplatevalue->title,
1037 + 'sub' => $emailTemplatevalue->sub,
1038 + 'body' => $emailTemplatevalue->body,
1168 1039 ];
1169 1040 }
1170 1041 }
1171 1042 // get all pdf template
1172 - if (class_exists('\BitCode\BitFormPro\Core\Messages\PdfTemplateHandler')) {
1173 - $pdfTemplateHandler = new \BitCode\BitFormPro\Core\Messages\PdfTemplateHandler($formID);
1174 - $pdfTemplates = $pdfTemplateHandler->getAll();
1043 + $pdfTemplateHandler = new PdfTemplateHandler($formID);
1044 + $pdfTemplates = $pdfTemplateHandler->getAll();
1175 1045
1176 - if (!is_wp_error($pdfTemplates)) {
1177 - foreach ($pdfTemplates as $value) {
1178 - $pdfTem[] =
1179 - [
1180 - 'id' => $value->id,
1181 - 'title' => $value->title,
1182 - 'setting' => json_decode($value->setting),
1183 - 'pdf_config' => !empty($value->pdf_config) ? json_decode($value->pdf_config) : (object) [
1184 - 'status' => 1,
1185 - 'header' => '',
1186 - 'footer' => '',
1187 - ],
1188 - 'body' => $value->body,
1189 - ];
1190 - }
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 + ];
1191 1055 }
1192 1056 }
1193 1057
1194 1058 $integrationHandler = new IntegrationHandler($formID);
@@ -1196,11 +1060,10 @@
1196 1060 if (!is_wp_error($formIntegrations)) {
1197 1061 foreach ($formIntegrations as $integrationkey => $integrationValue) {
1198 1062 if ('redirectPage' === $integrationValue->integration_type || 'webHooks' === $integrationValue->integration_type) {
1199 1063 $integrationData = [
1200 - 'id' => $integrationValue->id,
1201 - 'title' => $integrationValue->integration_name,
1202 - 'status' => isset($integrationValue->status) ? (int) $integrationValue->status : 1,
1064 + 'id' => $integrationValue->id,
1065 + 'title' => $integrationValue->integration_name,
1203 1066 ];
1204 1067 if (!empty($integrationValue->integration_details)) {
1205 1068 $integration_details = (array) json_decode($integrationValue->integration_details);
1206 1069 $integrationData = array_merge($integration_details, $integrationData);
@@ -1226,22 +1089,8 @@
1226 1089 );
1227 1090 }
1228 1091 }
1229 1092 }
1230 -
1231 - // get form abandonment integration if exist
1232 - $formAbandonmentInteg = $integrationHandler->getAllIntegration('formAbandonment', 'formAbandonment');
1233 - if (!is_wp_error($formAbandonmentInteg) && !empty($formAbandonmentInteg)) {
1234 - $formAbandonmentInteg = $formAbandonmentInteg[0];
1235 - if (!empty($formAbandonmentInteg->integration_details)) {
1236 - $formAbandonment = json_decode($formAbandonmentInteg->integration_details);
1237 - } else {
1238 - $formAbandonment = (object) [];
1239 - }
1240 - } else {
1241 - $formAbandonment = (object) [];
1242 - }
1243 -
1244 1093 $settingsContent = [
1245 1094 'formName' => $formManager->getFormName(),
1246 1095 'theme' => isset($form_content->theme) ? $form_content->theme : 'default',
1247 1096 'formPermissions' => isset($form_content->formPermissions) ? $form_content->formPermissions : (object) [],
@@ -1304,24 +1153,8 @@
1304 1153 'pdfTem' => [],
1305 1154 ]
1306 1155 );
1307 1156 }
1308 -
1309 - if (!empty($formAbandonment)) {
1310 - $settingsContent = array_merge(
1311 - $settingsContent,
1312 - [
1313 - 'formAbandonment' => $formAbandonment,
1314 - ]
1315 - );
1316 - } else {
1317 - $settingsContent = array_merge(
1318 - $settingsContent,
1319 - [
1320 - 'formAbandonment' => (object) [],
1321 - ]
1322 - );
1323 - }
1324 1157 $formSettings = [
1325 1158 'formSettings' => $settingsContent,
1326 1159 ];
1327 1160 $data = [
@@ -1332,14 +1165,12 @@
1332 1165 'style' => $helper_states->style,
1333 1166 'themeVars' => $helper_states->themeVars,
1334 1167 'themeColors' => $helper_states->themeColors,
1335 1168 'builderSettings' => $helper_states->builderSettings,
1336 - 'customCode' => FrontEndScriptGenerator::getCustomCodes($formID),
1337 1169 'additional' => empty($form_content->additional) ? [
1338 1170 'enabled' => [
1339 1171 'blocked_ip' => false,
1340 1172 'restrict_form' => false,
1341 - 'onePerIp' => false,
1342 1173 ],
1343 1174 'settings' => [
1344 1175 'restrict_form' => [
1345 1176 'day' => [],
@@ -1354,8 +1185,9 @@
1354 1185 ],
1355 1186 'entry_limit' => null,
1356 1187 'blocked_ip' => [],
1357 1188 ],
1189 + 'onePerIp' => false,
1358 1190 ] : $form_content->additional,
1359 1191 'created_at' => $formManager->getFormMetaData()['created_at'],
1360 1192 'views' => $formManager->getFormMetaData()['views'],
1361 1193 'entries' => $formManager->getFormMetaData()['entries'],
@@ -1396,9 +1228,9 @@
1396 1228 } else {
1397 1229 $returnedReportData[$reportKey]->details = [];
1398 1230 }
1399 1231 if ('1' === (string) $reportData->isDefault) {
1400 - $returnedReportData[$reportKey]->details->report_name = __('All Entries', 'bit-form');
1232 + $returnedReportData[$reportKey]->details->report_name = 'All Entries';
1401 1233 }
1402 1234 }
1403 1235 $reports = ['reports' => $returnedReportData];
1404 1236 $data = array_merge($data, $reports);
@@ -1412,10 +1244,10 @@
1412 1244 }
1413 1245
1414 1246 public function getAFormV1($Request, $post)
1415 1247 {
1416 - if (!empty($Request['id'])) {
1417 - $formID = absint(wp_unslash($Request['id']));
1248 + if (isset($Request['id'])) {
1249 + $formID = wp_unslash($Request['id']);
1418 1250 } else {
1419 1251 $formID = wp_unslash($post->id);
1420 1252 }
1421 1253 // return $post->fields;
@@ -1431,39 +1263,36 @@
1431 1263 $form_content_arr = [
1432 1264 'layout' => $form_content->layout,
1433 1265 'fields' => $form_content->fields,
1434 1266 'form_name' => $formManager->getFormName(),
1435 - 'workFlowExist' => isset($form_content->workFlowExist) ? $form_content->workFlowExist : [],
1267 + 'workFlowExist' => $form_content->workFlowExist,
1436 1268 'report_id' => isset($form_content->report_id) ? $form_content->report_id : null
1437 1269 ];
1438 1270 $successMessageHandler
1439 - = new SuccessMessageHandler($formID);
1271 + = new SuccessMessageHandler($formID);
1440 1272 $successMessages = $successMessageHandler->getAllMessage();
1441 1273 if (!is_wp_error($successMessages)) {
1442 1274 foreach ($successMessages as $sucessMessagekey => $sucessMessagevalue) {
1443 1275 $allConfirmation['type']['successMsg'][$sucessMessagekey] =
1444 - [
1445 - 'id' => $sucessMessagevalue->id,
1446 - 'title' => $sucessMessagevalue->message_title,
1447 - 'msg' => $sucessMessagevalue->message_content,
1448 - 'config' => !empty($sucessMessagevalue->message_config) ? json_decode($sucessMessagevalue->message_config) : (object) [],
1449 - ];
1276 + [
1277 + 'id' => $sucessMessagevalue->id,
1278 + 'title' => $sucessMessagevalue->message_title,
1279 + 'msg' => $sucessMessagevalue->message_content,
1280 + ];
1450 1281 }
1451 1282 }
1452 1283 $emailTemplateHandler
1453 - = new EmailTemplateHandler($formID);
1284 + = new EmailTemplateHandler($formID);
1454 1285 $emailTemplates = $emailTemplateHandler->getAllTemplate();
1455 1286 if (!is_wp_error($emailTemplates)) {
1456 1287 foreach ($emailTemplates as $emailTemplatekey => $emailTemplatevalue) {
1457 1288 $mailTem[] =
1458 - [
1459 - 'id' => $emailTemplatevalue->id,
1460 - 'title' => $emailTemplatevalue->title,
1461 - 'sub' => $emailTemplatevalue->sub,
1462 - 'body' => $emailTemplatevalue->body,
1463 - 'status' => isset($emailTemplatevalue->status) ? (int) $emailTemplatevalue->status : 1,
1464 - 'config' => EmailTemplateHandler::normalizeConfig($emailTemplatevalue->config ?? null),
1465 - ];
1289 + [
1290 + 'id' => $emailTemplatevalue->id,
1291 + 'title' => $emailTemplatevalue->title,
1292 + 'sub' => $emailTemplatevalue->sub,
1293 + 'body' => $emailTemplatevalue->body,
1294 + ];
1466 1295 }
1467 1296 }
1468 1297 $integrationHandler = new IntegrationHandler($formID);
1469 1298 $formIntegrations = $integrationHandler->getAllIntegration('form');
@@ -1470,11 +1299,10 @@
1470 1299 if (!is_wp_error($formIntegrations)) {
1471 1300 foreach ($formIntegrations as $integrationkey => $integrationValue) {
1472 1301 if ('redirectPage' === $integrationValue->integration_type || 'webHooks' === $integrationValue->integration_type) {
1473 1302 $integrationData = [
1474 - 'id' => $integrationValue->id,
1475 - 'title' => $integrationValue->integration_name,
1476 - 'status' => isset($integrationValue->status) ? (int) $integrationValue->status : 1,
1303 + 'id' => $integrationValue->id,
1304 + 'title' => $integrationValue->integration_name,
1477 1305 ];
1478 1306 if (!empty($integrationValue->integration_details)) {
1479 1307 // var_dump(json_decode($integrationValue->integration_details));
1480 1308 $integration_details = (array) json_decode($integrationValue->integration_details);
@@ -1485,9 +1313,9 @@
1485 1313 ];
1486 1314 $integrationData = array_merge($integrationData, $integration_details);
1487 1315 }
1488 1316 $allConfirmation['type'][$integrationValue->integration_type][]
1489 - = $integrationData;
1317 + = $integrationData;
1490 1318 } else {
1491 1319 $integrationData = [
1492 1320 'id' => $integrationValue->id,
1493 1321 'name' => $integrationValue->integration_name,
@@ -1495,10 +1323,10 @@
1495 1323 ];
1496 1324 $integrations[] = array_merge(
1497 1325 $integrationData,
1498 1326 is_string($integrationValue->integration_details) ?
1499 - (array) json_decode($integrationValue->integration_details) :
1500 - $integrationValue->integration_details
1327 + (array) json_decode($integrationValue->integration_details) :
1328 + $integrationValue->integration_details
1501 1329 );
1502 1330 }
1503 1331 }
1504 1332 }
@@ -1558,9 +1386,8 @@
1558 1386 'additional' => empty($form_content->additional) ? [
1559 1387 'enabled' => [
1560 1388 'blocked_ip' => false,
1561 1389 'restrict_form' => false,
1562 - 'onePerIp' => false,
1563 1390 ],
1564 1391 'settings' => [
1565 1392 'restrict_form' => [
1566 1393 'day' => [],
@@ -1575,8 +1402,9 @@
1575 1402 ],
1576 1403 'entry_limit' => null,
1577 1404 'blocked_ip' => [],
1578 1405 ],
1406 + 'onePerIp' => false,
1579 1407 ] : $form_content->additional,
1580 1408 'created_at' => $formManager->getFormMetaData()['created_at'],
1581 1409 'views' => $formManager->getFormMetaData()['views'],
1582 1410 'entries' => $formManager->getFormMetaData()['entries'],
@@ -1617,9 +1445,9 @@
1617 1445 } else {
1618 1446 $returnedReportData[$reportKey]->details = [];
1619 1447 }
1620 1448 if ('1' === (string) $reportData->isDefault) {
1621 - $returnedReportData[$reportKey]->details->report_name = __('All Entries', 'bit-form');
1449 + $returnedReportData[$reportKey]->details->report_name = 'All Entries';
1622 1450 }
1623 1451 }
1624 1452 $reports = ['reports' => $returnedReportData];
1625 1453 $data = array_merge($data, $reports);
@@ -1633,10 +1461,10 @@
1633 1461 }
1634 1462
1635 1463 public function deleteAForm($Request, $post)
1636 1464 {
1637 - if (!empty($Request['id'])) {
1638 - $formID = absint(wp_unslash($Request['id']));
1465 + if (isset($Request['id'])) {
1466 + $formID = wp_unslash($Request['id']);
1639 1467 } else {
1640 1468 $formID = wp_unslash($post->id);
1641 1469 }
1642 1470 if (is_null($formID)) {
@@ -1651,9 +1479,8 @@
1651 1479 [
1652 1480 'id' => $formID,
1653 1481 ]
1654 1482 );
1655 - do_action('bitform_admin_form_changed');
1656 1483
1657 1484 $successMessageModel = new SuccessMessageModel();
1658 1485 $deleteMsgStatus = $successMessageModel->delete(['form_id' => $formID]);
1659 1486
@@ -1659,12 +1486,10 @@
1659 1486
1660 1487 $emailTemplateModel = new EmailTemplateModel();
1661 1488 $deleteTemplateStatus = $emailTemplateModel->delete(['form_id' => $formID]);
1662 1489
1663 - if (class_exists('\BitCode\BitFormPro\Core\Database\PdfTemplateModel')) {
1664 - $pdfTemplateModel = new \BitCode\BitFormPro\Core\Database\PdfTemplateModel();
1665 - $deletePdfTemplateStatus = $pdfTemplateModel->delete(['form_id' => $formID]);
1666 - }
1490 + $pdfTemplateModel = new PdfTemplateModel();
1491 + $deletePdfTemplateStatus = $pdfTemplateModel->delete(['form_id' => $formID]);
1667 1492
1668 1493 $integrationModel = new IntegrationModel();
1669 1494 $deleteIntegrationStatus = $integrationModel->delete(['form_id' => $formID]);
1670 1495
@@ -1711,10 +1536,10 @@
1711 1536 }
1712 1537
1713 1538 public function deleteBlukForm($Request, $post)
1714 1539 {
1715 - if (!empty($Request['formID'])) {
1716 - $formID = array_map('absint', wp_unslash($Request['formID']));
1540 + if (isset($Request['formID'])) {
1541 + $formID = wp_unslash($Request['formID']);
1717 1542 } else {
1718 1543 $formID = wp_unslash($post->formID);
1719 1544 }
1720 1545
@@ -1741,9 +1566,8 @@
1741 1566 [
1742 1567 'id' => $formID,
1743 1568 ]
1744 1569 );
1745 - do_action('bitform_admin_form_changed');
1746 1570
1747 1571 if (is_wp_error($delete_status)) {
1748 1572 wp_send_json_error($delete_status->get_error_message(), 400);
1749 1573 }
@@ -1754,12 +1578,10 @@
1754 1578
1755 1579 $emailTemplateModel = new EmailTemplateModel();
1756 1580 $deleteTemplateStatus = $emailTemplateModel->bulkDelete(['form_id' => $formID]);
1757 1581
1758 - if (class_exists('\BitCode\BitFormPro\Core\Database\PdfTemplateModel')) {
1759 - $pdfTemplateModel = new \BitCode\BitFormPro\Core\Database\PdfTemplateModel();
1760 - $deletePdfTemplateStatus = $pdfTemplateModel->bulkDelete(['form_id' => $formID]);
1761 - }
1582 + $pdfTemplateModel = new PdfTemplateModel();
1583 + $deletePdfTemplateStatus = $pdfTemplateModel->bulkDelete(['form_id' => $formID]);
1762 1584
1763 1585 $integrationModel = new IntegrationModel();
1764 1586 $deleteIntegrationStatus = $integrationModel->bulkDelete(['form_id' => $formID]);
1765 1587
@@ -1792,14 +1614,8 @@
1792 1614 ]
1793 1615 );
1794 1616 }
1795 1617
1796 - // delete entry log and details; table name interpolation only — $wpdb->prepare() parameterizes the form_id value.
1797 - $wpdb->query($wpdb->prepare(
1798 - "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",
1799 - $formID
1800 - ));
1801 -
1802 1618 $fileHandler = new FileHandler();
1803 1619 foreach ($formID as $fId) {
1804 1620 if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $fId)) {
1805 1621 $fileHandler->rmrf(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $fId);
@@ -1846,15 +1662,21 @@
1846 1662 if (!is_wp_error($duplicateResponse) || (is_wp_error($duplicateResponse) && 'result_empty' === $duplicateResponse->get_error_code())) {
1847 1663 // duplicate stylesheet
1848 1664 $style_dir = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR;
1849 1665 // layout style copy
1850 - $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'));
1851 1668 $newStyle = str_replace(".bf$oldFormId-", ".bf$newFormId-", $styleStr);
1852 - 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);
1853 1672 // style copy
1854 - $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'));
1855 1675 $newStyle = str_replace("-$oldFormId", "-$newFormId", $styleStr);
1856 - FileHandler::writeFile($style_dir . "bitform-$newFormId.css", $newStyle);
1676 + $createStyleFile = fopen($style_dir . "bitform-$newFormId.css", 'w');
1677 + fwrite($createStyleFile, $newStyle);
1678 + fclose($createStyleFile);
1857 1679 $duplicatedForm = $this->getAForm(null, (object) ['id' => $newFormId]);
1858 1680 $duplicatedForm['message'] = __('Form duplicated successfully', 'bit-form');
1859 1681 return $duplicatedForm;
1860 1682 }
@@ -1867,15 +1689,15 @@
1867 1689 $newFormId = intval($post->newFormId);
1868 1690 if (!$oldFormId || empty($post->formDetail->fields) || empty($post->formDetail->layout)) {
1869 1691 return new WP_Error('invalid_form', __('Please import a valid json.', 'bit-form'));
1870 1692 }
1871 - $importtedForm = (array) $post->formDetail;
1693 + $importtedForm = (array)$post->formDetail;
1872 1694 $importtedForm['form_content']['fields'] = $importtedForm['fields'];
1873 1695 $importtedForm['form_content']['layout'] = $importtedForm['layout'];
1874 1696 $importtedForm['form_content']['nestedLayout'] = $importtedForm['nestedLayouts'];
1875 1697 $importtedForm['form_content']['formInfo'] = $importtedForm['formInfo'];
1876 1698 unset($importtedForm['fields'], $importtedForm['layout'], $importtedForm['nestedLayout'], $importtedForm['formInfo']);
1877 - $formData = FormDuplicateHelper::createReplica((array) $importtedForm, $oldFormId, $newFormId);
1699 + $formData = FormDuplicateHelper::createReplica((array)$importtedForm, $oldFormId, $newFormId);
1878 1700
1879 1701 if (!empty($importtedForm['rowHeight'])) {
1880 1702 $formData->rowHeight = $importtedForm['rowHeight'];
1881 1703 }
@@ -1962,9 +1784,9 @@
1962 1784 return new WP_Error('empty_form', __('Form does not exists.', 'bit-form'));
1963 1785 }
1964 1786
1965 1787 $newFormId = $oldFormId;
1966 - $duplicatedForm = $this->getAForm($Request, (object) ['id' => $oldFormId]);
1788 + $duplicatedForm = $this->getAForm($Request, (object)['id' => $oldFormId]);
1967 1789 $formData = FormDuplicateHelper::createReplica($duplicatedForm, $oldFormId, $newFormId);
1968 1790 // for custom css
1969 1791 $customCssPath = 'form-styles/bitform-custom-' . $newFormId . '.css';
1970 1792 $cssPath = Helpers::generatePathDirOrFile($customCssPath);
@@ -1984,10 +1806,10 @@
1984 1806 }
1985 1807
1986 1808 public function getFormEntryLabelAndCount($Request, $post)
1987 1809 {
1988 - if (!empty($Request['id'])) {
1989 - $id = absint(wp_unslash($Request['id']));
1810 + if (isset($Request['id'])) {
1811 + $id = wp_unslash($Request['id']);
1990 1812 } else {
1991 1813 $id = wp_unslash($post->id);
1992 1814 }
1993 1815 if (is_null($id)) {
@@ -2040,74 +1862,16 @@
2040 1862 $response['fieldDetails'] = $labels;
2041 1863 return $response;
2042 1864 }
2043 1865
2044 - /**
2045 - * Sanitize a request-supplied entry query condition before it reaches the Model
2046 - * layer. Only known entry-table columns are allowed as condition keys, operators
2047 - * are restricted to a safe allow-list ['form_id' => $id] when nothing valid remains.
2048 - *
2049 - * @param mixed $queryCondition
2050 - * @param int $id
2051 - * @return array
2052 - */
2053 - private function sanitizeEntryQueryCondition($queryCondition, $id)
2054 - {
2055 - $allowedColumns = [
2056 - 'id', 'form_id', 'status', 'created_at', 'updated_at',
2057 - 'user_id', 'user_ip', 'user_device', 'user_location', 'referer',
2058 - ];
2059 - $allowedOperators = ['=', '!=', '<>', '<', '>', '<=', '>=', 'LIKE', 'IN'];
2060 -
2061 - if (!is_array($queryCondition)) {
2062 - return ['form_id' => $id];
2063 - }
2064 -
2065 - $safe = [];
2066 - foreach ($queryCondition as $key => $value) {
2067 - if (!in_array($key, $allowedColumns, true)) {
2068 - continue;
2069 - }
2070 -
2071 - if (is_array($value)) {
2072 - // Never honour a request-supplied raw SQL fragment.
2073 - unset($value['raw']);
2074 -
2075 - if (array_key_exists('operator', $value) || array_key_exists('value', $value)) {
2076 - $operator = isset($value['operator']) && is_string($value['operator'])
2077 - ? strtoupper(trim($value['operator']))
2078 - : '=';
2079 - if (!in_array($operator, $allowedOperators, true)) {
2080 - $operator = '=';
2081 - }
2082 - $condValue = isset($value['value']) ? $value['value'] : '';
2083 - if (is_scalar($condValue)) {
2084 - $safe[$key] = ['operator' => $operator, 'value' => $condValue];
2085 - }
2086 - } else {
2087 - // IN-style list: keep scalar members only (bound by the Model).
2088 - $list = array_values(array_filter($value, 'is_scalar'));
2089 - if (!empty($list)) {
2090 - $safe[$key] = $list;
2091 - }
2092 - }
2093 - } elseif (is_scalar($value)) {
2094 - $safe[$key] = $value;
2095 - }
2096 - }
2097 -
2098 - return empty($safe) ? ['form_id' => $id] : $safe;
2099 - }
2100 -
2101 1866 public function getFormEntry($Request, $post)
2102 1867 {
2103 - if (!empty($Request['id'])) {
2104 - $id = absint(wp_unslash($Request['id']));
1868 + if (isset($Request['id'])) {
1869 + $id = wp_unslash($Request['id']);
2105 1870 $offset = isset($Request['offset']) ?
2106 1871 wp_unslash($Request['offset']) : 0;
2107 1872 $pageSize = isset($Request['pageSize']) ?
2108 1873 wp_unslash($Request['pageSize']) : 10;
2109 - $queryCondition = isset($Request['queryCondition']) ? wp_unslash($Request['queryCondition']) : ['form_id' => $id];
2110 1874 } else {
2111 1875 $id = wp_unslash($post->id);
2112 1876 $conditions = isset($post->conditions) ? wp_unslash($post->conditions) : [];
2113 1877 $dateBetweenFilter = isset($post->entriesFilterByDate) ? wp_unslash($post->entriesFilterByDate) : [];
@@ -2116,11 +1880,9 @@
2116 1880 $filters = isset($post->filters) ? wp_unslash($post->filters) : null;
2117 1881 $globalFilter = isset($post->globalFilter) ? wp_unslash($post->globalFilter) : null;
2118 1882 $pageSize = isset($post->pageSize) ?
2119 1883 wp_unslash($post->pageSize) : 10;
2120 - $queryCondition = isset($post->queryCondition) ? wp_unslash($post->queryCondition) : ['form_id' => $id];
2121 1884 }
2122 - $queryCondition = $this->sanitizeEntryQueryCondition($queryCondition, $id);
2123 1885 if (is_null($id)) {
2124 1886 return new WP_Error('empty_form', __('Form id is empty.', 'bit-form'));
2125 1887 }
2126 1888 $formManager = new AdminFormManager($id);
@@ -2126,12 +1888,15 @@
2126 1888 $formManager = new AdminFormManager($id);
2127 1889 if (!$formManager->isExist()) {
2128 1890 return new WP_Error('empty_form', __('Form does not exists', 'bit-form'));
2129 1891 }
1892 +
2130 1893 $formEntry = new FormEntryModel();
2131 1894 $entries = $formEntry->get(
2132 1895 'id',
2133 - $queryCondition,
1896 + [
1897 + 'form_id' => $id,
1898 + ],
2134 1899 null,
2135 1900 null,
2136 1901 'created_at',
2137 1902 'DESC'
@@ -2170,14 +1935,10 @@
2170 1935 $entryMeta = new FormEntryMetaModel();
2171 1936 // $formEntry = new FormEntryModel();
2172 1937
2173 1938 $entries = $entryMeta->getSingleEntryMeta($formFields, $entryId);
1939 + return $entries[0];
2174 1940
2175 - if (!is_wp_error($entries)) {
2176 - return $entries[0];
2177 - }
2178 - return new WP_Error('entry_not_fonud', __('Entry Not Found!', 'bit-form'));
2179 -
2180 1941 // $customFieldHandler = new CustomFieldHandler();
2181 1942 // $formEntries = $customFieldHandler->updatedEntries($formEntries, $fieldDetails);
2182 1943 // return $formEntries;
2183 1944 }
@@ -2183,10 +1944,10 @@
2183 1944 }
2184 1945
2185 1946 public function getEntriesForReport($Request, $post)
2186 1947 {
2187 - if (!empty($Request['id'])) {
2188 - $id = absint(wp_unslash($Request['id']));
1948 + if (isset($Request['id'])) {
1949 + $id = wp_unslash($Request['id']);
2189 1950 $offset = isset($Request['offset']) ?
2190 1951 wp_unslash($Request['offset']) : null;
2191 1952 $pageSize = isset($Request['pageSize']) ?
2192 1953 wp_unslash($Request['pageSize']) : null;
@@ -2247,9 +2008,8 @@
2247 2008 {
2248 2009 $formId = wp_unslash($post->formId);
2249 2010 $fileFormate = isset($post->fileFormate) ? wp_unslash($post->fileFormate) : null;
2250 2011 $limit = isset($post->limit) ? wp_unslash($post->limit) : null;
2251 - $entryCondition = isset($post->filter) ? wp_unslash($post->filter) : null;
2252 2012 $sortBy = isset($post->sort) ? wp_unslash($post->sort) : 'ASC';
2253 2013 $sortByField = isset($post->sortField) ? wp_unslash($post->sortField) : 'bitforms_form_entry_id';
2254 2014 $formFields = json_decode($post->selectedField);
2255 2015 if (is_null($formId)) {
@@ -2282,17 +2042,17 @@
2282 2042 return $entries;
2283 2043 }
2284 2044 $entryMeta = new FormEntryMetaModel();
2285 2045 $filter = [];
2286 - $formEntries = $entryMeta->getExportEntry($formFields, $entries, $formId, $fieldLabels, $limit, $sortBy, $sortByField, $offset, $entryCondition);
2046 + $formEntries = $entryMeta->getExportEntry($formFields, $entries, $formId, $fieldLabels, $limit, $sortBy, $sortByField);
2287 2047 return $formEntries;
2288 2048 }
2289 2049
2290 2050 public function deleteBlukFormEntries($Request, $post)
2291 2051 {
2292 - if (!empty($Request['formID'])) {
2293 - $formID = absint(wp_unslash($Request['formID']));
2294 - $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']);
2295 2055 } else {
2296 2056 $formID = wp_unslash($post->formID);
2297 2057 $entries = wp_unslash($post->entries);
2298 2058 }
@@ -2312,18 +2072,16 @@
2312 2072 if (!$formManager->isExist()) {
2313 2073 return new WP_Error('empty_form', __('Form does not exist.', 'bit-form'));
2314 2074 }
2315 2075 $workFlowRunHelper = new WorkFlow($formID);
2316 -
2317 2076 $workFlowreturnedOnDelete = $workFlowRunHelper->executeOnDelete(
2318 2077 $formManager,
2319 2078 $formID,
2320 2079 $entries
2321 2080 );
2322 -
2323 2081 if (isset($workFlowreturnedOnDelete['entries'])) {
2324 2082 if (0 === count($workFlowreturnedOnDelete['entries'])) {
2325 - return ['message' => __('Entry Deletetion prevented by workflow', 'bit-form')];
2083 + return ['message' => __('Entry Deletetion prevented by workflow', 'bit-form')];
2326 2084 } elseif (count($workFlowreturnedOnDelete['entries']) === count($entries)) {
2327 2085 $message = __('Entry Deleted successfully', 'bit-form');
2328 2086 } else {
2329 2087 $result['prevented'] = array_diff($entries, $workFlowreturnedOnDelete['entries']);
@@ -2344,9 +2102,9 @@
2344 2102 );
2345 2103 if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID)) {
2346 2104 $fileHandler = new FileHandler();
2347 2105 foreach ($entries as $enrtyKey => $entryID) {
2348 - $fileEntries = $fileHandler->getEntriesFileUploadDir($formID, $entryID);
2106 + $fileEntries = BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID . DIRECTORY_SEPARATOR . $entryID;
2349 2107 if (file_exists($fileEntries)) {
2350 2108 $fileHandler->rmrf($fileEntries);
2351 2109 }
2352 2110 }
@@ -2365,11 +2123,11 @@
2365 2123 }
2366 2124
2367 2125 public function duplicateFormEntry($Request, $post)
2368 2126 {
2369 - if (!empty($Request['formID'])) {
2370 - $formID = absint(wp_unslash($Request['formID']));
2371 - $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']);
2372 2130 } else {
2373 2131 $formID = wp_unslash($post->formID);
2374 2132 $entries = wp_unslash($post->entries);
2375 2133 }
@@ -2418,12 +2176,12 @@
2418 2176 );
2419 2177 if ($duplicate_status) {
2420 2178 $result['details'][$entryID] = $duplicatedEntryId;
2421 2179 $duplicate_count = $duplicate_count + 1;
2422 - if (file_exists(FileHandler::getEntriesFileUploadDir($formID, $entryID))) {
2180 + if (file_exists(BITFORMS_UPLOAD_DIR . "/$formID/$entryID")) {
2423 2181 $fileHandler->cpyr(
2424 - FileHandler::getEntriesFileUploadDir($formID, $entryID),
2425 - FileHandler::getEntriesFileUploadDir($formID, $duplicatedEntryId)
2182 + BITFORMS_UPLOAD_DIR . "/$formID/$entryID",
2183 + BITFORMS_UPLOAD_DIR . "/$formID/$duplicatedEntryId"
2426 2184 );
2427 2185 }
2428 2186 }
2429 2187 }
@@ -2440,11 +2198,11 @@
2440 2198 }
2441 2199
2442 2200 public function editFormEntry($Request, $post)
2443 2201 {
2444 - if (!empty($Request['formID'])) {
2445 - $formID = absint(wp_unslash($Request['formID']));
2446 - $entryID = absint(wp_unslash($Request['entryID']));
2202 + if (isset($Request['formID'])) {
2203 + $formID = wp_unslash($Request['formID']);
2204 + $entryID = wp_unslash($Request['entryID']);
2447 2205 } else {
2448 2206 $formID = wp_unslash($post->formID);
2449 2207 $entryID = wp_unslash($post->entryID);
2450 2208 }
@@ -2519,16 +2277,15 @@
2519 2277
2520 2278 public function updateFormEntry($Request, $post)
2521 2279 {
2522 2280 if (isset($Request['formID'], $Request['entryID'])) {
2523 - $formID = absint(wp_unslash($Request['formID']));
2524 - $entryID = absint(wp_unslash($Request['entryID']));
2281 + $formID = wp_unslash($Request['formID']);
2282 + $entryID = wp_unslash($Request['entryID']);
2525 2283 unset($Request['action'], $Request['formID'], $Request['entryID']);
2526 2284 }
2527 2285 $formManager = new AdminFormManager($formID);
2528 2286 $formManager->fieldNameReplaceOfPost();
2529 - // Called from AdminAjax handler; nonce already verified at AJAX entry before dispatch.
2530 - $updatedValue = is_array($post) ? $post : wp_unslash($_POST);
2287 + $updatedValue = wp_unslash($_POST);
2531 2288
2532 2289 if (is_null($updatedValue) || !is_array($updatedValue)) {
2533 2290 return new WP_Error('empty_data', __('Failed to update, Data is empty.', 'bit-form'));
2534 2291 }
@@ -2544,11 +2301,11 @@
2544 2301 }
2545 2302
2546 2303 public function getLogHistory($Request, $post)
2547 2304 {
2548 - if (!empty($Request['formID'])) {
2549 - $formID = absint(wp_unslash($Request['formID']));
2550 - $entryID = absint(wp_unslash($Request['entryID']));
2305 + if (isset($Request['formID'])) {
2306 + $formID = wp_unslash($Request['formID']);
2307 + $entryID = wp_unslash($Request['entryID']);
2551 2308 } else {
2552 2309 $formID = wp_unslash($post->formID);
2553 2310 $entryID = wp_unslash($post->entryID);
2554 2311 }
@@ -2568,10 +2325,10 @@
2568 2325 }
2569 2326
2570 2327 public function importDataStore($Request, $post)
2571 2328 {
2572 - if (!empty($Request['formID'])) {
2573 - $formID = absint(wp_unslash($Request['formID']));
2329 + if (isset($Request['formID'])) {
2330 + $formID = wp_unslash($Request['formID']);
2574 2331 } else {
2575 2332 $formID = wp_unslash($post->formID);
2576 2333 }
2577 2334 if (is_null($formID)) {
@@ -2583,14 +2340,10 @@
2583 2340 {
2584 2341 $pages = get_pages(['post_status' => 'publish', 'sort_column' => 'post_date', 'sort_order' => 'desc']);
2585 2342 $allPages = [];
2586 2343 foreach ($pages as $pageKey => $pageDetails) {
2587 - // $allPages[$pageKey]['title'] = $pageDetails->post_title;
2588 - // $allPages[$pageKey]['url'] = get_page_link($pageDetails->ID);
2589 - $allPages[] = (object) [
2590 - 'title' => $pageDetails->post_title,
2591 - 'url' => get_page_link($pageDetails->ID)
2592 - ];
2344 + $allPages[$pageKey]['title'] = $pageDetails->post_title;
2345 + $allPages[$pageKey]['url'] = get_page_link($pageDetails->ID);
2593 2346 }
2594 2347 return $allPages;
2595 2348 }
2596 2349
@@ -2595,11 +2348,11 @@
2595 2348 }
2596 2349
2597 2350 public function deleteAIntegration($Request, $post)
2598 2351 {
2599 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2600 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2601 - $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']);
2602 2355 } else {
2603 2356 $formID = wp_unslash($post->formID);
2604 2357 $id = wp_unslash($post->id);
2605 2358 }
@@ -2619,11 +2372,11 @@
2619 2372 }
2620 2373
2621 2374 public function deleteSuccessMessage($Request, $post)
2622 2375 {
2623 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2624 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2625 - $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']);
2626 2379 } else {
2627 2380 $formID = wp_unslash($post->formID);
2628 2381 $id = wp_unslash($post->id);
2629 2382 }
@@ -2642,11 +2395,11 @@
2642 2395 }
2643 2396
2644 2397 public function deleteAWorkflow($Request, $post)
2645 2398 {
2646 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2647 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2648 - $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']);
2649 2402 } else {
2650 2403 $formID = wp_unslash($post->formID);
2651 2404 $id = wp_unslash($post->id);
2652 2405 }
@@ -2664,11 +2417,11 @@
2664 2417 }
2665 2418
2666 2419 public function deleteAMailTemplate($Request, $post)
2667 2420 {
2668 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2669 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2670 - $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']);
2671 2424 } else {
2672 2425 $formID = wp_unslash($post->formID);
2673 2426 $id = wp_unslash($post->id);
2674 2427 }
@@ -2686,11 +2439,11 @@
2686 2439 }
2687 2440
2688 2441 public function duplicateAMailTemplate($Request, $post)
2689 2442 {
2690 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2691 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2692 - $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']);
2693 2446 } else {
2694 2447 $formID = wp_unslash($post->formID);
2695 2448 $id = wp_unslash($post->id);
2696 2449 }
@@ -2849,9 +2602,9 @@
2849 2602 $paySetting = json_decode($paySetting);
2850 2603 }
2851 2604
2852 2605 $canSave = null;
2853 - switch ($paySetting->type) {
2606 + switch($paySetting->type) {
2854 2607 case 'PayPal':
2855 2608 $canSave = $this->addWebhookToPaypal($paySetting);
2856 2609 break;
2857 2610 case 'Razorpay':
@@ -2952,16 +2705,15 @@
2952 2705 }
2953 2706 }
2954 2707
2955 2708 $data = [
2956 - 'enabled_events[]' => 'payment_intent.succeeded',
2957 - 'url' => $webhook_url,
2709 + 'enabled_events[]' => 'payment_intent.succeeded',
2710 + 'url' => $webhook_url,
2958 2711 ];
2959 2712
2960 2713 if (!$webhook_already_exist) {
2961 2714 $webhook_response = HttpHelper::post($create_webhook_url, $data, $headers);
2962 2715 if (is_wp_error($webhook_response) || (isset($webhook_response->error) && $webhook_response->error)) {
2963 - Log::debug_log(['Stripe webhook creation failed' => $webhook_response]);
2964 2716 return null;
2965 2717 }
2966 2718 }
2967 2719 return true;
@@ -3001,49 +2753,8 @@
3001 2753 } elseif (!$update_status) {
3002 2754 return new WP_Error('empty_form', __('Form update failed.', 'bit-form'));
3003 2755 } else {
3004 2756 return true;
3005 - }
3006 - }
3007 -
3008 - public function replaceAllFormsErrorMessagesByGlobalMessages()
3009 - {
3010 - try {
3011 - $formModel = new FormModel();
3012 - $allForms = $formModel->get(['id', 'form_content']);
3013 -
3014 - foreach ($allForms as $form) {
3015 - // Decode form_content JSON to stdClass
3016 - $formContent = \json_decode($form->form_content);
3017 - $fields = $formContent->fields ?? null;
3018 - // If decode fails, skip to next
3019 - if (!$fields) {
3020 - Log::debug_log("Form ID {$form->id}: invalid JSON in form_content");
3021 - continue;
3022 - }
3023 -
3024 - // Replace default error messages using your helper
3025 - $updatedFields = Helpers::replaceFieldsDefaultErrorMsg($fields);
3026 -
3027 - $formContent->fields = $updatedFields;
3028 - // Encode back to JSON
3029 - $updatedContent = \json_encode($formContent);
3030 -
3031 - if (false === $updatedContent) {
3032 - Log::debug_log("Form ID {$form->id}: JSON encoding failed");
3033 - continue;
3034 - }
3035 - // Update form content in DB
3036 - $formModel->update(
3037 - ['form_content' => $updatedContent], // data to update
3038 - ['id' => $form->id] // condition for update
3039 - );
3040 - }
3041 - } catch (\Exception $e) {
3042 - Log::debug_log([
3043 - 'message' => 'Error in updateAllFormsErrorMessagesWithGlobalMessages',
3044 - 'error' => $e->getMessage(),
3045 - ]);
3046 2757 }
3047 2758 }
3048 2759
3049 2760 public function updateSuccessMessageClassName($str, $msgIdx, $msgId)