Completed
Push — staging ( 18614b...46c850 )
by
unknown
05:49
created
public/classes/process/class.process_form_submission_handler.php 1 patch
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -260,18 +260,18 @@  discard block
 block discarded – undo
260 260
 		$this->handle_empty_email_message = __( 'Error: The email is invalid.', 'yikes-inc-easy-mailchimp-extender' );
261 261
 		$this->handle_non_empty_honeypot_message = __( 'Error: It looks like the honeypot was filled out and the form was not properly submitted.', 'yikes-inc-easy-mailchimp-extender' );
262 262
 		$this->handle_disallowed_existing_user_update_message = __( 'The email you entered is already a subscriber to this list.', 'yikes-inc-easy-mailchimp-extender' );
263
-		$this->default_error_response_message =  __( 'Whoops! It looks like something went wrong. Please try again.', 'yikes-inc-easy-mailchimp-extender' );
263
+		$this->default_error_response_message = __( 'Whoops! It looks like something went wrong. Please try again.', 'yikes-inc-easy-mailchimp-extender' );
264 264
 		$this->handle_updating_existing_user_message = __( 'You\'re already subscribed. ', 'yikes-inc-easy-mailchimp-extender' );
265 265
 		$this->handle_updating_existing_user_link_message = __( 'To update your MailChimp profile, please click to send yourself an update link', 'yikes-inc-easy-mailchimp-extender' );
266 266
 		$this->handle_empty_required_field_message = __( 'A required field is missing.', 'yikes-inc-easy-mailchimp-extender' );
267 267
 		$this->handle_empty_required_interest_group_message = __( 'A required interest group is missing.', 'yikes-inc-easy-mailchimp-extender' );
268
-		$this->handle_nonce_message = __( 'Error: Sorry, the nonce security check didn\'t pass. Please reload the page and try again. You may want to try clearing your browser cache as a last attempt.' , 'yikes-inc-easy-mailchimp-extender' );
268
+		$this->handle_nonce_message = __( 'Error: Sorry, the nonce security check didn\'t pass. Please reload the page and try again. You may want to try clearing your browser cache as a last attempt.', 'yikes-inc-easy-mailchimp-extender' );
269 269
 		$this->handle_non_filled_recaptcha_message_message = __( 'Please check the reCAPTCHA field.', 'yikes-inc-easy-mailchimp-extender' );
270
-		$this->generic_recaptcha_error_message =  __( 'Please refresh the page and try again.', 'yikes-inc-easy-mailchimp-extender' );
270
+		$this->generic_recaptcha_error_message = __( 'Please refresh the page and try again.', 'yikes-inc-easy-mailchimp-extender' );
271 271
 
272 272
 		// Define our success messages
273
-		$this->default_response_single_optin_success_message = __( 'Thank you for subscribing!' , 'yikes-inc-easy-mailchimp-extender' );
274
-		$this->default_response_double_optin_success_message = __( 'Thank you for subscribing. Check your email for the confirmation message.' , 'yikes-inc-easy-mailchimp-extender' );
273
+		$this->default_response_single_optin_success_message = __( 'Thank you for subscribing!', 'yikes-inc-easy-mailchimp-extender' );
274
+		$this->default_response_double_optin_success_message = __( 'Thank you for subscribing. Check your email for the confirmation message.', 'yikes-inc-easy-mailchimp-extender' );
275 275
 		$this->existing_subscriber_profile_update_message = __( 'Thank you for already being a subscriber! Your profile info has been updated.', 'yikes-inc-easy-mailchimp-extender' );
276 276
 	}
277 277
 
@@ -383,8 +383,8 @@  discard block
 block discarded – undo
383 383
 			}
384 384
 
385 385
 			// Check if the current iteration has a 'date_format' key set (i.e. date/birthday fields)
386
-			if ( isset( $form_fields[ $merge_tag ]['date_format'] ) ) {
387
-				$sanitized = $this->handle_date_format_merge_values( $sanitized, $form_fields[ $merge_tag ]['date_format'] );
386
+			if ( isset( $form_fields[ $merge_tag ][ 'date_format' ] ) ) {
387
+				$sanitized = $this->handle_date_format_merge_values( $sanitized, $form_fields[ $merge_tag ][ 'date_format' ] );
388 388
 			}
389 389
 
390 390
 			$merge_variables[ $merge_tag ] = $sanitized;
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 		if ( count( $pieces ) === 3 ) {
465 465
 
466 466
 			// $pieces[1] = MM. $pieces[0] = DD. $date = MM/DD/YYYY
467
-			$date = $pieces[1] . '/' . $pieces[0] . '/' . $pieces[2];
467
+			$date = $pieces[ 1 ] . '/' . $pieces[ 0 ] . '/' . $pieces[ 2 ];
468 468
 		}
469 469
 
470 470
 		return $date;
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
 		if ( count( $pieces ) === 2 ) {
490 490
 
491 491
 			// $pieces[1] = MM. $pieces[0] = DD. $birthday = MM/DD
492
-			$birthday = $pieces[1] . '/' . $pieces[0];
492
+			$birthday = $pieces[ 1 ] . '/' . $pieces[ 0 ];
493 493
 		}
494 494
 
495 495
 		return $birthday;
@@ -521,8 +521,8 @@  discard block
 block discarded – undo
521 521
 
522 522
 			// Loop through the interest groups and create a single array like {group_id} => false
523 523
 			foreach ( $interest_groupings as $group_data ) {
524
-				foreach ( $group_data['items'] as $item ) {
525
-					$groups[$item['id']] = false;
524
+				foreach ( $group_data[ 'items' ] as $item ) {
525
+					$groups[ $item[ 'id' ] ] = false;
526 526
 				}
527 527
 			}
528 528
 			return $groups;
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
 		do_action( "yikes-mailchimp-form-submission-{$this->form_id}", $this->email, $merge_variables, $this->form_id, $notifications );
634 634
 
635 635
 		// Get the optin value
636
-		$optin = isset( $optin_settings['optin'] ) ? (int) $optin_settings['optin'] : 0;
636
+		$optin = isset( $optin_settings[ 'optin' ] ) ? (int) $optin_settings[ 'optin' ] : 0;
637 637
 
638 638
 		if ( 1 === $optin ) {
639 639
 
@@ -663,13 +663,13 @@  discard block
 block discarded – undo
663 663
 
664 664
 		// Construct our success array variables
665 665
 		$return_success_array = array(
666
-			'hide'        		=> $submission_settings['hide_form_post_signup'],
666
+			'hide'        		=> $submission_settings[ 'hide_form_post_signup' ],
667 667
 			'error'       		=> 0,
668 668
 			'response'    		=> $response_message,
669
-			'redirection' 		=> $redirect_array['redirection'],
670
-			'redirect'    		=> $redirect_array['redirect'],
671
-			'new_window' 		=> $redirect_array['new_window'],
672
-			'redirect_timer'	=> $redirect_array['redirect_timer'],
669
+			'redirection' 		=> $redirect_array[ 'redirection' ],
670
+			'redirect'    		=> $redirect_array[ 'redirect' ],
671
+			'new_window' 		=> $redirect_array[ 'new_window' ],
672
+			'redirect_timer'	=> $redirect_array[ 'redirect_timer' ],
673 673
 		);
674 674
 
675 675
 		// Return success array
@@ -691,12 +691,12 @@  discard block
 block discarded – undo
691 691
 		$details    = '';
692 692
 
693 693
 		// Loop through the error data and retrieve any fields and messages
694
-		if ( isset( $error_data['data'] ) ) {
695
-			foreach ( $error_data['data'] as $datum ) {
696
-				if ( ! isset( $datum['field'], $datum['message'] ) ) {
694
+		if ( isset( $error_data[ 'data' ] ) ) {
695
+			foreach ( $error_data[ 'data' ] as $datum ) {
696
+				if ( ! isset( $datum[ 'field' ], $datum[ 'message' ] ) ) {
697 697
 					continue;
698 698
 				}
699
-				$details .= sprintf( '<br>Error with %1$s field: <strong>%2$s</strong>', $form_fields[ $datum['field'] ]['label'], $datum['message'] );
699
+				$details .= sprintf( '<br>Error with %1$s field: <strong>%2$s</strong>', $form_fields[ $datum[ 'field' ] ][ 'label' ], $datum[ 'message' ] );
700 700
 			}
701 701
 		}
702 702
 
@@ -739,20 +739,20 @@  discard block
 block discarded – undo
739 739
 		);
740 740
 
741 741
 		// Let's confirm we have a value before trying to use it
742
-		$redirect_setting = isset( $submission_settings['redirect_on_submission'] ) ? $submission_settings['redirect_on_submission'] : false;
742
+		$redirect_setting = isset( $submission_settings[ 'redirect_on_submission' ] ) ? $submission_settings[ 'redirect_on_submission' ] : false;
743 743
 
744 744
 		// Check the redirect flag
745 745
 		if ( '1' === $redirect_setting ) {
746 746
 
747 747
 			// Supply return array with default value of 1
748
-			$redirect_array['redirection']	= 1;
748
+			$redirect_array[ 'redirection' ] = 1;
749 749
 
750 750
 			// Let's confirm we have redirect_page/custom_redirect_url/new_window values
751
-			$redirect_page_setting	 = isset( $submission_settings['redirect_page'] ) ? $submission_settings['redirect_page'] : false;
752
-			$custom_redirect_setting = isset( $submission_settings['custom_redirect_url'] ) ? $submission_settings['custom_redirect_url'] : false;
753
-			$redirect_new_window	 = isset( $submission_settings['redirect_new_window'] ) ? $submission_settings['redirect_new_window'] : false;
751
+			$redirect_page_setting = isset( $submission_settings[ 'redirect_page' ] ) ? $submission_settings[ 'redirect_page' ] : false;
752
+			$custom_redirect_setting = isset( $submission_settings[ 'custom_redirect_url' ] ) ? $submission_settings[ 'custom_redirect_url' ] : false;
753
+			$redirect_new_window = isset( $submission_settings[ 'redirect_new_window' ] ) ? $submission_settings[ 'redirect_new_window' ] : false;
754 754
 
755
-			$redirect_array['new_window'] = $redirect_new_window;
755
+			$redirect_array[ 'new_window' ] = $redirect_new_window;
756 756
 
757 757
 			// Check if we're redirecting to a custom_url or just the redirect_page
758 758
 			$redirect_url = ( 'custom_url' !== $redirect_page_setting ) ? get_permalink( $redirect_page_setting ) : $custom_redirect_setting;
@@ -777,9 +777,9 @@  discard block
 block discarded – undo
777 777
 			*/
778 778
 			$redirect_timer = apply_filters( 'yikes-mailchimp-redirect-timer', $this->default_redirect_time_ms, $this->form_id );
779 779
 
780
-			$redirect_array['redirect_timer'] = $redirect_timer;
780
+			$redirect_array[ 'redirect_timer' ] = $redirect_timer;
781 781
 
782
-			$redirect_array['redirect'] = $redirect_url;
782
+			$redirect_array[ 'redirect' ] = $redirect_url;
783 783
 		}
784 784
 
785 785
 		return $redirect_array;
@@ -805,21 +805,21 @@  discard block
 block discarded – undo
805 805
 		$missing_fields = array();
806 806
 
807 807
 		// Loop through submitted form data
808
-		foreach( $data as $merge_tag => $value ) {
808
+		foreach ( $data as $merge_tag => $value ) {
809 809
 
810 810
 			// Skip interest groups
811
-			if ( isset( $form_fields[ $merge_tag ]['group_id'] ) ) {
811
+			if ( isset( $form_fields[ $merge_tag ][ 'group_id' ] ) ) {
812 812
 				continue;
813 813
 			}
814 814
 
815 815
 			// check if this field is required
816
-			if ( isset( $form_fields[ $merge_tag ] ) && isset( $form_fields[ $merge_tag ]['require'] ) && $form_fields[ $merge_tag ]['require'] === '1' ) {
816
+			if ( isset( $form_fields[ $merge_tag ] ) && isset( $form_fields[ $merge_tag ][ 'require' ] ) && $form_fields[ $merge_tag ][ 'require' ] === '1' ) {
817 817
 
818 818
 				// Check if the field(s) are empty
819 819
 				if ( is_array( $value ) ) {
820 820
 
821 821
 					// Loop through the data and check if any are empty
822
-					foreach( $value as $field => $val ) {
822
+					foreach ( $value as $field => $val ) {
823 823
 
824 824
 						/**
825 825
 						*	'yikes-mailchimp-ignore-required-array-field'
@@ -838,13 +838,13 @@  discard block
 block discarded – undo
838 838
 
839 839
 							// Set the merge label (e.g. MMERGE6) as the key so we don't get the same field multiple times
840 840
 							// (e.g. For arrays, like an address, where multiple address fields are empty)
841
-							$missing_fields[ $form_fields[ $merge_tag ]['merge'] ] = $form_fields[ $merge_tag ];
841
+							$missing_fields[ $form_fields[ $merge_tag ][ 'merge' ] ] = $form_fields[ $merge_tag ];
842 842
 						}
843 843
 					}
844 844
 
845 845
 				} else if ( empty( $value ) ) {
846 846
 					$field_is_missing = true;
847
-					$missing_fields[ $form_fields[ $merge_tag ]['merge'] ] = $form_fields[ $merge_tag ];
847
+					$missing_fields[ $form_fields[ $merge_tag ][ 'merge' ] ] = $form_fields[ $merge_tag ];
848 848
 				}
849 849
 			}
850 850
 		}
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
 		foreach ( $form_fields as $merge_tag => $field_data ) {
895 895
 
896 896
 			// If an interest group and it's required
897
-			if ( isset( $field_data['group_id'] ) && isset( $field_data['require'] ) && $field_data['require'] === '1' ) {
897
+			if ( isset( $field_data[ 'group_id' ] ) && isset( $field_data[ 'require' ] ) && $field_data[ 'require' ] === '1' ) {
898 898
 				
899 899
 				// Check if it was submitted (meaning, check if it's set in our $data array)
900 900
 				if ( ! isset( $data[ 'group-' . $merge_tag ] ) ) {
@@ -956,30 +956,30 @@  discard block
 block discarded – undo
956 956
 		}
957 957
 
958 958
 		// Construct the API URL
959
-		$url           = esc_url_raw( 'https://www.google.com/recaptcha/api/siteverify?secret=' . get_option( 'yikes-mc-recaptcha-secret-key', '' ) . '&response=' . $recaptcha_response . '&remoteip=' . $_SERVER['REMOTE_ADDR'] );
959
+		$url           = esc_url_raw( 'https://www.google.com/recaptcha/api/siteverify?secret=' . get_option( 'yikes-mc-recaptcha-secret-key', '' ) . '&response=' . $recaptcha_response . '&remoteip=' . $_SERVER[ 'REMOTE_ADDR' ] );
960 960
 		$response      = wp_remote_get( $url );
961
-		$response_body = json_decode( $response['body'], true );
961
+		$response_body = json_decode( $response[ 'body' ], true );
962 962
 
963 963
 		// Set up errors array
964 964
 		$recaptcha_errors = array();
965 965
 
966 966
 		// if we've hit an error, lets return the error!
967
-		if ( true !== $response_body['success'] ) {
967
+		if ( true !== $response_body[ 'success' ] ) {
968 968
 
969
-			if( isset( $response_body['error-codes'] ) ) {
969
+			if ( isset( $response_body[ 'error-codes' ] ) ) {
970 970
 
971 971
 				// Loop through response error codes
972
-				foreach ( $response_body['error-codes'] as $error_code ) {
972
+				foreach ( $response_body[ 'error-codes' ] as $error_code ) {
973 973
 					if ( 'missing-input-response' === $error_code ) {
974 974
 						$error_code = $this->handle_non_filled_recaptcha_message;
975 975
 					}
976 976
 
977 977
 					// Add our error_code to the errors array
978
-					$recaptcha_errors[] = $error_code;
978
+					$recaptcha_errors[ ] = $error_code;
979 979
 				}
980 980
 
981 981
 			} else {
982
-				$recaptcha_errors[] = $this->generic_recaptcha_error_message;
982
+				$recaptcha_errors[ ] = $this->generic_recaptcha_error_message;
983 983
 			}
984 984
 
985 985
 			/**
@@ -1087,7 +1087,7 @@  discard block
 block discarded – undo
1087 1087
 	* @param array | $fields_array | An array of fields to loop through and make sure they're not null
1088 1088
 	*/
1089 1089
 	public function handle_empty_fields_generic( $fields_array ) {
1090
-		foreach( $fields_array as $field ) {
1090
+		foreach ( $fields_array as $field ) {
1091 1091
 			if ( $field === null ) {
1092 1092
 				return $this->yikes_fail( $hide = 0, $error = 1, $this->handle_empty_fields_generic_message );
1093 1093
 			}
@@ -1153,7 +1153,7 @@  discard block
 block discarded – undo
1153 1153
 
1154 1154
 		// Append our 'send-update-email' link and text
1155 1155
 		$response .= $link_start_tag;
1156
-		$response .= 	$this->handle_updating_existing_user_link_message;
1156
+		$response .= $this->handle_updating_existing_user_link_message;
1157 1157
 		$response .= $link_close_tag;
1158 1158
 
1159 1159
 		// Check for a user-defined message
@@ -1176,14 +1176,14 @@  discard block
 block discarded – undo
1176 1176
 	*/
1177 1177
 	protected function check_for_user_defined_response_message( $slug, $response_text, $data = false ) {
1178 1178
 
1179
-		switch( $slug ) {
1179
+		switch ( $slug ) {
1180 1180
 			case 'already-subscribed':
1181 1181
 
1182 1182
 				// Check if this error message exists
1183
-				if ( isset( $this->error_messages['already-subscribed'] ) && ! empty( $this->error_messages['already-subscribed'] ) ) {
1183
+				if ( isset( $this->error_messages[ 'already-subscribed' ] ) && ! empty( $this->error_messages[ 'already-subscribed' ] ) ) {
1184 1184
 
1185 1185
 					// Check if the substring (that we replace) '[email]' is located in the string and replace it
1186
-					$response_text = str_replace( '[email]', $this->email, $this->error_messages['already-subscribed'] );
1186
+					$response_text = str_replace( '[email]', $this->email, $this->error_messages[ 'already-subscribed' ] );
1187 1187
 				}
1188 1188
 
1189 1189
 				/**
@@ -1202,13 +1202,13 @@  discard block
 block discarded – undo
1202 1202
 			case 'update-link':
1203 1203
 
1204 1204
 				// Check if this error message exists
1205
-				if ( $data !== false && isset( $this->error_messages['update-link'] ) && ! empty( $this->error_messages['update-link'] ) ) {
1205
+				if ( $data !== false && isset( $this->error_messages[ 'update-link' ] ) && ! empty( $this->error_messages[ 'update-link' ] ) ) {
1206 1206
 
1207 1207
 					// Check if the substring (that we replace) '[link]' is located in the string and replace it
1208
-					$response_text = str_replace( '[link]', $data['link_start_tag'], $this->error_messages['update-link'] );
1208
+					$response_text = str_replace( '[link]', $data[ 'link_start_tag' ], $this->error_messages[ 'update-link' ] );
1209 1209
 
1210 1210
 					// Remove [/link]
1211
-					$response_text = str_replace( '[/link]', $data['link_close_tag'], $response_text );
1211
+					$response_text = str_replace( '[/link]', $data[ 'link_close_tag' ], $response_text );
1212 1212
 				}
1213 1213
 
1214 1214
 				/**
@@ -1227,8 +1227,8 @@  discard block
 block discarded – undo
1227 1227
 			case 'success':
1228 1228
 
1229 1229
 				// 'success' is the user-defined success message for double opt-in
1230
-				if ( isset( $this->error_messages['success'] ) && ! empty( $this->error_messages['success'] ) ) {
1231
-					$response_text = $this->error_messages['success'];
1230
+				if ( isset( $this->error_messages[ 'success' ] ) && ! empty( $this->error_messages[ 'success' ] ) ) {
1231
+					$response_text = $this->error_messages[ 'success' ];
1232 1232
 				}
1233 1233
 
1234 1234
 				/**
@@ -1247,8 +1247,8 @@  discard block
 block discarded – undo
1247 1247
 
1248 1248
 			case 'success-single-optin':
1249 1249
 
1250
-				if ( isset( $this->error_messages['success-single-optin'] ) && ! empty( $this->error_messages['success-single-optin'] ) ) {
1251
-					$response_text = $this->error_messages['success-single-optin'];
1250
+				if ( isset( $this->error_messages[ 'success-single-optin' ] ) && ! empty( $this->error_messages[ 'success-single-optin' ] ) ) {
1251
+					$response_text = $this->error_messages[ 'success-single-optin' ];
1252 1252
 				}
1253 1253
 
1254 1254
 				/**
@@ -1267,8 +1267,8 @@  discard block
 block discarded – undo
1267 1267
 
1268 1268
 			case 'success-resubscribed':
1269 1269
 
1270
-				if ( isset( $this->error_messages['success-resubscribed'] ) && ! empty( $this->error_messages['success-resubscribed'] ) ) {
1271
-					$response_text = $this->error_messages['success-resubscribed'];
1270
+				if ( isset( $this->error_messages[ 'success-resubscribed' ] ) && ! empty( $this->error_messages[ 'success-resubscribed' ] ) ) {
1271
+					$response_text = $this->error_messages[ 'success-resubscribed' ];
1272 1272
 				}
1273 1273
 
1274 1274
 				/**
@@ -1290,8 +1290,8 @@  discard block
 block discarded – undo
1290 1290
 				$original_response_text     = $response_text;
1291 1291
 				$user_defined_response_text = '';
1292 1292
 
1293
-				if ( isset( $this->error_messages['general-error'] ) && ! empty( $this->error_messages['general-error'] ) ) {
1294
-					$user_defined_response_text = $this->error_messages['general-error'];
1293
+				if ( isset( $this->error_messages[ 'general-error' ] ) && ! empty( $this->error_messages[ 'general-error' ] ) ) {
1294
+					$user_defined_response_text = $this->error_messages[ 'general-error' ];
1295 1295
 				}
1296 1296
 
1297 1297
 				/**
@@ -1353,7 +1353,7 @@  discard block
 block discarded – undo
1353 1353
 		} else {
1354 1354
 			global $process_submission_response;
1355 1355
 
1356
-			$process_submission_response = isset( $success_array['response'] ) ? $success_array['response'] : ''; // DEFAULT SUCCESS?
1356
+			$process_submission_response = isset( $success_array[ 'response' ] ) ? $success_array[ 'response' ] : ''; // DEFAULT SUCCESS?
1357 1357
 			$process_submission_response = $this->wrap_form_submission_response( $process_submission_response, $is_success = true );
1358 1358
 		}
1359 1359
 	}
@@ -1406,8 +1406,8 @@  discard block
 block discarded – undo
1406 1406
 		// Add additional fields we've been supplied
1407 1407
 		if ( ! empty( $additional_fields ) ) {
1408 1408
 
1409
-			foreach( $additional_fields as $key => $value ) {
1410
-				$response_array[$key] = $value;
1409
+			foreach ( $additional_fields as $key => $value ) {
1410
+				$response_array[ $key ] = $value;
1411 1411
 			}
1412 1412
 		}
1413 1413
 
Please login to merge, or discard this patch.