PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / V3.3.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder vV3.3.2
V3.3.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 All 139 releases
← All changes | includes/Core/Integration/WooCommerce/WooCommerceHandler.php +50 -16 2.0 → V3.3.2 View file →
@@ -6,10 +6,15 @@
6 6 */
7 7
8 8 namespace BitCode\BitForm\Core\Integration\WooCommerce;
9 9
10 +if (!defined('ABSPATH')) {
11 + exit;
12 +}
13 +
10 14 use BitCode\BitForm\Core\Integration\IntegrationHandler;
11 15 use BitCode\BitForm\Core\Util\ApiResponse as UtilApiResponse;
16 +use BitCode\BitForm\GlobalHelper;
12 17 use WC_Data_Store;
13 18 use WP_Error;
14 19
15 20 /**
@@ -14,15 +19,17 @@
14 19
15 20 /**
16 21 * Provide functionality for ZohoCrm integration
17 22 */
18 -class WooCommerceHandler {
23 +class WooCommerceHandler
24 +{
19 25 private $_formID;
20 26 private $_integrationID;
21 27
22 28 private $_logResponse;
23 29
24 - public function __construct($integrationID, $formID) {
30 + public function __construct($integrationID, $formID)
31 + {
25 32 $this->_formID = $formID;
26 33 $this->_integrationID = $integrationID;
27 34 $this->_logResponse = new UtilApiResponse();
28 35 }
@@ -31,9 +38,10 @@
31 38 * Helps to register ajax function's with wp
32 39 *
33 40 * @return null
34 41 */
35 - public static function registerAjax() {
42 + public static function registerAjax()
43 + {
36 44 add_action('wp_ajax_bitforms_wc_authorize', [__CLASS__, 'authorizeWC']);
37 45 add_action('wp_ajax_bitforms_wc_refresh_fields', [__CLASS__, 'refreshFieldsAjaxHelper']);
38 46 add_action('wp_ajax_bitforms_wc_search_products', [__CLASS__, 'searchProjectsAjaxHelper']);
39 47 }
@@ -42,10 +50,11 @@
42 50 * Process ajax request for generate_token
43 51 *
44 52 * @return JSON zoho crm api response and status
45 53 */
46 - public static function authorizeWC() {
47 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
54 + public static function authorizeWC()
55 + {
56 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
48 57 include_once ABSPATH . 'wp-admin/includes/plugin.php';
49 58 if (is_plugin_active('woocommerce/woocommerce.php')) {
50 59 wp_send_json_success(true, 200);
51 60 }
@@ -61,9 +70,10 @@
61 70 );
62 71 }
63 72 }
64 73
65 - public static function metaboxFields($module) {
74 + public static function metaboxFields($module)
75 + {
66 76 $fileTypes = [
67 77 'image',
68 78 'image_upload',
69 79 'file_advanced',
@@ -109,14 +119,22 @@
109 119 * Process ajax request for refresh crm modules
110 120 *
111 121 * @return JSON crm module data
112 122 */
113 - public static function refreshFieldsAjaxHelper() {
123 + public static function refreshFieldsAjaxHelper()
124 + {
114 125 $required = null;
115 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
116 - $inputJSON = file_get_contents('php://input');
117 - $queryParams = json_decode($inputJSON);
126 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
127 + GlobalHelper::requirePostMethod();
118 128
129 + try {
130 + $queryParams = GlobalHelper::formatRequestData();
131 + } catch (\InvalidArgumentException $e) {
132 + wp_send_json_error($e->getMessage(), 400);
133 + }
134 +
135 + $uploadFields = [];
136 +
119 137 if (
120 138 empty($queryParams->module)
121 139 ) {
122 140 wp_send_json_error(
@@ -431,10 +449,13 @@
431 449 $required = ['user_login', 'user_email'];
432 450 }
433 451
434 452 uksort($fields, 'strnatcasecmp');
453 + // $uploadFields = !empty($uploadFields) && is_array($uploadFields) ? uksort($uploadFields, 'strnatcasecmp') : $uploadFields;
435 454 uksort($uploadFields, 'strnatcasecmp');
455 +
436 456 $fields = array_merge($fields, $metabox['meta_fields']);
457 +
437 458 $response = [
438 459 'fields' => $fields,
439 460 'uploadFields' => $uploadFields,
440 461 'required' => $required
@@ -451,13 +472,19 @@
451 472 );
452 473 }
453 474 }
454 475
455 - public function searchProjectsAjaxHelper() {
456 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
457 - $inputJSON = file_get_contents('php://input');
458 - $queryParams = json_decode($inputJSON);
476 + public static function searchProjectsAjaxHelper()
477 + {
478 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
479 + GlobalHelper::requirePostMethod();
459 480
481 + try {
482 + $queryParams = GlobalHelper::formatRequestData();
483 + } catch (\InvalidArgumentException $e) {
484 + wp_send_json_error($e->getMessage(), 400);
485 + }
486 +
460 487 include_once dirname(WC_PLUGIN_FILE) . '/includes/class-wc-product-functions.php';
461 488 $data_store = WC_Data_Store::load('product');
462 489 $search_results = $data_store->search_products($queryParams->searchTxt);
463 490 $products = [];
@@ -482,9 +509,10 @@
482 509 );
483 510 }
484 511 }
485 512
486 - public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID) {
513 + public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID)
514 + {
487 515 $integrationDetails = is_string($integrationData->integration_details) ? json_decode($integrationData->integration_details) : $integrationData->integration_details;
488 516
489 517 $module = $integrationDetails->module;
490 518 $fieldMap = $integrationDetails->field_map;
@@ -489,14 +517,20 @@
489 517 $module = $integrationDetails->module;
490 518 $fieldMap = $integrationDetails->field_map;
491 519 $uploadFieldMap = $integrationDetails->upload_field_map;
492 520 $required = $integrationDetails->default->fields->{$module}->required;
521 +
522 + $entryDetails = [
523 + 'formId' => $this->_formID,
524 + 'entryId' => $entryID,
525 + 'fieldValues' => $fieldValues
526 + ];
493 527 if (
494 528 empty($module)
495 529 || empty($fieldMap)
496 530 ) {
497 531 $error = new WP_Error('REQ_FIELD_EMPTY', __('module and field map are required for woocommerce', 'bit-form'));
498 - $this->_logResponse->apiResponse($logID, $this->_integrationID, 'record', 'validation', $error);
532 + $this->_logResponse->apiResponse($logID, $this->_integrationID, 'record', 'validation', $error, $entryDetails);
499 533 return $error;
500 534 }
501 535
502 536 $recordApiHelper = new RecordApiHelper($this->_integrationID, $logID);