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/Frontend/Form/FrontendFormManager.php +322 -364 3.2.22.15.3 View file →
@@ -9,9 +9,8 @@
9 9 /**
10 10 * FrontendFormManager class
11 11 */
12 12
13 -use BitCode\BitForm\Admin\Form\AdminFormHandler;
14 13 use BitCode\BitForm\Admin\Form\Helpers;
15 14 use BitCode\BitForm\Core\Database\FormEntryModel;
16 15 use BitCode\BitForm\Core\Form\FormManager;
17 16 use BitCode\BitForm\Core\Form\Validator\FormFieldValidator;
@@ -17,14 +16,15 @@
17 16 use BitCode\BitForm\Core\Form\Validator\FormFieldValidator;
18 17 use BitCode\BitForm\Core\Integration\IntegrationHandler;
19 18 use BitCode\BitForm\Core\Messages\SuccessMessageHandler;
20 19 use BitCode\BitForm\Core\Util\ApiResponse as UtilApiResponse;
20 +use BitCode\BitForm\Core\Util\DateTimeHelper;
21 21 use BitCode\BitForm\Core\Util\HttpHelper;
22 22 use BitCode\BitForm\Core\Util\IpTool;
23 -use BitCode\BitForm\Core\Util\Utilities;
24 23 use BitCode\BitForm\Core\WorkFlow\WorkFlow;
24 +use BitCode\BitForm\Core\WorkFlow\WorkFlowHandler;
25 25 use BitCode\BitForm\Frontend\Form\View\FormViewer;
26 -use BitCode\BitForm\GlobalHelper;
26 +use BitCode\BitFormPro\Admin\FormSettings\FormAbandonment;
27 27 use WP_Error;
28 28
29 29 final class FrontendFormManager extends FormManager
30 30 {
@@ -30,10 +30,10 @@
30 30 {
31 31 private $_form_identifier;
32 32 private $_form_token;
33 33 private $_form_id;
34 + private $_work_flows;
34 35 private $_conf_messages;
35 - private static $_instance = [];
36 36
37 37 // private $_has_upload = false;
38 38 public function __construct($form_id, $shortCodeCounter = null)
39 39 {
@@ -44,19 +44,8 @@
44 44 $this->_form_token = wp_create_nonce('bitforms_' . $form_id);
45 45 $this->_form_id = $form_id;
46 46 }
47 47
48 - public static function getInstance($form_id, $shortCodeCounter = null)
49 - {
50 - $key = $form_id . ':' . ($shortCodeCounter ?? 'default');
51 -
52 - if (!isset(self::$_instance[$key])) {
53 - self::$_instance[$key] = new self($form_id, $shortCodeCounter);
54 - }
55 -
56 - return self::$_instance[$key];
57 - }
58 -
59 48 public function getFormIdentifier()
60 49 {
61 50 return $this->_form_identifier;
62 51 }
@@ -70,8 +59,14 @@
70 59 {
71 60 return $this->_form_token;
72 61 }
73 62
63 + public function isSubmitted()
64 + {
65 + // return isset($_POST[$this->_form_identifier]) ? true : false;
66 + return (isset($_POST['bitforms_id']) && $_POST['bitforms_id'] === $this->_form_identifier) ? true : false;
67 + }
68 +
74 69 public function getSubmittedFields($submitted_data)
75 70 {
76 71 unset($submitted_data[$this->_form_identifier]);
77 72 // unset($submitted_data['bit-form-submit-btn']);
@@ -126,9 +121,9 @@
126 121 if ('button' === $fieldType) {
127 122 continue;
128 123 }
129 124 $fileUploadFieldTypes = ['file-up', 'advanced-file-up'];
130 - if ('decision-box' === $fieldType || 'gdpr' === $fieldType) {
125 + if ('decision-box' === $fieldType) {
131 126 continue;
132 127 }
133 128 $isFileType = in_array($fieldType, $fileUploadFieldTypes);
134 129 if ($this->isRepeatedField($key)) {
@@ -187,47 +182,13 @@
187 182 }
188 183 return $parameter;
189 184 }
190 185
191 - private function getFormFields($formID)
192 - {
193 - $adminFormHandler = new AdminFormHandler();
194 - $post = new \stdClass();
195 - $post = (object) [
196 - 'id' => $formID
197 - ];
198 - $getForm = $adminFormHandler->getAForm('', $post);
199 - $formContainer = $getForm['form_content'];
200 -
201 - return $formContainer['fields'];
202 - }
203 -
204 - private function transformDrpdwnValue($post)
205 - {
206 - $formFields = $this->getFormFields($this->_form_id);
207 -
208 - foreach ($post as $key => $value) {
209 - if (!str_starts_with($key, 'repeater') && isset($formFields->{$key}) && 'select' === $formFields->{$key}->typ) {
210 - if (is_array($value)) {
211 - foreach ($value as $k => $v) {
212 - $post[$key][$k] = !is_array($v) && is_string($v) ? explode(BITFORMS_BF_SEPARATOR, $v) : $v;
213 - }
214 - } else {
215 - $post[$key] = explode(BITFORMS_BF_SEPARATOR, $value);
216 - }
217 - };
218 - }
219 -
220 - return $post;
221 - }
222 -
223 186 public function handleSubmission()
224 187 {
225 - // CSRF verified via verifySubmissionNonce() before this method is called. All $_POST reads below occur after that verification.
226 188 $this->fieldNameReplaceOfPost();
227 189
228 190 $validated = $this->beforeSubmittedValidate();
229 -
230 191 $validated = apply_filters('bitform_filter_form_validation', $validated, $this->_form_id);
231 192
232 193 if (true === $validated) {
233 194 do_action('bitform_validation_success', $this->_form_id);
@@ -236,30 +197,30 @@
236 197 $redirectPage = '';
237 198 $regSuccMsg = '';
238 199
239 200 $existAuth = (new IntegrationHandler($this->_form_id))->getAllIntegration('wp_user_auth', 'wp_auth', 1);
240 - $unslashed_post = wp_unslash($_POST);
241 201 if (!is_wp_error($existAuth) && count($existAuth) > 0) {
242 202 $parameter = $this->getParams();
243 - $existAuthFilter = has_filter('bitform_wp_user_auth');
203 + $existAuthFilter = has_filter('bf_wp_user_auth');
244 204
245 205 if (true === $existAuthFilter) {
246 - $result = apply_filters('bitform_wp_user_auth', $existAuth[0], $unslashed_post, $parameter);
206 + $result = apply_filters('bf_wp_user_auth', $existAuth[0], $_POST, $parameter);
247 207
248 - $result = apply_filters('bitform_filter_wp_user_auth_response', $result, $this->_form_id, $unslashed_post, $parameter);
208 + $result = apply_filters('bitform_filter_wp_user_auth_response', $result, $_POST, $parameter);
249 209
250 - do_action('bitform_wp_user_auth_response', $result, $this->_form_id, $unslashed_post, $parameter);
210 + do_action('bitform_wp_user_auth_response', $result, $_POST, $parameter);
251 211
252 212 if (isset($result['auth_type']) && 'register' === $result['auth_type']) {
253 213 if (!$result['success']) {
254 - return new WP_Error('errors', esc_html($result['message']));
214 + return new WP_Error('errors', __($result['message'], 'bit-form'));
255 215 } elseif (isset($result['success'])) {
256 216 $redirectPage = $result['redirectPage'];
257 217 $regSuccMsg = $result['message'];
218 + $newNonce = wp_create_nonce('bitforms_' . $this->_form_id);
258 219 }
259 220 } else {
260 221 if (!$result['success']) {
261 - return new WP_Error('errors', esc_html($result['message']));
222 + return new WP_Error('errors', __($result['message'], 'bit-form'));
262 223 } else {
263 224 return $result;
264 225 }
265 226 }
@@ -265,33 +226,38 @@
265 226 }
266 227 }
267 228 }
268 229
269 - $saveResponse = $this->saveFormEntry($unslashed_post);
230 + $saveResponse = $this->saveFormEntry($_POST);
270 231 if (is_wp_error($saveResponse)) {
271 232 return $saveResponse;
272 233 }
273 234
274 235 $entryID = $saveResponse['entry_id'];
236 + do_action('bitform_submit_success', $this->_form_id, $entryID, $_POST);
275 237
276 - // transformed dropdown value from string to array
277 - $newPost = $this->transformDrpdwnValue($unslashed_post);
278 - $filesData = GlobalHelper::sanitize_files_input($_FILES);
279 - do_action('bitform_submit_success', $this->_form_id, $entryID, $newPost, $filesData);
238 + // check and replace signature field value
239 + $formFields = $this->getFields();
240 + $uploadPath = BITFORMS_UPLOAD_BASE_URL . "/uploads/{$this->_form_id}/{$entryID}";
280 241
242 + foreach ($formFields as $key => $field) {
243 + if ('signature' === $field['type']) {
244 + $saveResponse['fields'][$key] = $uploadPath . '/' . $saveResponse['fields'][$key];
245 + break;
246 + }
247 + }
248 +
281 249 $captchaV3Settings = $this->getCaptchaV3Settings();
282 250 if ($captchaV3Settings) {
283 - $token = isset($_POST['g-recaptcha-response']) ? sanitize_text_field(wp_unslash($_POST['g-recaptcha-response'])) : '';
251 + $token = $_POST['g-recaptcha-response'];
284 252 $integrationHandler = new IntegrationHandler(0);
285 253 $allFormIntegrations = $integrationHandler->getAllIntegration('app', 'gReCaptchaV3');
286 254 if (!is_wp_error($allFormIntegrations)) {
287 255 foreach ($allFormIntegrations as $integration) {
288 256 if (!is_null($integration->integration_type) && 'gReCaptchaV3' === $integration->integration_type) {
289 - $integrationDetails = Utilities::jsonObj($integration->integration_details);
290 - if ($integrationDetails) {
291 - $integrationDetails->id = $integration->id;
292 - $reCAPTCHA = $integrationDetails;
293 - }
257 + $integrationDetails = json_decode($integration->integration_details);
258 + $integrationDetails->id = $integration->id;
259 + $reCAPTCHA = $integrationDetails;
294 260 }
295 261 }
296 262 }
297 263 if (!empty($reCAPTCHA->secretKey)) {
@@ -313,14 +279,16 @@
313 279 }
314 280 if (!empty($regSuccMsg) && isset($saveResponse['dflt_message'])) {
315 281 $saveResponse['message'] = $regSuccMsg;
316 282 }
317 - $saveResponse['new_nonce'] = wp_create_nonce('bitforms_' . $this->_form_id);
318 283
319 284 $saveResponse = IntegrationHandler::maybeSetCronForIntegration($saveResponse, 'create');
320 285 $entryId = $saveResponse['entry_id'];
321 286
322 287 $responseMsg = is_array($saveResponse) && !empty($saveResponse) ? $saveResponse : __('Form Submitted Successfully', 'bit-form');
288 + if (isset($newNonce)) {
289 + $responseMsg['new_nonce'] = $newNonce;
290 + }
323 291 $_POST = [];
324 292 $responseMsg['entry_id'] = $entryId;
325 293 return $responseMsg;
326 294 }
@@ -329,15 +297,14 @@
329 297 }
330 298
331 299 public function handleUpdateEntry()
332 300 {
333 - // Entry token or capability verified by caller (FrontendAjax::update_entry). All $_POST reads occur after that check.
334 301 $this->fieldNameReplaceOfPost();
335 302 $validated = $this->beforeSubmittedValidate();
336 303 $validated = apply_filters('bitform_filter_form_validation', $validated, $this->_form_id);
337 304
338 - $entryID = isset($_REQUEST['entryID']) ? sanitize_text_field(wp_unslash($_REQUEST['entryID'])) : null;
339 - $GLOBALS['bitform_entry_id'] = $entryID;
305 + $entryID = $_REQUEST['entryID'];
306 + $GLOBALS['bf_entry_id'] = $entryID;
340 307 if (is_null($entryID)) {
341 308 return new WP_Error('empty_form', __('Entries id is invalid', 'bit-form'));
342 309 }
343 310 if (true === $validated) {
@@ -345,28 +312,28 @@
345 312 unset($_POST['hidden_fields'], $_POST['entryID']);
346 313
347 314 $redirectPage = '';
348 315 $regSuccMsg = '';
349 - $postData = wp_unslash($_POST);
350 316
351 317 $existAuth = (new IntegrationHandler($this->_form_id))->getAllIntegration('wp_user_auth', 'wp_auth', 1);
352 318 if (!is_wp_error($existAuth) && count($existAuth) > 0) {
353 319 $parameter = $this->getParams();
354 - $existAuthFilter = has_filter('bitform_wp_user_auth');
320 + $existAuthFilter = has_filter('bf_wp_user_auth');
355 321
356 322 if (true === $existAuthFilter) {
357 - $result = apply_filters('bitform_wp_user_auth', $existAuth[0], $postData, $parameter);
323 + $result = apply_filters('bf_wp_user_auth', $existAuth[0], $_POST, $parameter);
358 324
359 325 if (isset($result['auth_type']) && 'register' === $result['auth_type']) {
360 326 if (!$result['success']) {
361 - return new WP_Error('errors', esc_html($result['message']));
327 + return new WP_Error('errors', __($result['message'], 'bit-form'));
362 328 } elseif (isset($result['success'])) {
363 329 $redirectPage = $result['redirectPage'];
364 330 $regSuccMsg = $result['message'];
331 + $newNonce = wp_create_nonce('bitforms_' . $this->_form_id);
365 332 }
366 333 } else {
367 334 if (!$result['success']) {
368 - return new WP_Error('errors', esc_html($result['message']));
335 + return new WP_Error('errors', __($result['message'], 'bit-form'));
369 336 } else {
370 337 return $result;
371 338 }
372 339 }
@@ -372,34 +339,26 @@
372 339 }
373 340 }
374 341 }
375 342
376 - $updateResponse = $this->updateFormEntry(wp_unslash($_POST), $this->getFormID(), $entryID);
343 + $updateResponse = $this->updateFormEntry($_POST, $this->getFormID(), $entryID);
377 344 if (is_wp_error($updateResponse)) {
378 345 return $updateResponse;
379 346 }
380 347
381 - // transformed dropdown value from string to array
382 - $newPost = $this->transformDrpdwnValue($postData);
383 - $filesData = GlobalHelper::sanitize_files_input($_FILES);
348 + do_action('bitform_submit_success', $this->_form_id, $entryID, $_POST);
384 349
385 - //TO DO:: submit success action temporarily added for solution of a issue
386 - do_action('bitform_submit_success', $this->_form_id, $entryID, $newPost, $filesData);
387 - do_action('bitform_update_success', $this->_form_id, $entryID, $newPost, $filesData);
388 -
389 350 $captchaV3Settings = $this->getCaptchaV3Settings();
390 351 if ($captchaV3Settings) {
391 - $token = isset($_POST['g-recaptcha-response']) ? sanitize_text_field(wp_unslash($_POST['g-recaptcha-response'])) : '';
352 + $token = $_POST['g-recaptcha-response'];
392 353 $integrationHandler = new IntegrationHandler(0);
393 354 $allFormIntegrations = $integrationHandler->getAllIntegration('app', 'gReCaptchaV3');
394 355 if (!is_wp_error($allFormIntegrations)) {
395 356 foreach ($allFormIntegrations as $integration) {
396 357 if (!is_null($integration->integration_type) && 'gReCaptchaV3' === $integration->integration_type) {
397 - $integrationDetails = Utilities::jsonObj($integration->integration_details);
398 - if ($integrationDetails) {
399 - $integrationDetails->id = $integration->id;
400 - $reCAPTCHA = $integrationDetails;
401 - }
358 + $integrationDetails = json_decode($integration->integration_details);
359 + $integrationDetails->id = $integration->id;
360 + $reCAPTCHA = $integrationDetails;
402 361 }
403 362 }
404 363 }
405 364 if (!empty($reCAPTCHA->secretKey)) {
@@ -421,14 +380,15 @@
421 380 }
422 381 if (!empty($regSuccMsg) && isset($updateResponse['dflt_message'])) {
423 382 $updateResponse['message'] = $regSuccMsg;
424 383 }
425 - $updateResponse['new_nonce'] = wp_create_nonce('bitforms_' . $this->_form_id);
426 - $updateResponse = IntegrationHandler::maybeSetCronForIntegration($updateResponse, 'update');
384 + $updateResponse = IntegrationHandler::maybeSetCronForIntegration($updateResponse, 'create');
427 385 $entryId = $updateResponse['entry_id'];
428 386
429 387 $responseMsg = is_array($updateResponse) && !empty($updateResponse) ? $updateResponse : __('Entry Update Successfully', 'bit-form');
430 -
388 + if (isset($newNonce)) {
389 + $responseMsg['new_nonce'] = $newNonce;
390 + }
431 391 $_POST = [];
432 392 $responseMsg['entry_id'] = $entryId;
433 393 return $responseMsg;
434 394 }
@@ -452,9 +412,9 @@
452 412 }
453 413 return $submitted_data;
454 414 }
455 415
456 - public function beforeSubmittedValidate($verifyCaptcha = true)
416 + public function beforeSubmittedValidate()
457 417 {
458 418 if ($this->verifySubmissionNonce()) {
459 419 if ($this->isExist()) {
460 420 $isRestricted = $this->checkSubmissionRestriction();
@@ -460,31 +420,21 @@
460 420 $isRestricted = $this->checkSubmissionRestriction();
461 421 if ($isRestricted && !empty($isRestricted)) {
462 422 return new WP_Error('spam_detection', $isRestricted[0]);
463 423 }
464 - $postData = wp_unslash($_POST);
465 - $filesData = GlobalHelper::sanitize_files_input($_FILES);
466 - $isHoneypot = apply_filters('bitform_check_honeypot', false, $this->_form_id, $postData);
467 - if ($isHoneypot) {
424 + if ($this->isTrappedInHoneypot()) {
468 425 return new WP_Error('spam_detection', __('Token verification failed', 'bit-form'));
469 426 }
470 - $formCurrentStep = isset($_POST['form-current-step']) ? sanitize_text_field(wp_unslash($_POST['form-current-step'])) : null;
471 - // TODO: Temporary parameter to skip captcha verification in step change of multi step form
472 - if ($verifyCaptcha) {
473 - $verifyGRecaptchaResult = $this->verifyGRecaptcha();
474 - if (is_wp_error($verifyGRecaptchaResult)) {
475 - return $verifyGRecaptchaResult;
476 - }
477 - $verifyHCaptchaResult = $this->verifyHCaptcha();
478 - if (is_wp_error($verifyHCaptchaResult)) {
479 - return $verifyHCaptchaResult;
480 - }
481 - /* Implement Turnstile Captcha start */
482 - $verifyTurnstileCaptchaResult = $this->verifyTurnstileCaptcha();
483 - if (is_wp_error($verifyTurnstileCaptchaResult)) {
484 - return $verifyTurnstileCaptchaResult;
485 - }
427 + $formCurrentStep = isset($_POST['form-current-step']) ? $_POST['form-current-step'] : null;
428 +
429 + if (is_wp_error($this->verifyGRecaptcha())) {
430 + return $this->verifyGRecaptcha();
486 431 }
432 +
433 + /* Implement Turnstile Captcha start */
434 + if (is_wp_error($this->verifyTurnstileCaptcha())) {
435 + return $this->verifyTurnstileCaptcha();
436 + }
487 437 /* Implement Turnstile Captcha end */
488 438
489 439 $existAuth = (new IntegrationHandler($this->_form_id))->getAllIntegration('wp_user_auth', 'wp_auth', 1);
490 440
@@ -492,76 +442,39 @@
492 442 do_action('bitform_checked_exist_auth', $this->_form_id, $existAuth);
493 443 if (!is_wp_error($existAuth) && count($existAuth) > 0 && is_user_logged_in()) {
494 444 return new WP_Error('auth_error', __('You are already logged in', 'bit-form'));
495 445 }
496 - $validateForm = $this->validateFormSubmission($postData);
497 - $validateFormFiles = $this->validateFormSubmission($filesData);
446 + $validateForm = $this->validateFormSubmission($_POST);
447 + $validateFormFiles = $this->validateFormSubmission($_FILES);
498 448 $validateForm = array_merge($validateForm, $validateFormFiles);
499 - // Validate only provably-rendered fields: a field stranded in form_content->fields
500 - // with no layout entry (orphan) is never shown to the user and must not block
501 - // submission. getRenderedFields() unions ALL breakpoints × steps × nested layouts
502 - // + childFields of rendered parents, derives only from DB-stored form_content,
503 - // and fails closed (returns all fields) when the layout is unusable.
504 - $form_fields = $this->getRenderedFields();
449 + $form_fields = $this->getFields();
505 450 // check if form-current-step is set and form is multi-step
506 - $formCurrentStep = isset($_POST['form-current-step']) ? sanitize_text_field(wp_unslash($_POST['form-current-step'])) : null;
451 + $formCurrentStep = isset($_POST['form-current-step']) ? $_POST['form-current-step'] : null;
507 452 if (!is_null($formCurrentStep)) {
508 - // Narrow validation to the current step's fields. SECURITY: the step
509 - // key set unions ALL breakpoints (lg/md/sm) — an md/sm-only field was
510 - // previously null-skipped by the validator (silent bypass). A forged
511 - // step index or malformed layout skips the narrowing entirely so every
512 - // rendered field stays validated (fail closed).
513 453 $formContents = $this->getFormContent();
514 - $layout = isset($formContents->layout) ? $formContents->layout : null;
454 + $layout = $formContents->layout;
515 455 $stepIndex = (int) $formCurrentStep - 1;
516 - if (is_array($layout) && isset($layout[$stepIndex]->layout) && is_object($layout[$stepIndex]->layout)) {
517 - $stepLayout = $layout[$stepIndex]->layout;
518 - $nestedLayout = isset($formContents->nestedLayout) && is_object($formContents->nestedLayout)
519 - ? $formContents->nestedLayout : null;
520 - $stepKeys = [];
521 - foreach (['lg', 'md', 'sm'] as $brkpnt) {
522 - if (!isset($stepLayout->{$brkpnt}) || !is_array($stepLayout->{$brkpnt})) {
523 - continue;
456 + $stepLayout = $layout[$stepIndex]->layout->lg;
457 + $nestedLayout = $formContents->nestedLayout;
458 + $step_fields = [];
459 + foreach ($stepLayout as $lay) {
460 + $fk = $lay->i;
461 + if (isset($nestedLayout->{$fk})) {
462 + $nestedLg = $nestedLayout->{$fk}->lg;
463 + foreach ($nestedLg as $nestedLay) {
464 + $nestedFk = $nestedLay->i;
465 + $step_fields[$nestedFk] = $form_fields[$nestedFk];
524 466 }
525 - foreach ($stepLayout->{$brkpnt} as $lay) {
526 - if (!is_object($lay) || !isset($lay->i)) {
527 - continue;
528 - }
529 - $fk = $lay->i;
530 - $stepKeys[$fk] = true;
531 - if (!is_null($nestedLayout) && isset($nestedLayout->{$fk})) {
532 - foreach (['lg', 'md', 'sm'] as $nBrkpnt) {
533 - if (!isset($nestedLayout->{$fk}->{$nBrkpnt}) || !is_array($nestedLayout->{$fk}->{$nBrkpnt})) {
534 - continue;
535 - }
536 - foreach ($nestedLayout->{$fk}->{$nBrkpnt} as $nestedLay) {
537 - if (is_object($nestedLay) && isset($nestedLay->i)) {
538 - $stepKeys[$nestedLay->i] = true;
539 - }
540 - }
541 - }
542 - }
543 - }
544 467 }
545 - // Name/Address/Email/Password children live outside layouts; a child
546 - // is part of this step iff its parent is.
547 - self::expandChildFieldKeys($stepKeys, $form_fields);
548 - if (!empty($stepKeys)) {
549 - $step_fields = [];
550 - foreach (array_keys($stepKeys) as $fk) {
551 - if (isset($form_fields[$fk])) {
552 - $step_fields[$fk] = $form_fields[$fk];
553 - }
554 - }
555 - $form_fields = $step_fields;
556 - }
468 + $step_fields[$fk] = $form_fields[$fk];
557 469 }
470 + $form_fields = $step_fields;
558 471 }
559 - $formFieldValidator = new FormFieldValidator($form_fields, $postData, $filesData);
472 + $formFieldValidator = new FormFieldValidator($form_fields, $_POST, $_FILES);
560 473 $validUniuqFields = [];
561 - $existFilter = has_filter('bitform_check_duplicate_entry');
474 + $existFilter = has_filter('bf_check_duplicate_entry');
562 475 if (true === $existFilter) {
563 - $validUniuqFields = apply_filters('bitform_check_duplicate_entry', $form_fields, $postData);
476 + $validUniuqFields = apply_filters('bf_check_duplicate_entry', $form_fields, $_POST);
564 477
565 478 $fieldKeys = array_keys($validUniuqFields);
566 479 $form_fields_keys = array_keys($form_fields);
567 480 $uniqueFields = [];
@@ -569,9 +482,9 @@
569 482 if (in_array($key, $form_fields_keys)) {
570 483 $uniqueFields[] = $form_fields[$key];
571 484 }
572 485 }
573 - do_action('bitform_Unique_entry', $uniqueFields, $validUniuqFields, $this->_form_id, $postData);
486 + do_action('bitform_Unique_entry', $uniqueFields, $validUniuqFields, $this->_form_id, $_POST);
574 487 }
575 488 $validateField = $formFieldValidator->validate('create', $this->_form_id);
576 489
577 490 if ($validateForm && $validateField && 0 === count($validUniuqFields)) {
@@ -598,11 +511,11 @@
598 511 {
599 512 $captchaSettings = $this->getCaptchaSettings();
600 513 $captchaV3Settings = $this->getCaptchaV3Settings();
601 514 if ($captchaSettings || $captchaV3Settings) {
602 - $token = isset($_POST['g-recaptcha-response']) ? sanitize_text_field(wp_unslash($_POST['g-recaptcha-response'])) : '';
515 + $token = $_POST['g-recaptcha-response'];
603 516 if (!isset($_POST['g-recaptcha-response'])) {
604 - return new WP_Error('spam_detection', __('Please recheck your reCaptcha Configuration', 'bit-form'));
517 + return new WP_Error('spam_detection', __('Please verify reCAPTCHA', 'bit-form'));
605 518 }
606 519 $integrationHandler = new IntegrationHandler(0);
607 520 $allFormIntegrations = $integrationHandler->getAllIntegration('app', $captchaSettings ? 'gReCaptcha' : 'gReCaptchaV3');
608 521 if (!is_wp_error($allFormIntegrations)) {
@@ -607,13 +520,11 @@
607 520 $allFormIntegrations = $integrationHandler->getAllIntegration('app', $captchaSettings ? 'gReCaptcha' : 'gReCaptchaV3');
608 521 if (!is_wp_error($allFormIntegrations)) {
609 522 foreach ($allFormIntegrations as $integration) {
610 523 if (!is_null($integration->integration_type) && $integration->integration_type === ($captchaSettings ? 'gReCaptcha' : 'gReCaptchaV3')) {
611 - $integrationDetails = Utilities::jsonObj($integration->integration_details);
612 - if ($integrationDetails) {
613 - $integrationDetails->id = $integration->id;
614 - $reCAPTCHA = $integrationDetails;
615 - }
524 + $integrationDetails = json_decode($integration->integration_details);
525 + $integrationDetails->id = $integration->id;
526 + $reCAPTCHA = $integrationDetails;
616 527 }
617 528 }
618 529 }
619 530 if (!empty($reCAPTCHA->secretKey)) {
@@ -628,9 +539,12 @@
628 539 && !empty($gRecaptchaResponse->score)
629 540 && ((float) $gRecaptchaResponse->score < (float) $captchaV3Settings->score)
630 541 ) {
631 542 wp_send_json_error(
632 - sanitize_text_field((string) $captchaV3Settings->message)
543 + __(
544 + $captchaV3Settings->message,
545 + 'bit-form'
546 + )
633 547 );
634 548 }
635 549
636 550 $isgReCaptchaVerified = $gRecaptchaResponse->success;
@@ -641,63 +555,16 @@
641 555 }
642 556 }
643 557 }
644 558
645 - private function verifyHCaptcha()
646 - {
647 - $hCaptchaExist = $this->isFieldTypeExist('hcaptcha'); // You can rename this to getHCaptchaSettings() if needed
648 - if ($hCaptchaExist) {
649 - if (!isset($_POST['h-captcha-response'])) {
650 - return new WP_Error('spam_detection', __('Please verify hCaptcha', 'bit-form'));
651 - }
652 -
653 - $token = sanitize_text_field(wp_unslash($_POST['h-captcha-response']));
654 -
655 - $integrationHandler = new IntegrationHandler(0);
656 - $allFormIntegrations = $integrationHandler->getAllIntegration('app', 'hcaptcha');
657 -
658 - if (!is_wp_error($allFormIntegrations)) {
659 - foreach ($allFormIntegrations as $integration) {
660 - if (!is_null($integration->integration_type) && 'hcaptcha' === $integration->integration_type) {
661 - $integrationDetails = Utilities::jsonObj($integration->integration_details);
662 - if ($integrationDetails) {
663 - $integrationDetails->id = $integration->id;
664 - $hCaptcha = $integrationDetails;
665 - }
666 - }
667 - }
668 - }
669 -
670 - if (!empty($hCaptcha->secretKey)) {
671 - $hCaptchaResponse = HttpHelper::post(
672 - 'https://api.hcaptcha.com/siteverify',
673 - [
674 - 'secret' => $hCaptcha->secretKey,
675 - 'response' => $token,
676 - 'remoteip' => (isset($_SERVER['REMOTE_ADDR']) ? sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'])) : '')
677 - ]
678 - );
679 -
680 - $isVerified = false;
681 - if (!is_wp_error($hCaptchaResponse)) {
682 - $isVerified = $hCaptchaResponse->success;
683 - }
684 -
685 - if (!$isVerified) {
686 - return new WP_Error('spam_detection', __('hCaptcha verification failed', 'bit-form'));
687 - }
688 - }
689 - }
690 - }
691 -
692 559 private function verifyTurnstileCaptcha()
693 560 {
694 - $turnstileExist = $this->isFieldTypeExist('turnstile');
695 - if ($turnstileExist) {
561 + $turnstileSetting = $this->getTurnstileSettings();
562 + if ($turnstileSetting) {
696 563 if (!isset($_POST['cf-turnstile-response'])) {
697 564 return new WP_Error('spam_detection', __('Please verify Cloudflare Turnstile Captcha', 'bit-form'));
698 565 }
699 - $token = sanitize_text_field(wp_unslash($_POST['cf-turnstile-response']));
566 + $token = $_POST['cf-turnstile-response'];
700 567 $turnstileCaptcha = null;
701 568 $integrationHandler = new IntegrationHandler(0);
702 569 $turnstileIntegration = $integrationHandler->getAllIntegration('app', 'turnstileCaptcha')[0];
703 570 if (!is_wp_error($turnstileIntegration && !is_null($turnstileIntegration->integration_type))) {
@@ -712,14 +579,12 @@
712 579 ['secret' => $turnstileCaptcha->secretKey, 'response' => $token]
713 580 );
714 581 if (!is_wp_error($turnstileRecaptchaResponse)) {
715 582 if (!$turnstileRecaptchaResponse->success) {
716 - $errorCodes = implode(', ', (array) ($turnstileRecaptchaResponse->{'error-codes'} ?? []));
717 583 wp_send_json_error(
718 - sprintf(
719 - /* translators: %s: dynamic value. */
720 - __('Cloudflare Turnstile Validation Error: %s', 'bit-form'),
721 - $errorCodes
584 + __(
585 + 'Cloudflare Turnstile Validation Error: ' . implode(', ', $turnstileRecaptchaResponse->{'error-codes'}),
586 + 'bit-form'
722 587 )
723 588 );
724 589 }
725 590
@@ -733,13 +598,13 @@
733 598 }
734 599
735 600 public function verifySubmissionNonce()
736 601 {
737 - if (!isset($_POST['t_identity']) || !isset($_POST['csrf'])) {
602 + if (!isset($_POST['t_identity']) && !isset($_POST['csrf'])) {
738 603 return false;
739 604 }
740 - $tIdenty = sanitize_text_field(wp_unslash($_POST['t_identity']));
741 - $csrf = sanitize_text_field(wp_unslash($_POST['csrf']));
605 + $tIdenty = sanitize_text_field($_POST['t_identity']);
606 + $csrf = sanitize_text_field($_POST['csrf']);
742 607 unset($_POST['t_identity'], $_POST['action'], $_POST['bitforms_id'], $_POST['csrf']);
743 608 return Helpers::csrfDecrypted($tIdenty, $csrf);
744 609 }
745 610
@@ -759,106 +624,152 @@
759 624
760 625 public function checkSubmissionRestriction($checkedEmptySubmitted = true)
761 626 {
762 627 $formContents = $this->getFormContent();
763 - $additionalSettings = isset($formContents->additional) ? $formContents->additional : null;
764 - $fromRestrictionSetitingsEnabled = empty($additionalSettings->enabled) ? [] : $additionalSettings->enabled;
765 - $fromRestrictionSetitings = empty($additionalSettings->settings) ? null : $additionalSettings->settings;
766 -
767 - if (is_null($additionalSettings) || is_null($fromRestrictionSetitings) || empty((array) $fromRestrictionSetitingsEnabled)) {
628 + $fromRestrictionSetitingsEnabled = empty($formContents->additional->enabled) ? [] : $formContents->additional->enabled;
629 + $fromRestrictionSetitings = empty($formContents->additional->settings) ? null : $formContents->additional->settings;
630 + if (is_null($formContents->additional->enabled) || is_null($formContents->additional->settings)) {
768 631 return false;
769 632 }
770 -
771 633 $restrictionMessage = [];
772 634 $ipTool = new IpTool();
773 635 $ipAddress = $ipTool->getIP();
774 - $currentUserId = get_current_user_id();
775 -
776 636 foreach ($fromRestrictionSetitingsEnabled as $restrictionKey => $isEnabled) {
777 637 if ($isEnabled) {
778 - /**
779 - * Allow add-ons to handle any restriction key (Pro-only restrictions
780 - * should be implemented in the add-on, not shipped in the free plugin).
781 - *
782 - * Return a non-null string to block submission.
783 - */
784 - $addonMsg = apply_filters(
785 - 'bitform_submission_restriction',
786 - null,
787 - $restrictionKey,
788 - $this->form_id,
789 - $fromRestrictionSetitingsEnabled,
790 - $fromRestrictionSetitings,
791 - $ipAddress,
792 - $currentUserId
793 - );
794 -
795 - if (!is_null($addonMsg) && '' !== $addonMsg) {
796 - $restrictionMessage[] = $addonMsg;
797 - continue;
638 + if ('entry_limit' === $restrictionKey && isset($fromRestrictionSetitings->{$restrictionKey})) {
639 + $formEntry = new FormEntryModel();
640 + $countResult = $formEntry->count(
641 + [
642 + 'form_id' => $this->form_id
643 + ]
644 + );
645 + $count = !empty($countResult[0]) && !empty($countResult[0]->count) ? $countResult[0]->count : false;
646 + if ($count && $count >= intval($fromRestrictionSetitings->{$restrictionKey})) {
647 + $restrictionMessage[] = __('Sorry!! Entry limit exceeded', 'bit-form');
648 + }
798 649 }
799 -
800 650 if ('onePerIp' === $restrictionKey) {
801 651 $formEntry = new FormEntryModel();
802 -
803 - $getResult = $formEntry->get(
804 - ['user_ip', 'status'],
652 + $countResult = $formEntry->count(
805 653 [
806 654 'form_id' => $this->form_id,
807 - 'user_ip' => (int) ip2long((string) $ipAddress)
808 - ],
655 + 'user_ip' => ip2long($ipAddress)
656 + ]
809 657 );
658 + $count = !empty($countResult[0]) && !empty($countResult[0]->count) ? $countResult[0]->count : false;
810 659
811 - $count = 0;
812 - $status = 0;
660 + if ($count && $count > 0) {
661 + $restrictionMessage[] = __('Sorry!! You have already submitted', 'bit-form');
662 + }
663 + }
664 + if ('is_login' === $restrictionKey && 0 === get_current_user_id()) {
665 + $restrictionMessage[] = __($fromRestrictionSetitings->is_login->message, 'bit-form');
666 + }
667 + if ($checkedEmptySubmitted && 'empty_submission' === $restrictionKey) {
668 + $isEmpty = $this->checkEmptySubmission($_POST, $_FILES);
669 + if ($isEmpty) {
670 + $restrictionMessage[] = __($fromRestrictionSetitings->empty_submission->message, 'bit-form');
671 + }
672 + }
673 + if ('restrict_form' === $restrictionKey && isset($fromRestrictionSetitings->{$restrictionKey})) {
674 + $day = empty($fromRestrictionSetitings->{$restrictionKey}->day) ? null : $fromRestrictionSetitings->{$restrictionKey}->day;
675 + $date = empty($fromRestrictionSetitings->{$restrictionKey}->date) ? null : $fromRestrictionSetitings->{$restrictionKey}->date;
676 + $time = empty($fromRestrictionSetitings->{$restrictionKey}->time) ? null : $fromRestrictionSetitings->{$restrictionKey}->time;
813 677
814 - if (!is_wp_error($getResult) && count($getResult) > 0) {
815 - $count = count($getResult);
816 -
817 - foreach ($getResult as $row) {
818 - if (9 === (int) $row->status) {
819 - $status = 9;
820 - break;
678 + $isdayOk = $isdateOk = $istimeOk = true;
679 + $dayNotOkMsg = $dateNotOkMsg = $timeNotOkMsg = '';
680 + $dateTimeHelper = new DateTimeHelper();
681 + if (
682 + !empty($day)
683 + && is_array($day)
684 + && (in_array('Friday', $day)
685 + || in_array('Saturday', $day)
686 + || in_array('Sunday', $day)
687 + || in_array('Monday', $day)
688 + || in_array('Tuesday', $day)
689 + || in_array('Wednesday', $day)
690 + || in_array('Thursday', $day))
691 + && (!in_array($dateTimeHelper->getDay('full-name'), $day))
692 + ) {
693 + $isdayOk = false;
694 + $dayMsgVarsFormat = '';
695 + foreach ($day as $dayIndex => $dayValue) {
696 + if ($dayIndex > 0) {
697 + $dayMsgVarsFormat .= ', ';
821 698 }
699 + $dayMsgVarsFormat .= '%s';
822 700 }
701 + $dayNotOkMsg = vsprintf(__("in $dayMsgVarsFormat", 'bit-form'), $day);
823 702 }
703 + if (
704 + !empty($day)
705 + && is_array($day)
706 + && (in_array('Custom', $day))
707 + ) {
708 + $startDate = empty($date->from) ? '00-00-0000' : $date->from;
709 + $endDate = empty($date->to) ? '00-00-0000' : $date->to;
710 + $dateFormat = preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $startDate) ? 'Y-m-d' : 'm-d-Y';
711 + if (!empty($date->from) && false !== strpos($startDate, 'T')) {
712 + $startDate = $dateTimeHelper->getDate($startDate, false, null, $dateFormat);
713 + }
714 + if (!empty($date->to) && false !== strpos($endDate, 'T')) {
715 + $endDate = $dateTimeHelper->getDate($endDate, false, null, $dateFormat);
716 + }
717 + $currentDate = $dateTimeHelper->getDate(null, null, null, $dateFormat);
718 + if (!($currentDate >= $startDate && $currentDate <= $endDate)) {
719 + $isdateOk = false;
720 + $dateNotOkMsg = sprintf(__('within %s to %s', 'bit-form'), $startDate, $endDate);
721 + }
722 + }
824 723
825 - if ($count > 0 && 9 !== (int) $status) {
826 - $onePerIp = __('Sorry!! You have already submitted from this IP address', 'bit-form');
724 + if (!empty($time)) {
725 + $startTime = empty($time->from) ? '00:00' : $time->from;
726 + $endTime = empty($time->to) ? '23:59.999' : $time->to;
727 + $currentTime = $dateTimeHelper->getTime(null, null, null, 'H:i');
728 + if (!($currentTime >= $startTime && $currentTime <= $endTime)) {
729 + $istimeOk = false;
730 + $startTime = $dateTimeHelper->getTime($startTime, 'H:i', null);
731 + $endTime = $dateTimeHelper->getTime($endTime, 'H:i', null);
732 + $isTimeOk = false;
733 + $timeNotOkMsg = sprintf(__('%s to %s', 'bit-form'), $startTime, $endTime);
734 + }
735 + }
827 736
828 - $onePerIp = apply_filters(
829 - 'bitform_filter_restriction_one_per_ip_message',
830 - $onePerIp,
831 - $this->form_id
832 - );
833 -
834 - $restrictionMessage[] = $onePerIp;
737 + if (!($isdateOk && $isdayOk && $istimeOk)) {
738 + if (!$isdayOk) {
739 + $restrictionMessage[] = !empty($timeNotOkMsg) ? sprintf(__('Form is available %s From %s', 'bit-form'), $dayNotOkMsg, $timeNotOkMsg) :
740 + sprintf(__('Form is available %s', 'bit-form'), $dayNotOkMsg, $timeNotOkMsg);
741 + } elseif (!$isdateOk) {
742 + $restrictionMessage[] = !empty($timeNotOkMsg) ? sprintf(__('Form is available %s From %s', 'bit-form'), $dateNotOkMsg, $timeNotOkMsg) :
743 + sprintf(__('Form is available %s', 'bit-form'), $dateNotOkMsg, $timeNotOkMsg);
744 + } elseif (!$istimeOk) {
745 + $restrictionMessage[] = sprintf(__('Form is available on %s', 'bit-form'), $timeNotOkMsg);
746 + }
835 747 }
836 748 }
837 - if ('is_login' === $restrictionKey && 0 === get_current_user_id()) {
838 - $is_login_messages = $fromRestrictionSetitings->is_login->message;
839 -
840 - $is_login_messages = apply_filters(
841 - 'bitform_filter_restriction_is_login_message',
842 - $is_login_messages,
843 - $this->form_id
844 - );
845 -
846 - $restrictionMessage[] = $is_login_messages;
749 + if ('blocked_ip' === $restrictionKey && isset($fromRestrictionSetitings->{$restrictionKey})) {
750 + $isIpBlocked = false;
751 + foreach ($fromRestrictionSetitings->{$restrictionKey} as $ipIndex => $ipDetails) {
752 + if (!empty($ipDetails->status) && $ipDetails->status && !empty($ipDetails->ip) && $ipDetails->ip === $ipAddress) {
753 + $isIpBlocked = true;
754 + break;
755 + }
756 + }
757 + if ($isIpBlocked) {
758 + $restrictionMessage[] = sprintf(__('Sorry!! Your IP address is %s, Blocked from submitting the form', 'bit-form'), $ipAddress);
759 + }
847 760 }
848 - if ($checkedEmptySubmitted && 'empty_submission' === $restrictionKey) {
849 - $isEmpty = $this->checkEmptySubmission(wp_unslash($_POST), GlobalHelper::sanitize_files_input($_FILES));
850 - if ($isEmpty) {
851 - $restriction = $fromRestrictionSetitings->empty_submission->message;
852 -
853 - $restriction = apply_filters(
854 - 'bitform_filter_restriction_empty_submission_message',
855 - $restriction,
856 - $this->form_id
857 - );
858 -
859 - $restrictionMessage[] = $restriction;
761 + if ('private_ip' === $restrictionKey && isset($fromRestrictionSetitings->{$restrictionKey})) {
762 + $isIpWhiteListed = false;
763 + foreach ($fromRestrictionSetitings->{$restrictionKey} as $ipIndex => $ipDetails) {
764 + if (!empty($ipDetails->status) && $ipDetails->status && !empty($ipDetails->ip) && $ipDetails->ip === $ipAddress) {
765 + $isIpWhiteListed = true;
766 + break;
767 + }
860 768 }
769 + if (!$isIpWhiteListed) {
770 + $restrictionMessage[] = sprintf(__('Sorry!! Your IP address is %s, Blocked from submitting the form', 'bit-form'), $ipAddress);
771 + }
861 772 }
862 773 }
863 774 }
864 775 return $restrictionMessage;
@@ -864,21 +775,51 @@
864 775 return $restrictionMessage;
865 776 }
866 777
867 778 /**
868 - * Will check if form is submitted by a bot
869 - *
870 - * @return Boolean true - if submitted by bot else false
871 - */
779 + * Will check if form is submitted by a bot
780 + *
781 + * @return Boolean true - if submitted by bot else false
782 + */
872 783 public function isTrappedInHoneypot()
873 784 {
874 - // Honeypot is implemented by add-ons (e.g. Pro) via filter.
875 - return (bool) apply_filters('bitform_check_honeypot', false, $this->_form_id, wp_unslash($_POST));
785 + $isHoneyPot = false;
786 +
787 + if (!$this->isHoneypotActive()) {
788 + return false;
789 + }
790 +
791 + $token = $_POST['b_h_t'];
792 + $pattern = '/^([a-zA-Z0-9]*_[a-zA-Z0-9]*){4}$/';
793 + $decryptedToken = base64_decode(base64_decode($token));
794 +
795 + preg_match($pattern, $decryptedToken, $validToken);
796 +
797 + if ($validToken) {
798 + if (isset($_POST[$token]) && empty($_POST[$token])) {
799 + $isHoneyPot = false;
800 + } else {
801 + $isHoneyPot = true;
802 + }
803 + } else {
804 + $isHoneyPot = true;
805 + }
806 +
807 + if (isset($_POST[$token])) {
808 + unset($_POST[$token]);
809 + }
810 + unset($_POST['b_h_t']);
811 + return $isHoneyPot;
876 812 }
877 813
878 814 public function isHoneypotActive()
879 815 {
880 - return (bool) apply_filters('bitform_is_honeypot_active', false, $this->_form_id, $this->getFormContent());
816 + $formContents = $this->getFormContent();
817 + $enabled = empty($formContents->additional->enabled) ? null : $formContents->additional->enabled;
818 + if (!empty($enabled->honeypot) && $enabled->honeypot) {
819 + return true;
820 + }
821 + return false;
881 822 }
882 823
883 824 public function checkPaymentFields()
884 825 {
@@ -886,14 +827,11 @@
886 827 $fields = $formContents->fields;
887 828
888 829 $payments = [];
889 830 foreach ($fields as $fldData) {
890 - if (!is_object($fldData)) {
891 - continue;
892 - }
893 831 if ('paypal' === $fldData->typ && property_exists($fldData, 'payIntegID')) {
894 832 $payments['paypalKey'] = $this->getClientKey($fldData->payIntegID, 'clientID');
895 - } elseif ('razorpay' === $fldData->typ && isset($fldData->options) && is_object($fldData->options) && property_exists($fldData->options, 'payIntegID')) {
833 + } elseif ('razorpay' === $fldData->typ && property_exists($fldData->options, 'payIntegID')) {
896 834 $payments['razorpayKey'] = $this->getClientKey($fldData->options->payIntegID, 'apiKey');
897 835 }
898 836 }
899 837
@@ -906,13 +844,10 @@
906 844 if (!empty($integID)) {
907 845 $integrationHandler = new IntegrationHandler(0);
908 846 $integration = $integrationHandler->getAIntegration($integID, 'app', 'payments');
909 847 if (!is_wp_error($integration)) {
910 - $integrationRow = Utilities::firstRow($integration);
911 - $integration_details = Utilities::jsonObj($integrationRow->integration_details ?? '');
912 - if ($integration_details && isset($integration_details->{$keyName})) {
913 - $client = base64_encode($integration_details->{$keyName});
914 - }
848 + $integration_details = json_decode($integration[0]->integration_details);
849 + $client = base64_encode($integration_details->{$keyName});
915 850 }
916 851 }
917 852 return $client;
918 853 }
@@ -918,11 +853,38 @@
918 853 }
919 854
920 855 public function getSuccessMessageMarkups()
921 856 {
857 + if (is_null($this->_work_flows)) {
858 + $workFlowManager = new WorkFlowHandler($this->form_id);
859 + $this->_work_flows = $workFlowManager->getAllworkFlow();
860 + }
861 +
862 + $ids = [];
863 + foreach ($this->_work_flows as $msgItem) {
864 + foreach ($msgItem['conditions'] as $condition) {
865 + if (isset($condition->actions->success)) {
866 + foreach ($condition->actions->success as $msg) {
867 + if ('successMsg' === $msg->type && isset($msg->details->id)) {
868 + $idObj = json_decode(stripslashes($msg->details->id));
869 + if (is_object($idObj) && !empty($idObj->id)) {
870 + array_push($ids, $idObj->id);
871 + }
872 + }
873 + }
874 + }
875 + if (isset($condition->actions->failure)) {
876 + $idObj = json_decode(stripslashes($condition->actions->failure));
877 + if (is_object($idObj) && !empty($idObj->id)) {
878 + array_push($ids, $idObj->id);
879 + }
880 + }
881 + }
882 + }
883 + $ids = array_unique($ids);
922 884 if (is_null($this->_conf_messages)) {
923 885 $successMsgHandler = new SuccessMessageHandler($this->form_id);
924 - $this->_conf_messages = $successMsgHandler->getAllMessage();
886 + $this->_conf_messages = $successMsgHandler->getMessages($ids);
925 887 }
926 888
927 889 $messageMarkups = '';
928 890 if (is_wp_error($this->_conf_messages)) {
@@ -929,12 +891,8 @@
929 891 return $messageMarkups;
930 892 }
931 893
932 894 foreach ($this->_conf_messages as $msgItem) {
933 - $msgConfig = json_decode($msgItem->message_config);
934 - if (is_object($msgConfig) && property_exists($msgConfig, 'status') && empty($msgConfig->status)) {
935 - continue;
936 - }
937 895 $messageMarkups .= $this->messageMarkup($msgItem);
938 896 }
939 897
940 898 return $messageMarkups;
@@ -941,15 +899,26 @@
941 899 }
942 900
943 901 public function getFormAbandonmentMessage()
944 902 {
945 - $msg = apply_filters('bitform_form_abandonment_warning_markup', '', $this->form_id);
946 - return is_string($msg) ? $msg : '';
903 + if (class_exists('\BitCode\BitFormPro\Admin\FormSettings\FormAbandonment')) {
904 + $formAbandonmentSettings = FormAbandonment::getFormAbandonmentSettings($this->form_id);
905 + $msg = '';
906 + if (isset($formAbandonmentSettings->showWarningMsg) && $formAbandonmentSettings->showWarningMsg && !empty($formAbandonmentSettings->warningMsg)) {
907 + $msg = $formAbandonmentSettings->warningMsg;
908 + $msg = '<div class="bf-form-msg active warning">' . wp_kses_post($msg) . '</div>';
909 + }
910 + return $msg;
911 + }
947 912 }
948 913
949 914 public function getFormAbandonmentSettings()
950 915 {
951 - return apply_filters('bitform_form_abandonment_settings', null, $this->form_id);
916 + if (class_exists('\BitCode\BitFormPro\Admin\FormSettings\FormAbandonment')) {
917 + $formAbandonmentSettings = FormAbandonment::getFormAbandonmentSettings($this->form_id);
918 + return $formAbandonmentSettings;
919 + }
920 + return null;
952 921 }
953 922
954 923 private function messageMarkup($msg)
955 924 {
@@ -954,34 +923,23 @@
954 923 private function messageMarkup($msg)
955 924 {
956 925 $msgId = $msg->id;
957 926 $msgConfig = json_decode($msg->message_config);
958 - $msgType = (is_object($msgConfig) && isset($msgConfig->msgType)) ? $msgConfig->msgType : 'below';
959 - $scrollClass = 'below' === $msgType ? 'scroll' : '';
927 + $scrollClass = 'below' === $msgConfig->msgType ? 'scroll' : '';
960 928
961 - return '<div
962 - role="dialog"
963 - aria-hidden="true"
964 - data-modal-backdrop="true"
965 - class="' . $this->getAtomicCls("msg-container-{$msgId}") . ' deactive ' . $scrollClass . '">
966 - <div
967 - data-contentid="' . $this->getFormIdentifier() . '"
968 - data-msgid="' . $msgId . '"
969 - role="button"
970 - class="' . $this->getAtomicCls("msg-background-{$msgId}") . ' msg-backdrop">
971 - <div class="bf-msg-content ' . $this->getAtomicCls("msg-content-{$msgId}") . '">
972 - <button
973 - data-contentid="' . $this->getFormIdentifier() . '"
974 - data-msgid="' . $msgId . '"
975 - class="' . $this->getAtomicCls("close-{$msgId}") . ' bf-msg-close"
976 - type="button">
977 - <svg class="' . $this->getAtomicCls("close-icn-{$msgId}") . '" viewBox="0 0 30 30">
978 - <line fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" x1="4" y1="3.88" x2="26" y2="26.12"></line>
979 - <line fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" x1="26" y1="3.88" x2="4" y2="26.12"></line>
980 - </svg>
981 - </button>
982 - <div class="msg-content"></div>
983 - </div>
984 - </div>
985 - </div>';
929 + return <<<SUCCESSMSG
930 + <div role="dialog" aria-hidden="true" data-modal-backdrop="true" class="{$this->getAtomicCls("msg-container-{$msgId}")} deactive {$scrollClass}">
931 + <div data-contentid="{$this->getFormIdentifier()}" data-msgid="{$msgId}" role="button" class="{$this->getAtomicCls("msg-background-{$msgId}")} msg-backdrop">
932 + <div class="bf-msg-content {$this->getAtomicCls("msg-content-{$msgId}")}">
933 + <button data-contentid="{$this->getFormIdentifier()}" data-msgid="{$msgId}" class="{$this->getAtomicCls("close-{$msgId}")} bf-msg-close" type="button">
934 + <svg class="{$this->getAtomicCls("close-icn-{$msgId}")}" viewBox="0 0 30 30">
935 + <line fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" x1="4" y1="3.88" x2="26" y2="26.12"></line>
936 + <line fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" x1="26" y1="3.88" x2="4" y2="26.12"></line>
937 + </svg>
938 + </button>
939 + <div class="msg-content"></div>
940 + </div>
941 + </div>
942 + </div>
943 +SUCCESSMSG;
986 944 }
987 945 }