Completed
Pull Request — staging (#841)
by Evan
02:00
created
public/partials/shortcodes/process/process_form_submission.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 $data = $_POST;
15 15
 
16 16
 // Confirm we have a form id to work with
17
-$form_id = ( isset( $data['yikes-mailchimp-submitted-form'] ) ) ? absint( $data['yikes-mailchimp-submitted-form'] ) : false;
17
+$form_id = ( isset( $data[ 'yikes-mailchimp-submitted-form' ] ) ) ? absint( $data[ 'yikes-mailchimp-submitted-form' ] ) : false;
18 18
 
19 19
 // Set the form id in our class
20 20
 $submission_handler->set_form_id( $form_id );
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 }
29 29
 
30 30
 // Check our nonce
31
-if ( $submission_handler->handle_nonce( $_POST['yikes_easy_mc_new_subscriber'], 'yikes_easy_mc_form_submit' ) === false ) {
31
+if ( $submission_handler->handle_nonce( $_POST[ 'yikes_easy_mc_new_subscriber' ], 'yikes_easy_mc_form_submit' ) === false ) {
32 32
 	$process_submission_response = $submission_handler->wrap_form_submission_response( $submission_handler->handle_nonce_message, $is_success = false );
33 33
 	return;
34 34
 }
@@ -44,10 +44,10 @@  discard block
 block discarded – undo
44 44
 }
45 45
 
46 46
 // Set up some variables from the form data -- these are required
47
-$list_id             = isset( $form_data['list_id'] ) ? $form_data['list_id'] : null;
48
-$submission_settings = isset( $form_data['submission_settings'] ) ? $form_data['submission_settings'] : null;
49
-$optin_settings      = isset( $form_data['optin_settings'] ) ? $form_data['optin_settings'] : null;
50
-$form_fields         = isset( $form_data['fields'] ) ? $form_data['fields'] : null;
47
+$list_id             = isset( $form_data[ 'list_id' ] ) ? $form_data[ 'list_id' ] : null;
48
+$submission_settings = isset( $form_data[ 'submission_settings' ] ) ? $form_data[ 'submission_settings' ] : null;
49
+$optin_settings      = isset( $form_data[ 'optin_settings' ] ) ? $form_data[ 'optin_settings' ] : null;
50
+$form_fields         = isset( $form_data[ 'fields' ] ) ? $form_data[ 'fields' ] : null;
51 51
 
52 52
 // Send an error if for some reason we can't find the required form data
53 53
 if ( $submission_handler->handle_empty_fields_generic( array( $list_id, $submission_settings, $optin_settings, $form_fields ) ) === false ) {
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
 $submission_handler->set_list_id( $list_id );
71 71
 
72 72
 // Set up some variables from the form data -- these are not required
73
-$error_messages      = isset( $form_data['error_messages'] ) ? $form_data['error_messages'] : array();
74
-$notifications       = isset( $form_data['custom_notifications'] ) ? $form_data['custom_notifications'] : array(); // Do we need this?
73
+$error_messages      = isset( $form_data[ 'error_messages' ] ) ? $form_data[ 'error_messages' ] : array();
74
+$notifications       = isset( $form_data[ 'custom_notifications' ] ) ? $form_data[ 'custom_notifications' ] : array(); // Do we need this?
75 75
 
76 76
 // Set the error messages in our class
77 77
 $submission_handler->set_error_messages( $error_messages );
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 }
88 88
 
89 89
 // Get, sanitize, and lowercasify the email
90
-$submitted_email = isset( $data['EMAIL'] ) ? $data['EMAIL'] : '';
90
+$submitted_email = isset( $data[ 'EMAIL' ] ) ? $data[ 'EMAIL' ] : '';
91 91
 $sanitized_email = $submission_handler->get_sanitized_email( $submitted_email ); 
92 92
 $submission_handler->set_email( $sanitized_email );
93 93
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 }
99 99
 
100 100
 // Check for Honeypot filled
101
-$honey_pot_filled = ( isset( $data['yikes-mailchimp-honeypot'] ) && '' !== $data['yikes-mailchimp-honeypot'] ) ? true : false;
101
+$honey_pot_filled = ( isset( $data[ 'yikes-mailchimp-honeypot' ] ) && '' !== $data[ 'yikes-mailchimp-honeypot' ] ) ? true : false;
102 102
 
103 103
 // Send an error if honey pot is not empty
104 104
 if ( $submission_handler->handle_non_empty_honeypot( $honey_pot_filled ) === false ) {
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
 }
108 108
 
109 109
 // Check if reCAPTCHA Response was submitted with the form data, and handle it if needed
110
-if ( isset( $data['g-recaptcha-response'] ) ) {
111
-	$recaptcha_response = $data['g-recaptcha-response'];
110
+if ( isset( $data[ 'g-recaptcha-response' ] ) ) {
111
+	$recaptcha_response = $data[ 'g-recaptcha-response' ];
112 112
 	$recaptcha_handle = $submission_handler->handle_recaptcha( $recaptcha_response );
113
-	if ( isset( $recaptcha_handle['success'] ) && $recaptcha_handle['success'] === false ) {
114
-		$process_submission_response = $submission_handler->wrap_form_submission_response( $recaptcha_handle['message'], $is_success = false );
113
+	if ( isset( $recaptcha_handle[ 'success' ] ) && $recaptcha_handle[ 'success' ] === false ) {
114
+		$process_submission_response = $submission_handler->wrap_form_submission_response( $recaptcha_handle[ 'message' ], $is_success = false );
115 115
 		return;
116 116
 	}
117 117
 }
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 $merge_variables = $submission_handler->get_submitted_merge_values( $data, $form_fields );
121 121
 
122 122
 // Submission Setting: Replace interest groups or update interest groups
123
-$replace_interests = isset( $submission_settings['replace_interests'] ) ? (bool) $submission_settings['replace_interests'] : true;
123
+$replace_interests = isset( $submission_settings[ 'replace_interests' ] ) ? (bool) $submission_settings[ 'replace_interests' ] : true;
124 124
 
125 125
 // Get the default groups
126 126
 $groups = $submission_handler->get_default_interest_groups( $replace_interests, $list_handler );
@@ -135,17 +135,17 @@  discard block
 block discarded – undo
135 135
  *
136 136
  * @param $merge_variables array Array of merge variable to use
137 137
  */
138
-do_action( 'yikes-mailchimp-before-submission',            $merge_variables );
138
+do_action( 'yikes-mailchimp-before-submission', $merge_variables );
139 139
 do_action( "yikes-mailchimp-before-submission-{$form_id}", $merge_variables );
140 140
 
141 141
 // Allow users to check for form values (using the `yikes-mailchimp-filter-before-submission` filter hook in function `get_submitted_merge_values`) 
142 142
 // and pass back an error and message to the user
143 143
 // If error is set and no message, default to our class variable's default error message
144
-if ( isset( $merge_variables['error'] ) ) {
145
-	$merge_error_message = isset( $merge_variables['message'] ) ? $merge_variables['message'] : $submission_handler->default_error_response_message;
146
-	$merge_vars_error_array = $submission_handler->handle_merge_variables_error( $merge_variables['error'], $merge_error_message );
147
-	if ( $merge_vars_error_array['success'] === false ) {
148
-		$process_submission_response = $submission_handler->wrap_form_submission_response( $merge_vars_error_array['message'], $is_success = false );
144
+if ( isset( $merge_variables[ 'error' ] ) ) {
145
+	$merge_error_message = isset( $merge_variables[ 'message' ] ) ? $merge_variables[ 'message' ] : $submission_handler->default_error_response_message;
146
+	$merge_vars_error_array = $submission_handler->handle_merge_variables_error( $merge_variables[ 'error' ], $merge_error_message );
147
+	if ( $merge_vars_error_array[ 'success' ] === false ) {
148
+		$process_submission_response = $submission_handler->wrap_form_submission_response( $merge_vars_error_array[ 'message' ], $is_success = false );
149 149
 		return;
150 150
 	}
151 151
 }
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 
159 159
 // Only add groups if they exist
160 160
 if ( ! empty( $groups ) ) {
161
-	$member_data['interests'] = $groups;
161
+	$member_data[ 'interests' ] = $groups;
162 162
 }
163 163
 
164 164
 // Check if this member already exists
@@ -169,12 +169,12 @@  discard block
 block discarded – undo
169 169
 // Likewise, if this member exists but their status is 'pending' it means we're dealing with a double opt-in list and they never confirmed
170 170
 // Or, if this member but their status is 'unsubscribed' it means we're dealing with someone who unsubscribed and they need to re-subscribe
171 171
 // Continue as if they're a new member to force another double opt-in email.
172
-if ( is_array( $member_exists ) && isset( $member_exists['status'] ) ) {
173
-	$double_optin_resubscribe = $member_exists['status'] === 'pending' || $member_exists['status'] === 'unsubscribed';
172
+if ( is_array( $member_exists ) && isset( $member_exists[ 'status' ] ) ) {
173
+	$double_optin_resubscribe = $member_exists[ 'status' ] === 'pending' || $member_exists[ 'status' ] === 'unsubscribed';
174 174
 } else {
175 175
 
176 176
 	// If this member doesn't exist, set their timestamp signup to the current time.
177
-	$member_data['timestamp_signup'] = current_time( 'Y-m-d H:i:s', 1 );
177
+	$member_data[ 'timestamp_signup' ] = current_time( 'Y-m-d H:i:s', 1 );
178 178
 }
179 179
 
180 180
 if ( is_wp_error( $member_exists ) || $double_optin_resubscribe === true ) {
@@ -182,24 +182,24 @@  discard block
 block discarded – undo
182 182
 
183 183
 	// Check the opt-in value - is it double or single?
184 184
 	// Double opt-in means 'status_if_new' => 'pending'
185
-	$double_optin = isset( $optin_settings['optin'] ) ? (int) $optin_settings['optin'] : 0;
185
+	$double_optin = isset( $optin_settings[ 'optin' ] ) ? (int) $optin_settings[ 'optin' ] : 0;
186 186
 
187 187
 	// If the user was unsubscribed and is re-subscribing, we set the status to 'pending', which
188 188
 	// causes Mailchimp to send them a confirmation email.  This is the only way Mailchimp will
189 189
 	// allow us to re-subscribe the user.
190
-	$was_unsubscribed = is_array( $member_exists ) && isset( $member_exists['status'] ) && $member_exists['status'] === 'unsubscribed';
190
+	$was_unsubscribed = is_array( $member_exists ) && isset( $member_exists[ 'status' ] ) && $member_exists[ 'status' ] === 'unsubscribed';
191 191
 	$was_unsubscribed = apply_filters( 'yikes_mailchimp_single_resubscribe', $was_unsubscribed );
192 192
 
193 193
 	if ( $double_optin === 1 || $was_unsubscribed === true ) {
194 194
 
195 195
 		// Double opt-in
196
-		$member_data['status_if_new'] = 'pending';
197
-		$member_data['status']        = 'pending';
196
+		$member_data[ 'status_if_new' ] = 'pending';
197
+		$member_data[ 'status' ]        = 'pending';
198 198
 	} else {
199 199
 
200 200
 		// Single opt-in
201
-		$member_data['status_if_new'] = 'subscribed';
202
-		$member_data['status']        = 'subscribed';
201
+		$member_data[ 'status_if_new' ] = 'subscribed';
202
+		$member_data[ 'status' ]        = 'subscribed';
203 203
 	}
204 204
 
205 205
 } else {
@@ -208,28 +208,28 @@  discard block
 block discarded – undo
208 208
 
209 209
 	// But first let's set our flag, and set the Mailchimp status flag
210 210
 	$new_subscriber = false;
211
-	$member_data['status'] = 'subscribed';
211
+	$member_data[ 'status' ] = 'subscribed';
212 212
 
213 213
 	// Check our update_existing_user optin setting
214
-	$update_existing_user = ( $optin_settings['update_existing_user'] === '1' ) ? true : false;
214
+	$update_existing_user = ( $optin_settings[ 'update_existing_user' ] === '1' ) ? true : false;
215 215
 
216 216
 	// If update_existing_user is false (not allowed) then simply fail and return a response message
217 217
 	if ( $update_existing_user === false ) {
218 218
 		$disallow_update_array = $submission_handler->handle_disallowed_existing_user_update();
219
-		if ( $disallow_update_array['success'] === false ) {
220
-			$process_submission_response = $submission_handler->wrap_form_submission_response( $disallow_update_array['message'], $is_success = false );
219
+		if ( $disallow_update_array[ 'success' ] === false ) {
220
+			$process_submission_response = $submission_handler->wrap_form_submission_response( $disallow_update_array[ 'message' ], $is_success = false );
221 221
 			return;
222 222
 		}
223 223
 	}
224 224
 
225 225
 	// If update_existing_user is true, we need to check our 'send_update_email' option
226
-	$send_update_email = ( $optin_settings['send_update_email'] === '1' ) ? true : false;
226
+	$send_update_email = ( $optin_settings[ 'send_update_email' ] === '1' ) ? true : false;
227 227
 
228 228
 	// If $send_update_email is true (we send the email) then we need to fire off the 'send update email' logic
229 229
 	if ( $send_update_email === true ) {
230 230
 		$update_existing_user_array = $submission_handler->handle_updating_existing_user();
231
-		if ( $update_existing_user_array['success'] === false ) {
232
-			$process_submission_response = $submission_handler->wrap_form_submission_response( $update_existing_user_array['message'], $is_success = false );
231
+		if ( $update_existing_user_array[ 'success' ] === false ) {
232
+			$process_submission_response = $submission_handler->wrap_form_submission_response( $update_existing_user_array[ 'message' ], $is_success = false );
233 233
 			return;
234 234
 		}
235 235
 	}
@@ -250,9 +250,9 @@  discard block
 block discarded – undo
250 250
 
251 251
 // If this is the first time subscriber add the tags along with the subscribe request.
252 252
 // This allows for double opt-in forms submissions to be tagged.
253
-if ( ! empty( $form_data['tags'] ) && ! is_array( $member_exists ) ) {
254
-	foreach( $form_data['tags'] as $tag ) {
255
-		$member_data['tags'][] = $tag['name'];
253
+if ( ! empty( $form_data[ 'tags' ] ) && ! is_array( $member_exists ) ) {
254
+	foreach ( $form_data[ 'tags' ] as $tag ) {
255
+		$member_data[ 'tags' ][ ] = $tag[ 'name' ];
256 256
 	}
257 257
 }
258 258
 
@@ -272,9 +272,9 @@  discard block
 block discarded – undo
272 272
 }
273 273
 
274 274
 // Handle errors in the response
275
-if ( isset( $success_array ) && isset( $success_array['success'] ) && $success_array['success'] === false ) {
276
-	$process_submission_response = isset( $success_array['message'] ) ? $success_array['message'] : '';
277
-	$process_submission_response = $submission_handler->wrap_form_submission_response( $success_array['message'], $is_success = false );
275
+if ( isset( $success_array ) && isset( $success_array[ 'success' ] ) && $success_array[ 'success' ] === false ) {
276
+	$process_submission_response = isset( $success_array[ 'message' ] ) ? $success_array[ 'message' ] : '';
277
+	$process_submission_response = $submission_handler->wrap_form_submission_response( $success_array[ 'message' ], $is_success = false );
278 278
 	return;
279 279
 }
280 280
 
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 // For non-AJAX submissions, if we have a new subscriber we need to increment our submissions count by 1
285 285
 // For AJAX, this is an AJAX call that gets fired off after form submission
286 286
 if ( $new_subscriber === true ) {
287
-	$submissions = (int) $form_settings['submissions'] + 1;	
287
+	$submissions = (int) $form_settings[ 'submissions' ] + 1;	
288 288
 	$interface->update_form_field( $form_id, 'submissions', $submissions );
289 289
 }
290 290
 
Please login to merge, or discard this patch.