Test Failed
Push — master ( 328dfe...bf1f6f )
by Devin
06:13
created
includes/process-donation.php 1 patch
Spacing   +288 added lines, -289 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  */
11 11
 
12 12
 // Exit if accessed directly.
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -28,18 +28,18 @@  discard block
 block discarded – undo
28 28
  */
29 29
 function give_process_donation_form() {
30 30
 
31
-	$post_data = give_clean( $_POST ); // WPCS: input var ok, CSRF ok.
32
-	$is_ajax   = isset( $post_data['give_ajax'] );
31
+	$post_data = give_clean($_POST); // WPCS: input var ok, CSRF ok.
32
+	$is_ajax   = isset($post_data['give_ajax']);
33 33
 
34 34
 	// Verify donation form nonce.
35
-	if ( ! give_verify_donation_form_nonce( $post_data['give-form-hash'], $post_data['give-form-id'] ) ) {
36
-		if ( $is_ajax ) {
35
+	if ( ! give_verify_donation_form_nonce($post_data['give-form-hash'], $post_data['give-form-id'])) {
36
+		if ($is_ajax) {
37 37
 			/**
38 38
 			 * Fires when AJAX sends back errors from the donation form.
39 39
 			 *
40 40
 			 * @since 1.0
41 41
 			 */
42
-			do_action( 'give_ajax_donation_errors' );
42
+			do_action('give_ajax_donation_errors');
43 43
 			give_die();
44 44
 		} else {
45 45
 			give_send_back_to_checkout();
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 *
52 52
 	 * @since 1.0
53 53
 	 */
54
-	do_action( 'give_pre_process_donation' );
54
+	do_action('give_pre_process_donation');
55 55
 
56 56
 	// Validate the form $_POST data.
57 57
 	$valid_data = give_donation_form_validate_fields();
@@ -67,24 +67,24 @@  discard block
 block discarded – undo
67 67
 	 * @param array $deprecated Deprecated Since 2.0.2. Use $_POST instead.
68 68
 	 */
69 69
 	$deprecated = $post_data;
70
-	do_action( 'give_checkout_error_checks', $valid_data, $deprecated );
70
+	do_action('give_checkout_error_checks', $valid_data, $deprecated);
71 71
 
72 72
 	// Process the login form.
73
-	if ( isset( $post_data['give_login_submit'] ) ) {
73
+	if (isset($post_data['give_login_submit'])) {
74 74
 		give_process_form_login();
75 75
 	}
76 76
 
77 77
 	// Validate the user.
78
-	$user = give_get_donation_form_user( $valid_data );
78
+	$user = give_get_donation_form_user($valid_data);
79 79
 
80
-	if ( false === $valid_data || give_get_errors() || ! $user ) {
81
-		if ( $is_ajax ) {
80
+	if (false === $valid_data || give_get_errors() || ! $user) {
81
+		if ($is_ajax) {
82 82
 			/**
83 83
 			 * Fires when AJAX sends back errors from the donation form.
84 84
 			 *
85 85
 			 * @since 1.0
86 86
 			 */
87
-			do_action( 'give_ajax_donation_errors' );
87
+			do_action('give_ajax_donation_errors');
88 88
 			give_die();
89 89
 		} else {
90 90
 			return false;
@@ -92,17 +92,17 @@  discard block
 block discarded – undo
92 92
 	}
93 93
 
94 94
 	// If AJAX send back success to proceed with form submission.
95
-	if ( $is_ajax ) {
95
+	if ($is_ajax) {
96 96
 		echo 'success';
97 97
 		give_die();
98 98
 	}
99 99
 
100 100
 	// After AJAX: Setup session if not using php_sessions.
101
-	if ( ! Give()->session->use_php_sessions() ) {
101
+	if ( ! Give()->session->use_php_sessions()) {
102 102
 		// Double-check that set_cookie is publicly accessible.
103 103
 		// we're using a slightly modified class-wp-sessions.php.
104
-		$session_reflection = new ReflectionMethod( 'WP_Session', 'set_cookie' );
105
-		if ( $session_reflection->isPublic() ) {
104
+		$session_reflection = new ReflectionMethod('WP_Session', 'set_cookie');
105
+		if ($session_reflection->isPublic()) {
106 106
 			// Manually set the cookie.
107 107
 			Give()->session->init()->set_cookie();
108 108
 		}
@@ -117,20 +117,19 @@  discard block
 block discarded – undo
117 117
 		'address'    => $user['address'],
118 118
 	);
119 119
 
120
-	$auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
120
+	$auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
121 121
 
122
-	$price    = isset( $post_data['give-amount'] ) ?
123
-		(float) apply_filters( 'give_donation_total', give_maybe_sanitize_amount( $post_data['give-amount'] ) ) :
124
-		'0.00';
125
-	$purchase_key = strtolower( md5( $user['user_email'] . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'give', true ) ) );
122
+	$price    = isset($post_data['give-amount']) ?
123
+		(float) apply_filters('give_donation_total', give_maybe_sanitize_amount($post_data['give-amount'])) : '0.00';
124
+	$purchase_key = strtolower(md5($user['user_email'].date('Y-m-d H:i:s').$auth_key.uniqid('give', true)));
126 125
 
127 126
 	// Setup donation information.
128 127
 	$donation_data = array(
129 128
 		'price'         => $price,
130 129
 		'purchase_key'  => $purchase_key,
131 130
 		'user_email'    => $user['user_email'],
132
-		'date'          => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
133
-		'user_info'     => stripslashes_deep( $user_info ),
131
+		'date'          => date('Y-m-d H:i:s', current_time('timestamp')),
132
+		'user_info'     => stripslashes_deep($user_info),
134 133
 		'post_data'     => $post_data,
135 134
 		'gateway'       => $valid_data['gateway'],
136 135
 		'card_info'     => $valid_data['cc_info'],
@@ -150,10 +149,10 @@  discard block
 block discarded – undo
150 149
 	 * @param array      $user_info  Array containing basic user information.
151 150
 	 * @param bool|array $valid_data Validate fields.
152 151
 	 */
153
-	do_action( 'give_checkout_before_gateway', $post_data, $user_info, $valid_data );
152
+	do_action('give_checkout_before_gateway', $post_data, $user_info, $valid_data);
154 153
 
155 154
 	// Sanity check for price.
156
-	if ( ! $donation_data['price'] ) {
155
+	if ( ! $donation_data['price']) {
157 156
 		// Revert to manual.
158 157
 		$donation_data['gateway'] = 'manual';
159 158
 		$_POST['give-gateway']    = 'manual';
@@ -164,26 +163,26 @@  discard block
 block discarded – undo
164 163
 	 *
165 164
 	 * @since 1.7
166 165
 	 */
167
-	$donation_data = apply_filters( 'give_donation_data_before_gateway', $donation_data, $valid_data );
166
+	$donation_data = apply_filters('give_donation_data_before_gateway', $donation_data, $valid_data);
168 167
 
169 168
 	// Setup the data we're storing in the donation session.
170 169
 	$session_data = $donation_data;
171 170
 
172 171
 	// Make sure credit card numbers are never stored in sessions.
173
-	unset( $session_data['card_info']['card_number'] );
174
-	unset( $session_data['post_data']['card_number'] );
172
+	unset($session_data['card_info']['card_number']);
173
+	unset($session_data['post_data']['card_number']);
175 174
 
176 175
 	// Used for showing data to non logged-in users after donation, and for other plugins needing donation data.
177
-	give_set_purchase_session( $session_data );
176
+	give_set_purchase_session($session_data);
178 177
 
179 178
 	// Send info to the gateway for payment processing.
180
-	give_send_to_gateway( $donation_data['gateway'], $donation_data );
179
+	give_send_to_gateway($donation_data['gateway'], $donation_data);
181 180
 	give_die();
182 181
 }
183 182
 
184
-add_action( 'give_purchase', 'give_process_donation_form' );
185
-add_action( 'wp_ajax_give_process_donation', 'give_process_donation_form' );
186
-add_action( 'wp_ajax_nopriv_give_process_donation', 'give_process_donation_form' );
183
+add_action('give_purchase', 'give_process_donation_form');
184
+add_action('wp_ajax_give_process_donation', 'give_process_donation_form');
185
+add_action('wp_ajax_nopriv_give_process_donation', 'give_process_donation_form');
187 186
 
188 187
 /**
189 188
  * Verify that when a logged in user makes a donation that the email address used doesn't belong to a different customer.
@@ -194,27 +193,27 @@  discard block
 block discarded – undo
194 193
  *
195 194
  * @return void
196 195
  */
197
-function give_check_logged_in_user_for_existing_email( $valid_data ) {
196
+function give_check_logged_in_user_for_existing_email($valid_data) {
198 197
 
199 198
 	// Verify that the email address belongs to this customer.
200
-	if ( is_user_logged_in() ) {
199
+	if (is_user_logged_in()) {
201 200
 
202 201
 		$submitted_email = $valid_data['logged_in_user']['user_email'];
203
-		$donor           = new Give_Donor( get_current_user_id(), true );
202
+		$donor           = new Give_Donor(get_current_user_id(), true);
204 203
 
205 204
 		// If this email address is not registered with this customer, see if it belongs to any other customer.
206 205
 		if (
207 206
 			$submitted_email !== $donor->email
208
-			&& ( is_array( $donor->emails ) && ! in_array( $submitted_email, $donor->emails, true ) )
207
+			&& (is_array($donor->emails) && ! in_array($submitted_email, $donor->emails, true))
209 208
 		) {
210
-			$found_donor = new Give_Donor( $submitted_email );
209
+			$found_donor = new Give_Donor($submitted_email);
211 210
 
212
-			if ( $found_donor->id > 0 ) {
211
+			if ($found_donor->id > 0) {
213 212
 				give_set_error(
214 213
 					'give-customer-email-exists',
215 214
 					sprintf(
216 215
 						/* translators: 1. Donor Email, 2. Submitted Email */
217
-						__( 'You are logged in as %1$s, and are submitting a donation as %2$s, which is an existing donor. To ensure that the email address is tied to the correct donor, please submit this donation from a logged-out browser, or choose another email address.', 'give' ),
216
+						__('You are logged in as %1$s, and are submitting a donation as %2$s, which is an existing donor. To ensure that the email address is tied to the correct donor, please submit this donation from a logged-out browser, or choose another email address.', 'give'),
218 217
 						$donor->email,
219 218
 						$submitted_email
220 219
 					)
@@ -224,7 +223,7 @@  discard block
 block discarded – undo
224 223
 	}
225 224
 }
226 225
 
227
-add_action( 'give_checkout_error_checks', 'give_check_logged_in_user_for_existing_email', 10, 1 );
226
+add_action('give_checkout_error_checks', 'give_check_logged_in_user_for_existing_email', 10, 1);
228 227
 
229 228
 /**
230 229
  * Process the checkout login form
@@ -236,49 +235,49 @@  discard block
 block discarded – undo
236 235
  */
237 236
 function give_process_form_login() {
238 237
 
239
-	$is_ajax   = ! empty( $_POST['give_ajax'] ) ? give_clean( $_POST['give_ajax'] ) : 0; // WPCS: input var ok, sanitization ok, CSRF ok.
238
+	$is_ajax   = ! empty($_POST['give_ajax']) ? give_clean($_POST['give_ajax']) : 0; // WPCS: input var ok, sanitization ok, CSRF ok.
240 239
 	$referrer  = wp_get_referer();
241 240
 	$user_data = give_donation_form_validate_user_login();
242 241
 
243
-	if ( give_get_errors() || $user_data['user_id'] < 1 ) {
244
-		if ( $is_ajax ) {
242
+	if (give_get_errors() || $user_data['user_id'] < 1) {
243
+		if ($is_ajax) {
245 244
 			/**
246 245
 			 * Fires when AJAX sends back errors from the donation form.
247 246
 			 *
248 247
 			 * @since 1.0
249 248
 			 */
250 249
 			ob_start();
251
-			do_action( 'give_ajax_donation_errors' );
250
+			do_action('give_ajax_donation_errors');
252 251
 			$message = ob_get_contents();
253 252
 			ob_end_clean();
254
-			wp_send_json_error( $message );
253
+			wp_send_json_error($message);
255 254
 		} else {
256
-			wp_safe_redirect( $referrer );
255
+			wp_safe_redirect($referrer);
257 256
 			exit;
258 257
 		}
259 258
 	}
260 259
 
261
-	give_log_user_in( $user_data['user_id'], $user_data['user_login'], $user_data['user_pass'] );
260
+	give_log_user_in($user_data['user_id'], $user_data['user_login'], $user_data['user_pass']);
262 261
 
263
-	if ( $is_ajax ) {
262
+	if ($is_ajax) {
264 263
 		$message = Give()->notices->print_frontend_notice(
265 264
 			sprintf(
266 265
 				/* translators: %s: user first name */
267
-				esc_html__( 'Welcome %s! You have successfully logged into your account.', 'give' ),
268
-				( ! empty( $user_data['user_first'] ) ) ? $user_data['user_first'] : $user_data['user_login']
266
+				esc_html__('Welcome %s! You have successfully logged into your account.', 'give'),
267
+				( ! empty($user_data['user_first'])) ? $user_data['user_first'] : $user_data['user_login']
269 268
 			),
270 269
 			false,
271 270
 			'success'
272 271
 		);
273 272
 
274
-		wp_send_json_success( $message );
273
+		wp_send_json_success($message);
275 274
 	} else {
276
-		wp_safe_redirect( $referrer );
275
+		wp_safe_redirect($referrer);
277 276
 	}
278 277
 }
279 278
 
280
-add_action( 'wp_ajax_give_process_donation_login', 'give_process_form_login' );
281
-add_action( 'wp_ajax_nopriv_give_process_donation_login', 'give_process_form_login' );
279
+add_action('wp_ajax_give_process_donation_login', 'give_process_form_login');
280
+add_action('wp_ajax_nopriv_give_process_donation_login', 'give_process_form_login');
282 281
 
283 282
 /**
284 283
  * Donation Form Validate Fields.
@@ -290,49 +289,49 @@  discard block
 block discarded – undo
290 289
  */
291 290
 function give_donation_form_validate_fields() {
292 291
 
293
-	$post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok.
292
+	$post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok.
294 293
 
295 294
 	// Validate Honeypot First.
296
-	if ( ! empty( $post_data['give-honeypot'] ) ) {
297
-		give_set_error( 'invalid_honeypot', esc_html__( 'Honeypot field detected. Go away bad bot!', 'give' ) );
295
+	if ( ! empty($post_data['give-honeypot'])) {
296
+		give_set_error('invalid_honeypot', esc_html__('Honeypot field detected. Go away bad bot!', 'give'));
298 297
 	}
299 298
 
300 299
 	// Check spam detect.
301 300
 	if (
302
-		isset( $post_data['action'] ) &&
303
-		give_is_setting_enabled( give_get_option( 'akismet_spam_protection' ) ) &&
301
+		isset($post_data['action']) &&
302
+		give_is_setting_enabled(give_get_option('akismet_spam_protection')) &&
304 303
 		give_is_spam_donation()
305 304
 	) {
306
-		give_set_error( 'spam_donation', __( 'This donation has been flagged as spam. Please try again.', 'give' ) );
305
+		give_set_error('spam_donation', __('This donation has been flagged as spam. Please try again.', 'give'));
307 306
 	}
308 307
 
309 308
 	// Start an array to collect valid data.
310 309
 	$valid_data = array(
311 310
 		'gateway'          => give_donation_form_validate_gateway(), // Gateway fallback (amount is validated here).
312
-		'need_new_user'    => false,     // New user flag.
313
-		'need_user_login'  => false,     // Login user flag.
314
-		'logged_user_data' => array(),   // Logged user collected data.
315
-		'new_user_data'    => array(),   // New user collected data.
316
-		'login_user_data'  => array(),   // Login user collected data.
317
-		'guest_user_data'  => array(),   // Guest user collected data.
311
+		'need_new_user'    => false, // New user flag.
312
+		'need_user_login'  => false, // Login user flag.
313
+		'logged_user_data' => array(), // Logged user collected data.
314
+		'new_user_data'    => array(), // New user collected data.
315
+		'login_user_data'  => array(), // Login user collected data.
316
+		'guest_user_data'  => array(), // Guest user collected data.
318 317
 		'cc_info'          => give_donation_form_validate_cc(), // Credit card info.
319 318
 	);
320 319
 
321
-	$form_id = intval( $post_data['give-form-id'] );
320
+	$form_id = intval($post_data['give-form-id']);
322 321
 
323 322
 	// Validate agree to terms.
324
-	if ( give_is_terms_enabled( $form_id ) ) {
323
+	if (give_is_terms_enabled($form_id)) {
325 324
 		give_donation_form_validate_agree_to_terms();
326 325
 	}
327 326
 
328
-	if ( is_user_logged_in() ) {
327
+	if (is_user_logged_in()) {
329 328
 
330 329
 		// Collect logged in user data.
331 330
 		$valid_data['logged_in_user'] = give_donation_form_validate_logged_in_user();
332 331
 	} elseif (
333
-		isset( $post_data['give-purchase-var'] ) &&
332
+		isset($post_data['give-purchase-var']) &&
334 333
 		'needs-to-register' === $post_data['give-purchase-var'] &&
335
-		! empty( $post_data['give_create_account'] )
334
+		! empty($post_data['give_create_account'])
336 335
 	) {
337 336
 
338 337
 		// Set new user registration as required.
@@ -341,7 +340,7 @@  discard block
 block discarded – undo
341 340
 		// Validate new user data.
342 341
 		$valid_data['new_user_data'] = give_donation_form_validate_new_user();
343 342
 	} elseif (
344
-		isset( $post_data['give-purchase-var'] ) &&
343
+		isset($post_data['give-purchase-var']) &&
345 344
 		'needs-to-login' === $post_data['give-purchase-var']
346 345
 	) {
347 346
 
@@ -370,14 +369,14 @@  discard block
 block discarded – undo
370 369
 function give_is_spam_donation() {
371 370
 	$spam = false;
372 371
 
373
-	$user_agent = (string) isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
372
+	$user_agent = (string) isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
374 373
 
375
-	if ( strlen( $user_agent ) < 2 ) {
374
+	if (strlen($user_agent) < 2) {
376 375
 		$spam = true;
377 376
 	}
378 377
 
379 378
 	// Allow developer to customized Akismet spam detect API call and it's response.
380
-	return apply_filters( 'give_spam', $spam );
379
+	return apply_filters('give_spam', $spam);
381 380
 }
382 381
 
383 382
 /**
@@ -392,33 +391,33 @@  discard block
 block discarded – undo
392 391
  */
393 392
 function give_donation_form_validate_gateway() {
394 393
 
395
-	$post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok.
396
-	$form_id   = ! empty( $post_data['give-form-id'] ) ? $post_data['give-form-id'] : 0;
397
-	$amount    = ! empty( $post_data['give-amount'] ) ? give_maybe_sanitize_amount( $post_data['give-amount'] ) : 0;
398
-	$gateway   = ! empty( $post_data['give-gateway'] ) ? $post_data['give-gateway'] : 0;
394
+	$post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok.
395
+	$form_id   = ! empty($post_data['give-form-id']) ? $post_data['give-form-id'] : 0;
396
+	$amount    = ! empty($post_data['give-amount']) ? give_maybe_sanitize_amount($post_data['give-amount']) : 0;
397
+	$gateway   = ! empty($post_data['give-gateway']) ? $post_data['give-gateway'] : 0;
399 398
 
400 399
 	// Bailout, if payment gateway is not submitted with donation form data.
401
-	if ( empty( $gateway ) ) {
400
+	if (empty($gateway)) {
402 401
 
403
-		give_set_error( 'empty_gateway', __( 'The donation form will process with a valid payment gateway.', 'give' ) );
402
+		give_set_error('empty_gateway', __('The donation form will process with a valid payment gateway.', 'give'));
404 403
 
405
-	} elseif ( ! give_is_gateway_active( $gateway ) ) {
404
+	} elseif ( ! give_is_gateway_active($gateway)) {
406 405
 
407
-		give_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled.', 'give' ) );
406
+		give_set_error('invalid_gateway', __('The selected payment gateway is not enabled.', 'give'));
408 407
 
409
-	} elseif ( empty( $amount ) ) {
408
+	} elseif (empty($amount)) {
410 409
 
411
-		give_set_error( 'invalid_donation_amount', __( 'Please insert a valid donation amount.', 'give' ) );
410
+		give_set_error('invalid_donation_amount', __('Please insert a valid donation amount.', 'give'));
412 411
 
413
-	} elseif ( ! give_verify_minimum_price( 'minimum' ) ) {
412
+	} elseif ( ! give_verify_minimum_price('minimum')) {
414 413
 
415 414
 		give_set_error(
416 415
 			'invalid_donation_minimum',
417 416
 			sprintf(
418 417
 				/* translators: %s: minimum donation amount */
419
-				__( 'This form has a minimum donation amount of %s.', 'give' ),
418
+				__('This form has a minimum donation amount of %s.', 'give'),
420 419
 				give_currency_filter(
421
-					give_format_amount( give_get_form_minimum_price( $form_id ),
420
+					give_format_amount(give_get_form_minimum_price($form_id),
422 421
 						array(
423 422
 							'sanitize' => false,
424 423
 						)
@@ -426,15 +425,15 @@  discard block
 block discarded – undo
426 425
 				)
427 426
 			)
428 427
 		);
429
-	} elseif ( ! give_verify_minimum_price( 'maximum' ) ) {
428
+	} elseif ( ! give_verify_minimum_price('maximum')) {
430 429
 
431 430
 		give_set_error(
432 431
 			'invalid_donation_maximum',
433 432
 			sprintf(
434 433
 				/* translators: %s: Maximum donation amount */
435
-				__( 'This form has a maximum donation amount of %s.', 'give' ),
434
+				__('This form has a maximum donation amount of %s.', 'give'),
436 435
 				give_currency_filter(
437
-					give_format_amount( give_get_form_maximum_price( $form_id ),
436
+					give_format_amount(give_get_form_maximum_price($form_id),
438 437
 						array(
439 438
 							'sanitize' => false,
440 439
 						)
@@ -460,32 +459,32 @@  discard block
 block discarded – undo
460 459
  *
461 460
  * @return bool
462 461
  */
463
-function give_verify_minimum_price( $amount_range = 'minimum' ) {
462
+function give_verify_minimum_price($amount_range = 'minimum') {
464 463
 
465
-	$post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok.
466
-	$amount    = ! empty( $post_data['give-amount'] ) ? give_maybe_sanitize_amount( $post_data['give-amount'] ) : 0;
467
-	$form_id   = ! empty( $post_data['give-form-id'] ) ? $post_data['give-form-id'] : 0;
468
-	$price_id  = ! empty( $post_data['give-price-id'] ) ? $post_data['give-price-id'] : '';
464
+	$post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok.
465
+	$amount    = ! empty($post_data['give-amount']) ? give_maybe_sanitize_amount($post_data['give-amount']) : 0;
466
+	$form_id   = ! empty($post_data['give-form-id']) ? $post_data['give-form-id'] : 0;
467
+	$price_id  = ! empty($post_data['give-price-id']) ? $post_data['give-price-id'] : '';
469 468
 
470
-	$variable_prices = give_has_variable_prices( $form_id );
469
+	$variable_prices = give_has_variable_prices($form_id);
471 470
 	$verified_stat   = false;
472 471
 
473
-	if ( $variable_prices && in_array( $price_id, give_get_variable_price_ids( $form_id ), true ) ) {
472
+	if ($variable_prices && in_array($price_id, give_get_variable_price_ids($form_id), true)) {
474 473
 
475
-		$price_level_amount = give_get_price_option_amount( $form_id, $price_id );
474
+		$price_level_amount = give_get_price_option_amount($form_id, $price_id);
476 475
 
477
-		if ( $price_level_amount == $amount ) {
476
+		if ($price_level_amount == $amount) {
478 477
 			$verified_stat = true;
479 478
 		}
480 479
 	}
481 480
 
482
-	if ( ! $verified_stat ) {
483
-		switch ( $amount_range ) {
481
+	if ( ! $verified_stat) {
482
+		switch ($amount_range) {
484 483
 			case 'minimum' :
485
-				$verified_stat = ( give_get_form_minimum_price( $form_id ) > $amount ) ? false : true;
484
+				$verified_stat = (give_get_form_minimum_price($form_id) > $amount) ? false : true;
486 485
 				break;
487 486
 			case 'maximum' :
488
-				$verified_stat = ( give_get_form_maximum_price( $form_id ) < $amount ) ? false : true;
487
+				$verified_stat = (give_get_form_maximum_price($form_id) < $amount) ? false : true;
489 488
 				break;
490 489
 		}
491 490
 	}
@@ -499,7 +498,7 @@  discard block
 block discarded – undo
499 498
 	 * @param string  $amount_range  Type of the amount.
500 499
 	 * @param integer $form_id       Give Donation Form ID.
501 500
 	 */
502
-	return apply_filters( 'give_verify_minimum_maximum_price', $verified_stat, $amount_range, $form_id );
501
+	return apply_filters('give_verify_minimum_maximum_price', $verified_stat, $amount_range, $form_id);
503 502
 }
504 503
 
505 504
 /**
@@ -512,13 +511,13 @@  discard block
 block discarded – undo
512 511
  */
513 512
 function give_donation_form_validate_agree_to_terms() {
514 513
 
515
-	$agree_to_terms = ! empty( $_POST['give_agree_to_terms'] ) ? give_clean( $_POST['give_agree_to_terms'] ) : 0; // WPCS: input var ok, sanitization ok, CSRF ok.
514
+	$agree_to_terms = ! empty($_POST['give_agree_to_terms']) ? give_clean($_POST['give_agree_to_terms']) : 0; // WPCS: input var ok, sanitization ok, CSRF ok.
516 515
 
517 516
 	// Proceed only, if donor agreed to terms.
518
-	if ( ! $agree_to_terms ) {
517
+	if ( ! $agree_to_terms) {
519 518
 
520 519
 		// User did not agree.
521
-		give_set_error( 'agree_to_terms', apply_filters( 'give_agree_to_terms_text', __( 'You must agree to the terms and conditions.', 'give' ) ) );
520
+		give_set_error('agree_to_terms', apply_filters('give_agree_to_terms_text', __('You must agree to the terms and conditions.', 'give')));
522 521
 	}
523 522
 }
524 523
 
@@ -532,84 +531,84 @@  discard block
 block discarded – undo
532 531
  *
533 532
  * @return array
534 533
  */
535
-function give_get_required_fields( $form_id ) {
534
+function give_get_required_fields($form_id) {
536 535
 
537
-	$payment_mode = give_get_chosen_gateway( $form_id );
536
+	$payment_mode = give_get_chosen_gateway($form_id);
538 537
 
539 538
 	$required_fields = array(
540 539
 		'give_email' => array(
541 540
 			'error_id'      => 'invalid_email',
542
-			'error_message' => __( 'Please enter a valid email address.', 'give' ),
541
+			'error_message' => __('Please enter a valid email address.', 'give'),
543 542
 		),
544 543
 		'give_first' => array(
545 544
 			'error_id'      => 'invalid_first_name',
546
-			'error_message' => __( 'Please enter your first name.', 'give' ),
545
+			'error_message' => __('Please enter your first name.', 'give'),
547 546
 		),
548 547
 	);
549 548
 
550
-	$require_address = give_require_billing_address( $payment_mode );
549
+	$require_address = give_require_billing_address($payment_mode);
551 550
 
552
-	if ( $require_address ) {
553
-		$required_fields['card_address']    = array(
551
+	if ($require_address) {
552
+		$required_fields['card_address'] = array(
554 553
 			'error_id'      => 'invalid_card_address',
555
-			'error_message' => __( 'Please enter your primary billing address.', 'give' ),
554
+			'error_message' => __('Please enter your primary billing address.', 'give'),
556 555
 		);
557
-		$required_fields['card_zip']        = array(
556
+		$required_fields['card_zip'] = array(
558 557
 			'error_id'      => 'invalid_zip_code',
559
-			'error_message' => __( 'Please enter your zip / postal code.', 'give' ),
558
+			'error_message' => __('Please enter your zip / postal code.', 'give'),
560 559
 		);
561
-		$required_fields['card_city']       = array(
560
+		$required_fields['card_city'] = array(
562 561
 			'error_id'      => 'invalid_city',
563
-			'error_message' => __( 'Please enter your billing city.', 'give' ),
562
+			'error_message' => __('Please enter your billing city.', 'give'),
564 563
 		);
565 564
 		$required_fields['billing_country'] = array(
566 565
 			'error_id'      => 'invalid_country',
567
-			'error_message' => __( 'Please select your billing country.', 'give' ),
566
+			'error_message' => __('Please select your billing country.', 'give'),
568 567
 		);
569 568
 
570 569
 
571 570
 		$required_fields['card_state'] = array(
572 571
 			'error_id'      => 'invalid_state',
573
-			'error_message' => __( 'Please enter billing state / province / County.', 'give' ),
572
+			'error_message' => __('Please enter billing state / province / County.', 'give'),
574 573
 		);
575 574
 
576
-		$country = ! empty( $_POST['billing_country'] ) ? give_clean( $_POST['billing_country'] ) : 0; // WPCS: input var ok, sanitization ok, CSRF ok.
575
+		$country = ! empty($_POST['billing_country']) ? give_clean($_POST['billing_country']) : 0; // WPCS: input var ok, sanitization ok, CSRF ok.
577 576
 
578 577
 		// Check if billing country already exists.
579
-		if ( $country ) {
578
+		if ($country) {
580 579
 
581 580
 			// Get the country list that does not required any states init.
582 581
 			$states_country = give_states_not_required_country_list();
583 582
 
584 583
 			// Check if states is empty or not.
585
-			if ( array_key_exists( $country, $states_country ) ) {
584
+			if (array_key_exists($country, $states_country)) {
586 585
 				// If states is empty remove the required fields of state in billing cart.
587
-				unset( $required_fields['card_state'] );
586
+				unset($required_fields['card_state']);
588 587
 			}
589 588
 		}
590 589
 	} // End if().
591 590
 
592
-	if ( give_is_company_field_enabled( $form_id ) ) {
593
-		$form_option    = give_get_meta( $form_id, '_give_company_field', true );
594
-		$global_setting = give_get_option( 'company_field' );
591
+	if (give_is_company_field_enabled($form_id)) {
592
+		$form_option    = give_get_meta($form_id, '_give_company_field', true);
593
+		$global_setting = give_get_option('company_field');
595 594
 
596 595
 		$is_company_field_required = false;
597 596
 
598
-		if ( ! empty( $form_option ) && give_is_setting_enabled( $form_option, array( 'required' ) ) ) {
597
+		if ( ! empty($form_option) && give_is_setting_enabled($form_option, array('required'))) {
599 598
 			$is_company_field_required = true;
600 599
 
601
-		} elseif ( 'global' === $form_option && give_is_setting_enabled( $global_setting, array( 'required' ) ) ) {
600
+		} elseif ('global' === $form_option && give_is_setting_enabled($global_setting, array('required'))) {
602 601
 			$is_company_field_required = true;
603 602
 
604
-		} elseif ( empty( $form_option ) && give_is_setting_enabled( $global_setting, array( 'required' ) ) ) {
603
+		} elseif (empty($form_option) && give_is_setting_enabled($global_setting, array('required'))) {
605 604
 			$is_company_field_required = true;
606 605
 
607 606
 		}
608 607
 
609
-		if ( $is_company_field_required ) {
608
+		if ($is_company_field_required) {
610 609
 			$required_fields['give_company_name'] = array(
611 610
 				'error_id'      => 'invalid_company',
612
-				'error_message' => __( 'Please enter Company Name.', 'give' ),
611
+				'error_message' => __('Please enter Company Name.', 'give'),
613 612
 			);
614 613
 		}
615 614
 	}
@@ -619,7 +618,7 @@  discard block
 block discarded – undo
619 618
 	 *
620 619
 	 * @since 1.7
621 620
 	 */
622
-	$required_fields = apply_filters( 'give_donation_form_required_fields', $required_fields, $form_id );
621
+	$required_fields = apply_filters('give_donation_form_required_fields', $required_fields, $form_id);
623 622
 
624 623
 	return $required_fields;
625 624
 
@@ -634,17 +633,17 @@  discard block
 block discarded – undo
634 633
  *
635 634
  * @return bool
636 635
  */
637
-function give_require_billing_address( $payment_mode ) {
636
+function give_require_billing_address($payment_mode) {
638 637
 
639 638
 	$return          = false;
640
-	$billing_country = ! empty( $_POST['billing_country'] ) ? give_clean( $_POST['billing_country'] ) : 0; // WPCS: input var ok, sanitization ok, CSRF ok.
639
+	$billing_country = ! empty($_POST['billing_country']) ? give_clean($_POST['billing_country']) : 0; // WPCS: input var ok, sanitization ok, CSRF ok.
641 640
 
642
-	if ( $billing_country || did_action( "give_{$payment_mode}_cc_form" ) || did_action( 'give_cc_form' ) ) {
641
+	if ($billing_country || did_action("give_{$payment_mode}_cc_form") || did_action('give_cc_form')) {
643 642
 		$return = true;
644 643
 	}
645 644
 
646 645
 	// Let payment gateways and other extensions determine if address fields should be required.
647
-	return apply_filters( 'give_require_billing_address', $return );
646
+	return apply_filters('give_require_billing_address', $return);
648 647
 
649 648
 }
650 649
 
@@ -658,47 +657,47 @@  discard block
 block discarded – undo
658 657
  */
659 658
 function give_donation_form_validate_logged_in_user() {
660 659
 
661
-	$post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok.
660
+	$post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok.
662 661
 	$user_id   = get_current_user_id();
663
-	$form_id   = ! empty( $post_data['give-form-id'] ) ? $post_data['give-form-id'] : 0;
662
+	$form_id   = ! empty($post_data['give-form-id']) ? $post_data['give-form-id'] : 0;
664 663
 
665 664
 	// Start empty array to collect valid user data.
666 665
 	$valid_user_data = array(
667 666
 
668 667
 		// Assume there will be errors.
669
-		'user_id' => - 1,
668
+		'user_id' => -1,
670 669
 	);
671 670
 
672 671
 	// Proceed on;y, if valid $user_id found.
673
-	if ( $user_id > 0 ) {
672
+	if ($user_id > 0) {
674 673
 
675 674
 		// Get the logged in user data.
676
-		$user_data = get_userdata( $user_id );
675
+		$user_data = get_userdata($user_id);
677 676
 
678 677
 		// Validate Required Form Fields.
679
-		give_validate_required_form_fields( $form_id );
678
+		give_validate_required_form_fields($form_id);
680 679
 
681 680
 		// Verify data.
682
-		if ( is_object( $user_data ) && $user_data->ID > 0 ) {
681
+		if (is_object($user_data) && $user_data->ID > 0) {
683 682
 
684 683
 			// Collected logged in user data.
685 684
 			$valid_user_data = array(
686 685
 				'user_id'    => $user_id,
687
-				'user_email' => ! empty( $post_data['give_email'] ) ? sanitize_email( $post_data['give_email'] ) : $user_data->user_email,
688
-				'user_first' => ! empty( $post_data['give_first'] ) ? $post_data['give_first'] : $user_data->first_name,
689
-				'user_last'  => ! empty( $post_data['give_last'] ) ? $post_data['give_last'] : $user_data->last_name,
686
+				'user_email' => ! empty($post_data['give_email']) ? sanitize_email($post_data['give_email']) : $user_data->user_email,
687
+				'user_first' => ! empty($post_data['give_first']) ? $post_data['give_first'] : $user_data->first_name,
688
+				'user_last'  => ! empty($post_data['give_last']) ? $post_data['give_last'] : $user_data->last_name,
690 689
 			);
691 690
 
692 691
 			// Validate essential form fields.
693
-			give_donation_form_validate_name_fields( $post_data );
692
+			give_donation_form_validate_name_fields($post_data);
694 693
 
695
-			if ( ! is_email( $valid_user_data['user_email'] ) ) {
696
-				give_set_error( 'email_invalid', esc_html__( 'Invalid email.', 'give' ) );
694
+			if ( ! is_email($valid_user_data['user_email'])) {
695
+				give_set_error('email_invalid', esc_html__('Invalid email.', 'give'));
697 696
 			}
698 697
 		} else {
699 698
 
700 699
 			// Set invalid user information error.
701
-			give_set_error( 'invalid_user', esc_html__( 'The user information is invalid.', 'give' ) );
700
+			give_set_error('invalid_user', esc_html__('The user information is invalid.', 'give'));
702 701
 		}
703 702
 	}
704 703
 
@@ -716,12 +715,12 @@  discard block
 block discarded – undo
716 715
  */
717 716
 function give_donation_form_validate_new_user() {
718 717
 
719
-	$post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok.
720
-	$nonce     = ! empty( $post_data['give-form-user-register-hash'] ) ? $post_data['give-form-user-register-hash'] : '';
718
+	$post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok.
719
+	$nonce     = ! empty($post_data['give-form-user-register-hash']) ? $post_data['give-form-user-register-hash'] : '';
721 720
 
722 721
 	// Validate user creation nonce.
723
-	if ( ! wp_verify_nonce( $nonce, 'give_form_create_user_nonce' ) ) {
724
-		give_set_error( 'invalid_nonce', __( 'Nonce verification has failed.', 'give' ) );
722
+	if ( ! wp_verify_nonce($nonce, 'give_form_create_user_nonce')) {
723
+		give_set_error('invalid_nonce', __('Nonce verification has failed.', 'give'));
725 724
 	}
726 725
 
727 726
 	$auto_generated_password = wp_generate_password();
@@ -729,7 +728,7 @@  discard block
 block discarded – undo
729 728
 	// Default user data.
730 729
 	$default_user_data = array(
731 730
 		'give-form-id'           => '',
732
-		'user_id'                => - 1, // Assume there will be errors.
731
+		'user_id'                => -1, // Assume there will be errors.
733 732
 		'user_first'             => '',
734 733
 		'user_last'              => '',
735 734
 		'give_user_login'        => false,
@@ -739,17 +738,17 @@  discard block
 block discarded – undo
739 738
 	);
740 739
 
741 740
 	// Get user data.
742
-	$user_data            = wp_parse_args( $post_data, $default_user_data );
741
+	$user_data            = wp_parse_args($post_data, $default_user_data);
743 742
 	$registering_new_user = false;
744
-	$form_id              = absint( $user_data['give-form-id'] );
743
+	$form_id              = absint($user_data['give-form-id']);
745 744
 
746
-	give_donation_form_validate_name_fields( $user_data );
745
+	give_donation_form_validate_name_fields($user_data);
747 746
 
748 747
 	// Start an empty array to collect valid user data.
749 748
 	$valid_user_data = array(
750 749
 
751 750
 		// Assume there will be errors.
752
-		'user_id'    => - 1,
751
+		'user_id'    => -1,
753 752
 
754 753
 		// Get first name.
755 754
 		'user_first' => $user_data['give_first'],
@@ -762,13 +761,13 @@  discard block
 block discarded – undo
762 761
 	);
763 762
 
764 763
 	// Validate Required Form Fields.
765
-	give_validate_required_form_fields( $form_id );
764
+	give_validate_required_form_fields($form_id);
766 765
 
767 766
 	// Set Email as Username.
768 767
 	$valid_user_data['user_login'] = $user_data['give_email'];
769 768
 
770 769
 	// Check if we have an email to verify.
771
-	if ( give_validate_user_email( $user_data['give_email'], $registering_new_user ) ) {
770
+	if (give_validate_user_email($user_data['give_email'], $registering_new_user)) {
772 771
 		$valid_user_data['user_email'] = $user_data['give_email'];
773 772
 	}
774 773
 
@@ -785,47 +784,47 @@  discard block
 block discarded – undo
785 784
  */
786 785
 function give_donation_form_validate_user_login() {
787 786
 
788
-	$post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok.
787
+	$post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok.
789 788
 
790 789
 	// Start an array to collect valid user data.
791 790
 	$valid_user_data = array(
792 791
 
793 792
 		// Assume there will be errors.
794
-		'user_id' => - 1,
793
+		'user_id' => -1,
795 794
 	);
796 795
 
797 796
 	// Bailout, if Username is empty.
798
-	if ( empty( $post_data['give_user_login'] ) ) {
799
-		give_set_error( 'must_log_in', __( 'You must register or login to complete your donation.', 'give' ) );
797
+	if (empty($post_data['give_user_login'])) {
798
+		give_set_error('must_log_in', __('You must register or login to complete your donation.', 'give'));
800 799
 
801 800
 		return $valid_user_data;
802 801
 	}
803 802
 
804 803
 	// Get the user by login.
805
-	$user_data = get_user_by( 'login', strip_tags( $post_data['give_user_login'] ) );
804
+	$user_data = get_user_by('login', strip_tags($post_data['give_user_login']));
806 805
 
807 806
 	// Check if user exists.
808
-	if ( $user_data ) {
807
+	if ($user_data) {
809 808
 
810 809
 		// Get password.
811
-		$user_pass = ! empty( $post_data['give_user_pass'] ) ? $post_data['give_user_pass'] : false;
810
+		$user_pass = ! empty($post_data['give_user_pass']) ? $post_data['give_user_pass'] : false;
812 811
 
813 812
 		// Check user_pass.
814
-		if ( $user_pass ) {
813
+		if ($user_pass) {
815 814
 
816 815
 			// Check if password is valid.
817
-			if ( ! wp_check_password( $user_pass, $user_data->user_pass, $user_data->ID ) ) {
816
+			if ( ! wp_check_password($user_pass, $user_data->user_pass, $user_data->ID)) {
818 817
 
819
-				$current_page_url = site_url() . '/' . get_page_uri();
818
+				$current_page_url = site_url().'/'.get_page_uri();
820 819
 
821 820
 				// Incorrect password.
822 821
 				give_set_error(
823 822
 					'password_incorrect',
824 823
 					sprintf(
825 824
 						'%1$s <a href="%2$s">%3$s</a>',
826
-						__( 'The password you entered is incorrect.', 'give' ),
827
-						wp_lostpassword_url( $current_page_url ),
828
-						__( 'Reset Password', 'give' )
825
+						__('The password you entered is incorrect.', 'give'),
826
+						wp_lostpassword_url($current_page_url),
827
+						__('Reset Password', 'give')
829 828
 					)
830 829
 				);
831 830
 
@@ -843,11 +842,11 @@  discard block
 block discarded – undo
843 842
 			}
844 843
 		} else {
845 844
 			// Empty password.
846
-			give_set_error( 'password_empty', __( 'Enter a password.', 'give' ) );
845
+			give_set_error('password_empty', __('Enter a password.', 'give'));
847 846
 		}
848 847
 	} else {
849 848
 		// No username.
850
-		give_set_error( 'username_incorrect', __( 'The username you entered does not exist.', 'give' ) );
849
+		give_set_error('username_incorrect', __('The username you entered does not exist.', 'give'));
851 850
 	} // End if().
852 851
 
853 852
 	return $valid_user_data;
@@ -863,8 +862,8 @@  discard block
 block discarded – undo
863 862
  */
864 863
 function give_donation_form_validate_guest_user() {
865 864
 
866
-	$post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok.
867
-	$form_id   = ! empty( $post_data['give-form-id'] ) ? $post_data['give-form-id'] : 0;
865
+	$post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok.
866
+	$form_id   = ! empty($post_data['give-form-id']) ? $post_data['give-form-id'] : 0;
868 867
 
869 868
 	// Start an array to collect valid user data.
870 869
 	$valid_user_data = array(
@@ -873,22 +872,22 @@  discard block
 block discarded – undo
873 872
 	);
874 873
 
875 874
 	// Validate name fields.
876
-	give_donation_form_validate_name_fields( $post_data );
875
+	give_donation_form_validate_name_fields($post_data);
877 876
 
878 877
 	// Validate Required Form Fields.
879
-	give_validate_required_form_fields( $form_id );
878
+	give_validate_required_form_fields($form_id);
880 879
 
881 880
 	// Get the guest email.
882
-	$guest_email = ! empty( $post_data['give_email'] ) ? $post_data['give_email'] : false;
881
+	$guest_email = ! empty($post_data['give_email']) ? $post_data['give_email'] : false;
883 882
 
884 883
 	// Check email.
885
-	if ( $guest_email && strlen( $guest_email ) > 0 ) {
884
+	if ($guest_email && strlen($guest_email) > 0) {
886 885
 
887 886
 		// Validate email.
888
-		if ( ! is_email( $guest_email ) ) {
887
+		if ( ! is_email($guest_email)) {
889 888
 
890 889
 			// Invalid email.
891
-			give_set_error( 'email_invalid', __( 'Invalid email.', 'give' ) );
890
+			give_set_error('email_invalid', __('Invalid email.', 'give'));
892 891
 
893 892
 		} else {
894 893
 
@@ -896,15 +895,15 @@  discard block
 block discarded – undo
896 895
 			$valid_user_data['user_email'] = $guest_email;
897 896
 
898 897
 			// Get user_id from donor if exist.
899
-			$donor = new Give_Donor( $guest_email );
898
+			$donor = new Give_Donor($guest_email);
900 899
 
901
-			if ( $donor->id && $donor->user_id ) {
900
+			if ($donor->id && $donor->user_id) {
902 901
 				$valid_user_data['user_id'] = $donor->user_id;
903 902
 			}
904 903
 		}
905 904
 	} else {
906 905
 		// No email.
907
-		give_set_error( 'email_empty', __( 'Enter an email.', 'give' ) );
906
+		give_set_error('email_empty', __('Enter an email.', 'give'));
908 907
 	}
909 908
 
910 909
 	return $valid_user_data;
@@ -920,36 +919,36 @@  discard block
 block discarded – undo
920 919
  *
921 920
  * @return  integer
922 921
  */
923
-function give_register_and_login_new_user( $user_data = array() ) {
922
+function give_register_and_login_new_user($user_data = array()) {
924 923
 	// Verify the array.
925
-	if ( empty( $user_data ) ) {
926
-		return - 1;
924
+	if (empty($user_data)) {
925
+		return -1;
927 926
 	}
928 927
 
929
-	if ( give_get_errors() ) {
930
-		return - 1;
928
+	if (give_get_errors()) {
929
+		return -1;
931 930
 	}
932 931
 
933
-	$user_args = apply_filters( 'give_insert_user_args', array(
934
-		'user_login'      => isset( $user_data['user_login'] ) ? $user_data['user_login'] : '',
935
-		'user_pass'       => isset( $user_data['user_pass'] ) ? $user_data['user_pass'] : '',
936
-		'user_email'      => isset( $user_data['user_email'] ) ? $user_data['user_email'] : '',
937
-		'first_name'      => isset( $user_data['user_first'] ) ? $user_data['user_first'] : '',
938
-		'last_name'       => isset( $user_data['user_last'] ) ? $user_data['user_last'] : '',
939
-		'user_registered' => date( 'Y-m-d H:i:s' ),
940
-		'role'            => give_get_option( 'donor_default_user_role', 'give_donor' ),
941
-	), $user_data );
932
+	$user_args = apply_filters('give_insert_user_args', array(
933
+		'user_login'      => isset($user_data['user_login']) ? $user_data['user_login'] : '',
934
+		'user_pass'       => isset($user_data['user_pass']) ? $user_data['user_pass'] : '',
935
+		'user_email'      => isset($user_data['user_email']) ? $user_data['user_email'] : '',
936
+		'first_name'      => isset($user_data['user_first']) ? $user_data['user_first'] : '',
937
+		'last_name'       => isset($user_data['user_last']) ? $user_data['user_last'] : '',
938
+		'user_registered' => date('Y-m-d H:i:s'),
939
+		'role'            => give_get_option('donor_default_user_role', 'give_donor'),
940
+	), $user_data);
942 941
 
943 942
 	// Insert new user.
944
-	$user_id = wp_insert_user( $user_args );
943
+	$user_id = wp_insert_user($user_args);
945 944
 
946 945
 	// Validate inserted user.
947
-	if ( is_wp_error( $user_id ) ) {
948
-		return - 1;
946
+	if (is_wp_error($user_id)) {
947
+		return -1;
949 948
 	}
950 949
 
951 950
 	// Allow themes and plugins to filter the user data.
952
-	$user_data = apply_filters( 'give_insert_user_data', $user_data, $user_args );
951
+	$user_data = apply_filters('give_insert_user_data', $user_data, $user_args);
953 952
 
954 953
 	/**
955 954
 	 * Fires after inserting user.
@@ -959,7 +958,7 @@  discard block
 block discarded – undo
959 958
 	 * @param int $user_id User id.
960 959
 	 * @param array $user_data Array containing user data.
961 960
 	 */
962
-	do_action( 'give_insert_user', $user_id, $user_data );
961
+	do_action('give_insert_user', $user_id, $user_data);
963 962
 
964 963
 	/**
965 964
 	 * Filter allow user to alter if user when to login or not when user is register for the first time.
@@ -968,9 +967,9 @@  discard block
 block discarded – undo
968 967
 	 *
969 968
 	 * return bool True if login with registration and False if only want to register.
970 969
 	 */
971
-	if ( true === (bool) apply_filters( 'give_log_user_in_on_register', true ) ) {
970
+	if (true === (bool) apply_filters('give_log_user_in_on_register', true)) {
972 971
 		// Login new user.
973
-		give_log_user_in( $user_id, $user_data['user_login'], $user_data['user_pass'] );
972
+		give_log_user_in($user_id, $user_data['user_login'], $user_data['user_pass']);
974 973
 	}
975 974
 
976 975
 	// Return user id.
@@ -987,33 +986,33 @@  discard block
 block discarded – undo
987 986
  *
988 987
  * @return  array|bool
989 988
  */
990
-function give_get_donation_form_user( $valid_data = array() ) {
989
+function give_get_donation_form_user($valid_data = array()) {
991 990
 
992 991
 	// Initialize user.
993 992
 	$user      = false;
994
-	$is_ajax   = defined( 'DOING_AJAX' ) && DOING_AJAX;
995
-	$post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok.
993
+	$is_ajax   = defined('DOING_AJAX') && DOING_AJAX;
994
+	$post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok.
996 995
 
997
-	if ( $is_ajax ) {
996
+	if ($is_ajax) {
998 997
 
999 998
 		// Do not create or login the user during the ajax submission (check for errors only).
1000 999
 		return true;
1001
-	} elseif ( is_user_logged_in() ) {
1000
+	} elseif (is_user_logged_in()) {
1002 1001
 
1003 1002
 		// Set the valid user as the logged in collected data.
1004 1003
 		$user = $valid_data['logged_in_user'];
1005
-	} elseif ( true === $valid_data['need_new_user'] || true === $valid_data['need_user_login'] ) {
1004
+	} elseif (true === $valid_data['need_new_user'] || true === $valid_data['need_user_login']) {
1006 1005
 
1007 1006
 		// New user registration.
1008
-		if ( true === $valid_data['need_new_user'] ) {
1007
+		if (true === $valid_data['need_new_user']) {
1009 1008
 
1010 1009
 			// Set user.
1011 1010
 			$user = $valid_data['new_user_data'];
1012 1011
 
1013 1012
 			// Register and login new user.
1014
-			$user['user_id'] = give_register_and_login_new_user( $user );
1013
+			$user['user_id'] = give_register_and_login_new_user($user);
1015 1014
 
1016
-		} elseif ( true === $valid_data['need_user_login'] && ! $is_ajax ) {
1015
+		} elseif (true === $valid_data['need_user_login'] && ! $is_ajax) {
1017 1016
 
1018 1017
 			/**
1019 1018
 			 * The login form is now processed in the give_process_donation_login() function.
@@ -1025,42 +1024,42 @@  discard block
 block discarded – undo
1025 1024
 			$user = $valid_data['login_user_data'];
1026 1025
 
1027 1026
 			// Login user.
1028
-			give_log_user_in( $user['user_id'], $user['user_login'], $user['user_pass'] );
1027
+			give_log_user_in($user['user_id'], $user['user_login'], $user['user_pass']);
1029 1028
 		}
1030 1029
 	} // End if().
1031 1030
 
1032 1031
 	// Check guest checkout.
1033
-	if ( false === $user && false === give_logged_in_only( $post_data['give-form-id'] ) ) {
1032
+	if (false === $user && false === give_logged_in_only($post_data['give-form-id'])) {
1034 1033
 
1035 1034
 		// Set user.
1036 1035
 		$user = $valid_data['guest_user_data'];
1037 1036
 	}
1038 1037
 
1039 1038
 	// Verify we have an user.
1040
-	if ( false === $user || empty( $user ) ) {
1039
+	if (false === $user || empty($user)) {
1041 1040
 		return false;
1042 1041
 	}
1043 1042
 
1044 1043
 	// Get user first name.
1045
-	if ( ! isset( $user['user_first'] ) || strlen( trim( $user['user_first'] ) ) < 1 ) {
1046
-		$user['user_first'] = isset( $post_data['give_first'] ) ? strip_tags( trim( $post_data['give_first'] ) ) : '';
1044
+	if ( ! isset($user['user_first']) || strlen(trim($user['user_first'])) < 1) {
1045
+		$user['user_first'] = isset($post_data['give_first']) ? strip_tags(trim($post_data['give_first'])) : '';
1047 1046
 	}
1048 1047
 
1049 1048
 	// Get user last name.
1050
-	if ( ! isset( $user['user_last'] ) || strlen( trim( $user['user_last'] ) ) < 1 ) {
1051
-		$user['user_last'] = isset( $post_data['give_last'] ) ? strip_tags( trim( $post_data['give_last'] ) ) : '';
1049
+	if ( ! isset($user['user_last']) || strlen(trim($user['user_last'])) < 1) {
1050
+		$user['user_last'] = isset($post_data['give_last']) ? strip_tags(trim($post_data['give_last'])) : '';
1052 1051
 	}
1053 1052
 
1054 1053
 	// Get the user's billing address details.
1055 1054
 	$user['address']            = array();
1056
-	$user['address']['line1']   = ! empty( $post_data['card_address'] ) ? $post_data['card_address'] : false;
1057
-	$user['address']['line2']   = ! empty( $post_data['card_address_2'] ) ? $post_data['card_address_2'] : false;
1058
-	$user['address']['city']    = ! empty( $post_data['card_city'] ) ? $post_data['card_city'] : false;
1059
-	$user['address']['state']   = ! empty( $post_data['card_state'] ) ? $post_data['card_state'] : false;
1060
-	$user['address']['zip']     = ! empty( $post_data['card_zip'] ) ? $post_data['card_zip'] : false;
1061
-	$user['address']['country'] = ! empty( $post_data['billing_country'] ) ? $post_data['billing_country'] : false;
1062
-
1063
-	if ( empty( $user['address']['country'] ) ) {
1055
+	$user['address']['line1']   = ! empty($post_data['card_address']) ? $post_data['card_address'] : false;
1056
+	$user['address']['line2']   = ! empty($post_data['card_address_2']) ? $post_data['card_address_2'] : false;
1057
+	$user['address']['city']    = ! empty($post_data['card_city']) ? $post_data['card_city'] : false;
1058
+	$user['address']['state']   = ! empty($post_data['card_state']) ? $post_data['card_state'] : false;
1059
+	$user['address']['zip']     = ! empty($post_data['card_zip']) ? $post_data['card_zip'] : false;
1060
+	$user['address']['country'] = ! empty($post_data['billing_country']) ? $post_data['billing_country'] : false;
1061
+
1062
+	if (empty($user['address']['country'])) {
1064 1063
 		$user['address'] = false;
1065 1064
 	} // End if().
1066 1065
 
@@ -1081,16 +1080,16 @@  discard block
 block discarded – undo
1081 1080
 	$card_data = give_get_donation_cc_info();
1082 1081
 
1083 1082
 	// Validate the card zip.
1084
-	if ( ! empty( $card_data['card_zip'] ) ) {
1085
-		if ( ! give_donation_form_validate_cc_zip( $card_data['card_zip'], $card_data['card_country'] ) ) {
1086
-			give_set_error( 'invalid_cc_zip', __( 'The zip / postal code you entered for your billing address is invalid.', 'give' ) );
1083
+	if ( ! empty($card_data['card_zip'])) {
1084
+		if ( ! give_donation_form_validate_cc_zip($card_data['card_zip'], $card_data['card_country'])) {
1085
+			give_set_error('invalid_cc_zip', __('The zip / postal code you entered for your billing address is invalid.', 'give'));
1087 1086
 		}
1088 1087
 	}
1089 1088
 
1090 1089
 	// Ensure no spaces.
1091
-	if ( ! empty( $card_data['card_number'] ) ) {
1092
-		$card_data['card_number'] = str_replace( '+', '', $card_data['card_number'] ); // no "+" signs.
1093
-		$card_data['card_number'] = str_replace( ' ', '', $card_data['card_number'] ); // No spaces.
1090
+	if ( ! empty($card_data['card_number'])) {
1091
+		$card_data['card_number'] = str_replace('+', '', $card_data['card_number']); // no "+" signs.
1092
+		$card_data['card_number'] = str_replace(' ', '', $card_data['card_number']); // No spaces.
1094 1093
 	}
1095 1094
 
1096 1095
 	// This should validate card numbers at some point too.
@@ -1108,20 +1107,20 @@  discard block
 block discarded – undo
1108 1107
 function give_get_donation_cc_info() {
1109 1108
 
1110 1109
 	// Sanitize the values submitted with donation form.
1111
-	$post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok.
1110
+	$post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok.
1112 1111
 
1113 1112
 	$cc_info                   = array();
1114
-	$cc_info['card_name']      = ! empty( $post_data['card_name'] ) ? $post_data['card_name'] : '';
1115
-	$cc_info['card_number']    = ! empty( $post_data['card_number'] ) ? $post_data['card_number'] : '';
1116
-	$cc_info['card_cvc']       = ! empty( $post_data['card_cvc'] ) ? $post_data['card_cvc'] : '';
1117
-	$cc_info['card_exp_month'] = ! empty( $post_data['card_exp_month'] ) ? $post_data['card_exp_month'] : '';
1118
-	$cc_info['card_exp_year']  = ! empty( $post_data['card_exp_year'] ) ? $post_data['card_exp_year'] : '';
1119
-	$cc_info['card_address']   = ! empty( $post_data['card_address'] ) ? $post_data['card_address'] : '';
1120
-	$cc_info['card_address_2'] = ! empty( $post_data['card_address_2'] ) ? $post_data['card_address_2'] : '';
1121
-	$cc_info['card_city']      = ! empty( $post_data['card_city'] ) ? $post_data['card_city'] : '';
1122
-	$cc_info['card_state']     = ! empty( $post_data['card_state'] ) ? $post_data['card_state'] : '';
1123
-	$cc_info['card_country']   = ! empty( $post_data['billing_country'] ) ? $post_data['billing_country'] : '';
1124
-	$cc_info['card_zip']       = ! empty( $post_data['card_zip'] ) ? $post_data['card_zip'] : '';
1113
+	$cc_info['card_name']      = ! empty($post_data['card_name']) ? $post_data['card_name'] : '';
1114
+	$cc_info['card_number']    = ! empty($post_data['card_number']) ? $post_data['card_number'] : '';
1115
+	$cc_info['card_cvc']       = ! empty($post_data['card_cvc']) ? $post_data['card_cvc'] : '';
1116
+	$cc_info['card_exp_month'] = ! empty($post_data['card_exp_month']) ? $post_data['card_exp_month'] : '';
1117
+	$cc_info['card_exp_year']  = ! empty($post_data['card_exp_year']) ? $post_data['card_exp_year'] : '';
1118
+	$cc_info['card_address']   = ! empty($post_data['card_address']) ? $post_data['card_address'] : '';
1119
+	$cc_info['card_address_2'] = ! empty($post_data['card_address_2']) ? $post_data['card_address_2'] : '';
1120
+	$cc_info['card_city']      = ! empty($post_data['card_city']) ? $post_data['card_city'] : '';
1121
+	$cc_info['card_state']     = ! empty($post_data['card_state']) ? $post_data['card_state'] : '';
1122
+	$cc_info['card_country']   = ! empty($post_data['billing_country']) ? $post_data['billing_country'] : '';
1123
+	$cc_info['card_zip']       = ! empty($post_data['card_zip']) ? $post_data['card_zip'] : '';
1125 1124
 
1126 1125
 	// Return cc info.
1127 1126
 	return $cc_info;
@@ -1137,14 +1136,14 @@  discard block
 block discarded – undo
1137 1136
  *
1138 1137
  * @return bool|mixed
1139 1138
  */
1140
-function give_donation_form_validate_cc_zip( $zip = 0, $country_code = '' ) {
1139
+function give_donation_form_validate_cc_zip($zip = 0, $country_code = '') {
1141 1140
 	$ret = false;
1142 1141
 
1143
-	if ( empty( $zip ) || empty( $country_code ) ) {
1142
+	if (empty($zip) || empty($country_code)) {
1144 1143
 		return $ret;
1145 1144
 	}
1146 1145
 
1147
-	$country_code = strtoupper( $country_code );
1146
+	$country_code = strtoupper($country_code);
1148 1147
 
1149 1148
 	$zip_regex = array(
1150 1149
 		'AD' => 'AD\d{3}',
@@ -1304,11 +1303,11 @@  discard block
 block discarded – undo
1304 1303
 		'ZM' => '\d{5}',
1305 1304
 	);
1306 1305
 
1307
-	if ( ! isset( $zip_regex[ $country_code ] ) || preg_match( '/' . $zip_regex[ $country_code ] . '/i', $zip ) ) {
1306
+	if ( ! isset($zip_regex[$country_code]) || preg_match('/'.$zip_regex[$country_code].'/i', $zip)) {
1308 1307
 		$ret = true;
1309 1308
 	}
1310 1309
 
1311
-	return apply_filters( 'give_is_zip_valid', $ret, $zip, $country_code );
1310
+	return apply_filters('give_is_zip_valid', $ret, $zip, $country_code);
1312 1311
 }
1313 1312
 
1314 1313
 /**
@@ -1320,56 +1319,56 @@  discard block
 block discarded – undo
1320 1319
  *
1321 1320
  * @return bool
1322 1321
  */
1323
-function give_validate_donation_amount( $valid_data ) {
1322
+function give_validate_donation_amount($valid_data) {
1324 1323
 
1325
-	$post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok.
1324
+	$post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok.
1326 1325
 
1327 1326
 	/* @var Give_Donate_Form $form */
1328
-	$form = new Give_Donate_Form( $post_data['give-form-id'] );
1327
+	$form = new Give_Donate_Form($post_data['give-form-id']);
1329 1328
 
1330 1329
 	$donation_level_matched = false;
1331 1330
 
1332
-	if ( $form->is_set_type_donation_form() ) {
1331
+	if ($form->is_set_type_donation_form()) {
1333 1332
 
1334 1333
 		// Sanitize donation amount.
1335
-		$post_data['give-amount'] = give_maybe_sanitize_amount( $post_data['give-amount'] );
1334
+		$post_data['give-amount'] = give_maybe_sanitize_amount($post_data['give-amount']);
1336 1335
 
1337 1336
 		// Backward compatibility.
1338
-		if ( $form->is_custom_price( $post_data['give-amount'] ) ) {
1337
+		if ($form->is_custom_price($post_data['give-amount'])) {
1339 1338
 			$post_data['give-price-id'] = 'custom';
1340 1339
 		}
1341 1340
 
1342 1341
 		$donation_level_matched = true;
1343 1342
 
1344
-	} elseif ( $form->is_multi_type_donation_form() ) {
1343
+	} elseif ($form->is_multi_type_donation_form()) {
1345 1344
 
1346 1345
 		$variable_prices = $form->get_prices();
1347 1346
 
1348 1347
 		// Bailout.
1349
-		if ( ! $variable_prices ) {
1348
+		if ( ! $variable_prices) {
1350 1349
 			return false;
1351 1350
 		}
1352 1351
 
1353 1352
 		// Sanitize donation amount.
1354
-		$post_data['give-amount']     = give_maybe_sanitize_amount( $post_data['give-amount'] );
1355
-		$variable_price_option_amount = give_maybe_sanitize_amount( give_get_price_option_amount( $post_data['give-form-id'], $post_data['give-price-id'] ) );
1353
+		$post_data['give-amount']     = give_maybe_sanitize_amount($post_data['give-amount']);
1354
+		$variable_price_option_amount = give_maybe_sanitize_amount(give_get_price_option_amount($post_data['give-form-id'], $post_data['give-price-id']));
1356 1355
 
1357
-		if ( $post_data['give-amount'] === $variable_price_option_amount ) {
1356
+		if ($post_data['give-amount'] === $variable_price_option_amount) {
1358 1357
 			return true;
1359 1358
 		}
1360 1359
 
1361
-		if ( $form->is_custom_price( $post_data['give-amount'] ) ) {
1360
+		if ($form->is_custom_price($post_data['give-amount'])) {
1362 1361
 			$post_data['give-price-id'] = 'custom';
1363 1362
 		} else {
1364 1363
 
1365 1364
 			// Find correct donation level from all donation levels.
1366
-			foreach ( $variable_prices as $variable_price ) {
1365
+			foreach ($variable_prices as $variable_price) {
1367 1366
 
1368 1367
 				// Sanitize level amount.
1369
-				$variable_price['_give_amount'] = give_maybe_sanitize_amount( $variable_price['_give_amount'] );
1368
+				$variable_price['_give_amount'] = give_maybe_sanitize_amount($variable_price['_give_amount']);
1370 1369
 
1371 1370
 				// Set first match donation level ID.
1372
-				if ( $post_data['give-amount'] === $variable_price['_give_amount'] ) {
1371
+				if ($post_data['give-amount'] === $variable_price['_give_amount']) {
1373 1372
 					$post_data['give-price-id'] = $variable_price['_give_id']['level_id'];
1374 1373
 					break;
1375 1374
 				}
@@ -1378,15 +1377,15 @@  discard block
 block discarded – undo
1378 1377
 
1379 1378
 		// If donation amount is not find in donation levels then check if form has custom donation feature enable or not.
1380 1379
 		// If yes then set price id to custom if amount is greater then custom minimum amount (if any).
1381
-		if ( ! empty( $post_data['give-price-id'] ) ) {
1380
+		if ( ! empty($post_data['give-price-id'])) {
1382 1381
 			$donation_level_matched = true;
1383 1382
 		}
1384 1383
 	} // End if().
1385 1384
 
1386
-	return ( $donation_level_matched ? true : false );
1385
+	return ($donation_level_matched ? true : false);
1387 1386
 }
1388 1387
 
1389
-add_action( 'give_checkout_error_checks', 'give_validate_donation_amount', 10, 1 );
1388
+add_action('give_checkout_error_checks', 'give_validate_donation_amount', 10, 1);
1390 1389
 
1391 1390
 /**
1392 1391
  * Validate Required Form Fields.
@@ -1395,20 +1394,20 @@  discard block
 block discarded – undo
1395 1394
  *
1396 1395
  * @since 2.0
1397 1396
  */
1398
-function give_validate_required_form_fields( $form_id ) {
1397
+function give_validate_required_form_fields($form_id) {
1399 1398
 
1400 1399
 	// Sanitize values submitted with donation form.
1401
-	$post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok.
1400
+	$post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok.
1402 1401
 
1403 1402
 	// Loop through required fields and show error messages.
1404
-	foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) {
1403
+	foreach (give_get_required_fields($form_id) as $field_name => $value) {
1405 1404
 
1406 1405
 		// Clean Up Data of the input fields.
1407
-		$field_value = $post_data[ $field_name ];
1406
+		$field_value = $post_data[$field_name];
1408 1407
 
1409 1408
 		// Check whether the required field is empty, then show the error message.
1410
-		if ( in_array( $value, give_get_required_fields( $form_id ), true ) && empty( $field_value ) ) {
1411
-			give_set_error( $value['error_id'], $value['error_message'] );
1409
+		if (in_array($value, give_get_required_fields($form_id), true) && empty($field_value)) {
1410
+			give_set_error($value['error_id'], $value['error_message']);
1412 1411
 		}
1413 1412
 	}
1414 1413
 }
@@ -1422,12 +1421,12 @@  discard block
 block discarded – undo
1422 1421
  *
1423 1422
  * @return void
1424 1423
  */
1425
-function give_donation_form_validate_name_fields( $post_data ) {
1424
+function give_donation_form_validate_name_fields($post_data) {
1426 1425
 
1427
-	$is_alpha_first_name = ( ! is_email( $post_data['give_first'] ) && ! preg_match( '~[0-9]~', $post_data['give_first'] ) );
1428
-	$is_alpha_last_name  = ( ! is_email( $post_data['give_last'] ) && ! preg_match( '~[0-9]~', $post_data['give_last'] ) );
1426
+	$is_alpha_first_name = ( ! is_email($post_data['give_first']) && ! preg_match('~[0-9]~', $post_data['give_first']));
1427
+	$is_alpha_last_name  = ( ! is_email($post_data['give_last']) && ! preg_match('~[0-9]~', $post_data['give_last']));
1429 1428
 
1430
-	if ( ! $is_alpha_first_name || ( ! empty( $post_data['give_last'] ) && ! $is_alpha_last_name ) ) {
1431
-		give_set_error( 'invalid_name', esc_html__( 'The First Name and Last Name fields cannot contain an email address or numbers.', 'give' ) );
1429
+	if ( ! $is_alpha_first_name || ( ! empty($post_data['give_last']) && ! $is_alpha_last_name)) {
1430
+		give_set_error('invalid_name', esc_html__('The First Name and Last Name fields cannot contain an email address or numbers.', 'give'));
1432 1431
 	}
1433 1432
 }
Please login to merge, or discard this patch.