PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.3.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.3.1
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/Core/Integration/ActiveCampaign/ActiveCampaignHandler.php +59 -25 2.03.3.1 View file →
@@ -6,20 +6,27 @@
6 6 */
7 7
8 8 namespace BitCode\BitForm\Core\Integration\ActiveCampaign;
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\HttpHelper;
16 +use BitCode\BitForm\GlobalHelper;
12 17 use WP_Error;
13 18
14 19 /**
15 20 * Provide functionality for ZohoCrm integration
16 21 */
17 -class ActiveCampaignHandler {
22 +class ActiveCampaignHandler
23 +{
18 24 private $_formID;
19 25 private $_integrationID;
20 26
21 - public function __construct($integrationID, $fromID) {
27 + public function __construct($integrationID, $fromID)
28 + {
22 29 $this->_formID = $fromID;
23 30 $this->_integrationID = $integrationID;
24 31 }
25 32
@@ -27,9 +34,10 @@
27 34 * Helps to register ajax function's with wp
28 35 *
29 36 * @return null
30 37 */
31 - public static function registerAjax() {
38 + public static function registerAjax()
39 + {
32 40 add_action('wp_ajax_bitforms_aCampaign_authorize', [__CLASS__, 'activeCampaignAuthorize']);
33 41 add_action('wp_ajax_bitforms_aCampaign_headers', [__CLASS__, 'activeCampaignHeaders']);
34 42 add_action('wp_ajax_bitforms_aCampaign_lists', [__CLASS__, 'activeCampaignLists']);
35 43 add_action('wp_ajax_bitforms_aCampaign_tags', [__CLASS__, 'activeCampaignTags']);
@@ -34,9 +42,10 @@
34 42 add_action('wp_ajax_bitforms_aCampaign_lists', [__CLASS__, 'activeCampaignLists']);
35 43 add_action('wp_ajax_bitforms_aCampaign_tags', [__CLASS__, 'activeCampaignTags']);
36 44 }
37 45
38 - public static function _apiEndpoint($api_url, $method) {
46 + public static function _apiEndpoint($api_url, $method)
47 + {
39 48 return "{$api_url}/api/3/{$method}/";
40 49 }
41 50
42 51 /**
@@ -41,14 +50,21 @@
41 50
42 51 /**
43 52 * Process ajax request
44 53 *
45 - * @return JSON Active Campaign api response and status
54 + * @return string Active Campaign api response and status
46 55 */
47 - public static function activeCampaignAuthorize() {
48 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
49 - $inputJSON = file_get_contents('php://input');
50 - $requestsParams = json_decode($inputJSON);
56 + public static function activeCampaignAuthorize()
57 + {
58 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
59 + GlobalHelper::requirePostMethod();
60 +
61 + try {
62 + $requestsParams = GlobalHelper::formatRequestData();
63 + } catch (\InvalidArgumentException $e) {
64 + wp_send_json_error($e->getMessage(), 400);
65 + }
66 +
51 67 if (
52 68 empty($requestsParams->api_key)
53 69 || empty($requestsParams->api_url)
54 70 ) {
@@ -89,13 +105,17 @@
89 105 * Process ajax request for refresh lists
90 106 *
91 107 * @return JSON active campaign list data
92 108 */
93 - public static function activeCampaignLists() {
94 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
95 - $inputJSON = file_get_contents('php://input');
96 - $queryParams = json_decode($inputJSON);
97 -
109 + public static function activeCampaignLists()
110 + {
111 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
112 + GlobalHelper::requirePostMethod();
113 + try {
114 + $queryParams = GlobalHelper::formatRequestData();
115 + } catch (\InvalidArgumentException $e) {
116 + wp_send_json_error($e->getMessage(), 400);
117 + }
98 118 if (
99 119 empty($queryParams->api_key)
100 120 || empty($queryParams->api_url)
101 121 ) {
@@ -142,13 +162,19 @@
142 162 * Process ajax request for refresh Tags
143 163 *
144 164 * @return JSON active campaign tags data
145 165 */
146 - public static function activeCampaignTags() {
147 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
148 - $inputJSON = file_get_contents('php://input');
149 - $queryParams = json_decode($inputJSON);
166 + public static function activeCampaignTags()
167 + {
168 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
169 + GlobalHelper::requirePostMethod();
150 170
171 + try {
172 + $queryParams = GlobalHelper::formatRequestData();
173 + } catch (\InvalidArgumentException $e) {
174 + wp_send_json_error($e->getMessage(), 400);
175 + }
176 +
151 177 if (
152 178 empty($queryParams->api_key)
153 179 || empty($queryParams->api_url)
154 180 ) {
@@ -160,9 +186,9 @@
160 186 400
161 187 );
162 188 }
163 189
164 - $apiEndpoint = self::_apiEndpoint($queryParams->api_url, 'tags');
190 + $apiEndpoint = self::_apiEndpoint($queryParams->api_url, 'tags?limit=500');
165 191 $authorizationHeader = [];
166 192 $authorizationHeader['Api-Token'] = $queryParams->api_key;
167 193 $aCampaignResponse = HttpHelper::get($apiEndpoint, null, $authorizationHeader);
168 194
@@ -195,14 +221,20 @@
195 221 * Process ajax request for refresh crm modules
196 222 *
197 223 * @return JSON crm module data
198 224 */
199 - public static function activeCampaignHeaders() {
225 + public static function activeCampaignHeaders()
226 + {
200 227 $authorizationHeader = null;
201 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
202 - $inputJSON = file_get_contents('php://input');
203 - $queryParams = json_decode($inputJSON);
228 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
229 + GlobalHelper::requirePostMethod();
204 230
231 + try {
232 + $queryParams = GlobalHelper::formatRequestData();
233 + } catch (\InvalidArgumentException $e) {
234 + wp_send_json_error($e->getMessage(), 400);
235 + }
236 +
205 237 if (
206 238 empty($queryParams->api_key)
207 239 || empty($queryParams->api_url)
208 240 ) {
@@ -249,9 +281,10 @@
249 281 );
250 282 }
251 283 }
252 284
253 - public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID) {
285 + public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID)
286 + {
254 287 $integrationDetails = is_string($integrationData->integration_details) ? json_decode($integrationData->integration_details) : $integrationData->integration_details;
255 288 $api_key = $integrationDetails->api_key;
256 289 $api_url = $integrationDetails->api_url;
257 290 $fieldMap = $integrationDetails->field_map;
@@ -271,9 +304,10 @@
271 304 $fieldValues,
272 305 $fieldMap,
273 306 $actions,
274 307 $listId,
275 - $tags
308 + $tags,
309 + $this->_formID
276 310 );
277 311
278 312 if (is_wp_error($activeCampaignApiResponse)) {
279 313 return $activeCampaignApiResponse;