Skip to content

Commit fb30ec9

Browse files
authored
Merge pull request #24 from mailchimp/fix/linting
Resolves phpcs errors
2 parents 66aaf7f + cee743d commit fb30ec9

File tree

9 files changed

+690
-325
lines changed

9 files changed

+690
-325
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,20 @@ WordPress v2.8 or higher:
4343

4444
If you are adding it inside a php code block, pop this in:
4545

46-
` mailchimpSF_signup_form(); `
46+
` mailchimp_sf_signup_form(); `
4747

4848
Or, if you are dropping it in between a bunch of HTML, use this:
4949

50-
`<?php mailchimpSF_signup_form(); ?>`
50+
`<?php mailchimp_sf_signup_form(); ?>`
5151

5252
Where ever you want it to show up.
5353

5454
## Upgrading
5555

5656
If you are upgrading to version 1.2.1 and you used the widget in your sidebar previously, all you need to do is drag the `Mailchimp Widget` back into the sidebar, visit the Mailchimp settings page (which will have maintained your prior settings), click the "Update List" button, and you're done!
5757

58+
If you are upgrading to version 1.6.0, you will need to updated any references to display function `mailchimpSF_signup_form` to `mailchimp_sf_signup_form`.
59+
5860
## Internationalization (i18n)
5961

6062
Currently we have the plugin configured so it can be translated and the following languages supported:

lib/mailchimp/mailchimp.php

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,77 @@
11
<?php
2-
2+
/**
3+
* Handles Mailchimp API authorization.
4+
*
5+
* @package Mailchimp
6+
*/
7+
8+
/**
9+
* Handles Mailchimp API authorization.
10+
*/
311
class MailChimp_API {
412

13+
/**
14+
* The API key
15+
*
16+
* @var string
17+
*/
518
public $key;
19+
20+
/**
21+
* The API key
22+
*
23+
* @var string
24+
*/
25+
public $api_key;
26+
27+
/**
28+
* The API url
29+
*
30+
* @var string
31+
*/
32+
public $api_url;
33+
34+
/**
35+
* The datacenter.
36+
*
37+
* @var string
38+
*/
639
public $datacenter;
740

41+
/**
42+
* Initialize the class
43+
*
44+
* @param string $api_key The API key.
45+
* @throws Exception If no api key is set
46+
*/
847
public function __construct( $api_key ) {
948
$api_key = trim( $api_key );
1049
if ( ! $api_key ) {
11-
throw new Exception( __( 'Invalid API Key: ' . $api_key ) );
50+
throw new Exception(
51+
esc_html(
52+
sprintf(
53+
// translators: placeholder is an api key
54+
__( 'Invalid API Key: %s', 'mailchimp_i18n' ),
55+
$api_key
56+
)
57+
)
58+
);
1259
}
1360

1461
$this->key = $api_key;
1562
$dc = explode( '-', $api_key );
1663
$this->datacenter = empty( $dc[1] ) ? 'us1' : $dc[1];
1764
$this->api_url = 'https://' . $this->datacenter . '.api.mailchimp.com/3.0/';
18-
return;
1965
}
2066

67+
/**
68+
* Get endpoint.
69+
*
70+
* @param string $endpoint The Mailchimp endpoint.
71+
* @param integer $count The count to retrieve.
72+
* @param array $fields The fields to retrieve.
73+
* @return mixed
74+
*/
2175
public function get( $endpoint, $count = 10, $fields = array() ) {
2276
$query_params = '';
2377

@@ -47,7 +101,7 @@ public function get( $endpoint, $count = 10, $fields = array() ) {
47101

48102
$request = wp_remote_get( $url, $args );
49103

50-
if ( is_array( $request ) && 200 == $request['response']['code'] ) {
104+
if ( is_array( $request ) && 200 === $request['response']['code'] ) {
51105
return json_decode( $request['body'], true );
52106
} elseif ( is_array( $request ) && $request['response']['code'] ) {
53107
$error = json_decode( $request['body'], true );
@@ -58,6 +112,14 @@ public function get( $endpoint, $count = 10, $fields = array() ) {
58112
}
59113
}
60114

115+
/**
116+
* Sends request to Mailchimp endpoint.
117+
*
118+
* @param string $endpoint The endpoint to send the request.
119+
* @param string $body The body of the request
120+
* @param string $method The request method.
121+
* @return mixed
122+
*/
61123
public function post( $endpoint, $body, $method = 'POST' ) {
62124
$url = $this->api_url . $endpoint;
63125

@@ -68,11 +130,11 @@ public function post( $endpoint, $body, $method = 'POST' ) {
68130
'httpversion' => '1.1',
69131
'user-agent' => 'Mailchimp WordPress Plugin/' . get_bloginfo( 'url' ),
70132
'headers' => array( 'Authorization' => 'apikey ' . $this->key ),
71-
'body' => json_encode( $body ),
133+
'body' => wp_json_encode( $body ),
72134
);
73135
$request = wp_remote_post( $url, $args );
74136

75-
if ( is_array( $request ) && 200 == $request['response']['code'] ) {
137+
if ( is_array( $request ) && 200 === $request['response']['code'] ) {
76138
return json_decode( $request['body'], true );
77139
} else {
78140
if ( is_wp_error( $request ) ) {
@@ -86,7 +148,7 @@ public function post( $endpoint, $body, $method = 'POST' ) {
86148
// Email address doesn't come back from the API, so if something's wrong, it's that.
87149
$field_name = 'Email Address';
88150
$body['errors'][0]['message'] = 'Please fill out a valid email address.';
89-
} elseif ( $merge['tag'] == $body['errors'][0]['field'] ) {
151+
} elseif ( $merge['tag'] === $body['errors'][0]['field'] ) {
90152
$field_name = $merge['name'];
91153
}
92154
}

0 commit comments

Comments
 (0)