Completed
Push — staging ( 28ad9c...434281 )
by
unknown
07:22
created
public/classes/checkbox-integrations.php 1 patch
Braces   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 /**
10 10
  * Main Checkbox Integration class.
11 11
  */
12
-class Yikes_Easy_MC_Checkbox_Integration_Class {
12
+class Yikes_Easy_MC_Checkbox_Integration_Class {
13 13
 
14 14
 	/**
15 15
 	 * The integration type.
@@ -28,10 +28,10 @@  discard block
 block discarded – undo
28 28
 	 *
29 29
 	 * @return bool Whether the current user is subscribed to a list.
30 30
 	 */
31
-	public function is_user_already_subscribed( $type, $email = '' ) {
31
+	public function is_user_already_subscribed( $type, $email = '' ) {
32 32
 		// Make sure we have an email address to use.
33
-		if ( empty( $email ) ) {
34
-			if ( ! is_user_logged_in() ) {
33
+		if ( empty( $email ) ) {
34
+			if ( ! is_user_logged_in() ) {
35 35
 				return false;
36 36
 			}
37 37
 
@@ -40,13 +40,13 @@  discard block
 block discarded – undo
40 40
 		}
41 41
 
42 42
 		// Ensure we have a valid email.
43
-		if ( ! is_email( $email ) ) {
43
+		if ( ! is_email( $email ) ) {
44 44
 			return false;
45 45
 		}
46 46
 
47 47
 		// Convert the integration type to a list ID.
48 48
 		$checkbox_options = get_option( 'optin-checkbox-init', '' );
49
-		if ( empty( $checkbox_options ) || ! isset( $checkbox_options[ $type ] ) || ! isset( $checkbox_options[ $type ]['associated-list'] ) ) {
49
+		if ( empty( $checkbox_options ) || ! isset( $checkbox_options[ $type ] ) || ! isset( $checkbox_options[ $type ]['associated-list'] ) ) {
50 50
 			return false;
51 51
 		}
52 52
 
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
 		$list_ids = is_array( $list_ids ) ? $list_ids : array( $list_ids );
55 55
 
56 56
 		// Go through each list...
57
-		foreach ( $list_ids as $list_id ) {
58
-			if ( ! $this->is_user_subscribed( $email, $list_id, $type ) ) {
57
+		foreach ( $list_ids as $list_id ) {
58
+			if ( ! $this->is_user_subscribed( $email, $list_id, $type ) ) {
59 59
 				return false;
60 60
 			}
61 61
 		}
@@ -74,18 +74,18 @@  discard block
 block discarded – undo
74 74
 	 *
75 75
 	 * @return bool Whether the email is subscribed to the list.
76 76
 	 */
77
-	public function is_user_subscribed( $email, $list_id, $type ) {
77
+	public function is_user_subscribed( $email, $list_id, $type ) {
78 78
 		$email_hash = md5( $email );
79 79
 
80 80
 		// Check the API to see the status.
81 81
 		$response = yikes_get_mc_api_manager()->get_list_handler()->get_member( $list_id, $email_hash, false );
82
-		if ( is_wp_error( $response ) ) {
82
+		if ( is_wp_error( $response ) ) {
83 83
 			$data = $response->get_error_data();
84 84
 
85 85
 			// If the error response is a 404, they are not subscribed.
86
-			if ( isset( $data['status'] ) && 404 === (int) $data['status'] ) {
86
+			if ( isset( $data['status'] ) && 404 === (int) $data['status'] ) {
87 87
 				return false;
88
-			} else {
88
+			} else {
89 89
 				$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging();
90 90
 				$error_logging->maybe_write_to_log(
91 91
 					$response->get_error_code(),
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 *
110 110
 	 * @return string The HTML for the checkbox.
111 111
 	 */
112
-	public function yikes_get_checkbox() {
112
+	public function yikes_get_checkbox() {
113 113
 
114 114
 		// Enqueue our checkbox styles whenever the checkbox is displayed.
115 115
 		wp_enqueue_style( 'yikes-easy-mailchimp-checkbox-integration-styles', plugin_dir_url( __FILE__ ) . '../css/yikes-inc-easy-mailchimp-checkbox-integration.min.css' );
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 		$has_list_ids     = isset( $checkbox_options[ $this->type ]['associated-list'] ) && '-' !== $checkbox_options[ $this->type ]['associated-list'];
120 120
 		$has_list_ids     = $has_list_ids && ! in_array( '-', $checkbox_options[ $this->type ]['associated-list'], true );
121 121
 
122
-		if ( $has_list_ids ) {
122
+		if ( $has_list_ids ) {
123 123
 			$checked  = 'true' === $checkbox_options[ $this->type ]['precheck'] ? 'checked="checked"' : '';
124 124
 			$before   = apply_filters( 'yikes-mailchimp-before-checkbox-html', '' );
125 125
 			$content  = '<p id="yikes-easy-mailchimp-' . esc_attr( $this->type ) . '-checkbox" class="yikes-easy-mailchimp-' . esc_attr( $this->type ) . '-checkbox">';
@@ -145,18 +145,18 @@  discard block
 block discarded – undo
145 145
 	 * @param string $type       The integration type.
146 146
 	 * @param array  $merge_vars The array of form data to send.
147 147
 	 */
148
-	public function subscribe_user_integration( $email, $type, $merge_vars ) {
148
+	public function subscribe_user_integration( $email, $type, $merge_vars ) {
149 149
 		$options = get_option( 'optin-checkbox-init', '' );
150 150
 
151 151
 		// Make sure we have a list ID.
152
-		if ( ! isset( $options[ $type ] ) || ! isset( $options[ $type ]['associated-list'] ) ) {
152
+		if ( ! isset( $options[ $type ] ) || ! isset( $options[ $type ]['associated-list'] ) ) {
153 153
 			// @todo: Throw some kind of error?
154 154
 			return;
155 155
 		}
156 156
 
157 157
 		// Check for an IP address.
158 158
 		$user_ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
159
-		if ( isset( $merge_vars['OPTIN_IP'] ) ) {
159
+		if ( isset( $merge_vars['OPTIN_IP'] ) ) {
160 160
 			$user_ip = sanitize_text_field( $merge_vars['OPTIN_IP'] );
161 161
 		}
162 162
 
@@ -172,19 +172,19 @@  discard block
 block discarded – undo
172 172
 			'ip_signup'     => $user_ip,
173 173
 		);
174 174
 
175
-		foreach ( $list_ids as $list_id ) {
175
+		foreach ( $list_ids as $list_id ) {
176 176
 
177 177
 			$interests = isset( $options[ $type ]['interest-groups'] ) ? $options[ $type ]['interest-groups'] : array();
178 178
 			$interests = isset( $interests[ $list_id ] ) ? $interests[ $list_id ] : $interests;
179 179
 
180 180
 			// Only re-format and add interest groups if not empty.
181
-			if ( ! empty( $interests ) ) {
181
+			if ( ! empty( $interests ) ) {
182 182
 				$groups = array();
183 183
 
184 184
 				// Need to reformat interest groups array as $interest_group_ID => true.
185
-				foreach ( $interests as $interest ) {
186
-					if ( is_array( $interest ) ) {
187
-						foreach ( $interest as $group_id ) {
185
+				foreach ( $interests as $interest ) {
186
+					if ( is_array( $interest ) ) {
187
+						foreach ( $interest as $group_id ) {
188 188
 							$groups[ $group_id ] = true;
189 189
 						}
190 190
 					}
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 
218 218
 			// Subscribe the user to the list via the API.
219 219
 			$response = yikes_get_mc_api_manager()->get_list_handler()->member_subscribe( $list_id, $id, $data );
220
-			if ( is_wp_error( $response ) ) {
220
+			if ( is_wp_error( $response ) ) {
221 221
 				$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging();
222 222
 				$error_logging->maybe_write_to_log(
223 223
 					$response->get_error_code(),
@@ -235,15 +235,15 @@  discard block
 block discarded – undo
235 235
 	 *
236 236
 	 * @param WP_User $user A WP User.
237 237
 	 */
238
-	public function user_merge_vars( WP_User $user ) {
238
+	public function user_merge_vars( WP_User $user ) {
239 239
 
240 240
 		// Setup our array.
241 241
 		$merge_vars = array();
242 242
 		
243
-		if ( ! empty( $user->first_name ) ) {
243
+		if ( ! empty( $user->first_name ) ) {
244 244
 			$merge_vars['FNAME'] = $user->first_name;
245 245
 		}
246
-		if ( ! empty( $user->last_name ) ) {
246
+		if ( ! empty( $user->last_name ) ) {
247 247
 			$merge_vars['LNAME'] = $user->last_name;
248 248
 		}
249 249
 
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 *
268 268
 	 * @return bool True if the checkbox was checked.
269 269
 	 */
270
-	public function was_checkbox_checked( $type ) {
270
+	public function was_checkbox_checked( $type ) {
271 271
 		return isset( $_POST[ 'yikes_mailchimp_checkbox_' . $type ] ) && '1' === (string) filter_var( $_POST[ 'yikes_mailchimp_checkbox_' . $type ], FILTER_SANITIZE_STRING );
272 272
 	}
273 273
 }
Please login to merge, or discard this patch.