PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.4
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.4
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / Admin / AdminAjax.php

AdminAjax.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 1.4, at includes/Admin/AdminAjax.php

767 lines 27.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Admin;
4
5 use BitCode\BitForm\Core\Form\FormHandler;
6 use BitCode\BitForm\Core\Integration\Integrations;
7 use BitCode\BitForm\Core\Integration\IntegrationHandler;
8 use BitCode\BitForm\Admin\Form\Template\TemplateProvider;
9
10 class AdminAjax
11 {
12 public function register()
13 {
14 add_action('wp_ajax_bitforms_integrations', array($this, 'integrations'));
15 add_action('wp_ajax_integration', array($this, 'integration'));
16 add_action('wp_ajax_bitforms_update_form', array($this, 'updateForm'));
17 add_action('wp_ajax_bitforms_templates', array($this, 'templates'));
18 add_action('wp_ajax_bitforms_create_new_form', array($this, 'createNewForm'));
19 add_action('wp_ajax_bitforms_get_template', array($this, 'getTemplate'));
20 add_action('wp_ajax_bitforms_change_status', array($this, 'changeFormStatus'));
21 add_action('wp_ajax_bitforms_bulk_status_change', array($this, 'changeBulkFormStatus'));
22 add_action('wp_ajax_bitforms_get_a_form', array($this, 'getAForm'));
23 add_action('wp_ajax_bitforms_bulk_delete_form', array($this, 'deleteBlukForm'));
24 add_action('wp_ajax_bitforms_bulk_delete_form_entries', array($this, 'deleteBlukFormEntries'));
25 add_action('wp_ajax_bitforms_delete_aform', array($this, 'deleteAForm'));
26 add_action('wp_ajax_bitforms_duplicate_aform', array($this, 'duplicateAForm'));
27 add_action('wp_ajax_bitforms_export_aform', array($this, 'exportAForm'));
28 add_action('wp_ajax_bitforms_import_aform', array($this, 'importAForm'));
29 add_action('wp_ajax_bitforms_get_form_entries', array($this, 'getFormEntry'));
30 add_action('wp_ajax_bitforms_duplicate_form_entries', array($this, 'duplicateFormEntry'));
31 add_action('wp_ajax_bitforms_edit_form_entry', array($this, 'editFormEntry'));
32 add_action('wp_ajax_bitforms_update_form_entry', array($this, 'updateFormEntry'));
33 add_action('wp_ajax_bitforms_get_all_form', array($this, 'getAllForms'));
34 add_action('wp_ajax_bitforms_get_all_wp_pages', array($this, 'getAllWPPages'));
35 add_action('wp_ajax_bitforms_delete_success_messsage', array($this, 'deleteSuccessMessage'));
36 add_action('wp_ajax_bitforms_delete_integration', array($this, 'deleteAIntegration'));
37 add_action('wp_ajax_bitforms_delete_workflow', array($this, 'deleteAWorkflow'));
38 add_action('wp_ajax_bitforms_delete_mailtemplate', array($this, 'deleteAMailTemplate'));
39 add_action('wp_ajax_bitforms_duplicate_mailtemplate', array($this, 'duplicateAMailTemplate'));
40 add_action('wp_ajax_bitforms_save_allForm_report_prefs', array($this, 'setAllFormsReport'));
41 add_action('wp_ajax_bitforms_save_grecaptcha', array($this, 'savegReCaptcha'));
42 add_action('wp_ajax_bitforms_form_log_history', array($this, 'getLogHistory'));
43 add_action('wp_ajax_bitforms_import_file_data', array($this, 'importFileData'));
44 add_action('wp_ajax_bitforms_filter_export_data', array($this, 'filterExportEntry'));
45 add_action('wp_ajax_bitforms_api_key', array($this, 'saveApiKey'));
46
47
48 add_action(
49 'wp_ajax_bitforms_get_form_entry_count',
50 array($this, 'getFormEntryLabelAndCount')
51 );
52 }
53 /**
54 * Undocumented function
55 *
56 * @return void
57 */
58 public function integrations()
59 {
60 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
61 $testIntegration = new Integrations();
62 $allIntegrations = $testIntegration->getAllintegrations();
63 if ($allIntegrations) {
64 wp_send_json_success($allIntegrations, 200);
65 } else {
66 wp_send_json_error(
67 __('No Integration Found', 'bitform'),
68 404
69 );
70 }
71 } else {
72 wp_send_json_error(
73 __(
74 'Token expired',
75 'bitform'
76 ),
77 401
78 );
79 }
80 }
81
82 public function templates()
83 {
84 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
85 $templateProvider = new TemplateProvider();
86 $status = $templateProvider->getAllTemplates();
87 if (is_wp_error($status)) {
88 wp_send_json_error($status->get_error_message(), 411);
89 } else {
90 wp_send_json_success($status, 200);
91 }
92 } else {
93 wp_send_json_error(
94 __(
95 'Token expired',
96 'bitform'
97 ),
98 401
99 );
100 }
101 }
102 public function getTemplate()
103 {
104 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
105 $inputJSON = file_get_contents('php://input');
106 $input = json_decode($inputJSON);
107 $formHandler = FormHandler::getInstance();
108 $status = $formHandler->admin->getTemplate($_REQUEST, $input);
109 if (is_wp_error($status)) {
110 wp_send_json_error($status->get_error_message(), 411);
111 } else {
112 wp_send_json_success($status, 200);
113 }
114 } else {
115 wp_send_json_error(
116 __(
117 'Token expired',
118 'bitform'
119 ),
120 401
121 );
122 }
123 }
124 public function getAllForms()
125 {
126 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
127 $formHandler = FormHandler::getInstance();
128 $all_forms = $formHandler->admin->getAllForm();
129 if (is_wp_error($all_forms)) {
130 wp_send_json_error($all_forms->get_error_message(), 411);
131 } else {
132 wp_send_json_success($all_forms, 200);
133 }
134 } else {
135 wp_send_json_error(
136 __(
137 'Token expired',
138 'bitform'
139 ),
140 401
141 );
142 }
143 }
144
145 public function importDataStore()
146 {
147 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
148 $inputJSON = file_get_contents('php://input');
149 $input = json_decode($inputJSON);
150 echo json_encode($input);
151 die;
152 // $formHandler = FormHandler::getInstance();
153 // $status = $formHandler->admin->getFormEntryLabelAndCount($_REQUEST, $input);
154 // if (is_wp_error($status)) {
155 // wp_send_json_error($status->get_error_message(), 411);
156 // } else {
157 // wp_send_json_success($status, 200);
158 // }
159 } else {
160 wp_send_json_error(
161 __(
162 'Token expired',
163 'bitform'
164 ),
165 401
166 );
167 }
168 }
169 public function getFormEntryLabelAndCount()
170 {
171 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
172 $inputJSON = file_get_contents('php://input');
173 $input = json_decode($inputJSON);
174 $formHandler = FormHandler::getInstance();
175 $status = $formHandler->admin->getFormEntryLabelAndCount($_REQUEST, $input);
176 if (is_wp_error($status)) {
177 wp_send_json_error($status->get_error_message(), 411);
178 } else {
179 wp_send_json_success($status, 200);
180 }
181 } else {
182 wp_send_json_error(
183 __(
184 'Token expired',
185 'bitform'
186 ),
187 401
188 );
189 }
190 }
191 public function getFormEntry()
192 {
193 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
194 $inputJSON = file_get_contents('php://input');
195 $input = json_decode($inputJSON);
196 $formHandler = FormHandler::getInstance();
197 $status = $formHandler->admin->getFormEntry($_REQUEST, $input);
198 if (is_wp_error($status)) {
199 wp_send_json_error($status->get_error_message(), 411);
200 } else {
201 wp_send_json_success($status, 200);
202 }
203 } else {
204 wp_send_json_error(__('Token expired', 'bitform'), 401);
205 }
206 }
207
208 public function filterExportEntry()
209 {
210 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
211 $inputJSON = file_get_contents('php://input');
212 $input = json_decode($inputJSON);
213 $formHandler = FormHandler::getInstance();
214 $status = $formHandler->admin->getExportEntry($input->data);
215 if (is_wp_error($status)) {
216 wp_send_json_error($status->get_error_message(), 411);
217 } else {
218 wp_send_json_success($status, 200);
219 }
220 } else {
221 wp_send_json_error(__('Token expired', 'bitform'), 401);
222 }
223 }
224
225 /**
226 * Undocumented function
227 *
228 * @return void
229 */
230 public function updateForm()
231 {
232 \ignore_user_abort();
233 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
234 $inputJSON = file_get_contents('php://input');
235 $input = json_decode($inputJSON);
236 $formHandler = FormHandler::getInstance();
237 $status = $formHandler->admin->updateForm($_REQUEST, $input);
238 if (is_wp_error($status)) {
239 wp_send_json_error($status->get_error_message(), 411);
240 } else {
241 wp_send_json_success($status, 200);
242 }
243 } else {
244 wp_send_json_error(
245 __(
246 'Token expired',
247 'bitform'
248 ),
249 401
250 );
251 }
252 }
253 public function createNewForm()
254 {
255 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
256 $inputJSON = file_get_contents('php://input');
257 $input = json_decode($inputJSON);
258 $formHandler = FormHandler::getInstance();
259 $status = $formHandler->admin->createNewForm($_REQUEST, $input);
260 if (is_wp_error($status)) {
261 wp_send_json_error($status->get_error_message(), 411);
262 } else {
263 wp_send_json_success($status, 200);
264 }
265 } else {
266 wp_send_json_error(
267 __(
268 'Token expired',
269 'bitform'
270 ),
271 401
272 );
273 }
274 }
275 public function changeFormStatus()
276 {
277 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
278 $inputJSON = file_get_contents('php://input');
279 $input = json_decode($inputJSON);
280 $formHandler = FormHandler::getInstance();
281 $status = $formHandler->admin->changeFormStatus($_REQUEST, $input);
282 if (is_wp_error($status)) {
283 wp_send_json_error($status->get_error_message(), 411);
284 } else {
285 wp_send_json_success($status, 200);
286 }
287 } else {
288 wp_send_json_error(
289 __(
290 'Token expired',
291 'bitform'
292 ),
293 401
294 );
295 }
296 }
297 public function changeBulkFormStatus()
298 {
299 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
300 $inputJSON = file_get_contents('php://input');
301 $input = json_decode($inputJSON);
302 $formHandler = FormHandler::getInstance();
303 $status = $formHandler->admin->changeBulkFormStatus($_REQUEST, $input);
304 if (is_wp_error($status)) {
305 wp_send_json_error($status->get_error_message(), 411);
306 } else {
307 wp_send_json_success($status, 200);
308 }
309 } else {
310 wp_send_json_error(
311 __(
312 'Token expired',
313 'bitform'
314 ),
315 401
316 );
317 }
318 }
319
320 public function getAForm()
321 {
322 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
323 $inputJSON = file_get_contents('php://input');
324 $input = json_decode($inputJSON);
325 $formHandler = FormHandler::getInstance();
326 $status = $formHandler->admin->getAForm($_REQUEST, $input);
327 if (is_wp_error($status)) {
328 wp_send_json_error($status->get_error_message(), 411);
329 } else {
330 wp_send_json_success($status, 200);
331 }
332 } else {
333 wp_send_json_error(
334 __(
335 'Token expired',
336 'bitform'
337 ),
338 401
339 );
340 }
341 }
342 public function duplicateAForm()
343 {
344 \ignore_user_abort();
345 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
346 $inputJSON = file_get_contents('php://input');
347 $input = json_decode($inputJSON);
348 $formHandler = FormHandler::getInstance();
349 $status = $formHandler->admin->duplicateAForm($_REQUEST, $input);
350 if (is_wp_error($status)) {
351 wp_send_json_error($status->get_error_message(), 411);
352 } else {
353 wp_send_json_success($status, 200);
354 }
355 } else {
356 wp_send_json_error(
357 __(
358 'Token expired',
359 'bitform'
360 ),
361 401
362 );
363 }
364 }
365 public function importAForm()
366 {
367 \ignore_user_abort();
368 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
369 $inputJSON = file_get_contents('php://input');
370 $input = json_decode($inputJSON);
371 $formHandler = FormHandler::getInstance();
372 $status = $formHandler->admin->importAForm($input);
373 if (is_wp_error($status)) {
374 wp_send_json_error($status->get_error_message(), 411);
375 } else {
376 wp_send_json_success($status, 200);
377 }
378 } else {
379 wp_send_json_error(
380 __(
381 'Token expired',
382 'bitform'
383 ),
384 401
385 );
386 }
387 }
388 public function exportAForm()
389 {
390 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
391 $formHandler = FormHandler::getInstance();
392 $status = $formHandler->admin->exportAForm($_REQUEST);
393 if (is_wp_error($status)) {
394 wp_send_json_error($status->get_error_message(), 411);
395 }
396 } else {
397 wp_send_json_error(
398 __(
399 'Token expired',
400 'bitform'
401 ),
402 401
403 );
404 }
405 }
406 public function deleteAForm()
407 {
408 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
409 $inputJSON = file_get_contents('php://input');
410 $input = json_decode($inputJSON);
411 $formHandler = FormHandler::getInstance();
412 $status = $formHandler->admin->deleteAForm($_REQUEST, $input);
413 if (is_wp_error($status)) {
414 wp_send_json_error($status->get_error_message(), 411);
415 } else {
416 wp_send_json_success($status, 200);
417 }
418 } else {
419 wp_send_json_error(
420 __(
421 'Token expired',
422 'bitform'
423 ),
424 401
425 );
426 }
427 }
428 public function deleteBlukForm()
429 {
430 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
431 $inputJSON = file_get_contents('php://input');
432 $input = json_decode($inputJSON);
433 $formHandler = FormHandler::getInstance();
434 $status = $formHandler->admin->deleteBlukForm($_REQUEST, $input);
435 if (is_wp_error($status)) {
436 wp_send_json_error($status->get_error_message(), 411);
437 } else {
438 wp_send_json_success($status, 200);
439 }
440 } else {
441 wp_send_json_error(
442 __(
443 'Token expired',
444 'bitform'
445 ),
446 401
447 );
448 }
449 }
450 public function deleteBlukFormEntries()
451 {
452 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
453 $inputJSON = file_get_contents('php://input');
454 $input = json_decode($inputJSON);
455 $formHandler = FormHandler::getInstance();
456 $status = $formHandler->admin->deleteBlukFormEntries($_REQUEST, $input);
457 if (is_wp_error($status)) {
458 wp_send_json_error($status->get_error_message(), 411);
459 } else {
460 wp_send_json_success($status, 200);
461 }
462 } else {
463 wp_send_json_error(
464 __(
465 'Token expired',
466 'bitform'
467 ),
468 401
469 );
470 }
471 }
472 public function duplicateFormEntry()
473 {
474 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
475 $inputJSON = file_get_contents('php://input');
476 $input = json_decode($inputJSON);
477 $formHandler = FormHandler::getInstance();
478 $status = $formHandler->admin->duplicateFormEntry($_REQUEST, $input);
479 if (is_wp_error($status)) {
480 wp_send_json_error($status->get_error_message(), 411);
481 } else {
482 wp_send_json_success($status, 200);
483 }
484 } else {
485 wp_send_json_error(
486 __(
487 'Token expired',
488 'bitform'
489 ),
490 401
491 );
492 }
493 }
494 public function editFormEntry()
495 {
496 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
497 $inputJSON = file_get_contents('php://input');
498 $input = json_decode($inputJSON);
499 $formHandler = FormHandler::getInstance();
500 $status = $formHandler->admin->editFormEntry($_REQUEST, $input);
501 if (is_wp_error($status)) {
502 wp_send_json_error($status->get_error_message(), 411);
503 } else {
504 wp_send_json_success($status, 200);
505 }
506 } else {
507 wp_send_json_error(
508 __(
509 'Token expired',
510 'bitform'
511 ),
512 401
513 );
514 }
515 }
516
517 public function getLogHistory()
518 {
519 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
520 $inputJSON = file_get_contents('php://input');
521 $input = json_decode($inputJSON);
522 $formHandler = FormHandler::getInstance();
523 $status = $formHandler->admin->getLogHistory($_REQUEST, $input);
524 if (is_wp_error($status)) {
525 wp_send_json_error($status->get_error_message(), 411);
526 } else {
527 wp_send_json_success($status, 200);
528 }
529 } else {
530 wp_send_json_error(
531 __(
532 'Token expired',
533 'bitform'
534 ),
535 401
536 );
537 }
538 }
539 public function updateFormEntry()
540 {
541 \ignore_user_abort();
542 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
543 $formHandler = FormHandler::getInstance();
544 $status = $formHandler->admin->updateFormEntry($_REQUEST, $_POST);
545
546 if (is_wp_error($status)) {
547 wp_send_json_error($status->get_error_message(), 411);
548 } else {
549 $status = IntegrationHandler::maybeSetCronForIntegration($status, 'update');
550 wp_send_json_success($status, 200);
551 }
552 } else {
553 wp_send_json_error(
554 __(
555 'Token expired',
556 'bitform'
557 ),
558 401
559 );
560 }
561 }
562 public function getAllWPPages()
563 {
564 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
565 $inputJSON = file_get_contents('php://input');
566 $input = json_decode($inputJSON);
567 $formHandler = FormHandler::getInstance();
568 $status = $formHandler->admin->getAllWPPages($_REQUEST, $input);
569 if (is_wp_error($status)) {
570 wp_send_json_error($status->get_error_message(), 411);
571 } else {
572 wp_send_json_success($status, 200);
573 }
574 } else {
575 wp_send_json_error(
576 __(
577 'Token expired',
578 'bitform'
579 ),
580 401
581 );
582 }
583 }
584 public function deleteSuccessMessage()
585 {
586 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
587 $inputJSON = file_get_contents('php://input');
588 $input = json_decode($inputJSON);
589 $formHandler = FormHandler::getInstance();
590 $status = $formHandler->admin->deleteSuccessMessage($_REQUEST, $input);
591 if (is_wp_error($status)) {
592 wp_send_json_error($status->get_error_message(), 411);
593 } else {
594 wp_send_json_success($status, 200);
595 }
596 } else {
597 wp_send_json_error(
598 __(
599 'Token expired',
600 'bitform'
601 ),
602 401
603 );
604 }
605 }
606 public function deleteAIntegration()
607 {
608 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
609 $inputJSON = file_get_contents('php://input');
610 $input = json_decode($inputJSON);
611 $formHandler = FormHandler::getInstance();
612 $status = $formHandler->admin->deleteAIntegration($_REQUEST, $input);
613 if (is_wp_error($status)) {
614 wp_send_json_error($status->get_error_message(), 411);
615 } else {
616 wp_send_json_success($status, 200);
617 }
618 } else {
619 wp_send_json_error(
620 __(
621 'Token expired',
622 'bitform'
623 ),
624 401
625 );
626 }
627 }
628
629 public function deleteAWorkflow()
630 {
631 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
632 $inputJSON = file_get_contents('php://input');
633 $input = json_decode($inputJSON);
634 $formHandler = FormHandler::getInstance();
635 $status = $formHandler->admin->deleteAWorkflow($_REQUEST, $input);
636 if (is_wp_error($status)) {
637 wp_send_json_error($status->get_error_message(), 411);
638 } else {
639 wp_send_json_success($status, 200);
640 }
641 } else {
642 wp_send_json_error(
643 __(
644 'Token expired',
645 'bitform'
646 ),
647 401
648 );
649 }
650 }
651 public function deleteAMailTemplate()
652 {
653 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
654 $inputJSON = file_get_contents('php://input');
655 $input = json_decode($inputJSON);
656 $formHandler = FormHandler::getInstance();
657 $status = $formHandler->admin->deleteAMailTemplate($_REQUEST, $input);
658 if (is_wp_error($status)) {
659 wp_send_json_error($status->get_error_message(), 411);
660 } else {
661 wp_send_json_success($status, 200);
662 }
663 } else {
664 wp_send_json_error(
665 __(
666 'Token expired',
667 'bitform'
668 ),
669 401
670 );
671 }
672 }
673 public function duplicateAMailTemplate()
674 {
675 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
676 $inputJSON = file_get_contents('php://input');
677 $input = json_decode($inputJSON);
678 $formHandler = FormHandler::getInstance();
679 $status = $formHandler->admin->duplicateAMailTemplate($_REQUEST, $input);
680 if (is_wp_error($status)) {
681 wp_send_json_error($status->get_error_message(), 411);
682 } else {
683 wp_send_json_success($status, 200);
684 }
685 } else {
686 wp_send_json_error(
687 __(
688 'Token expired',
689 'bitform'
690 ),
691 401
692 );
693 }
694 }
695 public function setAllFormsReport()
696 {
697 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
698 $inputJSON = file_get_contents('php://input');
699 $input = json_decode($inputJSON);
700 $formHandler = FormHandler::getInstance();
701 $status = $formHandler->admin->setAllFormsReport($_REQUEST, $input);
702 if (is_wp_error($status)) {
703 wp_send_json_error($status->get_error_message(), 411);
704 } else {
705 wp_send_json_success($status, 200);
706 }
707 } else {
708 wp_send_json_error(
709 __(
710 'Token expired',
711 'bitform'
712 ),
713 401
714 );
715 }
716 }
717 public function savegReCaptcha()
718 {
719 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
720 $inputJSON = file_get_contents('php://input');
721 $input = json_decode($inputJSON);
722 $formHandler = FormHandler::getInstance();
723 $status = $formHandler->admin->savegReCaptcha($_REQUEST, $input);
724 if (is_wp_error($status)) {
725 wp_send_json_error($status->get_error_message(), 411);
726 } else {
727 wp_send_json_success($status, 200);
728 }
729 } else {
730 wp_send_json_error(
731 __(
732 'Token expired',
733 'bitform'
734 ),
735 401
736 );
737 }
738 }
739
740 public function saveApiKey()
741 {
742 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
743 $inputJSON = file_get_contents('php://input');
744 $input = json_decode($inputJSON);
745 if (empty($input->api_key)) {
746 $api_key = get_option('bitform_secret_api_key');
747 } elseif (!empty($input->api_key)) {
748 update_option('bitform_secret_api_key', $input->api_key);
749 $api_key = $input->api_key;
750 }
751 if (!$api_key) {
752 $api_key = hash('sha1', base64_encode(12345));
753 update_option('bitform_secret_api_key', $api_key);
754 }
755 wp_send_json_success($api_key, 200);
756 } else {
757 wp_send_json_error(
758 __(
759 'Token expired',
760 'bitform'
761 ),
762 401
763 );
764 }
765 }
766 }
767