MailChimp List Subscribe Form - Version 1.5.3

Version Description

  • Fix PHP7 compatibility issue
  • Cut down on size of API requests for users with large lists.
  • Fix CSS issue on removing MailChimp style.
Download this release

Release Info

Developer MailChimp
Plugin Icon wp plugin MailChimp List Subscribe Form
Version 1.5.3
Comparing to
See all releases

Code changes from version 1.5.1 to 1.5.3

README.md CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: crowdfavorite
3
  Tags: mailchimp, email, newsletter, signup, marketing, plugin, widget
4
  Requires at least: 2.8
5
- Tested up to: 4.5
6
  Stable tag: 1.5
7
 
8
  == Description ==
2
  Contributors: crowdfavorite
3
  Tags: mailchimp, email, newsletter, signup, marketing, plugin, widget
4
  Requires at least: 2.8
5
+ Tested up to: 4.0
6
  Stable tag: 1.5
7
 
8
  == Description ==
bin/install-wp-tests.sh ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+
3
+ if [ $# -lt 3 ]; then
4
+ echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
5
+ exit 1
6
+ fi
7
+
8
+ DB_NAME=$1
9
+ DB_USER=$2
10
+ DB_PASS=$3
11
+ DB_HOST=${4-localhost}
12
+ WP_VERSION=${5-latest}
13
+
14
+ WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
15
+ WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
16
+
17
+ download() {
18
+ if [ `which curl` ]; then
19
+ curl -s "$1" > "$2";
20
+ elif [ `which wget` ]; then
21
+ wget -nv -O "$2" "$1"
22
+ fi
23
+ }
24
+
25
+ if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
26
+ WP_TESTS_TAG="tags/$WP_VERSION"
27
+ elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
28
+ WP_TESTS_TAG="trunk"
29
+ else
30
+ # http serves a single offer, whereas https serves multiple. we only want one
31
+ download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
32
+ grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
33
+ LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
34
+ if [[ -z "$LATEST_VERSION" ]]; then
35
+ echo "Latest WordPress version could not be found"
36
+ exit 1
37
+ fi
38
+ WP_TESTS_TAG="tags/$LATEST_VERSION"
39
+ fi
40
+
41
+ set -ex
42
+
43
+ install_wp() {
44
+
45
+ if [ -d $WP_CORE_DIR ]; then
46
+ return;
47
+ fi
48
+
49
+ mkdir -p $WP_CORE_DIR
50
+
51
+ if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
52
+ mkdir -p /tmp/wordpress-nightly
53
+ download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
54
+ unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
55
+ mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
56
+ else
57
+ if [ $WP_VERSION == 'latest' ]; then
58
+ local ARCHIVE_NAME='latest'
59
+ else
60
+ local ARCHIVE_NAME="wordpress-$WP_VERSION"
61
+ fi
62
+ download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
63
+ tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
64
+ fi
65
+
66
+ download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
67
+ }
68
+
69
+ install_test_suite() {
70
+ # portable in-place argument for both GNU sed and Mac OSX sed
71
+ if [[ $(uname -s) == 'Darwin' ]]; then
72
+ local ioption='-i .bak'
73
+ else
74
+ local ioption='-i'
75
+ fi
76
+
77
+ # set up testing suite if it doesn't yet exist
78
+ if [ ! -d $WP_TESTS_DIR ]; then
79
+ # set up testing suite
80
+ mkdir -p $WP_TESTS_DIR
81
+ svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
82
+ fi
83
+
84
+ if [ ! -f wp-tests-config.php ]; then
85
+ download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
86
+ sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php
87
+ sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
88
+ sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
89
+ sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
90
+ sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
91
+ fi
92
+
93
+ }
94
+
95
+ install_db() {
96
+ # parse DB_HOST for port or socket references
97
+ local PARTS=(${DB_HOST//\:/ })
98
+ local DB_HOSTNAME=${PARTS[0]};
99
+ local DB_SOCK_OR_PORT=${PARTS[1]};
100
+ local EXTRA=""
101
+
102
+ if ! [ -z $DB_HOSTNAME ] ; then
103
+ if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
104
+ EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
105
+ elif ! [ -z $DB_SOCK_OR_PORT ] ; then
106
+ EXTRA=" --socket=$DB_SOCK_OR_PORT"
107
+ elif ! [ -z $DB_HOSTNAME ] ; then
108
+ EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
109
+ fi
110
+ fi
111
+
112
+ # create database
113
+ mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
114
+ }
115
+
116
+ install_wp
117
+ install_test_suite
118
+ install_db
lib/mailchimp/mailchimp.php CHANGED
@@ -18,11 +18,21 @@ class MailChimp_API {
18
  return;
19
  }
20
 
21
- public function get($endpoint, $count=10) {
22
  $url = $this->api_url . $endpoint;
23
 
24
  if($count) {
25
- $url .= '?count=' . $count;
 
 
 
 
 
 
 
 
 
 
26
  }
27
 
28
  $args = array(
@@ -68,7 +78,19 @@ class MailChimp_API {
68
  }
69
 
70
  $body = json_decode($request['body'], true);
71
- return new WP_Error('mc-subscribe-error-api', $body['detail']);
 
 
 
 
 
 
 
 
 
 
 
 
72
  }
73
  }
74
  }
18
  return;
19
  }
20
 
21
+ public function get($endpoint, $count=10, $fields) {
22
  $url = $this->api_url . $endpoint;
23
 
24
  if($count) {
25
+ $query_params = 'count=' . $count . '&';
26
+ }
27
+
28
+ if(!empty($fields)) {
29
+ foreach($fields as $field => $value) {
30
+ $query_params .= $field . '=' . $value . '&';
31
+ }
32
+ }
33
+
34
+ if($query_params){
35
+ $url .= "?{$query_params}";
36
  }
37
 
38
  $args = array(
78
  }
79
 
80
  $body = json_decode($request['body'], true);
81
+ $merges = get_option('mc_merge_vars');
82
+ foreach ($merges as $merge) {
83
+ if (empty($body['errors'])) {
84
+ //Email address doesn't come back from the API, so if something's wrong, it's that.
85
+ $field_name = 'Email Address';
86
+ $body['errors'][0]['message'] = 'Please fill out a valid email address.';
87
+ }
88
+ elseif ($merge['tag'] == $body['errors'][0]['field']) {
89
+ $field_name = $merge['name'];
90
+ }
91
+ }
92
+ $message = sprintf($field_name . ": " . $body['errors'][0]['message']);
93
+ return new WP_Error('mc-subscribe-error-api', $message);
94
  }
95
  }
96
  }
lib/sopresto/sopresto.php DELETED
@@ -1,355 +0,0 @@
1
- <?php
2
-
3
- class Sopresto_MailChimp {
4
- const DEFAULT_VERSION = '2.0';
5
- var $errorMessage = '';
6
- var $errorCode = 0;
7
-
8
- var $apiUrl;
9
- var $version;
10
- var $public;
11
- var $secret;
12
- var $timeout = 300;
13
- var $chunkSize = 8192;
14
- var $secure = false;
15
-
16
- function __construct($public, $secret, $version = self::DEFAULT_VERSION) {
17
- $this->public = $public;
18
- $this->secret = $secret;
19
- $this->apiUrl = parse_url('https://sopresto.socialize-this.com/mailchimp/');
20
- $this->setVersion($version);
21
- }
22
-
23
- function getApiUrl($uri = '') {
24
- return $this->apiUrl['scheme'].'://'.$this->apiUrl['host'].$this->apiUrl['path'] . '/' . $uri;
25
- }
26
-
27
- function setVersion($version = self::DEFAULT_VERSION) {
28
- if ( !in_array($version, array('1.3', '2.0') ) ) $version = self::DEFAULT_VERSION;
29
- $this->version = $version;
30
- }
31
-
32
- function __call($method, $params) {
33
- if ( $this->version == '2.0' ) {
34
- list($module, $method) = explode('_', $method, 2);
35
- $method = str_replace('_','-',$method);
36
-
37
- $method = "$module/$method";
38
- }
39
-
40
- $this->errorMessage = '';
41
- $this->errorCode = 0;
42
-
43
- $public = $this->public;
44
- $secret = $this->secret;
45
-
46
- //some distribs change this to &amp; by default
47
- $sep_changed = false;
48
- if (ini_get("arg_separator.output") != "&"){
49
- $sep_changed = true;
50
- $orig_sep = ini_get("arg_separator.output");
51
- ini_set("arg_separator.output", "&");
52
- }
53
-
54
- //mutate params
55
- $mutate = array();
56
- foreach($params as $k=>$v){
57
- $mutate[$this->function_map[$this->version][$method][$k]] = $v;
58
- }
59
- if ( $this->version != self::DEFAULT_VERSION) $method = $this->version . "/$method";
60
-
61
- $post_vars = array();
62
- $post_vars['api'] = $method;
63
- $post_vars['public_key'] = $public;
64
- $post_vars['hash'] = sha1($public.$secret);
65
- $post_vars['params'] = $mutate;
66
- //return $post_vars;
67
- $post_vars = http_build_query($post_vars);
68
-
69
- if ($sep_changed) ini_set("arg_separator.output", $orig_sep);
70
-
71
-
72
- $payload = "POST " . $this->apiUrl["path"] . " HTTP/1.0\r\n";
73
- $payload .= "Host: " . $this->apiUrl["host"] . "\r\n";
74
- $payload .= "User-Agent: Sopresto_MailChimp/1.0\r\n";
75
- $payload .= "Content-type: application/x-www-form-urlencoded\r\n";
76
- $payload .= "Content-length: " . strlen($post_vars) . "\r\n";
77
- $payload .= "Connection: close \r\n\r\n";
78
- $payload .= $post_vars;
79
-
80
- ob_start();
81
- if ($this->secure){
82
- $sock = fsockopen("ssl://".$host, 443, $errno, $errstr, 30);
83
- } else {
84
- $sock = fsockopen($this->apiUrl["host"], 80, $errno, $errstr, 30);
85
- }
86
- if(!$sock) {
87
- $this->errorMessage = "Could not connect (ERR $errno: $errstr)";
88
- $this->errorCode = "-99";
89
- ob_end_clean();
90
- return false;
91
- }
92
-
93
- $response = "";
94
- fwrite($sock, $payload);
95
- stream_set_timeout($sock, $this->timeout);
96
- $info = stream_get_meta_data($sock);
97
- while ((!feof($sock)) && (!$info["timed_out"])) {
98
- $response .= fread($sock, $this->chunkSize);
99
- $info = stream_get_meta_data($sock);
100
- }
101
- fclose($sock);
102
- ob_end_clean();
103
-
104
- if ($info["timed_out"]) {
105
- $this->errorMessage = "Could not read response (timed out)";
106
- $this->errorCode = -98;
107
- return false;
108
- }
109
-
110
- list($headers, $response) = explode("\r\n\r\n", $response, 2);
111
- $headers = explode("\r\n", $headers);
112
-
113
- if(ini_get("magic_quotes_runtime")) $response = stripslashes($response);
114
-
115
- $serial = json_decode($response,true);
116
- if($response && $serial === false) {
117
- $response = array("error" => "Bad Response. Got This: " . $response, "code" => "-99");
118
- } else {
119
- $response = $serial;
120
- }
121
-
122
- if ( $this->version == '2.0' ) {
123
- if ( is_array($response) && isset($response['response']['errors'][0]['code']) && $response['response']['errors'][0]['code'] ) {
124
- $this->errorMessage = $response['response']['errors'][0]['error'];
125
- $this->errorCode = $response['response']['errors'][0]['code'];
126
- return false;
127
- }
128
- } else {
129
- if (is_array($response) && isset($response["result"]) && $response["result"] == 'error') {
130
- list($code, $message) = explode('||',$response['response'],2);
131
- $this->errorMessage = $message;
132
- $this->errorCode = $code;
133
- return false;
134
- }
135
- }
136
- return $response['response'];
137
- }
138
-
139
- protected $function_map = array(
140
- '2.0' => array(
141
- 'campaigns/content'=>array('cid', 'options'),
142
- 'campaigns/create'=>array('type', 'options', 'content', 'segment_opts', 'type_opts'),
143
- 'campaigns/delete'=>array('cid'),
144
- 'campaigns/list'=>array('filters', 'start', 'limit', 'sort_field', 'sort_dir'),
145
- 'campaigns/pause'=>array('cid'),
146
- 'campaigns/ready'=>array('cid'),
147
- 'campaigns/replicate'=>array('cid'),
148
- 'campaigns/resume'=>array('cid'),
149
- 'campaigns/schedule-batch'=>array('cid', 'schedule_time', 'num_batches', 'stagger_mins'),
150
- 'campaigns/schedule'=>array('cid', 'schedule_time', 'schedule_time_b'),
151
- 'campaigns/segment-test'=>array('list_id', 'options'),
152
- 'campaigns/send'=>array('cid'),
153
- 'campaigns/send-test'=>array('cid', 'test_emails', 'send_type'),
154
- 'campaigns/template-content'=>array('cid'),
155
- 'campaigns/unschedule'=>array('cid'),
156
- 'campaigns/update'=>array('cid', 'name', 'value'),
157
- 'ecomm/order-add'=>array('order'),
158
- 'ecomm/order-del'=>array('store_id', 'order_id'),
159
- 'ecomm/orders'=>array('cid', 'start', 'limit', 'since'),
160
- 'folders/add'=>array('name', 'type'),
161
- 'folders/del'=>array('fid', 'type'),
162
- 'folders/list'=>array('type'),
163
- 'folders/update'=>array('fid', 'name', 'type'),
164
- 'gallery/list'=>array('opts'),
165
- 'lists/abuse-reports'=>array('id', 'start', 'limit', 'since'),
166
- 'lists/activity'=>array('id'),
167
- 'lists/batch-subscribe'=>array('id', 'batch', 'double_optin', 'update_existing', 'replace_interests'),
168
- 'lists/batch-unsubscribe'=>array('id', 'batch', 'delete_member', 'send_goodbye', 'send_notify'),
169
- 'lists/clients'=>array('id'),
170
- 'lists/growth-history'=>array('id'),
171
- 'lists/interest-group-add'=>array('id', 'group_name', 'grouping_id'),
172
- 'lists/interest-group-del'=>array('id', 'group_name', 'grouping_id'),
173
- 'lists/interest-group-update'=>array('id', 'old_name', 'new_name', 'grouping_id'),
174
- 'lists/interest-grouping-add'=>array('id', 'name', 'type', 'groups'),
175
- 'lists/interest-grouping-del'=>array('grouping_id'),
176
- 'lists/interest-grouping-update'=>array('grouping_id', 'name', 'value'),
177
- 'lists/interest-groupings'=>array('id', 'counts'),
178
- 'lists/list'=>array('filters', 'start', 'limit', 'sort_field', 'sort_dir'),
179
- 'lists/locations'=>array('id'),
180
- 'lists/member-activity'=>array('id', 'emails'),
181
- 'lists/member-info'=>array('id', 'emails'),
182
- 'lists/members'=>array('id', 'status', 'opts'),
183
- 'lists/merge-var-add'=>array('id', 'tag', 'name', 'options'),
184
- 'lists/merge-var-del'=>array('id', 'tag'),
185
- 'lists/merge-var-reset'=>array('id', 'tag'),
186
- 'lists/merge-var-set'=>array('id', 'tag', 'value'),
187
- 'lists/merge-var-update'=>array('id', 'tag', 'options'),
188
- 'lists/merge-vars'=>array('id'),
189
- 'lists/static-segment-add'=>array('id', 'name'),
190
- 'lists/static-segment-del'=>array('id', 'seg_id'),
191
- 'lists/static-segment-members-add'=>array('id', 'seg_id', 'batch'),
192
- 'lists/static-segment-members-del'=>array('id', 'seg_id', 'batch'),
193
- 'lists/static-segment-reset'=>array('id', 'seg_id'),
194
- 'lists/static-segments'=>array('id'),
195
- 'lists/subscribe'=>array('id', 'email', 'merge_vars', 'email_type', 'double_optin', 'update_existing', 'replace_interests', 'send_welcome'),
196
- 'lists/unsubscribe'=>array('id', 'email', 'delete_member', 'send_goodbye', 'send_notify'),
197
- 'lists/update-member'=>array('id', 'email', 'merge_vars', 'email_type', 'replace_interests'),
198
- 'lists/webhook-add'=>array('id', 'url', 'actions', 'sources'),
199
- 'lists/webhook-del'=>array('id', 'url'),
200
- 'lists/webhooks'=>array('id'),
201
- 'helper/account-details'=>array('exclude'),
202
- 'helper/campaigns-for-email'=>array('email', 'options'),
203
- 'helper/chimp-chatter'=>array(),
204
- 'helper/generate-text'=>array('type', 'content'),
205
- 'helper/inline-css'=>array('html', 'strip_css'),
206
- 'helper/lists-for-email'=>array('email'),
207
- 'helper/ping'=>array(),
208
- 'helper/search-campaigns'=>array('query', 'offset', 'snip_start', 'snip_end'),
209
- 'helper/search-members'=>array('query', 'id', 'offset'),
210
- 'helper/verified-domains'=>array(),
211
- 'reports/abuse'=>array('cid', 'opts'),
212
- 'reports/advice'=>array('cid'),
213
- 'reports/bounce-message'=>array('cid', 'email'),
214
- 'reports/bounce-messages'=>array('cid', 'opts'),
215
- 'reports/click-detail'=>array('cid', 'tid', 'opts'),
216
- 'reports/clicks'=>array('cid'),
217
- 'reports/domain-performance'=>array('cid'),
218
- 'reports/ecomm-orders'=>array('cid', 'opts'),
219
- 'reports/eepurl'=>array('cid'),
220
- 'reports/geo-opens'=>array('cid'),
221
- 'reports/google-analytics'=>array('cid'),
222
- 'reports/member-activity'=>array('cid', 'emails'),
223
- 'reports/not-opened'=>array('cid', 'opts'),
224
- 'reports/opened'=>array('cid', 'opts'),
225
- 'reports/sent-to'=>array('cid', 'opts'),
226
- 'reports/share'=>array('cid', 'opts'),
227
- 'reports/summary'=>array('cid'),
228
- 'reports/unsubscribes'=>array('cid', 'opts'),
229
- 'templates/add'=>array('name', 'html', 'folder_id'),
230
- 'templates/del'=>array('template_id'),
231
- 'templates/info'=>array('template_id', 'type'),
232
- 'templates/list'=>array('types', 'filters'),
233
- 'templates/undel'=>array('template_id'),
234
- 'templates/update'=>array('template_id', 'values'),
235
- 'users/invite'=>array('email', 'role', 'msg'),
236
- 'users/invite-resend'=>array('email'),
237
- 'users/invite-revoke'=>array('email'),
238
- 'users/invites'=>array(),
239
- 'users/login-revoke'=>array('username'),
240
- 'users/logins'=>array(),
241
- 'vip/activity'=>array(),
242
- 'vip/add'=>array('id', 'emails'),
243
- 'vip/del'=>array('id', 'emails'),
244
- 'vip/members'=>array()
245
- ),
246
- '1.3' => array(
247
- 'campaignUnschedule'=>array("cid"),
248
- 'campaignSchedule'=>array("cid","schedule_time","schedule_time_b"),
249
- 'campaignScheduleBatch'=>array("cid","schedule_time","num_batches","stagger_mins"),
250
- 'campaignResume'=>array("cid"),
251
- 'campaignPause'=>array("cid"),
252
- 'campaignSendNow'=>array("cid"),
253
- 'campaignSendTest'=>array("cid","test_emails","send_type"),
254
- 'campaignSegmentTest'=>array("list_id","options"),
255
- 'campaignCreate'=>array("type","options","content","segment_opts","type_opts"),
256
- 'campaignUpdate'=>array("cid","name","value"),
257
- 'campaignReplicate'=>array("cid"),
258
- 'campaignDelete'=>array("cid"),
259
- 'campaigns'=>array("filters","start","limit","sort_field","sort_dir"),
260
- 'campaignStats'=>array("cid"),
261
- 'campaignClickStats'=>array("cid"),
262
- 'campaignEmailDomainPerformance'=>array("cid"),
263
- 'campaignMembers'=>array("cid","status","start","limit"),
264
- 'campaignHardBounces'=>array("cid","start","limit"),
265
- 'campaignSoftBounces'=>array("cid","start","limit"),
266
- 'campaignUnsubscribes'=>array("cid","start","limit"),
267
- 'campaignAbuseReports'=>array("cid","since","start","limit"),
268
- 'campaignAdvice'=>array("cid"),
269
- 'campaignAnalytics'=>array("cid"),
270
- 'campaignGeoOpens'=>array("cid"),
271
- 'campaignGeoOpensForCountry'=>array("cid","code"),
272
- 'campaignEepUrlStats'=>array("cid"),
273
- 'campaignBounceMessage'=>array("cid","email"),
274
- 'campaignBounceMessages'=>array("cid","start","limit","since"),
275
- 'campaignEcommOrders'=>array("cid","start","limit","since"),
276
- 'campaignShareReport'=>array("cid","opts"),
277
- 'campaignContent'=>array("cid","for_archive"),
278
- 'campaignTemplateContent'=>array("cid"),
279
- 'campaignOpenedAIM'=>array("cid","start","limit"),
280
- 'campaignNotOpenedAIM'=>array("cid","start","limit"),
281
- 'campaignClickDetailAIM'=>array("cid","url","start","limit"),
282
- 'campaignEmailStatsAIM'=>array("cid","email_address"),
283
- 'campaignEmailStatsAIMAll'=>array("cid","start","limit"),
284
- 'campaignEcommOrderAdd'=>array("order"),
285
- 'lists'=>array("filters","start","limit","sort_field","sort_dir"),
286
- 'listMergeVars'=>array("id"),
287
- 'listMergeVarAdd'=>array("id","tag","name","options"),
288
- 'listMergeVarUpdate'=>array("id","tag","options"),
289
- 'listMergeVarDel'=>array("id","tag"),
290
- 'listMergeVarReset'=>array("id","tag"),
291
- 'listInterestGroupings'=>array("id"),
292
- 'listInterestGroupAdd'=>array("id","group_name","grouping_id"),
293
- 'listInterestGroupDel'=>array("id","group_name","grouping_id"),
294
- 'listInterestGroupUpdate'=>array("id","old_name","new_name","grouping_id"),
295
- 'listInterestGroupingAdd'=>array("id","name","type","groups"),
296
- 'listInterestGroupingUpdate'=>array("grouping_id","name","value"),
297
- 'listInterestGroupingDel'=>array("grouping_id"),
298
- 'listWebhooks'=>array("id"),
299
- 'listWebhookAdd'=>array("id","url","actions","sources"),
300
- 'listWebhookDel'=>array("id","url"),
301
- 'listStaticSegments'=>array("id"),
302
- 'listStaticSegmentAdd'=>array("id","name"),
303
- 'listStaticSegmentReset'=>array("id","seg_id"),
304
- 'listStaticSegmentDel'=>array("id","seg_id"),
305
- 'listStaticSegmentMembersAdd'=>array("id","seg_id","batch"),
306
- 'listStaticSegmentMembersDel'=>array("id","seg_id","batch"),
307
- 'listSubscribe'=>array("id","email_address","merge_vars","email_type","double_optin","update_existing","replace_interests","send_welcome"),
308
- 'listUnsubscribe'=>array("id","email_address","delete_member","send_goodbye","send_notify"),
309
- 'listUpdateMember'=>array("id","email_address","merge_vars","email_type","replace_interests"),
310
- 'listBatchSubscribe'=>array("id","batch","double_optin","update_existing","replace_interests"),
311
- 'listBatchUnsubscribe'=>array("id","emails","delete_member","send_goodbye","send_notify"),
312
- 'listMembers'=>array("id","status","since","start","limit","sort_dir"),
313
- 'listMemberInfo'=>array("id","email_address"),
314
- 'listMemberActivity'=>array("id","email_address"),
315
- 'listAbuseReports'=>array("id","start","limit","since"),
316
- 'listGrowthHistory'=>array("id"),
317
- 'listActivity'=>array("id"),
318
- 'listLocations'=>array("id"),
319
- 'listClients'=>array("id"),
320
- 'templates'=>array("types","category","inactives"),
321
- 'templateInfo'=>array("tid","type"),
322
- 'templateAdd'=>array("name","html"),
323
- 'templateUpdate'=>array("id","values"),
324
- 'templateDel'=>array("id"),
325
- 'templateUndel'=>array("id"),
326
- 'getAccountDetails'=>array("exclude"),
327
- 'getVerifiedDomains'=>array(),
328
- 'generateText'=>array("type","content"),
329
- 'inlineCss'=>array("html","strip_css"),
330
- 'folders'=>array("type"),
331
- 'folderAdd'=>array("name","type"),
332
- 'folderUpdate'=>array("fid","name","type"),
333
- 'folderDel'=>array("fid","type"),
334
- 'ecommOrders'=>array("start","limit","since"),
335
- 'ecommOrderAdd'=>array("order"),
336
- 'ecommOrderDel'=>array("store_id","order_id"),
337
- 'listsForEmail'=>array("email_address"),
338
- 'campaignsForEmail'=>array("email_address","options"),
339
- 'chimpChatter'=>array(),
340
- 'searchMembers'=>array("query","id","offset"),
341
- 'searchCampaigns'=>array("query","offset","snip_start","snip_end"),
342
- 'apikeys'=>array("username","password","expired"),
343
- 'apikeyAdd'=>array("username","password"),
344
- 'apikeyExpire'=>array("username","password"),
345
- 'ping'=>array(),
346
- 'deviceRegister'=>array("mobile_key","details"),
347
- 'deviceUnregister'=>array("mobile_key","device_id"),
348
- 'gmonkeyAdd'=>array("id","email_address"),
349
- 'gmonkeyDel'=>array("id","email_address"),
350
- 'gmonkeyMembers'=>array(),
351
- 'gmonkeyActivity'=>array()
352
- )
353
- );
354
- }
355
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/sopresto/test.php DELETED
@@ -1,20 +0,0 @@
1
- <?php
2
- require('sopresto.php');
3
- $public = 'XXX';
4
- $secret = 'YYY';
5
- $version = '1.3'; // or '2.0'
6
-
7
- $sopresto = new Sopresto_MailChimp($public, $secret, $version);
8
-
9
- if ( $version == '2.0' ) {
10
- // First underscore will be changed for a slash.
11
- // Remaning underscores will be changed by a dash
12
- // Ie.- to call 'helper/search-members' you should use $sopresto->helper_search_members()
13
-
14
- $response = $sopresto->campaigns_list(array(), 0, 2);
15
- } else {
16
- $response = $sopresto->campaigns(array(), 0, 2);
17
- }
18
-
19
- print_r($response);
20
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
mailchimp.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: MailChimp
4
  Plugin URI: http://www.mailchimp.com/plugins/mailchimp-wordpress-plugin/
5
  Description: The MailChimp plugin allows you to quickly and easily add a signup form for your MailChimp list.
6
- Version: 1.5.1
7
  Author: MailChimp
8
  Author URI: https://mailchimp.com/
9
  */
@@ -25,7 +25,7 @@ Author URI: https://mailchimp.com/
25
  */
26
 
27
  // Version constant for easy CSS refreshes
28
- define('MCSF_VER', '1.5.1');
29
 
30
  // What's our permission (capability) threshold
31
  define('MCSF_CAP_THRESHOLD', 'manage_options');
@@ -62,9 +62,14 @@ function mailchimpSF_plugin_init() {
62
  // Check for mc_api_key or sopresto key and continue if neither
63
  mailchimpSF_migrate_sopresto();
64
 
 
 
 
 
65
  // Bring in our appropriate JS and CSS resources
66
  mailchimpSF_load_resources();
67
  }
 
68
  add_action( 'init', 'mailchimpSF_plugin_init' );
69
 
70
 
@@ -104,12 +109,13 @@ function mailchimpSF_load_resources() {
104
 
105
  if (get_option('mc_use_datepicker') == 'on' && !is_admin()) {
106
  // Datepicker theme
107
- wp_enqueue_style('flick', MCSF_URL.'/css/flick/flick.css');
 
108
  // Datepicker JS
109
  wp_enqueue_script('datepicker', MCSF_URL.'/js/datepicker.js', array('jquery','jquery-ui-core'));
110
  }
111
 
112
- if(get_option('mc_nuke_all_styles') !== true) {
113
  wp_enqueue_style('mailchimpSF_main_css', home_url('?mcsf_action=main_css&ver='.MCSF_VER, 'relative'));
114
  wp_enqueue_style('mailchimpSF_ie_css', MCSF_URL.'css/ie.css');
115
  global $wp_styles;
@@ -125,7 +131,6 @@ function mailchimpSF_load_resources() {
125
  */
126
  function mc_admin_page_load_resources() {
127
  wp_enqueue_style('mailchimpSF_admin_css', MCSF_URL.'css/admin.css');
128
- wp_enqueue_script('mailchimpSF_admin_js', MCSF_URL.'js/admin.js');
129
  }
130
  add_action('load-settings_page_mailchimpSF_options', 'mc_admin_page_load_resources');
131
 
@@ -230,7 +235,6 @@ function mailchimpSF_request_handler() {
230
  case 'html':
231
  /* Allow to fall through. The widget will pick up the
232
  * global message left over from the signup_submit function */
233
- break;
234
  case 'js':
235
  if (!headers_sent()){ //just in case...
236
  header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT', true, 200);
@@ -295,6 +299,13 @@ function mailchimpSF_migrate_sopresto() {
295
  return;
296
  }
297
 
 
 
 
 
 
 
 
298
  function mailchimpSF_auth_nonce_key($salt = null) {
299
  if (is_null($salt)) {
300
  $salt = mailchimpSF_auth_nonce_salt();
@@ -475,6 +486,17 @@ function mailchimpSF_save_general_form_settings() {
475
  mailchimpSF_global_msg($msg);
476
  }
477
 
 
 
 
 
 
 
 
 
 
 
 
478
  if (isset($_POST['mc_use_unsub_link'])){
479
  update_option('mc_use_unsub_link', 'on');
480
  $msg = '<p class="success_msg">'.__('Unsubscribe link turned On!', 'mailchimp_i18n').'</p>';
@@ -558,7 +580,7 @@ function mailchimpSF_change_list_if_necessary() {
558
  if (!$api) { return; }
559
 
560
  //we *could* support paging, but few users have that many lists (and shouldn't)
561
- $lists = $api->get('lists',100);
562
  $lists = $lists['lists'];
563
 
564
  if (is_array($lists) && !empty($lists) && isset($_POST['mc_list_id'])) {
@@ -614,6 +636,12 @@ function mailchimpSF_change_list_if_necessary() {
614
  function mailchimpSF_get_merge_vars($list_id, $new_list) {
615
  $api = mailchimpSF_get_api();
616
  $mv = $api->get('lists/' . $list_id . '/merge-fields', 80);
 
 
 
 
 
 
617
  $mv['merge_fields'] = mailchimpSF_add_email_field($mv['merge_fields']);
618
  update_option('mc_merge_vars', $mv['merge_fields']);
619
  foreach($mv['merge_fields'] as $var){
@@ -645,6 +673,11 @@ function mailchimpSF_get_interest_categories($list_id, $new_list) {
645
  $api = mailchimpSF_get_api();
646
  $igs = $api->get('lists/' . $list_id . '/interest-categories', 60);
647
 
 
 
 
 
 
648
  if (is_array($igs)) {
649
  $key = 0;
650
  foreach($igs['categories'] as $ig) {
@@ -741,6 +774,16 @@ function mailchimpSF_signup_submit() {
741
 
742
  $url = 'lists/'. $listId . '/members/' . md5(strtolower($email));
743
  $status = mailchimpSF_check_status($url);
 
 
 
 
 
 
 
 
 
 
744
  $body = mailchimpSF_subscribe_body($merge, $igs, $email_type, $email, $status, get_option('mc_double_optin'));
745
  $retval = $api->post($url, $body, 'PUT');
746
 
@@ -770,7 +813,8 @@ function mailchimpSF_signup_submit() {
770
  API 3.0-friendly.
771
  */
772
 
773
- function mailchimpSF_subscribe_body($merge, $igs, $email_type, $email, $status, $double_optin) {
 
774
  $body = new stdClass();
775
  $body->email_address = $email;
776
  $body->email_type = $email_type;
@@ -779,16 +823,15 @@ function mailchimpSF_subscribe_body($merge, $igs, $email_type, $email, $status,
779
  $body->interests = $igs;
780
  }
781
 
782
- // single opt-in that covers new subscribers
783
- if (!$status && $double_optin == false) {
784
- $body->status = 'subscribed';
785
- }
786
- // anyone else
787
- else {
788
- $body->status = 'pending';
 
789
  }
790
-
791
-
792
  return $body;
793
  }
794
 
@@ -807,9 +850,10 @@ function mailchimpSF_merge_submit($mv) {
807
  $merge = new stdClass();
808
  foreach($mv as $var) {
809
  // We also want to create an array where the keys are the tags for easier validation later
810
- $mv_tag_keys[$var['tag']] = $var;
 
811
 
812
- $opt = 'mc_mv_'.$var['tag'];
813
 
814
  $opt_val = isset($_POST[$opt]) ? stripslashes_deep($_POST[$opt]) : '';
815
 
@@ -828,7 +872,7 @@ function mailchimpSF_merge_submit($mv) {
828
  }
829
 
830
  if($validate) {
831
- $merge->$var['tag'] = $validate;
832
  }
833
  continue;
834
 
@@ -848,8 +892,8 @@ function mailchimpSF_merge_submit($mv) {
848
  return $error;
849
  }
850
  else {
851
- if ($var['tag'] != 'EMAIL') {
852
- $merge->$var['tag'] = $opt_val;
853
  }
854
  }
855
  }
@@ -861,7 +905,7 @@ function mailchimpSF_merge_validate_phone($opt_val, $var) {
861
  $opt_val = array_filter($opt_val);
862
  // If they weren't all empty
863
  if (!$opt_val) {
864
- return false;
865
  }
866
 
867
  $opt_val = implode('-', $opt_val);
@@ -890,23 +934,25 @@ function mailchimpSF_merge_validate_address($opt_val, $var) {
890
  if (empty($opt_val['addr1']) || empty($opt_val['city'])) {
891
  return false;
892
  }
893
- $merge = new stdClass();
894
- $merge->addr1 = $opt_val['addr1'];
895
- $merge->addr2 = $opt_val['addr2'];
896
- $merge->city = $opt_val['city'];
897
- $merge->state = $opt_val['state'];
898
- $merge->zip = $opt_val['zip'];
899
- $merge->country = $opt_val['country'];
900
- return $merge;
901
  }
 
 
 
 
 
 
 
 
 
 
902
  }
903
 
904
- function mailchimpSF_merge_remove_empty($merge) {
 
905
  foreach ($merge as $k => $v) {
906
  if (is_object($v) && empty($v)) {
907
  unset($merge->$k);
908
- }
909
- else if (!is_object($v) && trim($v) === '') {
910
  unset($merge->$k);
911
  }
912
  }
@@ -919,28 +965,31 @@ function mailchimpSF_merge_remove_empty($merge) {
919
  return $merge;
920
  }
921
 
922
-
923
  function mailchimpSF_groups_submit($igs) {
 
 
924
  if(empty($igs)) {
925
  return new StdClass();
926
  }
927
-
928
- $groups = new stdClass();
 
929
 
930
  foreach ($igs as $ig) {
931
- if (get_option('mc_show_interest_groups_'.$ig['id']) == 'on' && $ig['type'] !== 'hidden') {
 
932
  switch ($ig['type']) {
933
  case 'dropdown':
934
  case 'radio':
935
  // there can only be one value submitted for radio/dropdowns, so use that at the group id.
936
- if (isset($_POST['group'][$ig['id']])){
937
- $value = $_POST['group'][$ig['id']];
938
  $groups->$value = true;
939
  }
940
  break;
941
  case 'checkboxes':
942
- if (isset($_POST['group'][$ig['id']])) {
943
- foreach ($_POST['group'][$ig['id']] as $id => $value) {
944
  $groups->$id = true;
945
  }
946
  }
@@ -954,6 +1003,21 @@ function mailchimpSF_groups_submit($igs) {
954
  return $groups;
955
  }
956
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
957
  function mailchimpSF_verify_key($api) {
958
  $user = $api->get('');
959
  if (is_wp_error($user)) {
3
  Plugin Name: MailChimp
4
  Plugin URI: http://www.mailchimp.com/plugins/mailchimp-wordpress-plugin/
5
  Description: The MailChimp plugin allows you to quickly and easily add a signup form for your MailChimp list.
6
+ Version: 1.5.3
7
  Author: MailChimp
8
  Author URI: https://mailchimp.com/
9
  */
25
  */
26
 
27
  // Version constant for easy CSS refreshes
28
+ define('MCSF_VER', '1.5.3');
29
 
30
  // What's our permission (capability) threshold
31
  define('MCSF_CAP_THRESHOLD', 'manage_options');
62
  // Check for mc_api_key or sopresto key and continue if neither
63
  mailchimpSF_migrate_sopresto();
64
 
65
+ if (get_option('mc_list_id') && get_option('mc_merge_field_migrate') != true && mailchimpSF_get_api() !== false) {
66
+ mailchimpSF_update_merge_fields(get_option('mc_list_id'));
67
+ }
68
+
69
  // Bring in our appropriate JS and CSS resources
70
  mailchimpSF_load_resources();
71
  }
72
+
73
  add_action( 'init', 'mailchimpSF_plugin_init' );
74
 
75
 
109
 
110
  if (get_option('mc_use_datepicker') == 'on' && !is_admin()) {
111
  // Datepicker theme
112
+ wp_enqueue_style('flick', MCSF_URL.'/css/flick/flick.css'
113
+ );
114
  // Datepicker JS
115
  wp_enqueue_script('datepicker', MCSF_URL.'/js/datepicker.js', array('jquery','jquery-ui-core'));
116
  }
117
 
118
+ if(get_option('mc_nuke_all_styles') != true) {
119
  wp_enqueue_style('mailchimpSF_main_css', home_url('?mcsf_action=main_css&ver='.MCSF_VER, 'relative'));
120
  wp_enqueue_style('mailchimpSF_ie_css', MCSF_URL.'css/ie.css');
121
  global $wp_styles;
131
  */
132
  function mc_admin_page_load_resources() {
133
  wp_enqueue_style('mailchimpSF_admin_css', MCSF_URL.'css/admin.css');
 
134
  }
135
  add_action('load-settings_page_mailchimpSF_options', 'mc_admin_page_load_resources');
136
 
235
  case 'html':
236
  /* Allow to fall through. The widget will pick up the
237
  * global message left over from the signup_submit function */
 
238
  case 'js':
239
  if (!headers_sent()){ //just in case...
240
  header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT', true, 200);
299
  return;
300
  }
301
 
302
+ function mailchimpSF_update_merge_fields($list_id)
303
+ {
304
+ mailchimpSF_get_merge_vars(get_option('mc_list_id'), true);
305
+ mailchimpSF_get_interest_categories(get_option('mc_list_id'), true);
306
+ update_option('mc_merge_field_migrate', true);
307
+ }
308
+
309
  function mailchimpSF_auth_nonce_key($salt = null) {
310
  if (is_null($salt)) {
311
  $salt = mailchimpSF_auth_nonce_salt();
486
  mailchimpSF_global_msg($msg);
487
  }
488
 
489
+ /* Update existing */
490
+ if (isset($_POST['mc_update_existing'])) {
491
+ update_option('mc_update_existing', true);
492
+ $msg = '<p class="success_msg">' . __('Update existing subscribers turned On!') . '</p>';
493
+ mailchimpSF_global_msg($msg);
494
+ } elseif (get_option('mc_update_existing') ==! false) {
495
+ update_option('mc_update_existing', false);
496
+ $msg = '<p class="success_msg">' . __('Update existing subscribers turned Off!') . '</p>';
497
+ mailchimpSF_global_msg($msg);
498
+ }
499
+
500
  if (isset($_POST['mc_use_unsub_link'])){
501
  update_option('mc_use_unsub_link', 'on');
502
  $msg = '<p class="success_msg">'.__('Unsubscribe link turned On!', 'mailchimp_i18n').'</p>';
580
  if (!$api) { return; }
581
 
582
  //we *could* support paging, but few users have that many lists (and shouldn't)
583
+ $lists = $api->get('lists',100, array('fields' => 'lists.id,lists.name,lists.email_type_option'));
584
  $lists = $lists['lists'];
585
 
586
  if (is_array($lists) && !empty($lists) && isset($_POST['mc_list_id'])) {
636
  function mailchimpSF_get_merge_vars($list_id, $new_list) {
637
  $api = mailchimpSF_get_api();
638
  $mv = $api->get('lists/' . $list_id . '/merge-fields', 80);
639
+
640
+ //if we get an error back from the api, exit this process.
641
+ if(is_wp_error($mv)) {
642
+ return;
643
+ }
644
+
645
  $mv['merge_fields'] = mailchimpSF_add_email_field($mv['merge_fields']);
646
  update_option('mc_merge_vars', $mv['merge_fields']);
647
  foreach($mv['merge_fields'] as $var){
673
  $api = mailchimpSF_get_api();
674
  $igs = $api->get('lists/' . $list_id . '/interest-categories', 60);
675
 
676
+ //if we get an error back from the api, exis
677
+ if(is_wp_error($igs)) {
678
+ return;
679
+ }
680
+
681
  if (is_array($igs)) {
682
  $key = 0;
683
  foreach($igs['categories'] as $ig) {
774
 
775
  $url = 'lists/'. $listId . '/members/' . md5(strtolower($email));
776
  $status = mailchimpSF_check_status($url);
777
+
778
+
779
+ // If update existing is turned off and the subscriber exists, error out.
780
+ if (get_option('mc_update_existing') == false && $status === 'subscribed') {
781
+ $msg = 'This email address is already subscribed to the list.';
782
+ $error = new WP_Error('mailchimp-update-existing', $msg);
783
+ mailchimpSF_global_msg('<strong class="mc_error_msg">' . $msg . '</strong>');
784
+ return false;
785
+ }
786
+
787
  $body = mailchimpSF_subscribe_body($merge, $igs, $email_type, $email, $status, get_option('mc_double_optin'));
788
  $retval = $api->post($url, $body, 'PUT');
789
 
813
  API 3.0-friendly.
814
  */
815
 
816
+ function mailchimpSF_subscribe_body($merge, $igs, $email_type, $email, $status, $double_optin)
817
+ {
818
  $body = new stdClass();
819
  $body->email_address = $email;
820
  $body->email_type = $email_type;
823
  $body->interests = $igs;
824
  }
825
 
826
+ if($status !== 'subscribed') {
827
+ // single opt-in that covers new subscribers
828
+ if (!$status && $double_optin == false) {
829
+ $body->status = 'subscribed';
830
+ } else {
831
+ // anyone else
832
+ $body->status = 'pending';
833
+ }
834
  }
 
 
835
  return $body;
836
  }
837
 
850
  $merge = new stdClass();
851
  foreach($mv as $var) {
852
  // We also want to create an array where the keys are the tags for easier validation later
853
+ $tag = $var['tag'];
854
+ $mv_tag_keys[$tag] = $var;
855
 
856
+ $opt = 'mc_mv_' . $tag;
857
 
858
  $opt_val = isset($_POST[$opt]) ? stripslashes_deep($_POST[$opt]) : '';
859
 
872
  }
873
 
874
  if($validate) {
875
+ $merge->$tag = $validate;
876
  }
877
  continue;
878
 
892
  return $error;
893
  }
894
  else {
895
+ if ($tag != 'EMAIL') {
896
+ $merge->$tag = $opt_val;
897
  }
898
  }
899
  }
905
  $opt_val = array_filter($opt_val);
906
  // If they weren't all empty
907
  if (!$opt_val) {
908
+ return;
909
  }
910
 
911
  $opt_val = implode('-', $opt_val);
934
  if (empty($opt_val['addr1']) || empty($opt_val['city'])) {
935
  return false;
936
  }
 
 
 
 
 
 
 
 
937
  }
938
+
939
+ $merge = new stdClass();
940
+ $merge->addr1 = $opt_val['addr1'];
941
+ $merge->addr2 = $opt_val['addr2'];
942
+ $merge->city = $opt_val['city'];
943
+ $merge->state = $opt_val['state'];
944
+ $merge->zip = $opt_val['zip'];
945
+ $merge->country = $opt_val['country'];
946
+ return $merge;
947
+
948
  }
949
 
950
+ function mailchimpSF_merge_remove_empty($merge)
951
+ {
952
  foreach ($merge as $k => $v) {
953
  if (is_object($v) && empty($v)) {
954
  unset($merge->$k);
955
+ } elseif ((is_string($v) && trim($v) === '') || is_null($v)) {
 
956
  unset($merge->$k);
957
  }
958
  }
965
  return $merge;
966
  }
967
 
 
968
  function mailchimpSF_groups_submit($igs) {
969
+ $groups = mailchimpSF_set_all_groups_to_false();
970
+
971
  if(empty($igs)) {
972
  return new StdClass();
973
  }
974
+
975
+ //get groups and ids
976
+ //set all to false
977
 
978
  foreach ($igs as $ig) {
979
+ $ig_id = $ig['id'];
980
+ if (get_option('mc_show_interest_groups_'.$ig_id) == 'on' && $ig['type'] !== 'hidden') {
981
  switch ($ig['type']) {
982
  case 'dropdown':
983
  case 'radio':
984
  // there can only be one value submitted for radio/dropdowns, so use that at the group id.
985
+ if (isset($_POST['group'][$ig_id]) && !empty($_POST['group'][$ig_id])) {
986
+ $value = $_POST['group'][$ig_id];
987
  $groups->$value = true;
988
  }
989
  break;
990
  case 'checkboxes':
991
+ if (isset($_POST['group'][$ig_id])) {
992
+ foreach ($_POST['group'][$ig_id] as $id => $value) {
993
  $groups->$id = true;
994
  }
995
  }
1003
  return $groups;
1004
  }
1005
 
1006
+ function mailchimpSF_set_all_groups_to_false() {
1007
+ $toreturn = new StdClass();
1008
+
1009
+ foreach (get_option('mc_interest_groups') as $grouping) {
1010
+ if($grouping['type'] !== 'hidden') {
1011
+ foreach ($grouping['groups'] as $group) {
1012
+ $id = $group['id'];
1013
+ $toreturn->$id = false;
1014
+ }
1015
+ }
1016
+ }
1017
+
1018
+ return $toreturn;
1019
+ }
1020
+
1021
  function mailchimpSF_verify_key($api) {
1022
  $user = $api->get('');
1023
  if (is_wp_error($user)) {
mailchimp_widget.php CHANGED
@@ -381,7 +381,7 @@ function mailchimp_form_field($var, $num_fields) {
381
  break;
382
  case 'birthday':
383
  $html .= '
384
- <input type="text" size="18" placeholder="'.esc_attr($var['default_value']).'" data-format="'.esc_attr($var['dateformat']).'" name="'.esc_attr($opt).'" id="'.esc_attr($opt).'" class="birthdate-pick mc_input"/>';
385
  break;
386
  case 'birthday-old':
387
  $days = range(1, 31);
@@ -472,7 +472,7 @@ function mailchimp_form_field($var, $num_fields) {
472
 
473
  class mailchimpSF_Widget extends WP_Widget {
474
 
475
- function mailchimpSF_Widget() {
476
  $widget_ops = array(
477
  'description' => __('Displays a MailChimp Subscribe box', 'mailchimp_i18n')
478
  );
381
  break;
382
  case 'birthday':
383
  $html .= '
384
+ <input type="text" size="18" placeholder="'.esc_attr($var['default_value']).'" data-format="'.esc_attr($var['options']['date_format']).'" name="'.esc_attr($opt).'" id="'.esc_attr($opt).'" class="birthdate-pick mc_input"/>';
385
  break;
386
  case 'birthday-old':
387
  $days = range(1, 31);
472
 
473
  class mailchimpSF_Widget extends WP_Widget {
474
 
475
+ function __construct() {
476
  $widget_ops = array(
477
  'description' => __('Displays a MailChimp Subscribe box', 'mailchimp_i18n')
478
  );
phpunit.xml.dist ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <phpunit
2
+ bootstrap="tests/bootstrap.php"
3
+ backupGlobals="false"
4
+ colors="true"
5
+ convertErrorsToExceptions="true"
6
+ convertNoticesToExceptions="true"
7
+ convertWarningsToExceptions="true"
8
+ >
9
+ <testsuites>
10
+ <testsuite>
11
+ <directory prefix="test-" suffix=".php">./tests/</directory>
12
+ </testsuite>
13
+ </testsuites>
14
+ </phpunit>
po/mailchimp.pot CHANGED
@@ -1,382 +1,1288 @@
1
- # SOME DESCRIPTIVE TITLE.
2
- # Copyright (C) YEAR MailChimp API Support Team
3
- # This file is distributed under the same license as the PACKAGE package.
4
- # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
- #
6
- #, fuzzy
7
  msgid ""
8
  msgstr ""
9
- "Project-Id-Version: MailChimp 1.1.5\n"
10
- "Report-Msgid-Bugs-To: http://wordpress.org/tag/mailchimp\n"
11
- "POT-Creation-Date: 2009-07-15 14:23-0400\n"
12
- "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
- "Language-Team: LANGUAGE <LL@li.org>\n"
15
  "MIME-Version: 1.0\n"
16
- "Content-Type: text/plain; charset=CHARSET\n"
17
  "Content-Transfer-Encoding: 8bit\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
- #: mailchimp_includes.php:27 mailchimp_includes.php:62
20
- msgid "You must fill in %s."
21
  msgstr ""
22
 
23
- #: mailchimp_includes.php:59
24
- msgid "That email address is already subscribed to the list"
25
  msgstr ""
26
 
27
- #: mailchimp_includes.php:66
28
- #, php-format
29
- msgid "%s has invalid content"
30
  msgstr ""
31
 
32
- #: mailchimp_includes.php:68
33
- msgid "An invalid Interest Group was selected"
34
  msgstr ""
35
 
36
- #: mailchimp_includes.php:69
37
- msgid "That email address is invalid"
38
  msgstr ""
39
 
40
- #: mailchimp_includes.php:75
41
- msgid "Success, you've been signed up! Please look for our confirmation email!"
42
  msgstr ""
43
 
44
- #: mailchimp_includes.php:131
45
- msgid "required field"
46
  msgstr ""
47
 
48
- #: mailchimp_includes.php:168
49
- msgid "unsubscribe from list"
50
  msgstr ""
51
 
52
- #: mailchimp_includes.php:171
53
- msgid "powered by"
54
  msgstr ""
55
 
56
- #: mailchimp.php:135
57
- msgid "MailChimp Setup"
58
  msgstr ""
59
 
60
- #: mailchimp.php:150
61
- msgid ""
62
- "While upgrading the plugin setup, we were unable to login to your account. "
63
- "You will need to login again and setup your list."
64
  msgstr ""
65
 
66
- #: mailchimp.php:156
67
- msgid "MailChimp List Setup"
68
  msgstr ""
69
 
70
- #: mailchimp.php:166
71
- msgid ""
72
- "Success! We were able to verify your username & password! Let's continue, "
73
- "shall we?"
74
  msgstr ""
75
 
76
- #: mailchimp.php:178
77
- msgid ""
78
- "Uh-oh, we were unable to login and verify your username & password. Please "
79
- "check them and try again!"
80
  msgstr ""
81
 
82
- #: mailchimp.php:179
83
- msgid "The server said:"
84
  msgstr ""
85
 
86
- #: mailchimp.php:222
87
- msgid "Sign up for"
88
  msgstr ""
89
 
90
- #: mailchimp.php:223
91
- msgid "Subscribe"
92
  msgstr ""
93
 
94
- #: mailchimp.php:253
95
- #, php-format
96
- msgid ""
97
- "Success! Loaded and saved the info for %d Merge Variables and %d Interest "
98
- "Groups from your list"
99
  msgstr ""
100
 
101
- #: mailchimp.php:256
102
- msgid ""
103
- "Now you should either Turn On the MailChimp Widget or change your options "
104
- "below, then turn it on."
105
  msgstr ""
106
 
107
- #: mailchimp.php:284
108
- msgid "Successfully Reset your List selection... Now you get to pick again!"
109
  msgstr ""
110
 
111
- #: mailchimp.php:290
112
- msgid "Monkey Rewards turned On!"
113
  msgstr ""
114
 
115
- #: mailchimp.php:294
116
- msgid "Monkey Rewards turned Off!"
117
  msgstr ""
118
 
119
- #: mailchimp.php:299
120
- msgid "Fancy Javascript submission turned On!"
121
  msgstr ""
122
 
123
- #: mailchimp.php:303
124
- msgid "Fancy Javascript submission turned Off!"
125
  msgstr ""
126
 
127
- #: mailchimp.php:309
128
- msgid "Unsubscribe link turned On!"
129
  msgstr ""
130
 
131
- #: mailchimp.php:313
132
- msgid "Unsubscribe link turned Off!"
133
  msgstr ""
134
 
135
- #: mailchimp.php:359
136
- msgid "Successfully Updated your List Subscribe Form Settings!"
137
  msgstr ""
138
 
139
- #: mailchimp.php:372
140
- msgid "Login Info"
141
  msgstr ""
142
 
143
- #: mailchimp.php:373
144
- msgid ""
145
- "To start using the MailChimp plugin, we first need to login and get your API "
146
- "Key. Please enter your MailChimp username and password below."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  msgstr ""
148
 
149
- #: mailchimp.php:375