MailChimp for WordPress - Version 4.1.8

Version Description

Download this release

Release Info

Developer DvanKooten
Plugin Icon 128x128 MailChimp for WordPress
Version 4.1.8
Comparing to
See all releases

Code changes from version 4.1.7 to 4.1.8

CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@ Changelog
2
  =========
3
 
4
 
5
- #### 4.1.7 - September 8, 2017
6
 
7
  **Fixes**
8
 
2
  =========
3
 
4
 
5
+ #### 4.1.7 & 4.1.8 - September 8, 2017
6
 
7
  **Fixes**
8
 
integrations/wpforms/bootstrap.php CHANGED
@@ -3,7 +3,11 @@
3
  mc4wp_register_integration( 'wpforms', 'MC4WP_WPForms_Integration', true );
4
 
5
  function _mc4wp_wpforms_register_field() {
6
- new MC4WP_WPForms_Field();
 
 
 
 
7
  }
8
 
9
  add_action( 'init', '_mc4wp_wpforms_register_field' );
3
  mc4wp_register_integration( 'wpforms', 'MC4WP_WPForms_Integration', true );
4
 
5
  function _mc4wp_wpforms_register_field() {
6
+ if( ! class_exists( 'WPForms_Field' ) ) {
7
+ return;
8
+ }
9
+
10
+ new MC4WP_WPForms_Field();
11
  }
12
 
13
  add_action( 'init', '_mc4wp_wpforms_register_field' );
integrations/wpforms/class-field.php CHANGED
@@ -1,315 +1,330 @@
1
  <?php
2
- /**
3
- * Checkbox field.
4
- *
5
- * @package WPForms
6
- * @author WPForms
7
- * @since 1.0.0
8
- * @license GPL-2.0+
9
- * @copyright Copyright (c) 2016, WPForms LLC
10
- */
11
- class MC4WP_WPForms_Field extends WPForms_Field {
12
 
13
- /**
14
- * @var MC4WP_MailChimp
15
- */
16
- private $mailchimp;
17
 
18
- /**
19
- * Primary class constructor.
20
- *
21
- * @since 1.0.0
22
- */
23
- public function init() {
24
-
25
- // Define field type information
26
- $this->name = 'MailChimp';
27
- $this->type = 'mailchimp';
28
- $this->icon = 'fa-envelope-o';
29
- $this->order = 21;
30
- $this->defaults = array(
31
- 0 => array(
32
- 'label' => __( 'Sign-up to our newsletter?', 'mailchimp-for-wp' ),
33
- 'value' => '1',
34
- 'default' => '',
35
- )
36
- );
37
- }
38
 
39
  /**
40
- * Field options panel inside the builder.
41
  *
42
- * @since 1.0.0
43
- * @param array $field
 
 
 
44
  */
45
- public function field_options( $field ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
- //--------------------------------------------------------------------//
48
- // Basic field options
49
- //--------------------------------------------------------------------//
 
 
 
 
 
50
 
51
- // Options open markup
52
- $this->field_option( 'basic-options', $field, array( 'markup' => 'open' ) );
 
53
 
54
- // MailChimp list
55
- $this->field_option_mailchimp_list( $field );
56
 
57
- // Choices
58
- $this->field_option_choices( $field );
59
 
60
- // Description
61
- $this->field_option( 'description', $field );
62
 
63
- // Required toggle
64
- $this->field_option( 'required', $field );
65
 
66
- // Options close markup
67
- $this->field_option( 'basic-options', $field, array( 'markup' => 'close' ) );
68
 
69
- //--------------------------------------------------------------------//
70
- // Advanced field options
71
- //--------------------------------------------------------------------//
72
 
73
- // Options open markup
74
- $this->field_option( 'advanced-options', $field, array( 'markup' => 'open' ) );
 
75
 
76
- // Custom CSS classes
77
- $this->field_option( 'css', $field );
78
 
79
- // Options close markup
80
- $this->field_option( 'advanced-options', $field, array( 'markup' => 'close' ) );
81
- }
82
 
83
- private function field_option_mailchimp_list( $field ) {
84
- $mailchimp = new MC4WP_MailChimp();
85
-
86
- // Field option label
87
- $tooltip = __( 'Select the MailChimp list to subscribe to.', 'mailchimp-for-wp' );
88
- $option_label = $this->field_element(
89
- 'label',
90
- $field,
91
- array(
92
- 'slug' => 'mailchimp-list',
93
- 'value' => __( 'MailChimp list', 'mailchimp-for-wp' ),
94
- 'tooltip' => $tooltip,
95
- ),
96
- false
97
- );
98
-
99
- $option_select = sprintf( '<select name="fields[%s][mailchimp_list]" data-field-id="%d" data-field-type="%s">', $field['id'], $field['id'], $this->type );
100
- $lists = $mailchimp->get_cached_lists();
101
- foreach( $lists as $list ) {
102
- $option_select .= sprintf( '<option value="%s" %s>%s</option>', $list->id, selected( $list->id, $field['mailchimp_list'], false), $list->name );
103
  }
104
- $option_select .= '</select>';
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
 
107
- // Field option row (markup) including label and input.
108
- $output = $this->field_element(
109
- 'row',
110
- $field,
111
- array(
112
- 'slug' => 'mailchimp-list',
113
- 'content' => $option_label . $option_select,
114
- )
115
- );
116
 
117
- }
118
 
119
- private function field_option_choices( $field ) {
120
- $tooltip = __( 'Set your sign-up label text and whether it should be pre-checked.', 'mailchimp-for-wp' );
121
- $values = ! empty( $field['choices'] ) ? $field['choices'] : $this->defaults;
122
- $class = ! empty( $field['show_values'] ) && $field['show_values'] == '1' ? 'show-values' : '';
123
- $class .= ! empty( $dynamic ) ? ' wpforms-hidden' : '';
124
-
125
- // Field option label
126
- $option_label = $this->field_element(
127
- 'label',
128
- $field,
129
- array(
130
- 'slug' => 'mailchimp-checkbox',
131
- 'value' => __( 'Sign-up checkbox', 'mailchimp-for-wp' ),
132
- 'tooltip' => $tooltip,
133
- ),
134
- false
135
- );
136
-
137
- // Field option choices inputs
138
- $option_choices = sprintf( '<ul class="choices-list %s" data-field-id="%d" data-field-type="%s">', $class, $field['id'], $this->type );
139
- foreach ( $values as $key => $value ) {
140
- $default = ! empty( $value['default'] ) ? $value['default'] : '';
141
- $option_choices .= sprintf( '<li data-key="%d">', $key );
142
- $option_choices .= sprintf( '<input type="checkbox" name="fields[%s][choices][%s][default]" class="default" value="1" %s>', $field['id'], $key, checked( '1', $default, false ) );
143
- $option_choices .= sprintf( '<input type="text" name="fields[%s][choices][%s][label]" value="%s" class="label">', $field['id'], $key, esc_attr( $value['label'] ) );
144
- $option_choices .= sprintf( '<input type="text" name="fields[%s][choices][%s][value]" value="%s" class="value">', $field['id'], $key, esc_attr( $value['value'] ) );
145
- $option_choices .= '</li>';
146
  }
147
- $option_choices .= '</ul>';
148
-
149
- // Field option row (markup) including label and input.
150
- $output = $this->field_element(
151
- 'row',
152
- $field,
153
- array(
154
- 'slug' => 'choices',
155
- 'content' => $option_label . $option_choices,
156
- )
157
- );
158
- }
159
-
160
- /**
161
- * Field preview inside the builder.
162
- *
163
- * @since 1.0.0
164
- * @param array $field
165
- */
166
- public function field_preview( $field ) {
167
- $values = !empty( $field['choices'] ) ? $field['choices'] : $this->defaults;
168
 
169
- // Field checkbox elements
170
- echo '<ul class="primary-input">';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
 
172
- // Notify if currently empty
173
- if ( empty( $values ) ) {
174
- $values = array( 'label' => __( '(empty)', 'wpforms' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  }
176
 
177
- // Individual checkbox options
178
- foreach ( $values as $key => $value ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
 
180
- $default = isset( $value['default'] ) ? $value['default'] : '';
181
- $selected = checked( '1', $default, false );
182
 
183
- printf( '<li><input type="checkbox" %s disabled>%s</li>', $selected, $value['label'] );
184
- }
185
 
186
- echo '</ul>';
 
187
 
188
- // Dynamic population is enabled and contains more than 20 items
189
- if ( isset( $total ) && $total > 20 ) {
190
- echo '<div class="wpforms-alert-dynamic wpforms-alert wpforms-alert-warning">';
191
- printf( __( 'Showing the first 20 choices.<br> All %d choices will be displayed when viewing the form.', 'wpforms' ), absint( $total ) );
192
- echo '</div>';
193
- }
194
 
195
- // Description
196
- $this->field_preview_option( 'description', $field );
197
- }
 
 
 
198
 
199
- /**
200
- * Field display on the form front-end.
201
- *
202
- * @since 1.0.0
203
- * @param array $field
204
- * @param array $form_data
205
- */
206
- public function field_display( $field, $field_atts, $form_data ) {
207
 
208
- // Setup and sanitize the necessary data
209
- $field_required = !empty( $field['required'] ) ? ' required' : '';
210
- $field_class = implode( ' ', array_map( 'sanitize_html_class', $field_atts['input_class'] ) );
211
- $field_id = implode( ' ', array_map( 'sanitize_html_class', $field_atts['input_id'] ) );
212
- $form_id = $form_data['id'];
213
- $choices = $field['choices'];
 
 
 
214
 
 
 
 
 
 
 
215
 
216
- // List
217
- printf( '<ul id="%s" class="%s">', $field_id, $field_class );
218
 
219
- foreach( $choices as $key => $choice ) {
 
220
 
221
- $selected = isset( $choice['default'] ) ? '1' : '0' ;
222
- $depth = isset( $choice['depth'] ) ? absint( $choice['depth'] ) : 1;
223
 
224
- printf( '<li class="choice-%d depth-%d">', $key, $depth );
 
225
 
226
- // Checkbox elements
227
- printf( '<input type="checkbox" id="wpforms-%d-field_%d_%d" name="wpforms[fields][%d]" value="%s" %s %s>',
228
- $form_id,
229
- $field['id'],
230
- $key,
231
- $field['id'],
232
- esc_attr( $choice['value'] ),
233
- checked( '1', $selected, false ),
234
- $field_required
235
- );
236
 
237
- printf( '<label class="wpforms-field-label-inline" for="wpforms-%d-field_%d_%d">%s</label>', $form_id, $field['id'], $key, wp_kses_post( $choice['label'] ) );
 
 
 
 
 
 
 
 
 
238
 
239
- echo '</li>';
240
- }
241
 
242
- echo '</ul>';
243
- }
244
 
245
- /**
246
- * Formats and sanitizes field.
247
- *
248
- * @since 1.0.2
249
- * @param int $field_id
250
- * @param array $field_submit
251
- * @param array $form_data
252
- */
253
- public function format( $field_id, $field_submit, $form_data ) {
254
 
255
- $field = $form_data['fields'][$field_id];
256
- $choice = array_pop( $field['choices' ] );
257
- $name = sanitize_text_field( $choice['label'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
 
259
- $data = array(
260
- 'name' => $name,
261
- 'value' => empty( $field_submit ) ? __( 'No' ) : __( 'Yes' ),
262
- 'value_raw' => $field_submit,
263
- 'id' => absint( $field_id ),
264
- 'type' => $this->type,
265
- );
266
 
 
 
267
 
268
- // Push field details to be saved
269
- wpforms()->process->fields[$field_id] = $data;
 
 
270
 
271
- // Subscribe to MailChimp
272
- if( ! empty( $field_submit ) ) {
273
- $this->subscribe( $field, $form_data, $_POST['wpforms'] );
274
  }
275
 
276
- }
277
-
278
- /**
279
- * @param $field
280
- * @param $form
281
- * @param $data
282
- */
283
- private function subscribe( $field, $form, $data ) {
284
- $mailchimp = new MC4WP_MailChimp();
285
-
286
- // get id of email field
287
- foreach( $form['fields'] as $form_field ) {
288
- if( $form_field['type'] === 'email' ) {
289
- $email_field_id = $form_field['id'];
290
- break;
291
  }
292
- }
293
 
294
- if( empty( $email_field_id ) || empty( $data['fields'][$email_field_id] ) ) {
295
- return;
296
- }
297
 
298
- $email_address = $data['fields'][$email_field_id];
299
- $mailchimp_list_id = $field['mailchimp_list'];
300
 
301
- $success = $mailchimp->list_subscribe( $mailchimp_list_id, $email_address );
302
- $log = mc4wp('log');
303
 
304
- if( $success ) {
305
- $log->info( sprintf( '%s > Successfully subscribed %s', 'WPForms', $email_address ) );
306
- } else {
307
- // log error
308
- if( $mailchimp->get_error_code() == 214 ) {
309
- $log->warning( sprintf( "%s > %s is already subscribed to the selected list(s)", 'WPForms', $email_address ) );
310
  } else {
311
- $log->error( sprintf( '%s > MailChimp API Error: %s', 'WPForms', $mailchimp->get_error_message() ) );
 
 
 
 
 
312
  }
313
  }
314
  }
315
- }
 
1
  <?php
 
 
 
 
 
 
 
 
 
 
2
 
3
+ if( class_exists( 'WPForms_Field' ) ) {
 
 
 
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  /**
7
+ * Checkbox field.
8
  *
9
+ * @package WPForms
10
+ * @author WPForms
11
+ * @since 1.0.0
12
+ * @license GPL-2.0+
13
+ * @copyright Copyright (c) 2016, WPForms LLC
14
  */
15
+ class MC4WP_WPForms_Field extends WPForms_Field
16
+ {
17
+
18
+ /**
19
+ * @var MC4WP_MailChimp
20
+ */
21
+ private $mailchimp;
22
+
23
+ /**
24
+ * Primary class constructor.
25
+ *
26
+ * @since 1.0.0
27
+ */
28
+ public function init()
29
+ {
30
+
31
+ // Define field type information
32
+ $this->name = 'MailChimp';
33
+ $this->type = 'mailchimp';
34
+ $this->icon = 'fa-envelope-o';
35
+ $this->order = 21;
36
+ $this->defaults = array(
37
+ 0 => array(
38
+ 'label' => __('Sign-up to our newsletter?', 'mailchimp-for-wp'),
39
+ 'value' => '1',
40
+ 'default' => '',
41
+ )
42
+ );
43
+ }
44
 
45
+ /**
46
+ * Field options panel inside the builder.
47
+ *
48
+ * @since 1.0.0
49
+ * @param array $field
50
+ */
51
+ public function field_options($field)
52
+ {
53
 
54
+ //--------------------------------------------------------------------//
55
+ // Basic field options
56
+ //--------------------------------------------------------------------//
57
 
58
+ // Options open markup
59
+ $this->field_option('basic-options', $field, array('markup' => 'open'));
60
 
61
+ // MailChimp list
62
+ $this->field_option_mailchimp_list($field);
63
 
64
+ // Choices
65
+ $this->field_option_choices($field);
66
 
67
+ // Description
68
+ $this->field_option('description', $field);
69
 
70
+ // Required toggle
71
+ $this->field_option('required', $field);
72
 
73
+ // Options close markup
74
+ $this->field_option('basic-options', $field, array('markup' => 'close'));
 
75
 
76
+ //--------------------------------------------------------------------//
77
+ // Advanced field options
78
+ //--------------------------------------------------------------------//
79
 
80
+ // Options open markup
81
+ $this->field_option('advanced-options', $field, array('markup' => 'open'));
82
 
83
+ // Custom CSS classes
84
+ $this->field_option('css', $field);
 
85
 
86
+ // Options close markup
87
+ $this->field_option('advanced-options', $field, array('markup' => 'close'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  }
 
89
 
90
+ private function field_option_mailchimp_list($field)
91
+ {
92
+ $mailchimp = new MC4WP_MailChimp();
93
+
94
+ // Field option label
95
+ $tooltip = __('Select the MailChimp list to subscribe to.', 'mailchimp-for-wp');
96
+ $option_label = $this->field_element(
97
+ 'label',
98
+ $field,
99
+ array(
100
+ 'slug' => 'mailchimp-list',
101
+ 'value' => __('MailChimp list', 'mailchimp-for-wp'),
102
+ 'tooltip' => $tooltip,
103
+ ),
104
+ false
105
+ );
106
 
107
+ $option_select = sprintf('<select name="fields[%s][mailchimp_list]" data-field-id="%d" data-field-type="%s">', $field['id'], $field['id'], $this->type);
108
+ $lists = $mailchimp->get_cached_lists();
109
+ foreach ($lists as $list) {
110
+ $option_select .= sprintf('<option value="%s" %s>%s</option>', $list->id, selected($list->id, $field['mailchimp_list'], false), $list->name);
111
+ }
112
+ $option_select .= '</select>';
 
 
 
113
 
 
114
 
115
+ // Field option row (markup) including label and input.
116
+ $output = $this->field_element(
117
+ 'row',
118
+ $field,
119
+ array(
120
+ 'slug' => 'mailchimp-list',
121
+ 'content' => $option_label . $option_select,
122
+ )
123
+ );
124
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
+ private function field_option_choices($field)
128
+ {
129
+ $tooltip = __('Set your sign-up label text and whether it should be pre-checked.', 'mailchimp-for-wp');
130
+ $values = !empty($field['choices']) ? $field['choices'] : $this->defaults;
131
+ $class = !empty($field['show_values']) && $field['show_values'] == '1' ? 'show-values' : '';
132
+ $class .= !empty($dynamic) ? ' wpforms-hidden' : '';
133
+
134
+ // Field option label
135
+ $option_label = $this->field_element(
136
+ 'label',
137
+ $field,
138
+ array(
139
+ 'slug' => 'mailchimp-checkbox',
140
+ 'value' => __('Sign-up checkbox', 'mailchimp-for-wp'),
141
+ 'tooltip' => $tooltip,
142
+ ),
143
+ false
144
+ );
145
 
146
+ // Field option choices inputs
147
+ $option_choices = sprintf('<ul class="choices-list %s" data-field-id="%d" data-field-type="%s">', $class, $field['id'], $this->type);
148
+ foreach ($values as $key => $value) {
149
+ $default = !empty($value['default']) ? $value['default'] : '';
150
+ $option_choices .= sprintf('<li data-key="%d">', $key);
151
+ $option_choices .= sprintf('<input type="checkbox" name="fields[%s][choices][%s][default]" class="default" value="1" %s>', $field['id'], $key, checked('1', $default, false));
152
+ $option_choices .= sprintf('<input type="text" name="fields[%s][choices][%s][label]" value="%s" class="label">', $field['id'], $key, esc_attr($value['label']));
153
+ $option_choices .= sprintf('<input type="text" name="fields[%s][choices][%s][value]" value="%s" class="value">', $field['id'], $key, esc_attr($value['value']));
154
+ $option_choices .= '</li>';
155
+ }
156
+ $option_choices .= '</ul>';
157
+
158
+ // Field option row (markup) including label and input.
159
+ $output = $this->field_element(
160
+ 'row',
161
+ $field,
162
+ array(
163
+ 'slug' => 'choices',
164
+ 'content' => $option_label . $option_choices,
165
+ )
166
+ );
167
  }
168
 
169
+ /**
170
+ * Field preview inside the builder.
171
+ *
172
+ * @since 1.0.0
173
+ * @param array $field
174
+ */
175
+ public function field_preview($field)
176
+ {
177
+ $values = !empty($field['choices']) ? $field['choices'] : $this->defaults;
178
+
179
+ // Field checkbox elements
180
+ echo '<ul class="primary-input">';
181
+
182
+ // Notify if currently empty
183
+ if (empty($values)) {
184
+ $values = array('label' => __('(empty)', 'wpforms'));
185
+ }
186
 
187
+ // Individual checkbox options
188
+ foreach ($values as $key => $value) {
189
 
190
+ $default = isset($value['default']) ? $value['default'] : '';
191
+ $selected = checked('1', $default, false);
192
 
193
+ printf('<li><input type="checkbox" %s disabled>%s</li>', $selected, $value['label']);
194
+ }
195
 
196
+ echo '</ul>';
 
 
 
 
 
197
 
198
+ // Dynamic population is enabled and contains more than 20 items
199
+ if (isset($total) && $total > 20) {
200
+ echo '<div class="wpforms-alert-dynamic wpforms-alert wpforms-alert-warning">';
201
+ printf(__('Showing the first 20 choices.<br> All %d choices will be displayed when viewing the form.', 'wpforms'), absint($total));
202
+ echo '</div>';
203
+ }
204
 
205
+ // Description
206
+ $this->field_preview_option('description', $field);
207
+ }
 
 
 
 
 
208
 
209
+ /**
210
+ * Field display on the form front-end.
211
+ *
212
+ * @since 1.0.0
213
+ * @param array $field
214
+ * @param array $form_data
215
+ */
216
+ public function field_display($field, $field_atts, $form_data)
217
+ {
218
 
219
+ // Setup and sanitize the necessary data
220
+ $field_required = !empty($field['required']) ? ' required' : '';
221
+ $field_class = implode(' ', array_map('sanitize_html_class', $field_atts['input_class']));
222
+ $field_id = implode(' ', array_map('sanitize_html_class', $field_atts['input_id']));
223
+ $form_id = $form_data['id'];
224
+ $choices = $field['choices'];
225
 
 
 
226
 
227
+ // List
228
+ printf('<ul id="%s" class="%s">', $field_id, $field_class);
229
 
230
+ foreach ($choices as $key => $choice) {
 
231
 
232
+ $selected = isset($choice['default']) ? '1' : '0';
233
+ $depth = isset($choice['depth']) ? absint($choice['depth']) : 1;
234
 
235
+ printf('<li class="choice-%d depth-%d">', $key, $depth);
 
 
 
 
 
 
 
 
 
236
 
237
+ // Checkbox elements
238
+ printf('<input type="checkbox" id="wpforms-%d-field_%d_%d" name="wpforms[fields][%d]" value="%s" %s %s>',
239
+ $form_id,
240
+ $field['id'],
241
+ $key,
242
+ $field['id'],
243
+ esc_attr($choice['value']),
244
+ checked('1', $selected, false),
245
+ $field_required
246
+ );
247
 
248
+ printf('<label class="wpforms-field-label-inline" for="wpforms-%d-field_%d_%d">%s</label>', $form_id, $field['id'], $key, wp_kses_post($choice['label']));
 
249
 
250
+ echo '</li>';
251
+ }
252
 
253
+ echo '</ul>';
254
+ }
 
 
 
 
 
 
 
255
 
256
+ /**
257
+ * Formats and sanitizes field.
258
+ *
259
+ * @since 1.0.2
260
+ * @param int $field_id
261
+ * @param array $field_submit
262
+ * @param array $form_data
263
+ */
264
+ public function format($field_id, $field_submit, $form_data)
265
+ {
266
+
267
+ $field = $form_data['fields'][$field_id];
268
+ $choice = array_pop($field['choices']);
269
+ $name = sanitize_text_field($choice['label']);
270
+
271
+ $data = array(
272
+ 'name' => $name,
273
+ 'value' => empty($field_submit) ? __('No') : __('Yes'),
274
+ 'value_raw' => $field_submit,
275
+ 'id' => absint($field_id),
276
+ 'type' => $this->type,
277
+ );
278
 
 
 
 
 
 
 
 
279
 
280
+ // Push field details to be saved
281
+ wpforms()->process->fields[$field_id] = $data;
282
 
283
+ // Subscribe to MailChimp
284
+ if (!empty($field_submit)) {
285
+ $this->subscribe($field, $form_data, $_POST['wpforms']);
286
+ }
287
 
 
 
 
288
  }
289
 
290
+ /**
291
+ * @param $field
292
+ * @param $form
293
+ * @param $data
294
+ */
295
+ private function subscribe($field, $form, $data)
296
+ {
297
+ $mailchimp = new MC4WP_MailChimp();
298
+
299
+ // get id of email field
300
+ foreach ($form['fields'] as $form_field) {
301
+ if ($form_field['type'] === 'email') {
302
+ $email_field_id = $form_field['id'];
303
+ break;
304
+ }
305
  }
 
306
 
307
+ if (empty($email_field_id) || empty($data['fields'][$email_field_id])) {
308
+ return;
309
+ }
310
 
311
+ $email_address = $data['fields'][$email_field_id];
312
+ $mailchimp_list_id = $field['mailchimp_list'];
313
 
314
+ $success = $mailchimp->list_subscribe($mailchimp_list_id, $email_address);
315
+ $log = mc4wp('log');
316
 
317
+ if ($success) {
318
+ $log->info(sprintf('%s > Successfully subscribed %s', 'WPForms', $email_address));
 
 
 
 
319
  } else {
320
+ // log error
321
+ if ($mailchimp->get_error_code() == 214) {
322
+ $log->warning(sprintf("%s > %s is already subscribed to the selected list(s)", 'WPForms', $email_address));
323
+ } else {
324
+ $log->error(sprintf('%s > MailChimp API Error: %s', 'WPForms', $mailchimp->get_error_message()));
325
+ }
326
  }
327
  }
328
  }
329
+
330
+ }
mailchimp-for-wp.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: MailChimp for WordPress
4
  Plugin URI: https://mc4wp.com/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=plugins-page
5
  Description: MailChimp for WordPress by ibericode. Adds various highly effective sign-up methods to your site.
6
- Version: 4.1.7
7
  Author: ibericode
8
  Author URI: https://ibericode.com/
9
  Text Domain: mailchimp-for-wp
@@ -47,7 +47,7 @@ function _mc4wp_load_plugin() {
47
  }
48
 
49
  // bootstrap the core plugin
50
- define( 'MC4WP_VERSION', '4.1.7' );
51
  define( 'MC4WP_PLUGIN_DIR', dirname( __FILE__ ) . '/' );
52
  define( 'MC4WP_PLUGIN_URL', plugins_url( '/' , __FILE__ ) );
53
  define( 'MC4WP_PLUGIN_FILE', __FILE__ );
3
  Plugin Name: MailChimp for WordPress
4
  Plugin URI: https://mc4wp.com/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=plugins-page
5
  Description: MailChimp for WordPress by ibericode. Adds various highly effective sign-up methods to your site.
6
+ Version: 4.1.8
7
  Author: ibericode
8
  Author URI: https://ibericode.com/
9
  Text Domain: mailchimp-for-wp
47
  }
48
 
49
  // bootstrap the core plugin
50
+ define( 'MC4WP_VERSION', '4.1.8' );
51
  define( 'MC4WP_PLUGIN_DIR', dirname( __FILE__ ) . '/' );
52
  define( 'MC4WP_PLUGIN_URL', plugins_url( '/' , __FILE__ ) );
53
  define( 'MC4WP_PLUGIN_FILE', __FILE__ );
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://mc4wp.com/#utm_source=wp-plugin-repo&utm_medium=mailchimp-f
4
  Tags: mailchimp, mc4wp, email, marketing, newsletter, subscribe, widget, mc4wp, contact form 7, woocommerce, buddypress, ibericode, mailchimp forms, mailchimp integrations
5
  Requires at least: 4.1
6
  Tested up to: 4.8.1
7
- Stable tag: 4.1.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  Requires PHP: 5.2.4
@@ -196,7 +196,7 @@ MailChimp for WordPress comes with many filter & action hooks which allow you to
196
 
197
 
198
 
199
- #### 4.1.7 - September 8, 2017
200
 
201
  **Fixes**
202
 
4
  Tags: mailchimp, mc4wp, email, marketing, newsletter, subscribe, widget, mc4wp, contact form 7, woocommerce, buddypress, ibericode, mailchimp forms, mailchimp integrations
5
  Requires at least: 4.1
6
  Tested up to: 4.8.1
7
+ Stable tag: 4.1.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  Requires PHP: 5.2.4
196
 
197
 
198
 
199
+ #### 4.1.7 & 4.1.8 - September 8, 2017
200
 
201
  **Fixes**
202
 
vendor/autoload_52.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once dirname(__FILE__) . '/composer'.'/autoload_real_52.php';
6
 
7
- return ComposerAutoloaderInit0a2b31248d2c149af3b942f640333fab::getLoader();
4
 
5
  require_once dirname(__FILE__) . '/composer'.'/autoload_real_52.php';
6
 
7
+ return ComposerAutoloaderInit917d1ee96416f31f0bb9c23fbeaa0ffa::getLoader();
vendor/composer/autoload_real_52.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real_52.php generated by xrstf/composer-php52
4
 
5
- class ComposerAutoloaderInit0a2b31248d2c149af3b942f640333fab {
6
  private static $loader;
7
 
8
  public static function loadClassLoader($class) {
@@ -19,9 +19,9 @@ class ComposerAutoloaderInit0a2b31248d2c149af3b942f640333fab {
19
  return self::$loader;
20
  }
21
 
22
- spl_autoload_register(array('ComposerAutoloaderInit0a2b31248d2c149af3b942f640333fab', 'loadClassLoader'), true /*, true */);
23
  self::$loader = $loader = new xrstf_Composer52_ClassLoader();
24
- spl_autoload_unregister(array('ComposerAutoloaderInit0a2b31248d2c149af3b942f640333fab', 'loadClassLoader'));
25
 
26
  $vendorDir = dirname(dirname(__FILE__));
27
  $baseDir = dirname($vendorDir);
2
 
3
  // autoload_real_52.php generated by xrstf/composer-php52
4
 
5
+ class ComposerAutoloaderInit917d1ee96416f31f0bb9c23fbeaa0ffa {
6
  private static $loader;
7
 
8
  public static function loadClassLoader($class) {
19
  return self::$loader;
20
  }
21
 
22
+ spl_autoload_register(array('ComposerAutoloaderInit917d1ee96416f31f0bb9c23fbeaa0ffa', 'loadClassLoader'), true /*, true */);
23
  self::$loader = $loader = new xrstf_Composer52_ClassLoader();
24
+ spl_autoload_unregister(array('ComposerAutoloaderInit917d1ee96416f31f0bb9c23fbeaa0ffa', 'loadClassLoader'));
25
 
26
  $vendorDir = dirname(dirname(__FILE__));
27
  $baseDir = dirname($vendorDir);