PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.15
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.15
6.2.15 6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 All 197 releases
← All changes | app/Services/Integrations/MailChimp/MailChimpIntegration.php +221 -155 3.6.31 → 6.2.15 View file →
@@ -1,14 +1,17 @@
1 1 <?php
2 2
3 3 namespace FluentForm\App\Services\Integrations\MailChimp;
4 4
5 -use FluentForm\App\Services\Integrations\IntegrationManager;
5 +defined('ABSPATH') or die;
6 +
7 +use FluentForm\App\Http\Controllers\IntegrationManagerController;
8 +use FluentForm\App\Modules\Acl\Acl;
6 9 use FluentForm\App\Services\Integrations\MailChimp\MailChimpSubscriber as Subscriber;
7 10 use FluentForm\Framework\Foundation\Application;
8 11 use FluentForm\Framework\Helpers\ArrayHelper;
9 12
10 -class MailChimpIntegration extends IntegrationManager
13 +class MailChimpIntegration extends IntegrationManagerController
11 14 {
12 15 /**
13 16 * MailChimp Subscriber that handles & process all the subscribing logics.
14 17 */
@@ -17,9 +20,9 @@
17 20 public function __construct(Application $application)
18 21 {
19 22 parent::__construct(
20 23 $application,
21 - 'MailChimp',
24 + 'Mailchimp',
22 25 'mailchimp',
23 26 '_fluentform_mailchimp_details',
24 27 'mailchimp_feeds',
25 28 12
@@ -24,16 +27,18 @@
24 27 'mailchimp_feeds',
25 28 12
26 29 );
27 30
28 - $this->description = 'WP Fluent Forms Mailchimp module allows you to create Mailchimp newsletter signup forms in WordPress';
31 + $this->description = __('Fluent Forms Mailchimp module allows you to create Mailchimp newsletter signup forms in WordPress', 'fluentform');
29 32
30 - $this->logo = $this->app->url('public/img/integrations/mailchimp.png');
33 + $this->logo = fluentFormMix('img/integrations/mailchimp.png');
31 34 $this->registerAdminHooks();
32 -
33 - add_action('wp_ajax_fluentform_mailchimp_interest_groups', array($this, 'fetchInterestGroups'));
34 35
35 -// add_filter('fluentform_notifying_async_mailchimp', '__return_false');
36 + add_action('wp_ajax_fluentform_mailchimp_interest_groups', [$this, 'fetchInterestGroups']);
37 +
38 + add_filter('fluentform/save_integration_value_mailchimp', [$this, 'sanitizeSettings'], 10, 3);
39 +
40 + // add_filter('fluentform/notifying_async_mailchimp', '__return_false');
36 41 }
37 42
38 43 public function getGlobalFields($fields)
39 44 {
@@ -39,9 +44,9 @@
39 44 {
40 45 return [
41 46 'logo' => $this->logo,
42 47 'menu_title' => __('Mailchimp Settings', 'fluentform'),
43 - 'menu_description' => __('Mailchimp is a marketing platform for small businesses. Send beautiful emails, connect your e-commerce store, advertise, and build your brand. Use Fluent Form to collect customer information and automatically add it to your Mailchimp campaign list. If you don\'t have a Mailchimp account, you can <a href="http://www.mailchimp.com/" target="_blank">sign up for one here.</a>', 'fluentform'),
48 + 'menu_description' => __('Mailchimp is a marketing platform for small businesses. Send beautiful emails, connect your e-commerce store, advertise, and build your brand. Use Fluent Forms to collect customer information and automatically add it to your Mailchimp campaign list. If you don\'t have a Mailchimp account, you can <a href="https://mailchimp.com/" target="_blank">sign up for one here.</a>', 'fluentform'),
44 49 'valid_message' => __('Your Mailchimp API Key is valid', 'fluentform'),
45 50 'invalid_message' => __('Your Mailchimp API Key is not valid', 'fluentform'),
46 51 'save_button_text' => __('Save Settings', 'fluentform'),
47 52 'fields' => [
@@ -46,21 +51,21 @@
46 51 'save_button_text' => __('Save Settings', 'fluentform'),
47 52 'fields' => [
48 53 'apiKey' => [
49 54 'type' => 'text',
50 - 'label_tips' => __("Enter your Mailchimp API Key, if you do not have <br>Please login to your MailChimp account and go to<br>Profile -> Extras -> Api Keys", 'fluentform'),
55 + 'label_tips' => __('Enter your Mailchimp API Key, if you do not have <br>Please login to your Mailchimp account and go to<br>Profile -> Extras -> Api Keys', 'fluentform'),
51 56 'label' => __('Mailchimp API Key', 'fluentform'),
52 - ]
57 + ],
53 58 ],
54 59 'hide_on_valid' => true,
55 60 'discard_settings' => [
56 - 'section_description' => 'Your Mailchimp API integration is up and running',
57 - 'button_text' => 'Disconnect Mailchimp',
61 + 'section_description' => __('Your Mailchimp API integration is up and running', 'fluentform'),
62 + 'button_text' => __('Disconnect Mailchimp', 'fluentform'),
58 63 'data' => [
59 - 'apiKey' => ''
64 + 'apiKey' => '',
60 65 ],
61 - 'show_verify' => true
62 - ]
66 + 'show_verify' => true,
67 + ],
63 68 ];
64 69 }
65 70
66 71 public function getGlobalSettings($settings)
@@ -65,14 +70,14 @@
65 70
66 71 public function getGlobalSettings($settings)
67 72 {
68 73 $globalSettings = get_option($this->optionKey);
69 - if (!$globalSettings) {
74 + if (! $globalSettings) {
70 75 $globalSettings = [];
71 76 }
72 77 $defaults = [
73 78 'apiKey' => '',
74 - 'status' => ''
79 + 'status' => '',
75 80 ];
76 81
77 82 return wp_parse_args($globalSettings, $defaults);
78 83 }
@@ -78,18 +83,18 @@
78 83 }
79 84
80 85 public function saveGlobalSettings($mailChimp)
81 86 {
82 - if (!$mailChimp['apiKey']) {
87 + if (! $mailChimp['apiKey']) {
83 88 $mailChimpSettings = [
84 89 'apiKey' => '',
85 - 'status' => false
90 + 'status' => false,
86 91 ];
87 92 // Update the reCaptcha details with siteKey & secretKey.
88 93 update_option($this->optionKey, $mailChimpSettings, 'no');
89 94 wp_send_json_success([
90 95 'message' => __('Your settings has been updated and disconnected', 'fluentform'),
91 - 'status' => false
96 + 'status' => false,
92 97 ], 200);
93 98 }
94 99
95 100 // Verify API key now
@@ -95,22 +100,22 @@
95 100 // Verify API key now
96 101 try {
97 102 $MailChimp = new MailChimp($mailChimp['apiKey']);
98 103 $result = $MailChimp->get('lists');
99 - if (!$MailChimp->success()) {
104 + if (! $MailChimp->success()) {
100 105 throw new \Exception($MailChimp->getLastError());
101 106 }
102 107 } catch (\Exception $exception) {
103 108 wp_send_json_error([
104 - 'message' => $exception->getMessage()
109 + 'message' => $exception->getMessage(),
105 110 ], 400);
106 111 }
107 112
108 - // MailChimp key is verified now, Proceed now
113 + // Mailchimp key is verified now, Proceed now
109 114
110 115 $mailChimpSettings = [
111 116 'apiKey' => sanitize_text_field($mailChimp['apiKey']),
112 - 'status' => true
117 + 'status' => true,
113 118 ];
114 119
115 120 // Update the reCaptcha details with siteKey & secretKey.
116 121 update_option($this->optionKey, $mailChimpSettings, 'no`');
@@ -115,10 +120,10 @@
115 120 // Update the reCaptcha details with siteKey & secretKey.
116 121 update_option($this->optionKey, $mailChimpSettings, 'no`');
117 122
118 123 wp_send_json_success([
119 - 'message' => __('Your mailchimp api key has been verfied and successfully set', 'fluentform'),
120 - 'status' => true
124 + 'message' => __('Your mailchimp api key has been verified and successfully set', 'fluentform'),
125 + 'status' => true,
121 126 ], 200);
122 127 }
123 128
124 129 public function pushIntegration($integrations, $formId)
@@ -127,11 +132,11 @@
127 132 'title' => __('Mailchimp Feed', 'fluentform'),
128 133 'logo' => $this->logo,
129 134 'is_active' => $this->isConfigured(),
130 135 'configure_title' => __('Configuration required!', 'fluentform'),
131 - 'global_configure_url' => admin_url('admin.php?page=fluent_forms_settings#mailchimp'),
136 + 'global_configure_url' => admin_url('admin.php?page=fluent_forms_settings#general-mailchimp-settings'),
132 137 'configure_message' => __('Mailchimp is not configured yet! Please configure your mailchimp api first', 'fluentform'),
133 - 'configure_button_text' => __('Set Mailchimp API', 'fluentform')
138 + 'configure_button_text' => __('Set Mailchimp API', 'fluentform'),
134 139 ];
135 140
136 141 return $integrations;
137 142 }
@@ -138,23 +143,26 @@
138 143
139 144 public function getIntegrationDefaults($settings, $formId)
140 145 {
141 146 $settings = [
142 - 'conditionals' => [
147 + 'conditionals' => [
143 148 'conditions' => [],
144 149 'status' => false,
145 - 'type' => 'all'
150 + 'type' => 'all',
146 151 ],
147 - 'enabled' => true,
148 - 'list_id' => '',
149 - 'list_name' => '',
150 - 'name' => '',
151 - 'merge_fields' => (object)[],
152 - 'tags' => '',
153 - 'markAsVIP' => false,
154 - 'fieldEmailAddress' => '',
155 - 'doubleOptIn' => false,
156 - 'note' => ''
152 + 'enabled' => true,
153 + 'list_id' => '',
154 + 'list_name' => '',
155 + 'name' => '',
156 + 'merge_fields' => (object) [],
157 + 'tags' => '',
158 + 'tag_routers' => [],
159 + 'tag_ids_selection_type' => 'simple',
160 + 'markAsVIP' => false,
161 + 'fieldEmailAddress' => '',
162 + 'doubleOptIn' => false,
163 + 'resubscribe' => false,
164 + 'note' => '',
157 165 ];
158 166
159 167 return $settings;
160 168 }
@@ -161,21 +169,21 @@
161 169
162 170 public function getSettingsFields($settings, $formId)
163 171 {
164 172 return [
165 - 'fields' => [
173 + 'fields' => [
166 174 [
167 175 'key' => 'name',
168 - 'label' => 'Name',
176 + 'label' => __('Name', 'fluentform'),
169 177 'required' => true,
170 - 'placeholder' => 'Your Feed Name',
171 - 'component' => 'text'
178 + 'placeholder' => __('Your Feed Name', 'fluentform'),
179 + 'component' => 'text',
172 180 ],
173 181 [
174 182 'key' => 'list_id',
175 - 'label' => 'Mailchimp List',
176 - 'placeholder' => 'Select Mailchimp List',
177 - 'tips' => 'Select the Mailchimp list you would like to add your contacts to.',
183 + 'label' => __('Mailchimp List', 'fluentform'),
184 + 'placeholder' => __('Select Mailchimp List', 'fluentform'),
185 + 'tips' => __('Select the Mailchimp list you would like to add your contacts to.', 'fluentform'),
178 186 'component' => 'list_ajax_options',
179 187 'options' => $this->getLists(),
180 188 ],
181 189 [
@@ -180,105 +188,118 @@
180 188 ],
181 189 [
182 190 'key' => 'merge_fields',
183 191 'require_list' => true,
184 - 'label' => 'Map Fields',
185 - 'tips' => 'Associate your Mailchimp merge tags to the appropriate Fluent Form fields by selecting the appropriate form field from the list.',
192 + 'label' => __('Map Fields', 'fluentform'),
193 + 'tips' => __('Associate your Mailchimp merge tags to the appropriate Fluent Forms fields by selecting the appropriate form field from the list. Also, Mailchimp Date fields supports only MM/DD/YYYY and DD/MM/YYYY format.', 'fluentform'),
186 194 'component' => 'map_fields',
187 - 'field_label_remote' => 'Mailchimp Field',
188 - 'field_label_local' => 'Form Field',
195 + 'field_label_remote' => __('Mailchimp Field', 'fluentform'),
196 + 'field_label_local' => __('Form Field', 'fluentform'),
189 197 'primary_fileds' => [
190 198 [
191 199 'key' => 'fieldEmailAddress',
192 - 'label' => 'Email Address',
200 + 'label' => __('Email Address', 'fluentform'),
193 201 'required' => true,
194 - 'input_options' => 'emails'
195 - ]
196 - ]
202 + 'input_options' => 'emails',
203 + ],
204 + ],
197 205 ],
198 206 [
199 - 'key' => 'interest_group',
200 - 'require_list' => true,
201 - 'label' => 'Interest Group',
202 - 'tips' => 'You can map your mailchimp interest group for this contact',
203 - 'component' => 'chained_fields',
204 - 'sub_type' => 'radio',
205 - 'category_label' => 'Select Interest Category',
206 - 'subcategory_label' => 'Select Interest',
207 - 'remote_url' => admin_url('admin-ajax.php?action=fluentform_mailchimp_interest_groups'),
208 - 'inline_tip' => 'Select the mailchimp interest category and interest'
207 + 'key' => 'interest_group',
208 + 'require_list' => true,
209 + 'label' => __('Interest Group', 'fluentform'),
210 + 'tips' => __('You can map your mailchimp interest group for this contact', 'fluentform'),
211 + 'component' => 'chained_fields',
212 + 'sub_type' => 'radio',
213 + 'category_label' => __('Select Interest Category', 'fluentform'),
214 + 'subcategory_label' => __('Select Interest', 'fluentform'),
215 + 'remote_url' => add_query_arg([
216 + 'action' => 'fluentform_mailchimp_interest_groups',
217 + 'form_id' => (int) $formId,
218 + ], admin_url('admin-ajax.php')),
219 + 'inline_tip' => __('Select the mailchimp interest category and interest', 'fluentform'),
209 220 ],
210 221 [
211 - 'key' => 'tags',
212 - 'require_list' => true,
213 - 'label' => 'Tags',
214 - 'tips' => 'Associate tags to your Mailchimp contacts with a comma separated list (e.g. new lead, FluentForms, web source). Commas within a merge tag value will be created as a single tag.',
215 - 'component' => 'value_text',
216 - 'inline_tip' => 'Please provide each tag by comma separated value'
222 + 'key' => 'tags',
223 + 'require_list' => true,
224 + 'label' => __('Tags', 'fluentform'),
225 + 'tips' => __('Associate tags to your Mailchimp contacts with a comma separated list (e.g. new lead, FluentForms, web source). Commas within a merge tag value will be created as a single tag.', 'fluentform'),
226 + 'component' => 'selection_routing',
227 + 'simple_component' => 'value_text',
228 + 'routing_input_type' => 'text',
229 + 'routing_key' => 'tag_ids_selection_type',
230 + 'settings_key' => 'tag_routers',
231 + 'labels' => [
232 + 'choice_label' => __('Enable Dynamic Tag Input', 'fluentform'),
233 + 'input_label' => '',
234 + 'input_placeholder' => __('Tag', 'fluentform'),
235 + ],
236 + 'inline_tip' => __('Please provide each tag by comma separated value, You can use dynamic smart codes', 'fluentform'),
217 237 ],
218 238 [
219 239 'key' => 'note',
220 240 'require_list' => true,
221 - 'label' => 'Note',
222 - 'tips' => 'You can write a note for this contact',
223 - 'component' => 'value_textarea'
241 + 'label' => __('Note', 'fluentform'),
242 + 'tips' => __('You can write a note for this contact', 'fluentform'),
243 + 'component' => 'value_textarea',
224 244 ],
225 245 [
226 - 'key' => 'doubleOptIn',
227 - 'require_list' => true,
228 - 'label' => 'Double Opt-in',
229 - 'tips' => 'When the double opt-in option is enabled,<br />Mailchimp will send a confirmation email<br />to the user and will only add them to your <br /Mailchimp list upon confirmation.',
230 - 'component' => 'checkbox-single',
231 - 'checkbox_label' => 'Enable Double Opt-in'
246 + 'key' => 'doubleOptIn',
247 + 'require_list' => true,
248 + 'label' => __('Double Opt-in', 'fluentform'),
249 + 'tips' => __('When the double opt-in option is enabled, Mailchimp will send a confirmation email to the user and will only add them to your <br /Mailchimp list upon confirmation.', 'fluentform'),
250 + 'component' => 'checkbox-single',
251 + 'checkbox_label' => __('Enable Double Opt-in', 'fluentform'),
232 252 ],
233 253 [
234 - 'key' => 'markAsVIP',
235 - 'require_list' => true,
236 - 'label' => 'VIP',
237 - 'tips' => 'When enabled,<br /> This contact will be marked as VIP.',
238 - 'component' => 'checkbox-single',
239 - 'checkbox_label' => 'Mark as VIP Contact'
254 + 'key' => 'resubscribe',
255 + 'require_list' => true,
256 + 'label' => __('ReSubscribe', 'fluentform'),
257 + 'tips' => __('When this option is enabled, if the subscriber is in an inactive state or has previously been unsubscribed, they will be re-added to the active list. Therefore, this option should be used with caution and only when appropriate.', 'fluentform'),
258 + 'component' => 'checkbox-single',
259 + 'checkbox_label' => __('Enable ReSubscription', 'fluentform'),
240 260 ],
241 261 [
262 + 'key' => 'markAsVIP',
263 + 'require_list' => true,
264 + 'label' => __('VIP', 'fluentform'),
265 + 'tips' => __('When enabled, This contact will be marked as VIP.', 'fluentform'),
266 + 'component' => 'checkbox-single',
267 + 'checkbox_label' => __('Mark as VIP Contact', 'fluentform'),
268 + ],
269 + [
242 270 'require_list' => true,
243 271 'key' => 'conditionals',
244 - 'label' => 'Conditional Logics',
245 - 'tips' => 'Allow mailchimp integration conditionally based on your submission values',
246 - 'component' => 'conditional_block'
272 + 'label' => __('Conditional Logics', 'fluentform'),
273 + 'tips' => __('Allow mailchimp integration conditionally based on your submission values', 'fluentform'),
274 + 'component' => 'conditional_block',
247 275 ],
248 276 [
249 - 'require_list' => true,
250 - 'key' => 'enabled',
251 - 'label' => 'Status',
252 - 'component' => 'checkbox-single',
253 - 'checkbox_label' => 'Enable This feed'
254 - ]
277 + 'require_list' => true,
278 + 'key' => 'enabled',
279 + 'label' => __('Status', 'fluentform'),
280 + 'component' => 'checkbox-single',
281 + 'checkbox_label' => __('Enable This feed', 'fluentform'),
282 + ],
255 283 ],
256 284 'button_require_list' => true,
257 - 'integration_title' => 'Mailchimp'
285 + 'integration_title' => __('Mailchimp', 'fluentform'),
258 286 ];
259 287 }
260 288
261 - public function setFeedAtributes($feed, $formId)
262 - {
263 - $feed['provider'] = 'mailchimp';
264 - $feed['provider_logo'] = $this->logo;
265 - return $feed;
266 - }
267 -
268 289 public function prepareIntegrationFeed($setting, $feed, $formId)
269 290 {
270 291 $defaults = $this->getIntegrationDefaults([], $formId);
271 292
272 293 foreach ($setting as $settingKey => $settingValue) {
273 - if ($settingValue == 'true') {
294 + if ('true' == $settingValue) {
274 295 $setting[$settingKey] = true;
275 - } else if ($settingValue == 'false') {
296 + } elseif ('false' == $settingValue) {
276 297 $setting[$settingKey] = false;
277 - } else if ($settingKey == 'conditionals') {
278 - if ($settingValue['status'] == 'true') {
298 + } elseif ('conditionals' == $settingKey) {
299 + if ('true' == $settingValue['status']) {
279 300 $settingValue['status'] = true;
280 - } else if ($settingValue['status'] == 'false') {
301 + } elseif ('false' == $settingValue['status']) {
281 302 $settingValue['status'] = false;
282 303 }
283 304 $setting['conditionals'] = $settingValue;
284 305 }
@@ -283,10 +304,10 @@
283 304 $setting['conditionals'] = $settingValue;
284 305 }
285 306 }
286 307
287 - if (!empty($setting['list_id'])) {
288 - $setting['list_id'] = (string)$setting['list_id'];
308 + if (! empty($setting['list_id'])) {
309 + $setting['list_id'] = (string) $setting['list_id'];
289 310 }
290 311
291 312 $settings['markAsVIP'] = ArrayHelper::isTrue($setting, 'markAsVIP');
292 313 $settings['doubleOptIn'] = ArrayHelper::isTrue($setting, 'doubleOptIn');
@@ -298,10 +319,10 @@
298 319 {
299 320 $settings = get_option('_fluentform_mailchimp_details');
300 321 try {
301 322 $MailChimp = new MailChimp($settings['apiKey']);
302 - $lists = $MailChimp->get('lists', array('count' => 9999));
303 - if (!$MailChimp->success()) {
323 + $lists = $MailChimp->get('lists', ['count' => 9999]);
324 + if (! $MailChimp->success()) {
304 325 return [];
305 326 }
306 327 } catch (\Exception $exception) {
307 328 return [];
@@ -307,10 +328,12 @@
307 328 return [];
308 329 }
309 330
310 331 $formattedLists = [];
311 - foreach ($lists['lists'] as $list) {
312 - $formattedLists[$list['id']] = $list['name'];
332 + if (is_array($lists) && isset($lists['lists'])) {
333 + foreach ($lists['lists'] as $list) {
334 + $formattedLists[$list['id']] = $list['name'];
335 + }
313 336 }
314 337
315 338 return $formattedLists;
316 339 }
@@ -316,18 +339,33 @@
316 339 }
317 340
318 341 public function getMergeFields($list, $listId, $formId)
319 342 {
343 + if (! $this->isConfigured()) {
344 + return false;
345 + }
320 346
321 - if (!$this->isConfigured()) {
322 - return false;
347 + $mergedFields = $this->findMergeFields($listId);
348 +
349 + $fields = [];
350 +
351 + foreach ($mergedFields as $merged_field) {
352 + $fields[$merged_field['tag']] = $merged_field['name'];
323 353 }
354 +
355 + return $fields;
356 + }
357 +
358 + public function findMergeFields($listId)
359 + {
324 360 $settings = get_option('_fluentform_mailchimp_details');
325 361
326 362 try {
327 363 $MailChimp = new MailChimp($settings['apiKey']);
328 - $list = $MailChimp->get('lists/' . $listId . '/merge-fields', array('count' => 9999));
329 - if (!$MailChimp->success()) {
364 +
365 + $list = $MailChimp->get('lists/' . $listId . '/merge-fields', ['count' => 9999]);
366 +
367 + if (! $MailChimp->success()) {
330 368 return false;
331 369 }
332 370 } catch (\Exception $exception) {
333 371 return false;
@@ -332,44 +370,43 @@
332 370 } catch (\Exception $exception) {
333 371 return false;
334 372 }
335 373
336 - $mergedFields = $list['merge_fields'];
337 - $fields = array();
338 -
339 - foreach ($mergedFields as $merged_field) {
340 - $fields[$merged_field['tag']] = $merged_field['name'];
341 - }
342 -
343 - return $fields;
374 + return $list['merge_fields'];
344 375 }
345 376
346 -
347 377 public function fetchInterestGroups()
348 378 {
349 - $settings = $_REQUEST['settings'];
379 + // SECURITY (FINDING-04): this AJAX action reads the site's global Mailchimp API key and
380 + // issues an authenticated request on the caller's behalf; it had no capability/nonce check.
381 + // Acl::verify enforces both the capability and the fluent_forms_admin_nonce for AJAX.
382 + $formId = Acl::verifyFormId($this->app->request->get('form_id'));
383 + Acl::verify('fluentform_forms_manager', $formId);
350 384
351 - $listId = ArrayHelper::get($settings, 'list_id');
352 - if(!$listId) {
385 + $settings = $this->app->request->get('settings', []);
386 + $settings = is_array($settings) ? wp_unslash($settings) : [];
387 +
388 + $listId = sanitize_text_field((string) ArrayHelper::get($settings, 'list_id'));
389 + if (! $listId) {
353 390 wp_send_json_success([
354 - 'categories' => [],
391 + 'categories' => [],
355 392 'subcategories' => [],
356 - 'reset_values' => true
393 + 'reset_values' => true,
357 394 ]);
358 395 }
359 396
360 - $categoryId = ArrayHelper::get($settings, 'interest_group.category');
397 + $categoryId = sanitize_text_field((string) ArrayHelper::get($settings, 'interest_group.category'));
361 398 $categories = $this->getInterestCategories($listId);
362 399
363 400 $subCategories = [];
364 - if($categoryId) {
401 + if ($categoryId) {
365 402 $subCategories = $this->getInterestSubCategories($listId, $categoryId);
366 403 }
367 404
368 405 wp_send_json_success([
369 - 'categories' => $categories,
406 + 'categories' => $categories,
370 407 'subcategories' => $subCategories,
371 - 'reset_values' => !$categories && !$subCategories
408 + 'reset_values' => ! $categories && ! $subCategories,
372 409 ]);
373 410 }
374 411
375 412 private function getInterestCategories($listId)
@@ -376,13 +413,13 @@
376 413 {
377 414 $settings = get_option('_fluentform_mailchimp_details');
378 415 try {
379 416 $MailChimp = new MailChimp($settings['apiKey']);
380 - $categories = $MailChimp->get('/lists/'.$listId.'/interest-categories', array(
381 - 'count' => 9999,
382 - 'fields' => 'categories.id,categories.title'
383 - ));
384 - if (!$MailChimp->success()) {
417 + $categories = $MailChimp->get('/lists/' . $listId . '/interest-categories', [
418 + 'count' => 9999,
419 + 'fields' => 'categories.id,categories.title',
420 + ]);
421 + if (! $MailChimp->success()) {
385 422 return [];
386 423 }
387 424 } catch (\Exception $exception) {
388 425 return [];
@@ -390,10 +427,10 @@
390 427 $categories = ArrayHelper::get($categories, 'categories', []);
391 428 $formattedLists = [];
392 429 foreach ($categories as $list) {
393 430 $formattedLists[] = [
394 - 'value' => $list['id'],
395 - 'label' => $list['title']
431 + 'value' => $list['id'],
432 + 'label' => $list['title'],
396 433 ];
397 434 }
398 435 return $formattedLists;
399 436 }
@@ -402,13 +439,13 @@
402 439 {
403 440 $settings = get_option('_fluentform_mailchimp_details');
404 441 try {
405 442 $MailChimp = new MailChimp($settings['apiKey']);
406 - $categories = $MailChimp->get('/lists/'.$listId.'/interest-categories/'.$categoryId.'/interests', array(
407 - 'count' => 9999,
408 - 'fields' => 'interests.id,interests.name'
409 - ));
410 - if (!$MailChimp->success()) {
443 + $categories = $MailChimp->get('/lists/' . $listId . '/interest-categories/' . $categoryId . '/interests', [
444 + 'count' => 9999,
445 + 'fields' => 'interests.id,interests.name',
446 + ]);
447 + if (! $MailChimp->success()) {
411 448 return [];
412 449 }
413 450 } catch (\Exception $exception) {
414 451 return [];
@@ -417,14 +454,35 @@
417 454 $formattedLists = [];
418 455 foreach ($categories as $list) {
419 456 $formattedLists[] = [
420 457 'value' => $list['id'],
421 - 'label' => $list['name']
458 + 'label' => $list['name'],
422 459 ];
423 460 }
424 461 return $formattedLists;
425 462 }
426 463
464 + public function sanitizeSettings($integration, $integrationId, $formId)
465 + {
466 + if (fluentformCanUnfilteredHTML()) {
467 + return $integration;
468 + }
469 + $sanitizeMap = [
470 + 'status' => 'rest_sanitize_boolean',
471 + 'enabled' => 'rest_sanitize_boolean',
472 + 'type' => 'sanitize_text_field',
473 + 'list_id' => 'sanitize_text_field',
474 + 'list_name' => 'sanitize_text_field',
475 + 'name' => 'sanitize_text_field',
476 + 'tags' => 'sanitize_text_field',
477 + 'tag_ids_selection_type' => 'sanitize_text_field',
478 + 'fieldEmailAddress' => 'sanitize_text_field',
479 + 'doubleOptIn' => 'rest_sanitize_boolean',
480 + 'resubscribe' => 'rest_sanitize_boolean',
481 + 'note' => 'sanitize_text_field',
482 + ];
483 + return fluentform_backend_sanitizer($integration, $sanitizeMap);
484 + }
427 485
428 486 /*
429 487 * For Handling Notifications broadcast
430 488 */
@@ -430,16 +488,24 @@
430 488 */
431 489 public function notify($feed, $formData, $entry, $form)
432 490 {
433 491 $response = $this->subscribe($feed, $formData, $entry, $form);
434 -
435 - if ($response == true) {
436 - do_action('ff_integration_action_result', $feed, 'success', 'MailChimp feed has been successfully initialed and pushed data');
492 +
493 + if (true == $response && !is_wp_error($response)) {
494 + $message = __('Mailchimp feed has been successfully initialed and pushed data', 'fluentform');
495 + do_action('fluentform/integration_action_result', $feed, 'success', $message);
437 496 } else {
438 - $message = 'Mailchimp feed has been failed to deliver feed';
497 + $message = __('Mailchimp feed has been failed to deliver feed', 'fluentform');
439 498 if (is_wp_error($response)) {
440 499 $message = $response->get_error_message();
500 + if (is_array($message)) {
501 + $messageArray = $message;
502 + $message = '';
503 + foreach ($messageArray as $error) {
504 + $message .= ArrayHelper::get($error, 'message');
505 + }
506 + }
441 507 }
442 - do_action('ff_integration_action_result', $feed, 'failed', $message);
508 + do_action('fluentform/integration_action_result', $feed, 'failed', $message);
443 509 }
444 510 }
445 511 }