Completed
Push — staging ( 743430...b134a1 )
by
unknown
03:25
created
public/classes/checkbox-integrations.php 1 patch
Braces   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 	// Prevent direct access to the file
8 8
 	defined('ABSPATH') or die( __( "Whoops, you shouldn't be accessing this file directly. Abort!" , 'yikes-inc-easy-mailchimp-extender' ) );
9 9
 
10
-	class Yikes_Easy_MC_Checkbox_Integration_Class {
10
+	class Yikes_Easy_MC_Checkbox_Integration_Class {
11 11
 
12 12
 		// declare our integration type
13 13
 		protected $type = 'integration';
@@ -24,10 +24,10 @@  discard block
 block discarded – undo
24 24
 		 *
25 25
 		 * @return bool Whether the current user is subscribed to a list.
26 26
 		 */
27
-		public function is_user_already_subscribed( $type, $email = '' ) {
27
+		public function is_user_already_subscribed( $type, $email = '' ) {
28 28
 			// Make sure we have an email address to use.
29
-			if ( empty( $email ) ) {
30
-				if ( ! is_user_logged_in() ) {
29
+			if ( empty( $email ) ) {
30
+				if ( ! is_user_logged_in() ) {
31 31
 					return false;
32 32
 				}
33 33
 
@@ -36,16 +36,16 @@  discard block
 block discarded – undo
36 36
 			}
37 37
 
38 38
 			// Ensure we have a valid email.
39
-			if ( ! is_email( $email ) ) {
39
+			if ( ! is_email( $email ) ) {
40 40
 				return false;
41 41
 			}
42 42
 
43 43
 			// Convert the integration type to a list ID
44 44
 			$checkbox_options = get_option( 'optin-checkbox-init', '' );
45
-			if ( empty( $checkbox_options ) ) {
45
+			if ( empty( $checkbox_options ) ) {
46 46
 				return false;
47 47
 			}
48
-			if ( ! isset( $checkbox_options[ $type ] ) || ! isset( $checkbox_options[ $type ]['associated-list'] ) ) {
48
+			if ( ! isset( $checkbox_options[ $type ] ) || ! isset( $checkbox_options[ $type ]['associated-list'] ) ) {
49 49
 				return false;
50 50
 			}
51 51
 
@@ -53,9 +53,9 @@  discard block
 block discarded – undo
53 53
 			$list_ids = is_array( $list_ids ) ? $list_ids : array( $list_ids );
54 54
 
55 55
 			// Go through each list...
56
-			foreach ( $list_ids as $list_id ) {
56
+			foreach ( $list_ids as $list_id ) {
57 57
 
58
-				if ( ! $this->is_user_subscribed( $email, $list_id, $type ) ) {
58
+				if ( ! $this->is_user_subscribed( $email, $list_id, $type ) ) {
59 59
 					return false;
60 60
 				}
61 61
 
@@ -75,18 +75,18 @@  discard block
 block discarded – undo
75 75
 		 *
76 76
 		 * @return bool Whether the email is subscribed to the list.
77 77
 		 */
78
-		public function is_user_subscribed( $email, $list_id, $type ) {
78
+		public function is_user_subscribed( $email, $list_id, $type ) {
79 79
 			$email_hash = md5( $email );
80 80
 
81 81
 			// Check the API to see the status
82 82
 			$response = yikes_get_mc_api_manager()->get_list_handler()->get_member( $list_id, $email_hash, false );
83
-			if ( is_wp_error( $response ) ) {
83
+			if ( is_wp_error( $response ) ) {
84 84
 				$data = $response->get_error_data();
85 85
 
86 86
 				// If the error response is a 404, they are not subscribed.
87
-				if ( isset( $data['status'] ) && 404 == $data['status'] ) {
87
+				if ( isset( $data['status'] ) && 404 == $data['status'] ) {
88 88
 					return false;
89
-				} else {
89
+				} else {
90 90
 					$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging();
91 91
 					$error_logging->maybe_write_to_log(
92 92
 						$response->get_error_code(),
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 		* 	@return string
111 111
 		*	@since 6.0.0
112 112
 		*/
113
-		public function yikes_get_checkbox() {
113
+		public function yikes_get_checkbox() {
114 114
 
115 115
 			// Enqueue our checkbox styles whenever the checkbox is displayed
116 116
 			wp_enqueue_style( 'yikes-easy-mailchimp-checkbox-integration-styles', plugin_dir_url( __FILE__ ) . '../css/yikes-inc-easy-mailchimp-checkbox-integration.min.css' );
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 
123 123
 			// We need to make sure we have a legit list ID right here. I don't think it will ever equal '-'
124 124
 
125
-			if ( $has_list_ids ) {
125
+			if ( $has_list_ids ) {
126 126
 				$checked = ( $checkbox_options[$this->type]['precheck'] == 'true' ) ? 'checked' : '';
127 127
 				// before checkbox HTML (comment, ...)
128 128
 				$before = '<!-- Easy Forms for MailChimp - https://www.yikesplugins.com/ -->';
@@ -150,19 +150,19 @@  discard block
 block discarded – undo
150 150
 		 * @param string $type       The integration type.
151 151
 		 * @param array  $merge_vars The array of form data to send.
152 152
 		 */
153
-		public function subscribe_user_integration( $email, $type, $merge_vars ) {
153
+		public function subscribe_user_integration( $email, $type, $merge_vars ) {
154 154
 			// get checkbox data
155 155
 			$options = get_option( 'optin-checkbox-init', '' );
156 156
 
157 157
 			// Make sure we have a list ID.
158
-			if ( ! isset( $options[ $type ] ) || ! isset( $options[ $type ]['associated-list'] ) ) {
158
+			if ( ! isset( $options[ $type ] ) || ! isset( $options[ $type ]['associated-list'] ) ) {
159 159
 				// @todo: Throw some kind of error?
160 160
 				return;
161 161
 			}
162 162
 
163 163
 			// Check for an IP address.
164 164
 			$user_ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
165
-			if ( isset( $merge_vars['OPTIN_IP'] ) ) {
165
+			if ( isset( $merge_vars['OPTIN_IP'] ) ) {
166 166
 				$user_ip = sanitize_text_field( $merge_vars['OPTIN_IP'] );
167 167
 			}
168 168
 
@@ -181,20 +181,20 @@  discard block
 block discarded – undo
181 181
 				'ip_signup'     => $user_ip,
182 182
 			);
183 183
 
184
-			foreach ( $list_ids as $list_id ) {
184
+			foreach ( $list_ids as $list_id ) {
185 185
 
186 186
 				$interests = isset( $options[ $type ]['interest-groups'] ) ? $options[ $type ]['interest-groups'] : array();
187 187
 				$interests = isset( $interests[$list_id] ) ? $interests[$list_id] : $interests;
188 188
 
189 189
 				// Only re-format and add interest groups if not empty
190
-				if ( ! empty( $interests ) ) {
190
+				if ( ! empty( $interests ) ) {
191 191
 
192 192
 					$groups = array();
193 193
 
194 194
 					// Need to reformat interest groups array as $interest_group_ID => true
195
-					foreach( $interests as $interest ) {
196
-						if ( is_array( $interest ) ) {
197
-							foreach( $interest as $group_id ) {
195
+					foreach( $interests as $interest ) {
196
+						if ( is_array( $interest ) ) {
197
+							foreach( $interest as $group_id ) {
198 198
 								$groups[ $group_id ] = true;
199 199
 							}
200 200
 						}
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 
229 229
 				// Subscribe the user to the list via the API.
230 230
 				$response = yikes_get_mc_api_manager()->get_list_handler()->member_subscribe( $list_id, $id, $data );
231
-				if ( is_wp_error( $response ) ) {
231
+				if ( is_wp_error( $response ) ) {
232 232
 					$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging();
233 233
 					$error_logging->maybe_write_to_log(
234 234
 						$response->get_error_code(),
@@ -245,21 +245,21 @@  discard block
 block discarded – undo
245 245
 		* Build merge varaibles array
246 246
 		*	@since 6.0.0
247 247
 		*/
248
-		public function user_merge_vars( WP_User $user ) {
248
+		public function user_merge_vars( WP_User $user ) {
249 249
 
250 250
 			// Start with user_login as name, since that's always known
251 251
 			$merge_vars = array(
252 252
 				'NAME' => $user->user_login,
253 253
 			);
254 254
 			
255
-			if ( ! empty( $user->first_name ) ) {
255
+			if ( ! empty( $user->first_name ) ) {
256 256
 				$merge_vars['NAME'] = $user->first_name;
257 257
 				$merge_vars['FNAME'] = $user->first_name;
258 258
 			}
259
-			if ( ! empty( $user->last_name ) ) {
259
+			if ( ! empty( $user->last_name ) ) {
260 260
 				$merge_vars['LNAME'] = $user->last_name;
261 261
 			}
262
-			if ( ! empty( $user->first_name ) && ! empty( $user->last_name ) ) {
262
+			if ( ! empty( $user->first_name ) && ! empty( $user->last_name ) ) {
263 263
 				$merge_vars['NAME'] = sprintf( '%s %s', $user->first_name, $user->last_name );
264 264
 			}
265 265
 
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 		*	before continuing
282 282
 		*	@since 6.0.0
283 283
 		*/
284
-		public function was_checkbox_checked( $type ) {
284
+		public function was_checkbox_checked( $type ) {
285 285
 			return ( isset( $_POST[ 'yikes_mailchimp_checkbox_' . $type ] ) && $_POST[ 'yikes_mailchimp_checkbox_' . $type ] == 1 );
286 286
 		}
287 287
 
@@ -291,15 +291,15 @@  discard block
 block discarded – undo
291 291
 		*	if the registration form checkbox integration is toggled on
292 292
 		* 	@since 6.0.0
293 293
 		**/
294
-		public function yikes_reg_complete_msg( $errors, $redirect_to ) {
295
-			if( isset( $errors->errors['registered'] ) ) {
294
+		public function yikes_reg_complete_msg( $errors, $redirect_to ) {
295
+			if( isset( $errors->errors['registered'] ) ) {
296 296
 				$email_error = get_option( 'yikes_register_subscription_error' , '' );
297
-				if( isset( $email_error ) && $email_error != '' ) {
297
+				if( isset( $email_error ) && $email_error != '' ) {
298 298
 					// Use the magic __get method to retrieve the errors array:
299 299
 					$tmp = $errors->errors;
300 300
 					$old = 'Registration complete. Please check your e-mail.';
301
-					foreach( $tmp['registered'] as $index => $msg ) {
302
-						if( $msg === $old ) {
301
+					foreach( $tmp['registered'] as $index => $msg ) {
302
+						if( $msg === $old ) {
303 303
 							$tmp['registered'][$index] = $old . ' <p class="message"><strong>' . __( 'Note' , 'yikes-inc-easy-mailchimp-extender' ) . '</strong>: ' . $email_error . '</p>';
304 304
 						}
305 305
 					}
Please login to merge, or discard this patch.