PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.2
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
bit-form / includes / Admin / AdminAjax.php

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

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