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.3 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 All 140 releases
← All changes | includes/Core/Integration/Twilio/TwilioHandler.php +31 -12 2.0 → V3.3.2 View file →
@@ -6,30 +6,48 @@
6 6 */
7 7
8 8 namespace BitCode\BitForm\Core\Integration\Twilio;
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 -final class TwilioHandler {
19 +final class TwilioHandler
20 +{
15 21 private $_integrationID;
16 22 public static $apiBaseUri = 'https://api.twilio.com/2010-04-01';
17 23 protected $_defaultHeader;
18 24
19 - public function __construct($integrationID) {
25 + private $_formID;
26 +
27 + public function __construct($integrationID, $formID)
28 + {
20 29 $this->_integrationID = $integrationID;
30 +
31 + $this->_formID = $formID;
21 32 }
22 33
23 - public static function registerAjax() {
34 + public static function registerAjax()
35 + {
24 36 add_action('wp_ajax_bitforms_twilio_authorization', [__CLASS__, 'checkAuthorization']);
25 37 }
26 38
27 - public static function checkAuthorization() {
28 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
29 - $inputJSON = file_get_contents('php://input');
30 - $tokenRequestParams = json_decode($inputJSON);
39 + public static function checkAuthorization()
40 + {
41 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
42 + GlobalHelper::requirePostMethod();
31 43
44 + try {
45 + $tokenRequestParams = GlobalHelper::formatRequestData();
46 + } catch (\InvalidArgumentException $e) {
47 + wp_send_json_error($e->getMessage(), 400);
48 + }
49 +
32 50 if (
33 51 empty($tokenRequestParams->sid)
34 52 || empty($tokenRequestParams->token)
35 53 || empty($tokenRequestParams->from_num)
@@ -36,9 +54,9 @@
36 54 ) {
37 55 wp_send_json_error(
38 56 __(
39 57 'Requested parameter is empty',
40 - 'bit-integrations'
58 + 'bit-form'
41 59 ),
42 60 400
43 61 );
44 62 }
@@ -51,9 +69,9 @@
51 69
52 70 $apiResponse = HttpHelper::get($apiEndpoint, null, $header);
53 71
54 72 $xml = simplexml_load_string($apiResponse);
55 - $json = json_encode($xml);
73 + $json = wp_json_encode($xml);
56 74 $response = json_decode($json, true);
57 75
58 76 if (array_key_exists('RestException', $response)) {
59 77 wp_send_json_error(
@@ -65,9 +83,10 @@
65 83 }
66 84 }
67 85 }
68 86
69 - public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID) {
87 + public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID)
88 + {
70 89 $integrationDetails = $integrationData->integration_details;
71 90 if (is_string($integrationDetails)) {
72 91 $integrationDetails = json_decode($integrationDetails);
73 92 }
@@ -80,12 +99,12 @@
80 99 || empty($token)
81 100 || empty($from_num)
82 101 || empty($fieldMap)
83 102 ) {
84 - $error = new WP_Error('REQ_FIELD_EMPTY', __('SID, Auth Token,From Number and mapping fields are required for rapidmail api', 'bitform'));
103 + $error = new WP_Error('REQ_FIELD_EMPTY', __('SID, Auth Token,From Number and mapping fields are required for rapidmail api', 'bit-form'));
85 104 return $error;
86 105 }
87 - $recordApiHelper = new RecordApiHelper($integrationDetails, $sid, $token, $from_num, $logID);
106 + $recordApiHelper = new RecordApiHelper($integrationDetails, $sid, $token, $from_num, $logID, $this->_formID, $entryID);
88 107 $twilioResponse = $recordApiHelper->executeRecordApi(
89 108 $this->_integrationID,
90 109 $fieldValues,
91 110 $fieldMap