MailChimp for WordPress - Version 2.0.4

Version Description

  • July 2, 2014 =

Fixes

  • Double sign-up requests for checkbox sign-ups

Improvements

  • Reset checkbox label in default CSS for improved theme compatibility
  • Improved checkbox integration classes
  • Optimised function to retrieve the current URL

Additions

  • Added {language} text variable to print the current site language.
  • Added merge tag names to list overview table
Download this release

Release Info

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

Code changes from version 2.0.3 to 2.0.4

assets/css/admin.css CHANGED
@@ -19,7 +19,7 @@
19
  vertical-align: top !important;
20
  }
21
 
22
- .mc4wp-box{
23
  margin-bottom:20px;
24
  }
25
 
@@ -67,7 +67,7 @@
67
  color:#aaa;
68
  }
69
 
70
- .mc4wp-settings span.status{
71
  display:inline-block;
72
  padding:3px 6px;
73
  color:white;
@@ -75,28 +75,28 @@
75
  font-weight:bold;
76
  }
77
 
78
- .mc4wp-settings span.positive{
79
  background-color:green;
80
  }
81
 
82
- .mc4wp-settings span.negative{
83
  background-color:lightGrey;
84
  }
85
 
86
- .mc4wp-settings table th{
87
  text-align:left;
88
  }
89
 
90
- .mc4wp-settings table.form-table tr td:first-child,
91
- .mc4wp-settings table.form-table tr th:first-child{
92
  padding-left:0;
93
  }
94
 
95
- .mc4wp-settings td.nowrap{
96
  white-space: nowrap
97
  }
98
 
99
- .mc4wp-settings td.desc{
100
  font-style:italic;
101
  font-size:11px;
102
  }
@@ -109,7 +109,7 @@
109
  margin: 1em 0 !important;
110
  }
111
 
112
- .mc4wp-col {
113
  float:left;
114
  -webkit-box-sizing: border-box;
115
  -moz-box-sizing:border-box;
@@ -118,11 +118,11 @@
118
  padding:0 5px;
119
  }
120
 
121
- .mc4wp-first{
122
  padding-left:0;
123
  }
124
 
125
- .mc4wp-last{
126
  padding-right:0;
127
  }
128
 
@@ -139,7 +139,6 @@
139
  border-bottom:1px solid #ddd;
140
  }
141
 
142
-
143
  table.mc4wp-help,
144
  table.mc4wp-help th,
145
  table.mc4wp-help td {
19
  vertical-align: top !important;
20
  }
21
 
22
+ #mc4wp .mc4wp-box{
23
  margin-bottom:20px;
24
  }
25
 
67
  color:#aaa;
68
  }
69
 
70
+ #mc4wp span.status{
71
  display:inline-block;
72
  padding:3px 6px;
73
  color:white;
75
  font-weight:bold;
76
  }
77
 
78
+ #mc4wp span.positive{
79
  background-color:green;
80
  }
81
 
82
+ #mc4wp span.negative{
83
  background-color:lightGrey;
84
  }
85
 
86
+ #mc4wp table th{
87
  text-align:left;
88
  }
89
 
90
+ #mc4wp table.form-table tr td:first-child,
91
+ #mc4wp table.form-table tr th:first-child{
92
  padding-left:0;
93
  }
94
 
95
+ #mc4wptd.nowrap{
96
  white-space: nowrap
97
  }
98
 
99
+ #mc4wp td.desc{
100
  font-style:italic;
101
  font-size:11px;
102
  }
109
  margin: 1em 0 !important;
110
  }
111
 
112
+ #mc4wp .mc4wp-col {
113
  float:left;
114
  -webkit-box-sizing: border-box;
115
  -moz-box-sizing:border-box;
118
  padding:0 5px;
119
  }
120
 
121
+ #mc4wp .mc4wp-first{
122
  padding-left:0;
123
  }
124
 
125
+ #mc4wp .mc4wp-last{
126
  padding-right:0;
127
  }
128
 
139
  border-bottom:1px solid #ddd;
140
  }
141
 
 
142
  table.mc4wp-help,
143
  table.mc4wp-help th,
144
  table.mc4wp-help td {
assets/css/checkbox.css CHANGED
@@ -1 +1 @@
1
- #mc4wp-checkbox{clear:both;display:block}#mc4wp-checkbox input{position:relative;margin:0 6px 0 0;padding:0;vertical-align:middle;display:inline-block !important;max-width:21px}#mc4wp-checkbox label{display:block;cursor:pointer;width:auto}#registerform #mc4wp-checkbox{margin-bottom:10px}
1
+ #mc4wp-checkbox{clear:both;display:block}#mc4wp-checkbox input{position:relative;margin:0 6px 0 0;padding:0;vertical-align:middle;display:inline-block !important;max-width:21px}#mc4wp-checkbox label{display:block;cursor:pointer;width:auto;position:static}#registerform #mc4wp-checkbox{margin-bottom:10px}
assets/sass/checkbox.scss CHANGED
@@ -17,6 +17,7 @@
17
  display: block;
18
  cursor: pointer;
19
  width: auto;
 
20
  }
21
 
22
  }
17
  display: block;
18
  cursor: pointer;
19
  width: auto;
20
+ position: static;
21
  }
22
 
23
  }
includes/class-admin.php CHANGED
@@ -232,10 +232,21 @@ class MC4WP_Lite_Admin
232
  public function show_api_settings()
233
  {
234
  $opts = mc4wp_get_options( 'general' );
235
- $tab = 'api-settings';
236
  $connected = ( mc4wp_get_api()->is_connected() );
237
 
238
- $lists = $this->get_mailchimp_lists();
 
 
 
 
 
 
 
 
 
 
 
 
239
  require MC4WP_LITE_PLUGIN_DIR . 'includes/views/api-settings.php';
240
  }
241
 
@@ -244,10 +255,9 @@ class MC4WP_Lite_Admin
244
  */
245
  public function show_checkbox_settings()
246
  {
 
247
  $opts = mc4wp_get_options( 'checkbox' );
248
- $lists = $this->get_mailchimp_lists();
249
-
250
- $tab = 'checkbox-settings';
251
  require MC4WP_LITE_PLUGIN_DIR . 'includes/views/checkbox-settings.php';
252
  }
253
 
@@ -257,8 +267,8 @@ class MC4WP_Lite_Admin
257
  public function show_form_settings()
258
  {
259
  $opts = mc4wp_get_options( 'form' );
260
- $lists = $this->get_mailchimp_lists();
261
- $tab = 'form-settings';
262
 
263
  // create array of missing form fields
264
  $missing_form_fields = array();
@@ -281,7 +291,7 @@ class MC4WP_Lite_Admin
281
  foreach( $opts['lists'] as $list_id ) {
282
 
283
  // get list object
284
- $list = $this->get_mailchimp_list( $list_id );
285
  if( ! is_object( $list ) ) {
286
  continue;
287
  }
@@ -308,142 +318,4 @@ class MC4WP_Lite_Admin
308
  require MC4WP_LITE_PLUGIN_DIR . 'includes/views/form-settings.php';
309
  }
310
 
311
- /**
312
- * Get MailChimp lists
313
- * Try cache first, then try API, then try fallback cache.
314
- *
315
- * @return array
316
- */
317
- private function get_mailchimp_lists()
318
- {
319
- $cached_lists = get_transient( 'mc4wp_mailchimp_lists' );
320
- $refresh_cache = ( isset( $_POST['mc4wp-renew-cache'] ) && $_POST['mc4wp-renew-cache'] == 1 );
321
-
322
- if( true === $refresh_cache || false === $cached_lists || empty( $cached_lists ) ) {
323
- // make api request for lists
324
- $api = mc4wp_get_api();
325
- $lists = array();
326
- $lists_data = $api->get_lists();
327
-
328
- if( $lists_data ) {
329
-
330
- $list_ids = array();
331
- foreach( $lists_data as $list ) {
332
- $list_ids[] = $list->id;
333
-
334
- $lists["{$list->id}"] = (object) array(
335
- 'id' => $list->id,
336
- 'name' => $list->name,
337
- 'subscriber_count' => $list->stats->member_count,
338
- 'merge_vars' => array(),
339
- 'interest_groupings' => array()
340
- );
341
-
342
- // get interest groupings
343
- $groupings_data = $api->get_list_groupings( $list->id );
344
- if( $groupings_data ) {
345
- $lists["{$list->id}"]->interest_groupings = array_map( array( $this, 'strip_unnecessary_grouping_properties' ), $groupings_data );
346
- }
347
- }
348
-
349
- // get merge vars for all lists at once
350
- $merge_vars_data = $api->get_lists_with_merge_vars( $list_ids );
351
- if( $merge_vars_data ) {
352
- foreach( $merge_vars_data as $list ) {
353
- // add merge vars to list
354
- $lists["{$list->id}"]->merge_vars = array_map( array( $this, 'strip_unnecessary_merge_vars_properties' ), $list->merge_vars );
355
- }
356
- }
357
-
358
- // cache renewal triggered manually?
359
- if( $refresh_cache ) {
360
- if( false === empty( $lists ) ) {
361
- add_settings_error( "mc4wp", "cache-renewed", __('MailChimp cache successfully renewed.', 'mailchimp-for-wp' ), 'updated' );
362
- } else {
363
- add_settings_error( "mc4wp", "cache-renew-failed", __('Failed to renew MailChimp cache - please try again later.', 'mailchimp-for-wp' ) );
364
- }
365
- }
366
-
367
- // store lists in transients
368
- set_transient( 'mc4wp_mailchimp_lists', $lists, ( 24 * 3600 ) ); // 1 day
369
- set_transient( 'mc4wp_mailchimp_lists_fallback', $lists, 1209600 ); // 2 weeks
370
- return $lists;
371
- } else {
372
- // api request failed, get fallback data (with longer lifetime)
373
- $cached_lists = get_transient('mc4wp_mailchimp_lists_fallback');
374
-
375
- if( ! $cached_lists ) {
376
- return array();
377
- }
378
- }
379
-
380
- }
381
-
382
- return $cached_lists;
383
- }
384
-
385
- /**
386
- * @param $list_id
387
- *
388
- * @return bool
389
- */
390
- private function get_mailchimp_list( $list_id ) {
391
- $lists = $this->get_mailchimp_lists();
392
-
393
- foreach( $lists as $list ) {
394
- if( $list->id === $list_id ) {
395
- return $list;
396
- }
397
- }
398
-
399
- return false;
400
- }
401
-
402
- /**
403
- * Build the group array object which will be stored in cache
404
- * @param object $group
405
- * @return object
406
- */
407
- public function strip_unnecessary_group_properties( $group ) {
408
- return (object) array(
409
- 'name' => $group->name
410
- );
411
- }
412
-
413
- /**
414
- * Build the groupings array object which will be stored in cache
415
- * @param object $grouping
416
- * @return object
417
- */
418
- public function strip_unnecessary_grouping_properties( $grouping )
419
- {
420
- return (object) array(
421
- 'id' => $grouping->id,
422
- 'name' => $grouping->name,
423
- 'groups' => array_map( array( $this, 'strip_unnecessary_group_properties' ), $grouping->groups ),
424
- 'form_field' => $grouping->form_field
425
- );
426
- }
427
-
428
- /**
429
- * Build the merge_var array object which will be stored in cache
430
- * @param object $merge_var
431
- * @return object
432
- */
433
- public function strip_unnecessary_merge_vars_properties( $merge_var )
434
- {
435
- $array = array(
436
- 'name' => $merge_var->name,
437
- 'field_type' => $merge_var->field_type,
438
- 'req' => $merge_var->req,
439
- 'tag' => $merge_var->tag
440
- );
441
-
442
- if ( isset( $merge_var->choices ) ) {
443
- $array["choices"] = $merge_var->choices;
444
- }
445
-
446
- return (object) $array;
447
- }
448
-
449
  }
232
  public function show_api_settings()
233
  {
234
  $opts = mc4wp_get_options( 'general' );
 
235
  $connected = ( mc4wp_get_api()->is_connected() );
236
 
237
+ // cache renewal triggered manually?
238
+ $force_cache_refresh = isset( $_POST['mc4wp-renew-cache'] ) && $_POST['mc4wp-renew-cache'] == 1;
239
+ $mailchimp = new MC4WP_MailChimp();
240
+ $lists = $mailchimp->get_lists( $force_cache_refresh );
241
+
242
+ if ( $force_cache_refresh ) {
243
+ if ( false === empty ( $lists ) ) {
244
+ add_settings_error( "mc4wp", "mc4wp-cache-success", __( 'Renewed MailChimp cache.', 'mailchimp-for-wp' ), 'updated' );
245
+ } else {
246
+ add_settings_error( "mc4wp", "mc4wp-cache-error", __( 'Failed to renew MailChimp cache - please try again later.', 'mailchimp-for-wp' ) );
247
+ }
248
+ }
249
+
250
  require MC4WP_LITE_PLUGIN_DIR . 'includes/views/api-settings.php';
251
  }
252
 
255
  */
256
  public function show_checkbox_settings()
257
  {
258
+ $mailchimp = new MC4WP_MailChimp();
259
  $opts = mc4wp_get_options( 'checkbox' );
260
+ $lists = $mailchimp->get_lists();
 
 
261
  require MC4WP_LITE_PLUGIN_DIR . 'includes/views/checkbox-settings.php';
262
  }
263
 
267
  public function show_form_settings()
268
  {
269
  $opts = mc4wp_get_options( 'form' );
270
+ $mailchimp = new MC4WP_MailChimp();
271
+ $lists = $mailchimp->get_lists();
272
 
273
  // create array of missing form fields
274
  $missing_form_fields = array();
291
  foreach( $opts['lists'] as $list_id ) {
292
 
293
  // get list object
294
+ $list = $mailchimp->get_list( $list_id );
295
  if( ! is_object( $list ) ) {
296
  continue;
297
  }
318
  require MC4WP_LITE_PLUGIN_DIR . 'includes/views/form-settings.php';
319
  }
320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  }
includes/class-mailchimp.php ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if( ! defined("MC4WP_LITE_VERSION") ) {
3
+ header( 'Status: 403 Forbidden' );
4
+ header( 'HTTP/1.1 403 Forbidden' );
5
+ exit;
6
+ }
7
+
8
+ class MC4WP_MailChimp {
9
+
10
+ /**
11
+ * Get MailChimp lists
12
+ * Try cache first, then try API, then try fallback cache.
13
+ *
14
+ * @return array
15
+ */
16
+ public function get_lists( $force_renewal = false ) {
17
+
18
+ $cached_lists = get_transient( 'mc4wp_mailchimp_lists' );
19
+
20
+ if ( true === $force_renewal || false === $cached_lists || empty( $cached_lists ) ) {
21
+
22
+ // make api request for lists
23
+ $api = mc4wp_get_api();
24
+ $lists = array();
25
+
26
+ $lists_data = $api->get_lists();
27
+
28
+ if ( $lists_data ) {
29
+
30
+ $lists = array();
31
+
32
+ foreach ( $lists_data as $list ) {
33
+
34
+ $lists["{$list->id}"] = (object) array(
35
+ 'id' => $list->id,
36
+ 'name' => $list->name,
37
+ 'subscriber_count' => $list->stats->member_count,
38
+ 'merge_vars' => array(),
39
+ 'interest_groupings' => array()
40
+ );
41
+
42
+ // get interest groupings
43
+ $groupings_data = $api->get_list_groupings( $list->id );
44
+ if ( $groupings_data ) {
45
+ $lists["{$list->id}"]->interest_groupings = array_map( array( $this, 'strip_unnecessary_grouping_properties' ), $groupings_data );
46
+ }
47
+
48
+ }
49
+
50
+
51
+ // get merge vars for all lists at once
52
+ $merge_vars_data = $api->get_lists_with_merge_vars( array_keys($lists) );
53
+ if ( $merge_vars_data ) {
54
+ foreach ( $merge_vars_data as $list ) {
55
+ // add merge vars to list
56
+ $lists["{$list->id}"]->merge_vars = array_map( array( $this, 'strip_unnecessary_merge_vars_properties' ), $list->merge_vars );
57
+ }
58
+ }
59
+
60
+ // store lists in transients
61
+ set_transient( 'mc4wp_mailchimp_lists', $lists, ( 24 * 3600 ) ); // 1 day
62
+ set_transient( 'mc4wp_mailchimp_lists_fallback', $lists, 1209600 ); // 2 weeks
63
+ return $lists;
64
+ } else {
65
+ // api request failed, get fallback data (with longer lifetime)
66
+ $cached_lists = get_transient( 'mc4wp_mailchimp_lists_fallback' );
67
+
68
+ if ( ! $cached_lists ) {
69
+ return array();
70
+ }
71
+ }
72
+
73
+ }
74
+
75
+ return $cached_lists;
76
+ }
77
+
78
+ /**
79
+ * Get a given MailChimp list
80
+ *
81
+ * @param int $list_id
82
+ *
83
+ * @return bool
84
+ */
85
+ public function get_list( $list_id ) {
86
+ $lists = $this->get_lists();
87
+
88
+ foreach( $lists as $list ) {
89
+ if( $list->id === $list_id ) {
90
+ return $list;
91
+ }
92
+ }
93
+
94
+ return false;
95
+ }
96
+
97
+ /**
98
+ * Get the name of the MailChimp list with the given ID.
99
+ *
100
+ * @param int $id
101
+ * @return string
102
+ */
103
+ public function get_list_name( $id ) {
104
+ $list = $this->get_list( $id );
105
+
106
+ if( is_object( $list ) ) {
107
+ return $list->name;
108
+ }
109
+
110
+ return '';
111
+ }
112
+
113
+ /**
114
+ * Build the group array object which will be stored in cache
115
+ * @return object
116
+ */
117
+ public function strip_unnecessary_group_properties( $group ) {
118
+ return (object) array(
119
+ 'name' => $group->name
120
+ );
121
+ }
122
+
123
+ /**
124
+ * Build the groupings array object which will be stored in cache
125
+ * @return object
126
+ */
127
+ public function strip_unnecessary_grouping_properties( $grouping ) {
128
+ return (object) array(
129
+ 'id' => $grouping->id,
130
+ 'name' => $grouping->name,
131
+ 'groups' => array_map( array( $this, 'strip_unnecessary_group_properties' ), $grouping->groups ),
132
+ 'form_field' => $grouping->form_field
133
+ );
134
+ }
135
+
136
+ /**
137
+ * Build the merge_var array object which will be stored in cache
138
+ * @return object
139
+ */
140
+ public function strip_unnecessary_merge_vars_properties( $merge_var ) {
141
+ $array = array(
142
+ 'name' => $merge_var->name,
143
+ 'field_type' => $merge_var->field_type,
144
+ 'req' => $merge_var->req,
145
+ 'tag' => $merge_var->tag
146
+ );
147
+
148
+ if ( isset( $merge_var->choices ) ) {
149
+ $array["choices"] = $merge_var->choices;
150
+ }
151
+
152
+ return (object) $array;
153
+
154
+ }
155
+
156
+ }
includes/class-plugin.php CHANGED
@@ -67,6 +67,7 @@ class MC4WP_Lite {
67
  'mc4wp_lite_checkbox_manager' => $include_path . 'class-checkbox-manager.php',
68
  'mc4wp_lite_form_manager' => $include_path . 'class-form-manager.php',
69
  'mc4wp_lite_widget' => $include_path . 'class-widget.php',
 
70
 
71
  // integrations
72
  'mc4wp_integration' => $include_path . 'integrations/class-integration.php',
67
  'mc4wp_lite_checkbox_manager' => $include_path . 'class-checkbox-manager.php',
68
  'mc4wp_lite_form_manager' => $include_path . 'class-form-manager.php',
69
  'mc4wp_lite_widget' => $include_path . 'class-widget.php',
70
+ 'mc4wp_mailchimp' => $include_path . 'class-mailchimp.php',
71
 
72
  // integrations
73
  'mc4wp_integration' => $include_path . 'integrations/class-integration.php',
includes/functions/template.php CHANGED
@@ -48,8 +48,13 @@ function mc4wp_get_form( $id = 0 ) {
48
  * @return string $text with {variables} replaced.
49
  */
50
  function mc4wp_replace_variables( $text, $list_ids = array() ) {
51
- $needles = array( '{ip}', '{current_url}', '{date}', '{time}' );
52
- $replacements = array( $_SERVER['REMOTE_ADDR'], mc4wp_get_current_url(), date( "m/d/Y" ), date( "H:i:s" ) );
 
 
 
 
 
53
  $text = str_ireplace( $needles, $replacements, $text );
54
 
55
  // subscriber count? only fetch these if the tag is actually used
@@ -58,14 +63,14 @@ function mc4wp_replace_variables( $text, $list_ids = array() ) {
58
  $text = str_ireplace( '{subscriber_count}', $subscriber_count, $text );
59
  }
60
 
 
61
  $needles = array( '{user_email}', '{user_firstname}', '{user_lastname}', '{user_name}', '{user_id}' );
62
  if ( is_user_logged_in() && ( $user = wp_get_current_user() ) && ( $user instanceof WP_User ) ) {
63
  // logged in user, replace vars by user vars
64
- $user = wp_get_current_user();
65
  $replacements = array( $user->user_email, $user->user_firstname, $user->user_lastname, $user->display_name, $user->ID );
66
  $text = str_replace( $needles, $replacements, $text );
67
  } else {
68
- // no logged in user, remove vars
69
  $text = str_replace( $needles, '', $text );
70
  }
71
 
@@ -79,6 +84,12 @@ function mc4wp_replace_variables( $text, $list_ids = array() ) {
79
  * @return int Sum of subscribers for given lists.
80
  */
81
  function mc4wp_get_subscriber_count( $list_ids ) {
 
 
 
 
 
 
82
  $list_counts = get_transient( 'mc4wp_list_counts' );
83
 
84
  if ( false === $list_counts ) {
@@ -96,7 +107,7 @@ function mc4wp_get_subscriber_count( $list_ids ) {
96
  $transient_lifetime = apply_filters( 'mc4wp_lists_count_cache_time', 1200 ); // 20 mins by default
97
 
98
  set_transient( 'mc4wp_list_counts', $list_counts, $transient_lifetime );
99
- set_transient( 'mc4wp_list_counts_fallback', $list_counts, 3600 * 24 ); // 1 day
100
  } else {
101
  // use fallback transient
102
  $list_counts = get_transient( 'mc4wp_list_counts_fallback' );
@@ -122,27 +133,9 @@ function mc4wp_get_subscriber_count( $list_ids ) {
122
  * @return string The current URL, escaped for safe usage inside attributes.
123
  */
124
  function mc4wp_get_current_url() {
125
- $page_url = 'http';
126
-
127
- if( is_ssl() ) {
128
- $page_url .= 's';
129
- }
130
-
131
- $page_url .= '://';
132
-
133
- if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
134
- $request_uri = substr( $_SERVER['PHP_SELF'], 1 );
135
-
136
- if ( isset( $_SERVER['QUERY_STRING'] ) ) {
137
- $request_uri .='?'.$_SERVER['QUERY_STRING'];
138
- }
139
- } else {
140
- $request_uri = $_SERVER['REQUEST_URI'];
141
- }
142
-
143
- $page_url .= $_SERVER["HTTP_HOST"] . $request_uri;
144
-
145
- return esc_url( $page_url );
146
  }
147
 
148
 
48
  * @return string $text with {variables} replaced.
49
  */
50
  function mc4wp_replace_variables( $text, $list_ids = array() ) {
51
+
52
+ // get current WPML language or general site language
53
+ $language = defined( 'ICL_LANGUAGE_CODE' ) ? ICL_LANGUAGE_CODE : get_locale();
54
+
55
+ // replace general vars
56
+ $needles = array( '{ip}', '{current_url}', '{date}', '{time}', '{language}' );
57
+ $replacements = array( $_SERVER['REMOTE_ADDR'], mc4wp_get_current_url(), date( "m/d/Y" ), date( "H:i:s" ), $language );
58
  $text = str_ireplace( $needles, $replacements, $text );
59
 
60
  // subscriber count? only fetch these if the tag is actually used
63
  $text = str_ireplace( '{subscriber_count}', $subscriber_count, $text );
64
  }
65
 
66
+ // replace user variables
67
  $needles = array( '{user_email}', '{user_firstname}', '{user_lastname}', '{user_name}', '{user_id}' );
68
  if ( is_user_logged_in() && ( $user = wp_get_current_user() ) && ( $user instanceof WP_User ) ) {
69
  // logged in user, replace vars by user vars
 
70
  $replacements = array( $user->user_email, $user->user_firstname, $user->user_lastname, $user->display_name, $user->ID );
71
  $text = str_replace( $needles, $replacements, $text );
72
  } else {
73
+ // no logged in user, replace vars with empty string
74
  $text = str_replace( $needles, '', $text );
75
  }
76
 
84
  * @return int Sum of subscribers for given lists.
85
  */
86
  function mc4wp_get_subscriber_count( $list_ids ) {
87
+
88
+ // don't count when $list_ids is empty or not an array
89
+ if( ! is_array( $list_ids ) || count( $list_ids ) === 0 ) {
90
+ return 0;
91
+ }
92
+
93
  $list_counts = get_transient( 'mc4wp_list_counts' );
94
 
95
  if ( false === $list_counts ) {
107
  $transient_lifetime = apply_filters( 'mc4wp_lists_count_cache_time', 1200 ); // 20 mins by default
108
 
109
  set_transient( 'mc4wp_list_counts', $list_counts, $transient_lifetime );
110
+ set_transient( 'mc4wp_list_counts_fallback', $list_counts, 86400 ); // 1 day
111
  } else {
112
  // use fallback transient
113
  $list_counts = get_transient( 'mc4wp_list_counts_fallback' );
133
  * @return string The current URL, escaped for safe usage inside attributes.
134
  */
135
  function mc4wp_get_current_url() {
136
+ $current_url = is_ssl() ? 'https://' : 'http://';
137
+ $current_url .= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
138
+ return esc_url( $current_url );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  }
140
 
141
 
includes/integrations/class-bbpress.php CHANGED
@@ -12,6 +12,9 @@ class MC4WP_bbPress_Integration extends MC4WP_Integration {
12
  protected $type = 'bbpress_forms';
13
 
14
  public function __construct() {
 
 
 
15
  add_action( 'bbp_theme_after_topic_form_subscriptions', array( $this, 'output_checkbox' ), 10 );
16
  add_action( 'bbp_theme_after_reply_form_subscription', array( $this, 'output_checkbox' ), 10 );
17
  add_action( 'bbp_theme_anonymous_form_extras_bottom', array( $this, 'output_checkbox' ), 10 );
@@ -26,6 +29,7 @@ class MC4WP_bbPress_Integration extends MC4WP_Integration {
26
  * @return boolean
27
  */
28
  public function subscribe_from_bbpress( $anonymous_data, $user_id, $trigger ) {
 
29
  if ( $this->checkbox_was_checked === false ) {
30
  return false;
31
  }
12
  protected $type = 'bbpress_forms';
13
 
14
  public function __construct() {
15
+
16
+ parent::__construct();
17
+
18
  add_action( 'bbp_theme_after_topic_form_subscriptions', array( $this, 'output_checkbox' ), 10 );
19
  add_action( 'bbp_theme_after_reply_form_subscription', array( $this, 'output_checkbox' ), 10 );
20
  add_action( 'bbp_theme_anonymous_form_extras_bottom', array( $this, 'output_checkbox' ), 10 );
29
  * @return boolean
30
  */
31
  public function subscribe_from_bbpress( $anonymous_data, $user_id, $trigger ) {
32
+
33
  if ( $this->checkbox_was_checked === false ) {
34
  return false;
35
  }
includes/integrations/class-buddypress.php CHANGED
@@ -12,6 +12,9 @@ class MC4WP_BuddyPress_Integration extends MC4WP_Integration {
12
  protected $type = 'buddypress_form';
13
 
14
  public function __construct() {
 
 
 
15
  add_action( 'bp_before_registration_submit_buttons', array( $this, 'output_checkbox' ), 20 );
16
  add_action( 'bp_core_signup_user', array( $this, 'subscribe_from_buddypress' ), 10, 4 );
17
  }
12
  protected $type = 'buddypress_form';
13
 
14
  public function __construct() {
15
+
16
+ parent::__construct();
17
+
18
  add_action( 'bp_before_registration_submit_buttons', array( $this, 'output_checkbox' ), 20 );
19
  add_action( 'bp_core_signup_user', array( $this, 'subscribe_from_buddypress' ), 10, 4 );
20
  }
includes/integrations/class-comment-form.php CHANGED
@@ -11,6 +11,9 @@ class MC4WP_Comment_Form_Integration extends MC4WP_Integration {
11
  protected $type = 'comment_form';
12
 
13
  public function __construct() {
 
 
 
14
  // hooks for outputting the checkbox
15
  add_action( 'thesis_hook_after_comment_box', array( $this, 'output_checkbox' ), 10 );
16
  add_action( 'comment_form', array( $this, 'output_checkbox' ), 10 );
@@ -22,10 +25,10 @@ class MC4WP_Comment_Form_Integration extends MC4WP_Integration {
22
  /**
23
  * Grabs data from WP Comment Form
24
  *
25
- * @param int $comment_ID
26
  * @param string $comment_approved
27
  */
28
- public function subscribe_from_comment( $comment_ID, $comment_approved = '' ) {
29
 
30
  // was sign-up checkbox checked?
31
  if ( $this->checkbox_was_checked() === false ) {
@@ -37,7 +40,7 @@ class MC4WP_Comment_Form_Integration extends MC4WP_Integration {
37
  return false;
38
  }
39
 
40
- $comment = get_comment( $comment_ID );
41
 
42
  $email = $comment->comment_author_email;
43
  $merge_vars = array(
@@ -45,6 +48,6 @@ class MC4WP_Comment_Form_Integration extends MC4WP_Integration {
45
  'OPTIN_IP' => $comment->comment_author_IP
46
  );
47
 
48
- return $this->subscribe( $email, $merge_vars, 'comment', $comment_ID );
49
  }
50
  }
11
  protected $type = 'comment_form';
12
 
13
  public function __construct() {
14
+
15
+ parent::__construct();
16
+
17
  // hooks for outputting the checkbox
18
  add_action( 'thesis_hook_after_comment_box', array( $this, 'output_checkbox' ), 10 );
19
  add_action( 'comment_form', array( $this, 'output_checkbox' ), 10 );
25
  /**
26
  * Grabs data from WP Comment Form
27
  *
28
+ * @param int $comment_id
29
  * @param string $comment_approved
30
  */
31
+ public function subscribe_from_comment( $comment_id, $comment_approved = '' ) {
32
 
33
  // was sign-up checkbox checked?
34
  if ( $this->checkbox_was_checked() === false ) {
40
  return false;
41
  }
42
 
43
+ $comment = get_comment( $comment_id );
44
 
45
  $email = $comment->comment_author_email;
46
  $merge_vars = array(
48
  'OPTIN_IP' => $comment->comment_author_IP
49
  );
50
 
51
+ return $this->subscribe( $email, $merge_vars, 'comment', $comment_id );
52
  }
53
  }
includes/integrations/class-general.php CHANGED
@@ -9,13 +9,21 @@ if( ! defined( "MC4WP_LITE_VERSION" ) ) {
9
 
10
  class MC4WP_General_Integration extends MC4WP_Integration {
11
 
12
-
 
 
13
  protected $type = 'general';
14
 
 
 
 
 
 
15
  /**
16
  * Constructor
17
  */
18
  public function __construct() {
 
19
  // run backwards compatibility routine
20
  $this->upgrade();
21
 
@@ -26,15 +34,15 @@ class MC4WP_General_Integration extends MC4WP_Integration {
26
  /**
27
  * Upgrade routine
28
  */
29
- public function upgrade() {
30
  // set new $_POST trigger value
31
  if( isset( $_POST['mc4wp-try-subscribe'] ) ) {
32
- $_POST[ 'mc4wp-subscribe' ] = 1;
33
  unset( $_POST['mc4wp-try-subscribe'] );
34
  }
35
 
36
  if( isset( $_POST['mc4wp-do-subscribe'] ) ) {
37
- $_POST['mc4wp-subscribe'] = 1;
38
  unset( $_POST['mc4wp-do-subscribe'] );
39
  }
40
  }
@@ -43,12 +51,12 @@ class MC4WP_General_Integration extends MC4WP_Integration {
43
  * Maybe fire a general subscription request
44
  */
45
  public function maybe_subscribe() {
 
46
  if ( $this->checkbox_was_checked() === false ) {
47
  return;
48
  }
49
 
50
  // don't run if this is a CF7 request
51
- // @todo handle this in a better way. noob.
52
  if( isset( $_POST['_wpcf7'] ) ) {
53
  return false;
54
  }
@@ -61,16 +69,15 @@ class MC4WP_General_Integration extends MC4WP_Integration {
61
  */
62
  public function checkbox_was_checked() {
63
 
64
- // Check if honeypot was filled (by spam bots)
65
- if( isset( $_POST['_mc4wp_required_but_not_really'] ) && ! empty( $_POST['_mc4wp_required_but_not_really'] ) ) {
66
  return false;
67
  }
68
 
69
- if ( isset( $_POST[ '_mc4wp_subscribe' ] ) && $_POST[ '_mc4wp_subscribe' ] == 1 ) {
70
  return true;
71
  }
72
 
73
- return ( isset( $_POST['mc4wp-subscribe'] ) && $_POST['mc4wp-subscribe'] == 1 );
74
  }
75
 
76
  /**
@@ -88,7 +95,7 @@ class MC4WP_General_Integration extends MC4WP_Integration {
88
 
89
  foreach( $_POST as $key => $value ) {
90
 
91
- if( $key[0] === '_' || $key === 'mc4wp-subscribe' ) {
92
  continue;
93
  } elseif( strtolower( substr( $key, 0, 6 ) ) === 'mc4wp-' ) {
94
  // find extra fields which should be sent to MailChimp
9
 
10
  class MC4WP_General_Integration extends MC4WP_Integration {
11
 
12
+ /**
13
+ * @var string
14
+ */
15
  protected $type = 'general';
16
 
17
+ /**
18
+ * @var string
19
+ */
20
+ protected $checkbox_name = 'mc4wp-subscribe';
21
+
22
  /**
23
  * Constructor
24
  */
25
  public function __construct() {
26
+
27
  // run backwards compatibility routine
28
  $this->upgrade();
29
 
34
  /**
35
  * Upgrade routine
36
  */
37
+ private function upgrade() {
38
  // set new $_POST trigger value
39
  if( isset( $_POST['mc4wp-try-subscribe'] ) ) {
40
+ $_POST[ $this->checkbox_name ] = 1;
41
  unset( $_POST['mc4wp-try-subscribe'] );
42
  }
43
 
44
  if( isset( $_POST['mc4wp-do-subscribe'] ) ) {
45
+ $_POST[ $this->checkbox_name ] = 1;
46
  unset( $_POST['mc4wp-do-subscribe'] );
47
  }
48
  }
51
  * Maybe fire a general subscription request
52
  */
53
  public function maybe_subscribe() {
54
+
55
  if ( $this->checkbox_was_checked() === false ) {
56
  return;
57
  }
58
 
59
  // don't run if this is a CF7 request
 
60
  if( isset( $_POST['_wpcf7'] ) ) {
61
  return false;
62
  }
69
  */
70
  public function checkbox_was_checked() {
71
 
72
+ if( $this->is_honeypot_filled() ) {
 
73
  return false;
74
  }
75
 
76
+ if( isset( $_POST[ '_mc4wp_subscribe' ] ) && $_POST[ '_mc4wp_subscribe' ] == 1 ) {
77
  return true;
78
  }
79
 
80
+ return ( isset( $_POST[ $this->checkbox_name ] ) && $_POST[ $this->checkbox_name ] == 1 );
81
  }
82
 
83
  /**
95
 
96
  foreach( $_POST as $key => $value ) {
97
 
98
+ if( $key[0] === '_' || $key === $this->checkbox_name ) {
99
  continue;
100
  } elseif( strtolower( substr( $key, 0, 6 ) ) === 'mc4wp-' ) {
101
  // find extra fields which should be sent to MailChimp
includes/integrations/class-integration.php CHANGED
@@ -13,22 +13,43 @@ abstract class MC4WP_Integration {
13
  */
14
  protected $type = 'integration';
15
 
 
 
 
 
 
16
  /**
17
  * Constructor
18
  */
19
- public function __construct() {}
 
 
20
 
21
  /**
22
- * @return boolean
23
- */
24
- public function checkbox_was_checked() {
 
 
25
 
26
  // Check if honeypot was filled (by spam bots)
27
  if( isset( $_POST['_mc4wp_required_but_not_really'] ) && ! empty( $_POST['_mc4wp_required_but_not_really'] ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
28
  return false;
29
  }
30
 
31
- return ( isset( $_POST[ '_mc4wp_subscribe' ] ) && $_POST[ '_mc4wp_subscribe' ] == 1 );
32
  }
33
 
34
  /**
@@ -77,14 +98,14 @@ abstract class MC4WP_Integration {
77
 
78
  }
79
 
80
- $content = "\n<!-- MailChimp for WP v". MC4WP_LITE_VERSION ." -->\n";
81
 
82
  do_action( 'mc4wp_before_checkbox' );
83
 
84
  // checkbox
85
  $content .= '<p id="mc4wp-checkbox">';
86
  $content .= '<label>';
87
- $content .= '<input type="checkbox" name="_mc4wp_subscribe" value="1" '. $checked . ' /> ';
88
  $content .= $label;
89
  $content .= '</label>';
90
  $content .= '</p>';
13
  */
14
  protected $type = 'integration';
15
 
16
+ /**
17
+ * @var string
18
+ */
19
+ protected $checkbox_name = '_mc4wp_subscribe';
20
+
21
  /**
22
  * Constructor
23
  */
24
+ public function __construct() {
25
+ $this->checkbox_name = '_mc4wp_subscribe' . '_' . $this->type;
26
+ }
27
 
28
  /**
29
+ * Was the honeypot filled?
30
+ *
31
+ * @return bool
32
+ */
33
+ protected function is_honeypot_filled() {
34
 
35
  // Check if honeypot was filled (by spam bots)
36
  if( isset( $_POST['_mc4wp_required_but_not_really'] ) && ! empty( $_POST['_mc4wp_required_but_not_really'] ) ) {
37
+ return true;
38
+ }
39
+
40
+ return false;
41
+ }
42
+
43
+ /**
44
+ * @return bool
45
+ */
46
+ public function checkbox_was_checked() {
47
+
48
+ if( $this->is_honeypot_filled() ) {
49
  return false;
50
  }
51
 
52
+ return ( isset( $_POST[ $this->checkbox_name ] ) && $_POST[ $this->checkbox_name ] == 1 );
53
  }
54
 
55
  /**
98
 
99
  }
100
 
101
+ $content = "\n<!-- MailChimp for WP v". MC4WP_LITE_VERSION ." - https://dannyvankooten.com/mailchimp-for-wordpress/ -->\n";
102
 
103
  do_action( 'mc4wp_before_checkbox' );
104
 
105
  // checkbox
106
  $content .= '<p id="mc4wp-checkbox">';
107
  $content .= '<label>';
108
+ $content .= '<input type="checkbox" name="'. $this->checkbox_name .'" value="1" '. $checked . ' /> ';
109
  $content .= $label;
110
  $content .= '</label>';
111
  $content .= '</p>';
includes/integrations/class-multisite.php CHANGED
@@ -12,6 +12,9 @@ class MC4WP_MultiSite_Integration extends MC4WP_Integration {
12
  protected $type = 'multisite_form';
13
 
14
  public function __construct() {
 
 
 
15
  add_action( 'signup_extra_fields', array( $this, 'output_checkbox' ), 20 );
16
  add_action( 'signup_blogform', array( $this, 'add_multisite_hidden_checkbox' ), 20 );
17
  add_action( 'wpmu_activate_blog', array( $this, 'on_multisite_blog_signup' ), 20, 5 );
12
  protected $type = 'multisite_form';
13
 
14
  public function __construct() {
15
+
16
+ parent::__construct();
17
+
18
  add_action( 'signup_extra_fields', array( $this, 'output_checkbox' ), 20 );
19
  add_action( 'signup_blogform', array( $this, 'add_multisite_hidden_checkbox' ), 20 );
20
  add_action( 'wpmu_activate_blog', array( $this, 'on_multisite_blog_signup' ), 20, 5 );
includes/integrations/class-registration-form.php CHANGED
@@ -9,15 +9,12 @@ if( ! defined("MC4WP_LITE_VERSION") ) {
9
 
10
  class MC4WP_Registration_Form_Integration extends MC4WP_Integration {
11
 
12
- /**
13
- * @var string
14
- */
15
  protected $type = 'registration_form';
16
 
17
- /**
18
- * Constructor, adds the registration hooks
19
- */
20
  public function __construct() {
 
 
 
21
  add_action( 'register_form', array( $this, 'output_checkbox' ), 20 );
22
  add_action( 'user_register', array( $this, 'subscribe_from_registration' ), 90, 1 );
23
  }
9
 
10
  class MC4WP_Registration_Form_Integration extends MC4WP_Integration {
11
 
 
 
 
12
  protected $type = 'registration_form';
13
 
 
 
 
14
  public function __construct() {
15
+
16
+ parent::__construct();
17
+
18
  add_action( 'register_form', array( $this, 'output_checkbox' ), 20 );
19
  add_action( 'user_register', array( $this, 'subscribe_from_registration' ), 90, 1 );
20
  }
includes/views/api-settings.php CHANGED
@@ -7,7 +7,7 @@ if( ! defined("MC4WP_LITE_VERSION") ) {
7
  }
8
 
9
  ?>
10
- <div id="mc4wp-<?php echo $tab; ?>" class="wrap mc4wp-settings">
11
 
12
  <h2><img src="<?php echo MC4WP_LITE_PLUGIN_URL . 'assets/img/menu-icon.png'; ?>" /> <?php _e( 'MailChimp for WordPress', 'mailchimp-for-wp' ); ?>: <?php _e( 'MailChimp Settings', 'mailchimp-for-wp' ); ?></h2>
13
 
@@ -62,7 +62,7 @@ if( ! defined("MC4WP_LITE_VERSION") ) {
62
  <th scope="col">List Name</th>
63
  <th scope="col">Merge Fields</th>
64
  <th scope="col">Groupings</th>
65
- <th scope="col">Subscriber Count</th>
66
  </tr>
67
  </thead>
68
  <tbody>
@@ -78,7 +78,7 @@ if( ! defined("MC4WP_LITE_VERSION") ) {
78
  <?php if( ! empty( $list->merge_vars ) && is_array( $list->merge_vars ) ) { ?>
79
  <ul class="ul-square" style="margin-top: 0;">
80
  <?php foreach( $list->merge_vars as $merge_var ) { ?>
81
- <li><?php echo esc_html( $merge_var->name ); ?></li>
82
  <?php } ?>
83
  </ul>
84
  <?php } ?>
@@ -102,7 +102,7 @@ if( ! defined("MC4WP_LITE_VERSION") ) {
102
  } ?>
103
 
104
  </td>
105
- <td><?php echo esc_html( $list->subscriber_count ); ?></td>
106
  </tr>
107
  <?php
108
  }
7
  }
8
 
9
  ?>
10
+ <div id="mc4wp" class="wrap mc4wp-settings">
11
 
12
  <h2><img src="<?php echo MC4WP_LITE_PLUGIN_URL . 'assets/img/menu-icon.png'; ?>" /> <?php _e( 'MailChimp for WordPress', 'mailchimp-for-wp' ); ?>: <?php _e( 'MailChimp Settings', 'mailchimp-for-wp' ); ?></h2>
13
 
62
  <th scope="col">List Name</th>
63
  <th scope="col">Merge Fields</th>
64
  <th scope="col">Groupings</th>
65
+ <th class="mc4wp-hide-smallscreens" scope="col">Subscribers</th>
66
  </tr>
67
  </thead>
68
  <tbody>
78
  <?php if( ! empty( $list->merge_vars ) && is_array( $list->merge_vars ) ) { ?>
79
  <ul class="ul-square" style="margin-top: 0;">
80
  <?php foreach( $list->merge_vars as $merge_var ) { ?>
81
+ <li><?php echo esc_html( $merge_var->name ); ?> <code><?php echo esc_html( $merge_var->tag ); ?></code></li>
82
  <?php } ?>
83
  </ul>
84
  <?php } ?>
102
  } ?>
103
 
104
  </td>
105
+ <td class="mc4wp-hide-smallscreens"><?php echo esc_html( $list->subscriber_count ); ?></td>
106
  </tr>
107
  <?php
108
  }
includes/views/checkbox-settings.php CHANGED
@@ -6,7 +6,7 @@ if( ! defined("MC4WP_LITE_VERSION") ) {
6
  }
7
 
8
  ?>
9
- <div id="mc4wp-<?php echo $tab; ?>" class="wrap mc4wp-settings">
10
 
11
  <h2><img src="<?php echo MC4WP_LITE_PLUGIN_URL . 'assets/img/menu-icon.png'; ?>" /> <?php _e( 'MailChimp for WordPress', 'mailchimp-for-wp' ); ?>: <?php _e( 'Checkbox Settings', 'mailchimp-for-wp' ); ?></h2>
12
 
6
  }
7
 
8
  ?>
9
+ <div id="mc4wp" class="wrap mc4wp-settings">
10
 
11
  <h2><img src="<?php echo MC4WP_LITE_PLUGIN_URL . 'assets/img/menu-icon.png'; ?>" /> <?php _e( 'MailChimp for WordPress', 'mailchimp-for-wp' ); ?>: <?php _e( 'Checkbox Settings', 'mailchimp-for-wp' ); ?></h2>
12
 
includes/views/form-settings.php CHANGED
@@ -4,7 +4,7 @@ if( ! defined("MC4WP_LITE_VERSION") ) {
4
  header( 'HTTP/1.1 403 Forbidden' );
5
  exit;
6
  } ?>
7
- <div id="mc4wp-<?php echo esc_attr( $tab ); ?>" class="wrap mc4wp-settings">
8
 
9
  <h2><img src="<?php echo MC4WP_LITE_PLUGIN_URL . 'assets/img/menu-icon.png'; ?>" /> <?php _e( 'MailChimp for WordPress', 'mailchimp-for-wp' ); ?>: <?php _e( 'Form Settings', 'mailchimp-for-wp' ); ?></h2>
10
 
@@ -217,31 +217,33 @@ if( ! defined("MC4WP_LITE_VERSION") ) {
217
  <h3 class="mc4wp-title"><?php _e( 'Form variables', 'mailchimp-for-wp' ); ?></h3>
218
  <p><?php _e( 'Use the following variables to add some dynamic content to your form.', 'mailchimp-for-wp' ); ?></p>
219
 
 
 
220
  <table class="mc4wp-help">
221
  <tr>
222
  <th>{subscriber_count}</th>
223
  <td><?php _e( 'Replaced with the number of subscribers on the selected list(s)', 'mailchimp-for-wp' ); ?></td>
224
  </tr>
 
 
 
 
225
  <tr>
226
  <th>{ip}</th>
227
  <td><?php _e( 'Replaced with the visitor\'s IP address', 'mailchimp-for-wp' ); ?></td>
228
  </tr>
229
  <tr>
230
  <th>{date}</th>
231
- <td><?php printf( __( 'Replaced with the current date (yyyy/mm/dd eg: %s)', 'mailchimp-for-wp' ), date("Y/m/d") ); ?></td>
232
  </tr>
233
  <tr>
234
  <th>{time}</th>
235
- <td><?php printf( __( 'Replaced with the current time (hh:mm:ss eg: %s)', 'mailchimp-for-wp' ), date("H:i:s") ); ?></td>
236
  </tr>
237
  <tr>
238
  <th>{user_email}</th>
239
  <td><?php _e( 'Replaced with the logged in user\'s email (or nothing, if there is no logged in user)', 'mailchimp-for-wp' ); ?></td>
240
  </tr>
241
- <tr>
242
- <th>{user_name}</th>
243
- <td><?php _e( 'Display name of the current user', 'mailchimp-for-wp' ); ?></td>
244
- </tr>
245
  <tr>
246
  <th>{user_firstname}</th>
247
  <td><?php _e( 'First name of the current user', 'mailchimp-for-wp' ); ?></td>
4
  header( 'HTTP/1.1 403 Forbidden' );
5
  exit;
6
  } ?>
7
+ <div id="mc4wp" class="wrap mc4wp-settings">
8
 
9
  <h2><img src="<?php echo MC4WP_LITE_PLUGIN_URL . 'assets/img/menu-icon.png'; ?>" /> <?php _e( 'MailChimp for WordPress', 'mailchimp-for-wp' ); ?>: <?php _e( 'Form Settings', 'mailchimp-for-wp' ); ?></h2>
10
 
217
  <h3 class="mc4wp-title"><?php _e( 'Form variables', 'mailchimp-for-wp' ); ?></h3>
218
  <p><?php _e( 'Use the following variables to add some dynamic content to your form.', 'mailchimp-for-wp' ); ?></p>
219
 
220
+ <?php $language = defined( 'ICL_LANGUAGE_CODE' ) ? ICL_LANGUAGE_CODE : get_locale(); ?>
221
+
222
  <table class="mc4wp-help">
223
  <tr>
224
  <th>{subscriber_count}</th>
225
  <td><?php _e( 'Replaced with the number of subscribers on the selected list(s)', 'mailchimp-for-wp' ); ?></td>
226
  </tr>
227
+ <tr>
228
+ <th>{language}</th>
229
+ <td><?php printf( __( 'Replaced with the current site language, eg: %s', 'mailchimp-for-wp' ), '<em>' . $language . '</em>' ); ?></td>
230
+ </tr>
231
  <tr>
232
  <th>{ip}</th>
233
  <td><?php _e( 'Replaced with the visitor\'s IP address', 'mailchimp-for-wp' ); ?></td>
234
  </tr>
235
  <tr>
236
  <th>{date}</th>
237
+ <td><?php printf( __( 'Replaced with the current date (yyyy/mm/dd eg: %s)', 'mailchimp-for-wp' ), '<em>' . date("Y/m/d") . '</em>' ); ?></td>
238
  </tr>
239
  <tr>
240
  <th>{time}</th>
241
+ <td><?php printf( __( 'Replaced with the current time (hh:mm:ss eg: %s)', 'mailchimp-for-wp' ), '<em>' . date("H:i:s") . '</em>' ); ?></td>
242
  </tr>
243
  <tr>
244
  <th>{user_email}</th>
245
  <td><?php _e( 'Replaced with the logged in user\'s email (or nothing, if there is no logged in user)', 'mailchimp-for-wp' ); ?></td>
246
  </tr>
 
 
 
 
247
  <tr>
248
  <th>{user_firstname}</th>
249
  <td><?php _e( 'First name of the current user', 'mailchimp-for-wp' ); ?></td>
mailchimp-for-wp.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: MailChimp for WordPress Lite
4
  Plugin URI: https://dannyvankooten.com/mailchimp-for-wordpress/
5
  Description: Lite version of MailChimp for WordPress. Adds various sign-up methods to your website.
6
- Version: 2.0.3
7
  Author: Danny van Kooten
8
  Author URI: http://dannyvankooten.com
9
  Text Domain: mailchimp-for-wp
@@ -47,7 +47,7 @@ function mc4wp_load_plugin() {
47
  }
48
 
49
  // bootstrap the lite plugin
50
- define( "MC4WP_LITE_VERSION", "2.0.3" );
51
  define( "MC4WP_LITE_PLUGIN_DIR", plugin_dir_path( __FILE__ ) );
52
  define( "MC4WP_LITE_PLUGIN_URL", plugins_url( '/' , __FILE__ ) );
53
  define( "MC4WP_LITE_PLUGIN_FILE", __FILE__ );
@@ -57,7 +57,7 @@ function mc4wp_load_plugin() {
57
  require_once MC4WP_LITE_PLUGIN_DIR . 'includes/class-plugin.php';
58
  $GLOBALS['mc4wp'] = new MC4WP_Lite();
59
 
60
- if( is_admin() && ( ! defined( "DOING_AJAX" ) || ! DOING_AJAX ) ) {
61
 
62
  // ADMIN
63
  require_once MC4WP_LITE_PLUGIN_DIR . 'includes/class-admin.php';
3
  Plugin Name: MailChimp for WordPress Lite
4
  Plugin URI: https://dannyvankooten.com/mailchimp-for-wordpress/
5
  Description: Lite version of MailChimp for WordPress. Adds various sign-up methods to your website.
6
+ Version: 2.0.4
7
  Author: Danny van Kooten
8
  Author URI: http://dannyvankooten.com
9
  Text Domain: mailchimp-for-wp
47
  }
48
 
49
  // bootstrap the lite plugin
50
+ define( "MC4WP_LITE_VERSION", "2.0.4" );
51
  define( "MC4WP_LITE_PLUGIN_DIR", plugin_dir_path( __FILE__ ) );
52
  define( "MC4WP_LITE_PLUGIN_URL", plugins_url( '/' , __FILE__ ) );
53
  define( "MC4WP_LITE_PLUGIN_FILE", __FILE__ );
57
  require_once MC4WP_LITE_PLUGIN_DIR . 'includes/class-plugin.php';
58
  $GLOBALS['mc4wp'] = new MC4WP_Lite();
59
 
60
+ if( is_admin() && ( false === defined( 'DOING_AJAX' ) || false === DOING_AJAX ) ) {
61
 
62
  // ADMIN
63
  require_once MC4WP_LITE_PLUGIN_DIR . 'includes/class-admin.php';
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://dannyvankooten.com/mailchimp-for-wordpress/
4
  Tags: mailchimp,form,shortcode,widget,checkbox,comment,newsletter,buddypress,multisite,bbpress,woocommerce,easy digital downloads,contact form,contact form 7
5
  Requires at least: 3.6
6
  Tested up to: 3.9.1
7
- Stable tag: 2.0.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -34,9 +34,16 @@ Add sign-up checkboxes to *any* form on your website. The plugin offers built-in
34
  [Installation](http://wordpress.org/plugins/mailchimp-for-wp/installation/) | [Frequently Asked Questions](http://wordpress.org/plugins/mailchimp-for-wp/faq/) | [Screenshots](http://wordpress.org/plugins/mailchimp-for-wp/screenshots/)
35
 
36
  > **Premium features**
37
- >
38
- > Multiple forms, AJAX, form designer, custom themes, detailed statistics, more built-in checkbox integrations and priority support.
39
- >
 
 
 
 
 
 
 
40
  > [More information](https://dannyvankooten.com/mailchimp-for-wordpress/#utm_source=wp-plugin-repo&utm_medium=link&utm_campaign=after-features-link) | [Form demo's](https://dannyvankooten.com/mailchimp-for-wordpress/demo/#utm_source=wp-plugin-repo&utm_medium=link&utm_campaign=after-features-link) | [Upgrade now >>](https://dannyvankooten.com/mailchimp-for-wordpress/#utm_source=wp-plugin-repo&utm_medium=link&utm_campaign=after-features-link)
41
 
42
  **Translators**
@@ -78,18 +85,18 @@ If you have created your own language pack (or have an update of an existing one
78
  Need help? Please take a look at the [frequently asked questions](http://wordpress.org/plugins/mailchimp-for-wp/faq/) first
79
 
80
  = Upgrade to Pro =
81
- If you like the plugin, upgrade to [MailChimp for WordPress Pro](https://dannyvankooten.com/mailchimp-for-wordpress/#utm_source=wp-plugin-repo&utm_medium=link&utm_campaign=installation-instructions-link) for an even better plugin.
82
 
83
  == Frequently Asked Questions ==
84
 
85
  > **Is there a premium version of this plugin?**
86
  >
87
- > Yes, you will love it. Some Pro features are:
88
  >
89
- > 1. Multiple forms, each subscribing to one or multiple MailChimp list(s).
90
- > 1. AJAX - no page reload after submitting a sign-up form.
91
- > 1. Custom color themes and a form designer (CSS Builder)
92
- > 1. Statistics & log. Learn when, where and how your visitors subscribed.
93
  >
94
  > [More Pro features](https://dannyvankooten.com/mailchimp-for-wordpress/#utm_source=wp-plugin-repo&utm_medium=link&utm_campaign=faq-link) | [Demo](https://dannyvankooten.com/mailchimp-for-wordpress/demo/#utm_source=wp-plugin-repo&utm_medium=link&utm_campaign=faq-link)
95
 
@@ -133,10 +140,10 @@ You can use CSS rules to style the sign-up form, use the following CSS selectors
133
 
134
  Add your custom CSS rules to the end of your theme stylesheet, **/wp-content/themes/your-theme-name/style.css**. Do not add them to the plugin stylesheet as they will be automatically overwritten on the next plugin update.
135
 
136
- [PS: With the Pro version, you can design beautiful forms easily >>](https://dannyvankooten.com/mailchimp-for-wordpress/#utm_source=wp-plugin-repo&utm_medium=link&utm_campaign=after-css-link)
137
 
138
  = Where can I find my MailChimp API key? =
139
- [Here](http://kb.mailchimp.com/article/where-can-i-find-my-api-key)
140
 
141
  = How to add a sign-up checkbox to my Contact Form 7 forms? =
142
  Use the following shortcode in your CF7 form mark-up to display a sign-up checkbox.
@@ -210,6 +217,23 @@ Your theme folder can be found by browsing to `/wp-content/themes/your-theme-nam
210
 
211
  == Changelog ==
212
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  = 2.0.3 - June 17, 2014 =
214
 
215
  **Fixes**
@@ -422,5 +446,5 @@ Your theme folder can be found by browsing to `/wp-content/themes/your-theme-nam
422
 
423
  == Upgrade Notice ==
424
 
425
- = 2.0.3 =
426
- Fix undefined index notice in Contact Form 7 integrations.
4
  Tags: mailchimp,form,shortcode,widget,checkbox,comment,newsletter,buddypress,multisite,bbpress,woocommerce,easy digital downloads,contact form,contact form 7
5
  Requires at least: 3.6
6
  Tested up to: 3.9.1
7
+ Stable tag: 2.0.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
34
  [Installation](http://wordpress.org/plugins/mailchimp-for-wp/installation/) | [Frequently Asked Questions](http://wordpress.org/plugins/mailchimp-for-wp/faq/) | [Screenshots](http://wordpress.org/plugins/mailchimp-for-wp/screenshots/)
35
 
36
  > **Premium features**
37
+ >
38
+ > The Pro version of the plugin comes with the following features:
39
+ >
40
+ > - Multiple forms, each form can subscribe to one or multiple MailChimp lists
41
+ > - AJAX forms, forms do not need to reload the page
42
+ > - Easy CSS Builder and custom color themes
43
+ > - Reports: Statistical graphs & subscription log
44
+ > - Checkbox integration for WooCommerce & Easy Digital Downloads checkout
45
+ > - Priority support
46
+ >
47
  > [More information](https://dannyvankooten.com/mailchimp-for-wordpress/#utm_source=wp-plugin-repo&utm_medium=link&utm_campaign=after-features-link) | [Form demo's](https://dannyvankooten.com/mailchimp-for-wordpress/demo/#utm_source=wp-plugin-repo&utm_medium=link&utm_campaign=after-features-link) | [Upgrade now >>](https://dannyvankooten.com/mailchimp-for-wordpress/#utm_source=wp-plugin-repo&utm_medium=link&utm_campaign=after-features-link)
48
 
49
  **Translators**
85
  Need help? Please take a look at the [frequently asked questions](http://wordpress.org/plugins/mailchimp-for-wp/faq/) first
86
 
87
  = Upgrade to Pro =
88
+ If you like the plugin, [get the Pro version of MailChimp for WordPress](https://dannyvankooten.com/mailchimp-for-wordpress/#utm_source=wp-plugin-repo&utm_medium=link&utm_campaign=installation-instructions-link) for an even better plugin!
89
 
90
  == Frequently Asked Questions ==
91
 
92
  > **Is there a premium version of this plugin?**
93
  >
94
+ > Yes, you'll love it. Some Pro only features are:
95
  >
96
+ > - Unlimited amount of forms. Each form can subscribe to one or multiple MailChimp lists.
97
+ > - Easy CSS Builder and custom color themes.
98
+ > - AJAX. Forms can be submitted using JavaScript, causing no page reload.
99
+ > - Reports: Graphs & log. Learn when, where and how your visitors subscribed.
100
  >
101
  > [More Pro features](https://dannyvankooten.com/mailchimp-for-wordpress/#utm_source=wp-plugin-repo&utm_medium=link&utm_campaign=faq-link) | [Demo](https://dannyvankooten.com/mailchimp-for-wordpress/demo/#utm_source=wp-plugin-repo&utm_medium=link&utm_campaign=faq-link)
102
 
140
 
141
  Add your custom CSS rules to the end of your theme stylesheet, **/wp-content/themes/your-theme-name/style.css**. Do not add them to the plugin stylesheet as they will be automatically overwritten on the next plugin update.
142
 
143
+ [>> With the Pro plugin it's really easy to design beautiful forms <<](https://dannyvankooten.com/mailchimp-for-wordpress/#utm_source=wp-plugin-repo&utm_medium=link&utm_campaign=after-css-link)
144
 
145
  = Where can I find my MailChimp API key? =
146
+ [You can find your MailChimp API key here](http://kb.mailchimp.com/article/where-can-i-find-my-api-key)
147
 
148
  = How to add a sign-up checkbox to my Contact Form 7 forms? =
149
  Use the following shortcode in your CF7 form mark-up to display a sign-up checkbox.
217
 
218
  == Changelog ==
219
 
220
+ = 2.0.4 - July 2, 2014 =
221
+
222
+ **Fixes**
223
+
224
+ - Double sign-up requests for checkbox sign-ups
225
+
226
+ **Improvements**
227
+
228
+ - Reset checkbox label in default CSS for improved theme compatibility
229
+ - Improved checkbox integration classes
230
+ - Optimised function to retrieve the current URL
231
+
232
+ **Additions**
233
+
234
+ - Added `{language}` text variable to print the current site language.
235
+ - Added merge tag names to list overview table
236
+
237
  = 2.0.3 - June 17, 2014 =
238
 
239
  **Fixes**
446
 
447
  == Upgrade Notice ==
448
 
449
+ = 2.0.4 =
450
+ Recommended update! Fixes double subscription requests for checkbox sign-ups.