MailChimp List Subscribe Form - Version 1.5.4

Version Description

  • Make field selection optional in API wrapper.
Download this release

Release Info

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

Code changes from version 1.5.3 to 1.5.4

lib/mailchimp/mailchimp.php CHANGED
@@ -18,20 +18,21 @@ class MailChimp_API {
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
 
@@ -39,15 +40,15 @@ class MailChimp_API {
39
  'timeout' => 5,
40
  'redirection' => 5,
41
  'httpversion' => '1.1',
42
- 'user-agent' => 'MailChimp WordPress Plugin/' . get_bloginfo( 'url' ),
43
  'headers' => array("Authorization" => 'apikey ' . $this->key)
44
  );
45
 
46
  $request = wp_remote_get($url, $args);
47
 
48
- if(is_array($request) && $request['response']['code'] == 200) {
49
  return json_decode($request['body'], true);
50
- } elseif(is_array($request) && $request['response']['code']) {
51
  $error = json_decode($request['body'], true);
52
  $error = new WP_Error('mailchimp-get-error', $error['detail']);
53
  return $error;
@@ -56,7 +57,7 @@ class MailChimp_API {
56
  }
57
  }
58
 
59
- public function post($endpoint, $body, $method='POST') {
60
  $url = $this->api_url . $endpoint;
61
 
62
  $args = array(
18
  return;
19
  }
20
 
21
+ public function get($endpoint, $count = 10, $fields = [])
22
+ {
23
  $url = $this->api_url . $endpoint;
24
 
25
+ if ($count) {
26
  $query_params = 'count=' . $count . '&';
27
  }
28
 
29
+ if (!empty($fields)) {
30
+ foreach ($fields as $field => $value) {
31
  $query_params .= $field . '=' . $value . '&';
32
  }
33
  }
34
 
35
+ if ($query_params) {
36
  $url .= "?{$query_params}";
37
  }
38
 
40
  'timeout' => 5,
41
  'redirection' => 5,
42
  'httpversion' => '1.1',
43
+ 'user-agent' => 'MailChimp WordPress Plugin/' . get_bloginfo('url'),
44
  'headers' => array("Authorization" => 'apikey ' . $this->key)
45
  );
46
 
47
  $request = wp_remote_get($url, $args);
48
 
49
+ if (is_array($request) && $request['response']['code'] == 200) {
50
  return json_decode($request['body'], true);
51
+ } elseif (is_array($request) && $request['response']['code']) {
52
  $error = json_decode($request['body'], true);
53
  $error = new WP_Error('mailchimp-get-error', $error['detail']);
54
  return $error;
57
  }
58
  }
59
 
60
+ public function post($endpoint, $body, $method = 'POST') {
61
  $url = $this->api_url . $endpoint;
62
 
63
  $args = array(
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.3
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.3');
29
 
30
  // What's our permission (capability) threshold
31
  define('MCSF_CAP_THRESHOLD', 'manage_options');
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.4
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.4');
29
 
30
  // What's our permission (capability) threshold
31
  define('MCSF_CAP_THRESHOLD', 'manage_options');
phpunit.xml.dist DELETED
@@ -1,14 +0,0 @@
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>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: MailChimp
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.3
7
 
8
  == Description ==
9
 
@@ -92,6 +92,8 @@ If your language is not listed above, feel free to create a translation. Here ar
92
  5. An example Signup Form Widget
93
 
94
  == Upgrade Notice ==
 
 
95
 
96
  = 1.5 =
97
  Updates the MailChimp API version, adds double/single opt-in toggle.
@@ -127,6 +129,12 @@ Added support for multiple interest groups, field formatting based on type and d
127
 
128
  == Changelog ==
129
 
 
 
 
 
 
 
130
  = 1.5.3 =
131
  * Fix PHP7 compatibility issue
132
  * Cut down on size of API requests for users with large lists.
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.5
7
 
8
  == Description ==
9
 
92
  5. An example Signup Form Widget
93
 
94
  == Upgrade Notice ==
95
+ = 1.5.5 =
96
+ If you have not upgraded since 1.4.x, you will need to reauthenticate with an API Key.
97
 
98
  = 1.5 =
99
  Updates the MailChimp API version, adds double/single opt-in toggle.
129
 
130
  == Changelog ==
131
 
132
+ = 1.5.5 =
133
+ * Resolve timeout issues.
134
+
135
+ = 1.5.4 =
136
+ * Make field selection optional in API wrapper.
137
+
138
  = 1.5.3 =
139
  * Fix PHP7 compatibility issue
140
  * Cut down on size of API requests for users with large lists.
test.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- $phone = array('area' => '123', 'base' => '456','ext' => '0000');
3
- var_dump(array_filter($phone));
 
 
 
tests/bootstrap.php DELETED
@@ -1,25 +0,0 @@
1
- <?php
2
- /**
3
- * PHPUnit bootstrap file
4
- *
5
- * @package mailchimp
6
- */
7
-
8
- $_tests_dir = getenv( 'WP_TESTS_DIR' );
9
- if ( ! $_tests_dir ) {
10
- $_tests_dir = '/tmp/wordpress-tests-lib';
11
- }
12
-
13
- // Give access to tests_add_filter() function.
14
- require_once $_tests_dir . '/includes/functions.php';
15
-
16
- /**
17
- * Manually load the plugin being tested.
18
- */
19
- function _manually_load_plugin() {
20
- require dirname( dirname( __FILE__ ) ) . '/mailchimp.php';
21
- }
22
- tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
23
-
24
- // Start up the WP testing environment.
25
- require $_tests_dir . '/includes/bootstrap.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tests/test-sample.php DELETED
@@ -1,167 +0,0 @@
1
- <?php
2
- /**
3
- * Class SampleTest
4
- *
5
- * @package
6
- */
7
-
8
- /**
9
- * Sample test case.
10
- */
11
- class SampleTest extends WP_UnitTestCase {
12
- public $apikey = 'a885bcc7f6edcd28f0060ac9b336312d-us3';
13
- public $list_id = '';
14
-
15
- function test_missing_apikey() {
16
- $apikey = 'asdf';
17
- $api = new MailChimp_API($apikey);
18
- $key = mailchimpSF_verify_key($api);
19
-
20
- $this->assertTrue(is_wp_error($key));
21
- }
22
-
23
- function test_correct_apikey() {
24
- $apikey = $this->apikey; // REMOVE ME.
25
- try {
26
- $api = new MailChimp_API($apikey);
27
- $value = true;
28
- } catch (Exception $e) {
29
- $value = false;
30
- }
31
-
32
- $this->assertTrue($value);
33
- }
34
-
35
- function test_missing_required_merge_vars() {
36
- $fname = array(
37
- 'tag' => 'FNAME',
38
- 'name' => 'First Name',
39
- 'type' => 'text',
40
- 'required' => 'Y'
41
- );
42
-
43
- $merge_vars[] = $fname;
44
-
45
- $submit = mailchimpSF_merge_submit($merge_vars);
46
-
47
- // Merge value defaults to empty string, which should error
48
- $this->assertTrue(is_wp_error($submit));
49
- $this->assertTrue(is_object($submit));
50
- }
51
-
52
- function test_required_merge_var() {
53
- $name = 'mc_mv_FNAME';
54
- $fname = array(
55
- 'tag' => 'FNAME',
56
- 'name' => 'First Name',
57
- 'type' => 'text',
58
- 'required' => 'Y'
59
- );
60
- $merge_vars[] = $fname;
61
- $_POST[$name] = 'Hello World';
62
-
63
- $submit = mailchimpSF_merge_submit($merge_vars);
64
-
65
- $this->assertFalse(is_wp_error($submit));
66
- $this->assertTrue(is_object($submit));
67
- }
68
-
69
- function test_invalid_phone_number() {
70
- $var['name'] = 'Phone';
71
- $value = array('asd','555','1234');
72
- $phone = mailchimpSF_merge_validate_phone($value, $var);
73
-
74
- $this->assertTrue(is_wp_error($phone));
75
- $this->assertTrue(is_object($phone));
76
- }
77
-
78
- function test_valid_phone_number() {
79
- $var['name'] = 'Phone';
80
- $value = array('123','456','7890');
81
- $phone = mailchimpSF_merge_validate_phone($value, $var);
82
-
83
- $this->assertFalse(is_wp_error($phone));
84
- $this->assertTrue(is_string($phone));
85
- }
86
-
87
- function test_invalid_address() {
88
- $var = array(
89
- 'tag' => 'ADDRESS',
90
- 'name' => 'Address',
91
- 'type' => 'Address',
92
- 'required' => 'Y'
93
- );
94
- $value = array(
95
- 'addr1' => '123 Magic Street'
96
- );
97
- $submit = mailchimpSF_merge_validate_address($value, $var);
98
-
99
- $this->assertTrue(is_wp_error($submit));
100
- $this->assertTrue(is_object($submit));
101
- }
102
-
103
- function test_remove_empty_merge_feilds() {
104
- $merge = new StdClass();
105
- $merge->fname = 'test';
106
- $merge->test = ' ';
107
- $merge->hello = null;
108
-
109
- $submit = mailchimpSF_merge_remove_empty($merge);
110
-
111
- $this->assertTrue($merge->fname === $submit->fname);
112
- $this->assertTrue(empty($submit->test));
113
- $this->assertTrue(empty($submit->hello));
114
- }
115
-
116
- function test_delete_everything() {
117
- $fname = array(
118
- 'tag' => 'FNAME',
119
- 'name' => 'First Name',
120
- 'type' => 'text',
121
- 'required' => 'Y'
122
- );
123
-
124
- $ig = array(
125
- 'id' => '123'
126
- );
127
-
128
- $igs[] = $ig;
129
-
130
- update_option('mc_list_id', '123');
131
- update_option('mc_list_name', 'asdf');
132
- update_option('mc_interest_groups', $igs);
133
- update_option('mc_merge_vars', array($fname));
134
- update_option('mc_show_interest_groups_123', 'on');
135
- update_option('mc_mv_FNAME', $fname);
136
-
137
- $this->assertTrue(is_string(get_option('mc_list_id')));
138
- $this->assertTrue(is_string(get_option('mc_list_name')));
139
- $this->assertTrue(is_string(get_option('mc_show_interest_groups_123')));
140
- $this->assertTrue(is_array(get_option('mc_mv_FNAME')));
141
-
142
- mailchimpSF_delete_setup();
143
-
144
- $this->assertFalse(get_option('mc_list_id'));
145
- $this->assertFalse(get_option('mc_list_name'));
146
- $this->assertFalse(get_option('mc_show_interest_groups_123'));
147
- $this->assertFalse(get_option('mc_mv_FNAME'));
148
- }
149
-
150
- function test_add_email_field() {
151
- $merge = array(
152
- array(
153
- 'tag' => 'TEST',
154
- 'name' => 'test',
155
- 'type' => 'text',
156
- 'required' => false,
157
- 'public' => true,
158
- 'display_order' => 2,
159
- 'default_value' => null
160
- )
161
- );
162
- $merge = mailchimpSF_add_email_field($merge);
163
-
164
- $this->assertTrue($merge[0]['tag'] == 'EMAIL');
165
- }
166
-
167
- }