Test Failed
Pull Request — master (#2079)
by
unknown
08:04
created
includes/filters.php 1 patch
Spacing   +35 added lines, -35 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
 
@@ -26,34 +26,34 @@  discard block
 block discarded – undo
26 26
  *
27 27
  * @return void
28 28
  */
29
-function give_set_settings_with_disable_prefix( $old_settings, $settings ) {
29
+function give_set_settings_with_disable_prefix($old_settings, $settings) {
30 30
 	// Bailout.
31
-	if ( ! function_exists( 'give_v18_renamed_core_settings' ) ) {
31
+	if ( ! function_exists('give_v18_renamed_core_settings')) {
32 32
 		return;
33 33
 	}
34 34
 
35 35
 	// Get old setting names.
36
-	$old_settings   = array_flip( give_v18_renamed_core_settings() );
36
+	$old_settings   = array_flip(give_v18_renamed_core_settings());
37 37
 	$update_setting = false;
38 38
 
39
-	foreach ( $settings as $key => $value ) {
39
+	foreach ($settings as $key => $value) {
40 40
 
41 41
 		// Check 1. Check if new option is really updated or not.
42 42
 		// Check 2. Continue if key is not renamed.
43
-		if ( ! isset( $old_settings[ $key ] ) ) {
43
+		if ( ! isset($old_settings[$key])) {
44 44
 			continue;
45 45
 		}
46 46
 
47 47
 		// Set old setting.
48
-		$settings[ $old_settings[ $key ] ] = 'on';
48
+		$settings[$old_settings[$key]] = 'on';
49 49
 
50 50
 		// Do not need to set old setting if new setting is not set.
51 51
 		if (
52
-			( give_is_setting_enabled( $value ) && ( false !== strpos( $old_settings[ $key ], 'disable_' ) ) )
53
-			|| ( ! give_is_setting_enabled( $value ) && ( false !== strpos( $old_settings[ $key ], 'enable_' ) ) )
52
+			(give_is_setting_enabled($value) && (false !== strpos($old_settings[$key], 'disable_')))
53
+			|| ( ! give_is_setting_enabled($value) && (false !== strpos($old_settings[$key], 'enable_')))
54 54
 
55 55
 		) {
56
-			unset( $settings[ $old_settings[ $key ] ] );
56
+			unset($settings[$old_settings[$key]]);
57 57
 		}
58 58
 
59 59
 		// Tell bot to update setting.
@@ -61,12 +61,12 @@  discard block
 block discarded – undo
61 61
 	}
62 62
 
63 63
 	// Update setting if any old setting set.
64
-	if ( $update_setting ) {
65
-		update_option( 'give_settings', $settings );
64
+	if ($update_setting) {
65
+		update_option('give_settings', $settings);
66 66
 	}
67 67
 }
68 68
 
69
-add_action( 'update_option_give_settings', 'give_set_settings_with_disable_prefix', 10, 2 );
69
+add_action('update_option_give_settings', 'give_set_settings_with_disable_prefix', 10, 2);
70 70
 
71 71
 /**
72 72
  * Check spam through Akismet.
@@ -77,44 +77,44 @@  discard block
 block discarded – undo
77 77
  *
78 78
  * @return bool|mixed
79 79
  */
80
-function give_akismet( $spam ) {
80
+function give_akismet($spam) {
81 81
 
82 82
 	// Bail out, If spam.
83
-	if ( $spam ) {
83
+	if ($spam) {
84 84
 		return $spam;
85 85
 	}
86 86
 
87 87
 	// Bail out, if Akismet key not exist.
88
-	if ( ! give_check_akismet_key() ) {
88
+	if ( ! give_check_akismet_key()) {
89 89
 		return false;
90 90
 	}
91 91
 
92 92
 	// Build args array.
93 93
 	$args = array();
94 94
 
95
-	$args['comment_author']       = isset( $_POST['give_first'] ) ? strip_tags( trim( $_POST['give_first'] ) ) : '';
96
-	$args['comment_author_email'] = isset( $_POST['give_email'] ) ? $_POST['give_email'] : false;
97
-	$args['blog']                 = get_option( 'home' );
95
+	$args['comment_author']       = isset($_POST['give_first']) ? strip_tags(trim($_POST['give_first'])) : '';
96
+	$args['comment_author_email'] = isset($_POST['give_email']) ? $_POST['give_email'] : false;
97
+	$args['blog']                 = get_option('home');
98 98
 	$args['blog_lang']            = get_locale();
99
-	$args['blog_charset']         = get_option( 'blog_charset' );
99
+	$args['blog_charset']         = get_option('blog_charset');
100 100
 	$args['user_ip']              = $_SERVER['REMOTE_ADDR'];
101 101
 	$args['user_agent']           = $_SERVER['HTTP_USER_AGENT'];
102 102
 	$args['referrer']             = $_SERVER['HTTP_REFERER'];
103 103
 	$args['comment_type']         = 'contact-form';
104 104
 
105
-	$ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' );
105
+	$ignore = array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW');
106 106
 
107
-	foreach ( $_SERVER as $key => $value ) {
108
-		if ( ! in_array( $key, (array) $ignore ) ) {
107
+	foreach ($_SERVER as $key => $value) {
108
+		if ( ! in_array($key, (array) $ignore)) {
109 109
 			$args["$key"] = $value;
110 110
 		}
111 111
 	}
112 112
 
113
-	return give_akismet_spam_check( $args );
113
+	return give_akismet_spam_check($args);
114 114
 
115 115
 }
116 116
 
117
-add_filter( 'give_spam', 'give_akismet' );
117
+add_filter('give_spam', 'give_akismet');
118 118
 
119 119
 /**
120 120
  * Check Akismet API Key.
@@ -124,11 +124,11 @@  discard block
 block discarded – undo
124 124
  * @return bool
125 125
  */
126 126
 function give_check_akismet_key() {
127
-	if ( is_callable( array( 'Akismet', 'get_api_key' ) ) ) { // Akismet v3.0+
127
+	if (is_callable(array('Akismet', 'get_api_key'))) { // Akismet v3.0+
128 128
 		return (bool) Akismet::get_api_key();
129 129
 	}
130 130
 
131
-	if ( function_exists( 'akismet_get_key' ) ) {
131
+	if (function_exists('akismet_get_key')) {
132 132
 		return (bool) akismet_get_key();
133 133
 	}
134 134
 
@@ -144,23 +144,23 @@  discard block
 block discarded – undo
144 144
  *
145 145
  * @return bool|mixed
146 146
  */
147
-function give_akismet_spam_check( $args ) {
147
+function give_akismet_spam_check($args) {
148 148
 	global $akismet_api_host, $akismet_api_port;
149 149
 
150 150
 	$spam         = false;
151
-	$query_string = http_build_query( $args );
151
+	$query_string = http_build_query($args);
152 152
 
153
-	if ( is_callable( array( 'Akismet', 'http_post' ) ) ) { // Akismet v3.0+
154
-		$response = Akismet::http_post( $query_string, 'comment-check' );
153
+	if (is_callable(array('Akismet', 'http_post'))) { // Akismet v3.0+
154
+		$response = Akismet::http_post($query_string, 'comment-check');
155 155
 	} else {
156
-		$response = akismet_http_post( $query_string, $akismet_api_host,
157
-			'/1.1/comment-check', $akismet_api_port );
156
+		$response = akismet_http_post($query_string, $akismet_api_host,
157
+			'/1.1/comment-check', $akismet_api_port);
158 158
 	}
159 159
 
160 160
 	// It's spam if response status is true.
161
-	if ( 'true' == $response[1] ) {
161
+	if ('true' == $response[1]) {
162 162
 		$spam = true;
163 163
 	}
164 164
 
165
-	return apply_filters( 'give_akismet_span_check', $spam, $args );
165
+	return apply_filters('give_akismet_span_check', $spam, $args);
166 166
 }
167 167
\ No newline at end of file
Please login to merge, or discard this patch.
includes/process-donation.php 1 patch
Spacing   +252 added lines, -253 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
 
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	 *
31 31
 	 * @since 1.0
32 32
 	 */
33
-	do_action( 'give_pre_process_donation' );
33
+	do_action('give_pre_process_donation');
34 34
 
35 35
 	// Validate the form $_POST data
36 36
 	$valid_data = give_donation_form_validate_fields();
@@ -45,26 +45,26 @@  discard block
 block discarded – undo
45 45
 	 * @param bool|array $valid_data Validate fields.
46 46
 	 * @param array $_POST Array of variables passed via the HTTP POST.
47 47
 	 */
48
-	do_action( 'give_checkout_error_checks', $valid_data, $_POST );
48
+	do_action('give_checkout_error_checks', $valid_data, $_POST);
49 49
 
50
-	$is_ajax = isset( $_POST['give_ajax'] );
50
+	$is_ajax = isset($_POST['give_ajax']);
51 51
 
52 52
 	// Process the login form
53
-	if ( isset( $_POST['give_login_submit'] ) ) {
53
+	if (isset($_POST['give_login_submit'])) {
54 54
 		give_process_form_login();
55 55
 	}
56 56
 
57 57
 	// Validate the user
58
-	$user = give_get_donation_form_user( $valid_data );
58
+	$user = give_get_donation_form_user($valid_data);
59 59
 
60
-	if ( false === $valid_data || give_get_errors() || ! $user ) {
61
-		if ( $is_ajax ) {
60
+	if (false === $valid_data || give_get_errors() || ! $user) {
61
+		if ($is_ajax) {
62 62
 			/**
63 63
 			 * Fires when AJAX sends back errors from the donation form.
64 64
 			 *
65 65
 			 * @since 1.0
66 66
 			 */
67
-			do_action( 'give_ajax_donation_errors' );
67
+			do_action('give_ajax_donation_errors');
68 68
 			give_die();
69 69
 		} else {
70 70
 			return false;
@@ -72,17 +72,17 @@  discard block
 block discarded – undo
72 72
 	}
73 73
 
74 74
 	// If AJAX send back success to proceed with form submission
75
-	if ( $is_ajax ) {
75
+	if ($is_ajax) {
76 76
 		echo 'success';
77 77
 		give_die();
78 78
 	}
79 79
 
80 80
 	// After AJAX: Setup session if not using php_sessions
81
-	if ( ! Give()->session->use_php_sessions() ) {
81
+	if ( ! Give()->session->use_php_sessions()) {
82 82
 		// Double-check that set_cookie is publicly accessible;
83 83
 		// we're using a slightly modified class-wp-sessions.php
84
-		$session_reflection = new ReflectionMethod( 'WP_Session', 'set_cookie' );
85
-		if ( $session_reflection->isPublic() ) {
84
+		$session_reflection = new ReflectionMethod('WP_Session', 'set_cookie');
85
+		if ($session_reflection->isPublic()) {
86 86
 			// Manually set the cookie.
87 87
 			Give()->session->init()->set_cookie();
88 88
 		}
@@ -97,20 +97,19 @@  discard block
 block discarded – undo
97 97
 		'address'    => $user['address'],
98 98
 	);
99 99
 
100
-	$auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
100
+	$auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
101 101
 
102
-	$price        = isset( $_POST['give-amount'] ) ?
103
-		(float) apply_filters( 'give_donation_total', give_maybe_sanitize_amount( $_POST['give-amount'] ) ) :
104
-		'0.00';
105
-	$purchase_key = strtolower( md5( $user['user_email'] . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'give', true ) ) );
102
+	$price        = isset($_POST['give-amount']) ?
103
+		(float) apply_filters('give_donation_total', give_maybe_sanitize_amount($_POST['give-amount'])) : '0.00';
104
+	$purchase_key = strtolower(md5($user['user_email'].date('Y-m-d H:i:s').$auth_key.uniqid('give', true)));
106 105
 
107 106
 	// Setup donation information
108 107
 	$donation_data = array(
109 108
 		'price'        => $price,
110 109
 		'purchase_key' => $purchase_key,
111 110
 		'user_email'   => $user['user_email'],
112
-		'date'         => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
113
-		'user_info'    => stripslashes_deep( $user_info ),
111
+		'date'         => date('Y-m-d H:i:s', current_time('timestamp')),
112
+		'user_info'    => stripslashes_deep($user_info),
114 113
 		'post_data'    => $_POST,
115 114
 		'gateway'      => $valid_data['gateway'],
116 115
 		'card_info'    => $valid_data['cc_info'],
@@ -130,10 +129,10 @@  discard block
 block discarded – undo
130 129
 	 * @param array $user_info Array containing basic user information.
131 130
 	 * @param bool|array $valid_data Validate fields.
132 131
 	 */
133
-	do_action( 'give_checkout_before_gateway', $_POST, $user_info, $valid_data );
132
+	do_action('give_checkout_before_gateway', $_POST, $user_info, $valid_data);
134 133
 
135 134
 	// Sanity check for price
136
-	if ( ! $donation_data['price'] ) {
135
+	if ( ! $donation_data['price']) {
137 136
 		// Revert to manual
138 137
 		$donation_data['gateway'] = 'manual';
139 138
 		$_POST['give-gateway']    = 'manual';
@@ -144,27 +143,27 @@  discard block
 block discarded – undo
144 143
 	 *
145 144
 	 * @since 1.7
146 145
 	 */
147
-	$donation_data = apply_filters( 'give_donation_data_before_gateway', $donation_data, $valid_data );
146
+	$donation_data = apply_filters('give_donation_data_before_gateway', $donation_data, $valid_data);
148 147
 
149 148
 	// Setup the data we're storing in the donation session
150 149
 	$session_data = $donation_data;
151 150
 
152 151
 	// Make sure credit card numbers are never stored in sessions
153
-	unset( $session_data['card_info']['card_number'] );
154
-	unset( $session_data['post_data']['card_number'] );
152
+	unset($session_data['card_info']['card_number']);
153
+	unset($session_data['post_data']['card_number']);
155 154
 
156 155
 	// Used for showing data to non logged-in users after donation, and for other plugins needing donation data.
157
-	give_set_purchase_session( $session_data );
156
+	give_set_purchase_session($session_data);
158 157
 
159 158
 	// Send info to the gateway for payment processing
160
-	give_send_to_gateway( $donation_data['gateway'], $donation_data );
159
+	give_send_to_gateway($donation_data['gateway'], $donation_data);
161 160
 	give_die();
162 161
 
163 162
 }
164 163
 
165
-add_action( 'give_purchase', 'give_process_donation_form' );
166
-add_action( 'wp_ajax_give_process_donation', 'give_process_donation_form' );
167
-add_action( 'wp_ajax_nopriv_give_process_donation', 'give_process_donation_form' );
164
+add_action('give_purchase', 'give_process_donation_form');
165
+add_action('wp_ajax_give_process_donation', 'give_process_donation_form');
166
+add_action('wp_ajax_nopriv_give_process_donation', 'give_process_donation_form');
168 167
 
169 168
 
170 169
 /**
@@ -177,29 +176,29 @@  discard block
 block discarded – undo
177 176
  *
178 177
  * @return void
179 178
  */
180
-function give_check_logged_in_user_for_existing_email( $valid_data, $post ) {
179
+function give_check_logged_in_user_for_existing_email($valid_data, $post) {
181 180
 
182 181
 	// Verify that the email address belongs to this customer.
183
-	if ( is_user_logged_in() ) {
182
+	if (is_user_logged_in()) {
184 183
 
185 184
 		$submitted_email = $valid_data['logged_in_user']['user_email'];
186
-		$donor           = new Give_Donor( get_current_user_id(), true );
185
+		$donor           = new Give_Donor(get_current_user_id(), true);
187 186
 
188 187
 		// If this email address is not registered with this customer, see if it belongs to any other customer
189 188
 		if (
190 189
 			$submitted_email !== $donor->email
191
-			&& ( is_array( $donor->emails ) && ! in_array( $submitted_email, $donor->emails ) )
190
+			&& (is_array($donor->emails) && ! in_array($submitted_email, $donor->emails))
192 191
 		) {
193
-			$found_donor = new Give_Donor( $submitted_email );
192
+			$found_donor = new Give_Donor($submitted_email);
194 193
 
195
-			if ( $found_donor->id > 0 ) {
196
-				give_set_error( 'give-customer-email-exists', sprintf( __( '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' ), $donor->email, $submitted_email ) );
194
+			if ($found_donor->id > 0) {
195
+				give_set_error('give-customer-email-exists', sprintf(__('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'), $donor->email, $submitted_email));
197 196
 			}
198 197
 		}
199 198
 	}
200 199
 }
201 200
 
202
-add_action( 'give_checkout_error_checks', 'give_check_logged_in_user_for_existing_email', 10, 2 );
201
+add_action('give_checkout_error_checks', 'give_check_logged_in_user_for_existing_email', 10, 2);
203 202
 
204 203
 /**
205 204
  * Process the checkout login form
@@ -209,49 +208,49 @@  discard block
 block discarded – undo
209 208
  * @return      void
210 209
  */
211 210
 function give_process_form_login() {
212
-	$is_ajax = isset( $_POST['give_ajax'] );
211
+	$is_ajax = isset($_POST['give_ajax']);
213 212
 
214 213
 	$user_data = give_donation_form_validate_user_login();
215 214
 
216
-	if ( give_get_errors() || $user_data['user_id'] < 1 ) {
217
-		if ( $is_ajax ) {
215
+	if (give_get_errors() || $user_data['user_id'] < 1) {
216
+		if ($is_ajax) {
218 217
 			/**
219 218
 			 * Fires when AJAX sends back errors from the donation form.
220 219
 			 *
221 220
 			 * @since 1.0
222 221
 			 */
223 222
 			ob_start();
224
-			do_action( 'give_ajax_donation_errors' );
223
+			do_action('give_ajax_donation_errors');
225 224
 			$message = ob_get_contents();
226 225
 			ob_end_clean();
227
-			wp_send_json_error( $message );
226
+			wp_send_json_error($message);
228 227
 		} else {
229
-			wp_redirect( $_SERVER['HTTP_REFERER'] );
228
+			wp_redirect($_SERVER['HTTP_REFERER']);
230 229
 			exit;
231 230
 		}
232 231
 	}
233 232
 
234
-	give_log_user_in( $user_data['user_id'], $user_data['user_login'], $user_data['user_pass'] );
233
+	give_log_user_in($user_data['user_id'], $user_data['user_login'], $user_data['user_pass']);
235 234
 
236
-	if ( $is_ajax ) {
235
+	if ($is_ajax) {
237 236
 		$message = Give()->notices->print_frontend_notice(
238 237
 			sprintf(
239 238
 			/* translators: %s: user first name */
240
-				esc_html__( 'Welcome %s! You have successfully logged into your account.', 'give' ),
241
-				( ! empty( $user_data['user_first'] ) ) ? $user_data['user_first'] : $user_data['user_login']
239
+				esc_html__('Welcome %s! You have successfully logged into your account.', 'give'),
240
+				( ! empty($user_data['user_first'])) ? $user_data['user_first'] : $user_data['user_login']
242 241
 			),
243 242
 			false,
244 243
 			'success'
245 244
 		);
246 245
 
247
-		wp_send_json_success( $message );
246
+		wp_send_json_success($message);
248 247
 	} else {
249
-		wp_redirect( $_SERVER['HTTP_REFERER'] );
248
+		wp_redirect($_SERVER['HTTP_REFERER']);
250 249
 	}
251 250
 }
252 251
 
253
-add_action( 'wp_ajax_give_process_donation_login', 'give_process_form_login' );
254
-add_action( 'wp_ajax_nopriv_give_process_donation_login', 'give_process_form_login' );
252
+add_action('wp_ajax_give_process_donation_login', 'give_process_form_login');
253
+add_action('wp_ajax_nopriv_give_process_donation_login', 'give_process_form_login');
255 254
 
256 255
 /**
257 256
  * Donation Form Validate Fields.
@@ -263,60 +262,60 @@  discard block
 block discarded – undo
263 262
 function give_donation_form_validate_fields() {
264 263
 
265 264
 	// Check if there is $_POST
266
-	if ( empty( $_POST ) ) {
265
+	if (empty($_POST)) {
267 266
 		return false;
268 267
 	}
269 268
 
270
-	$form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : '';
269
+	$form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : '';
271 270
 
272 271
 	// Start an array to collect valid data
273 272
 	$valid_data = array(
274 273
 		'gateway'          => give_donation_form_validate_gateway(), // Gateway fallback (amount is validated here)
275
-		'need_new_user'    => false,     // New user flag
276
-		'need_user_login'  => false,     // Login user flag
277
-		'logged_user_data' => array(),   // Logged user collected data
278
-		'new_user_data'    => array(),   // New user collected data
279
-		'login_user_data'  => array(),   // Login user collected data
280
-		'guest_user_data'  => array(),   // Guest user collected data
281
-		'cc_info'          => give_donation_form_validate_cc(),// Credit card info
274
+		'need_new_user'    => false, // New user flag
275
+		'need_user_login'  => false, // Login user flag
276
+		'logged_user_data' => array(), // Logged user collected data
277
+		'new_user_data'    => array(), // New user collected data
278
+		'login_user_data'  => array(), // Login user collected data
279
+		'guest_user_data'  => array(), // Guest user collected data
280
+		'cc_info'          => give_donation_form_validate_cc(), // Credit card info
282 281
 	);
283 282
 
284 283
 	// Validate Honeypot First
285
-	if ( ! empty( $_POST['give-honeypot'] ) ) {
286
-		give_set_error( 'invalid_honeypot', esc_html__( 'Honeypot field detected. Go away bad bot!', 'give' ) );
284
+	if ( ! empty($_POST['give-honeypot'])) {
285
+		give_set_error('invalid_honeypot', esc_html__('Honeypot field detected. Go away bad bot!', 'give'));
287 286
 	}
288 287
 
289 288
 	// Check spam detect.
290
-	if ( is_spam_donation() ) {
291
-		give_set_error( 'invalid_donation', __( 'Spam detected. Go away bad bot!', 'give' ) );
289
+	if (is_spam_donation()) {
290
+		give_set_error('invalid_donation', __('Spam detected. Go away bad bot!', 'give'));
292 291
 	}
293 292
 
294 293
 	// Validate agree to terms
295
-	if ( give_is_terms_enabled( $form_id ) ) {
294
+	if (give_is_terms_enabled($form_id)) {
296 295
 		give_donation_form_validate_agree_to_terms();
297 296
 	}
298 297
 
299 298
 	// Stop processing donor registration, if donor registration is optional and donor can do guest checkout.
300 299
 	// If registration form username field is empty that means donor do not want to registration instead want guest checkout.
301 300
 	if (
302
-		! give_logged_in_only( $form_id )
303
-		&& isset( $_POST['give-purchase-var'] )
301
+		! give_logged_in_only($form_id)
302
+		&& isset($_POST['give-purchase-var'])
304 303
 		&& $_POST['give-purchase-var'] == 'needs-to-register'
305
-		&& empty( $_POST['give_user_login'] )
304
+		&& empty($_POST['give_user_login'])
306 305
 	) {
307
-		unset( $_POST['give-purchase-var'] );
306
+		unset($_POST['give-purchase-var']);
308 307
 	}
309 308
 
310
-	if ( is_user_logged_in() ) {
309
+	if (is_user_logged_in()) {
311 310
 		// Collect logged in user data.
312 311
 		$valid_data['logged_in_user'] = give_donation_form_validate_logged_in_user();
313
-	} elseif ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-register' ) {
312
+	} elseif (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-register') {
314 313
 		// Set new user registration as required.
315 314
 		$valid_data['need_new_user'] = true;
316 315
 		// Validate new user data.
317 316
 		$valid_data['new_user_data'] = give_donation_form_validate_new_user();
318 317
 		// Check if login validation is needed.
319
-	} elseif ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-login' ) {
318
+	} elseif (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-login') {
320 319
 		// Set user login as required.
321 320
 		$valid_data['need_user_login'] = true;
322 321
 		// Validate users login info.
@@ -340,13 +339,13 @@  discard block
 block discarded – undo
340 339
 function is_spam_donation() {
341 340
 	$spam = false;
342 341
 
343
-	$user_agent = (string) isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : "";
342
+	$user_agent = (string) isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";
344 343
 
345
-	if ( strlen( $user_agent ) < 2 ) {
344
+	if (strlen($user_agent) < 2) {
346 345
 		$spam = true;
347 346
 	}
348 347
 
349
-	return apply_filters( 'give_spam', $spam );
348
+	return apply_filters('give_spam', $spam);
350 349
 }
351 350
 
352 351
 /**
@@ -360,41 +359,41 @@  discard block
 block discarded – undo
360 359
  */
361 360
 function give_donation_form_validate_gateway() {
362 361
 
363
-	$form_id = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0;
364
-	$amount  = isset( $_REQUEST['give-amount'] ) ? give_maybe_sanitize_amount( $_REQUEST['give-amount'] ) : 0;
365
-	$gateway = give_get_default_gateway( $form_id );
362
+	$form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0;
363
+	$amount  = isset($_REQUEST['give-amount']) ? give_maybe_sanitize_amount($_REQUEST['give-amount']) : 0;
364
+	$gateway = give_get_default_gateway($form_id);
366 365
 
367 366
 	// Check if a gateway value is present.
368
-	if ( ! empty( $_REQUEST['give-gateway'] ) ) {
367
+	if ( ! empty($_REQUEST['give-gateway'])) {
369 368
 
370
-		$gateway = sanitize_text_field( $_REQUEST['give-gateway'] );
369
+		$gateway = sanitize_text_field($_REQUEST['give-gateway']);
371 370
 
372 371
 		// Is amount being donated in LIVE mode 0.00? If so, error:
373
-		if ( $amount == 0 && ! give_is_test_mode() ) {
372
+		if ($amount == 0 && ! give_is_test_mode()) {
374 373
 
375
-			give_set_error( 'invalid_donation_amount', __( 'Please insert a valid donation amount.', 'give' ) );
374
+			give_set_error('invalid_donation_amount', __('Please insert a valid donation amount.', 'give'));
376 375
 
377 376
 		} // End if().
378
-		elseif ( ! give_verify_minimum_price() ) {
377
+		elseif ( ! give_verify_minimum_price()) {
379 378
 			// translators: %s: minimum donation amount.
380 379
 			give_set_error(
381 380
 				'invalid_donation_minimum',
382 381
 				sprintf(
383 382
 				/* translators: %s: minimum donation amount */
384
-					__( 'This form has a minimum donation amount of %s.', 'give' ),
385
-					give_currency_filter( give_format_amount( give_get_form_minimum_price( $form_id ), array( 'sanitize' => false ) ) )
383
+					__('This form has a minimum donation amount of %s.', 'give'),
384
+					give_currency_filter(give_format_amount(give_get_form_minimum_price($form_id), array('sanitize' => false)))
386 385
 				)
387 386
 			);
388 387
 
389 388
 		} //Is this test mode zero donation? Let it through but set to manual gateway.
390
-		elseif ( $amount == 0 && give_is_test_mode() ) {
389
+		elseif ($amount == 0 && give_is_test_mode()) {
391 390
 
392 391
 			$gateway = 'manual';
393 392
 
394 393
 		} //Check if this gateway is active.
395
-		elseif ( ! give_is_gateway_active( $gateway ) ) {
394
+		elseif ( ! give_is_gateway_active($gateway)) {
396 395
 
397
-			give_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled.', 'give' ) );
396
+			give_set_error('invalid_gateway', __('The selected payment gateway is not enabled.', 'give'));
398 397
 
399 398
 		}
400 399
 	}
@@ -412,21 +411,21 @@  discard block
 block discarded – undo
412 411
  */
413 412
 function give_verify_minimum_price() {
414 413
 
415
-	$amount          = give_maybe_sanitize_amount( $_REQUEST['give-amount'] );
416
-	$form_id         = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0;
417
-	$price_id        = isset( $_REQUEST['give-price-id'] ) ? $_REQUEST['give-price-id'] : null;
418
-	$variable_prices = give_has_variable_prices( $form_id );
414
+	$amount          = give_maybe_sanitize_amount($_REQUEST['give-amount']);
415
+	$form_id         = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0;
416
+	$price_id        = isset($_REQUEST['give-price-id']) ? $_REQUEST['give-price-id'] : null;
417
+	$variable_prices = give_has_variable_prices($form_id);
419 418
 
420
-	if ( $variable_prices && in_array( $price_id, give_get_variable_price_ids( $form_id ) ) ) {
419
+	if ($variable_prices && in_array($price_id, give_get_variable_price_ids($form_id))) {
421 420
 
422
-		$price_level_amount = give_get_price_option_amount( $form_id, $price_id );
421
+		$price_level_amount = give_get_price_option_amount($form_id, $price_id);
423 422
 
424
-		if ( $price_level_amount == $amount ) {
423
+		if ($price_level_amount == $amount) {
425 424
 			return true;
426 425
 		}
427 426
 	}
428 427
 
429
-	if ( give_get_form_minimum_price( $form_id ) > $amount ) {
428
+	if (give_get_form_minimum_price($form_id) > $amount) {
430 429
 		return false;
431 430
 	}
432 431
 
@@ -442,9 +441,9 @@  discard block
 block discarded – undo
442 441
  */
443 442
 function give_donation_form_validate_agree_to_terms() {
444 443
 	// Validate agree to terms.
445
-	if ( ! isset( $_POST['give_agree_to_terms'] ) || $_POST['give_agree_to_terms'] != 1 ) {
444
+	if ( ! isset($_POST['give_agree_to_terms']) || $_POST['give_agree_to_terms'] != 1) {
446 445
 		// User did not agree.
447
-		give_set_error( 'agree_to_terms', apply_filters( 'give_agree_to_terms_text', __( 'You must agree to the terms and conditions.', 'give' ) ) );
446
+		give_set_error('agree_to_terms', apply_filters('give_agree_to_terms_text', __('You must agree to the terms and conditions.', 'give')));
448 447
 	}
449 448
 }
450 449
 
@@ -458,59 +457,59 @@  discard block
 block discarded – undo
458 457
  *
459 458
  * @return      array
460 459
  */
461
-function give_get_required_fields( $form_id ) {
460
+function give_get_required_fields($form_id) {
462 461
 
463
-	$payment_mode = give_get_chosen_gateway( $form_id );
462
+	$payment_mode = give_get_chosen_gateway($form_id);
464 463
 
465 464
 	$required_fields = array(
466 465
 		'give_email' => array(
467 466
 			'error_id'      => 'invalid_email',
468
-			'error_message' => __( 'Please enter a valid email address.', 'give' ),
467
+			'error_message' => __('Please enter a valid email address.', 'give'),
469 468
 		),
470 469
 		'give_first' => array(
471 470
 			'error_id'      => 'invalid_first_name',
472
-			'error_message' => __( 'Please enter your first name.', 'give' ),
471
+			'error_message' => __('Please enter your first name.', 'give'),
473 472
 		),
474 473
 	);
475 474
 
476
-	$require_address = give_require_billing_address( $payment_mode );
475
+	$require_address = give_require_billing_address($payment_mode);
477 476
 
478
-	if ( $require_address ) {
479
-		$required_fields['card_address']    = array(
477
+	if ($require_address) {
478
+		$required_fields['card_address'] = array(
480 479
 			'error_id'      => 'invalid_card_address',
481
-			'error_message' => __( 'Please enter your primary billing address.', 'give' ),
480
+			'error_message' => __('Please enter your primary billing address.', 'give'),
482 481
 		);
483
-		$required_fields['card_zip']        = array(
482
+		$required_fields['card_zip'] = array(
484 483
 			'error_id'      => 'invalid_zip_code',
485
-			'error_message' => __( 'Please enter your zip / postal code.', 'give' ),
484
+			'error_message' => __('Please enter your zip / postal code.', 'give'),
486 485
 		);
487
-		$required_fields['card_city']       = array(
486
+		$required_fields['card_city'] = array(
488 487
 			'error_id'      => 'invalid_city',
489
-			'error_message' => __( 'Please enter your billing city.', 'give' ),
488
+			'error_message' => __('Please enter your billing city.', 'give'),
490 489
 		);
491 490
 		$required_fields['billing_country'] = array(
492 491
 			'error_id'      => 'invalid_country',
493
-			'error_message' => __( 'Please select your billing country.', 'give' ),
492
+			'error_message' => __('Please select your billing country.', 'give'),
494 493
 		);
495 494
 
496 495
 
497 496
 		$required_fields['card_state'] = array(
498 497
 			'error_id'      => 'invalid_state',
499
-			'error_message' => __( 'Please enter billing state / province / County.', 'give' ),
498
+			'error_message' => __('Please enter billing state / province / County.', 'give'),
500 499
 		);
501 500
 
502 501
 		// Check if billing country alredy exists.
503
-		if ( ! empty( $_POST['billing_country'] ) ) {
502
+		if ( ! empty($_POST['billing_country'])) {
504 503
 			// Get the value from $_POST.
505
-			$country = sanitize_text_field( $_POST['billing_country'] );
504
+			$country = sanitize_text_field($_POST['billing_country']);
506 505
 
507 506
 			// Get the country list that does not required any states init.
508 507
 			$states_country = give_states_not_required_country_list();
509 508
 
510 509
 			// Check if states is empty or not.
511
-			if ( array_key_exists( $country, $states_country ) ) {
510
+			if (array_key_exists($country, $states_country)) {
512 511
 				// If states is empty remove the required feilds of state in billing cart.
513
-				unset( $required_fields['card_state'] );
512
+				unset($required_fields['card_state']);
514 513
 			}
515 514
 		}
516 515
 	}
@@ -520,7 +519,7 @@  discard block
 block discarded – undo
520 519
 	 *
521 520
 	 * @since 1.7
522 521
 	 */
523
-	$required_fields = apply_filters( 'give_donation_form_required_fields', $required_fields, $form_id );
522
+	$required_fields = apply_filters('give_donation_form_required_fields', $required_fields, $form_id);
524 523
 
525 524
 	return $required_fields;
526 525
 
@@ -535,16 +534,16 @@  discard block
 block discarded – undo
535 534
  *
536 535
  * @return bool
537 536
  */
538
-function give_require_billing_address( $payment_mode ) {
537
+function give_require_billing_address($payment_mode) {
539 538
 
540 539
 	$return = false;
541 540
 
542
-	if ( isset( $_POST['billing_country'] ) || did_action( "give_{$payment_mode}_cc_form" ) || did_action( 'give_cc_form' ) ) {
541
+	if (isset($_POST['billing_country']) || did_action("give_{$payment_mode}_cc_form") || did_action('give_cc_form')) {
543 542
 		$return = true;
544 543
 	}
545 544
 
546 545
 	// Let payment gateways and other extensions determine if address fields should be required.
547
-	return apply_filters( 'give_require_billing_address', $return );
546
+	return apply_filters('give_require_billing_address', $return);
548 547
 
549 548
 }
550 549
 
@@ -558,42 +557,42 @@  discard block
 block discarded – undo
558 557
 function give_donation_form_validate_logged_in_user() {
559 558
 	global $user_ID;
560 559
 
561
-	$form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : '';
560
+	$form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : '';
562 561
 
563 562
 	// Start empty array to collect valid user data.
564 563
 	$valid_user_data = array(
565 564
 		// Assume there will be errors.
566
-		'user_id' => - 1,
565
+		'user_id' => -1,
567 566
 	);
568 567
 
569 568
 	// Verify there is a user_ID.
570
-	if ( $user_ID > 0 ) {
569
+	if ($user_ID > 0) {
571 570
 		// Get the logged in user data.
572
-		$user_data = get_userdata( $user_ID );
571
+		$user_data = get_userdata($user_ID);
573 572
 
574 573
 		// Loop through required fields and show error messages.
575
-		foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) {
576
-			if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) {
577
-				give_set_error( $value['error_id'], $value['error_message'] );
574
+		foreach (give_get_required_fields($form_id) as $field_name => $value) {
575
+			if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) {
576
+				give_set_error($value['error_id'], $value['error_message']);
578 577
 			}
579 578
 		}
580 579
 
581 580
 		// Verify data.
582
-		if ( $user_data ) {
581
+		if ($user_data) {
583 582
 			// Collected logged in user data.
584 583
 			$valid_user_data = array(
585 584
 				'user_id'    => $user_ID,
586
-				'user_email' => isset( $_POST['give_email'] ) ? sanitize_email( $_POST['give_email'] ) : $user_data->user_email,
587
-				'user_first' => isset( $_POST['give_first'] ) && ! empty( $_POST['give_first'] ) ? sanitize_text_field( $_POST['give_first'] ) : $user_data->first_name,
588
-				'user_last'  => isset( $_POST['give_last'] ) && ! empty( $_POST['give_last'] ) ? sanitize_text_field( $_POST['give_last'] ) : $user_data->last_name,
585
+				'user_email' => isset($_POST['give_email']) ? sanitize_email($_POST['give_email']) : $user_data->user_email,
586
+				'user_first' => isset($_POST['give_first']) && ! empty($_POST['give_first']) ? sanitize_text_field($_POST['give_first']) : $user_data->first_name,
587
+				'user_last'  => isset($_POST['give_last']) && ! empty($_POST['give_last']) ? sanitize_text_field($_POST['give_last']) : $user_data->last_name,
589 588
 			);
590 589
 
591
-			if ( ! is_email( $valid_user_data['user_email'] ) ) {
592
-				give_set_error( 'email_invalid', esc_html__( 'Invalid email.', 'give' ) );
590
+			if ( ! is_email($valid_user_data['user_email'])) {
591
+				give_set_error('email_invalid', esc_html__('Invalid email.', 'give'));
593 592
 			}
594 593
 		} else {
595 594
 			// Set invalid user error.
596
-			give_set_error( 'invalid_user', esc_html__( 'The user information is invalid.', 'give' ) );
595
+			give_set_error('invalid_user', esc_html__('The user information is invalid.', 'give'));
597 596
 		}
598 597
 	}
599 598
 
@@ -612,7 +611,7 @@  discard block
 block discarded – undo
612 611
 	// Default user data.
613 612
 	$default_user_data = array(
614 613
 		'give-form-id'           => '',
615
-		'user_id'                => - 1, // Assume there will be errors.
614
+		'user_id'                => -1, // Assume there will be errors.
616 615
 		'user_first'             => '',
617 616
 		'user_last'              => '',
618 617
 		'give_user_login'        => false,
@@ -622,14 +621,14 @@  discard block
 block discarded – undo
622 621
 	);
623 622
 
624 623
 	// Get user data.
625
-	$user_data            = wp_parse_args( array_map( 'trim', give_clean( $_POST ) ), $default_user_data );
624
+	$user_data            = wp_parse_args(array_map('trim', give_clean($_POST)), $default_user_data);
626 625
 	$registering_new_user = false;
627
-	$form_id              = absint( $user_data['give-form-id'] );
626
+	$form_id              = absint($user_data['give-form-id']);
628 627
 
629 628
 	// Start an empty array to collect valid user data.
630 629
 	$valid_user_data = array(
631 630
 		// Assume there will be errors.
632
-		'user_id'    => - 1,
631
+		'user_id'    => -1,
633 632
 
634 633
 		// Get first name.
635 634
 		'user_first' => $user_data['give_first'],
@@ -639,25 +638,25 @@  discard block
 block discarded – undo
639 638
 	);
640 639
 
641 640
 	// Loop through required fields and show error messages.
642
-	foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) {
643
-		if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) {
644
-			give_set_error( $value['error_id'], $value['error_message'] );
641
+	foreach (give_get_required_fields($form_id) as $field_name => $value) {
642
+		if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) {
643
+			give_set_error($value['error_id'], $value['error_message']);
645 644
 		}
646 645
 	}
647 646
 
648 647
 	// Check if we have an username to register.
649
-	if ( give_validate_username( $user_data['give_user_login'] ) ) {
648
+	if (give_validate_username($user_data['give_user_login'])) {
650 649
 		$registering_new_user          = true;
651 650
 		$valid_user_data['user_login'] = $user_data['give_user_login'];
652 651
 	}
653 652
 
654 653
 	// Check if we have an email to verify.
655
-	if ( give_validate_user_email( $user_data['give_email'], $registering_new_user ) ) {
654
+	if (give_validate_user_email($user_data['give_email'], $registering_new_user)) {
656 655
 		$valid_user_data['user_email'] = $user_data['give_email'];
657 656
 	}
658 657
 
659 658
 	// Check password.
660
-	if ( give_validate_user_password( $user_data['give_user_pass'], $user_data['give_user_pass_confirm'], $registering_new_user ) ) {
659
+	if (give_validate_user_password($user_data['give_user_pass'], $user_data['give_user_pass_confirm'], $registering_new_user)) {
661 660
 		// All is good to go.
662 661
 		$valid_user_data['user_pass'] = $user_data['give_user_pass'];
663 662
 	}
@@ -677,36 +676,36 @@  discard block
 block discarded – undo
677 676
 	// Start an array to collect valid user data.
678 677
 	$valid_user_data = array(
679 678
 		// Assume there will be errors.
680
-		'user_id' => - 1,
679
+		'user_id' => -1,
681 680
 	);
682 681
 
683 682
 	// Username.
684
-	if ( ! isset( $_POST['give_user_login'] ) || $_POST['give_user_login'] == '' ) {
685
-		give_set_error( 'must_log_in', __( 'You must register or login to complete your donation.', 'give' ) );
683
+	if ( ! isset($_POST['give_user_login']) || $_POST['give_user_login'] == '') {
684
+		give_set_error('must_log_in', __('You must register or login to complete your donation.', 'give'));
686 685
 
687 686
 		return $valid_user_data;
688 687
 	}
689 688
 
690 689
 	// Get the user by login.
691
-	$user_data = get_user_by( 'login', strip_tags( $_POST['give_user_login'] ) );
690
+	$user_data = get_user_by('login', strip_tags($_POST['give_user_login']));
692 691
 
693 692
 	// Check if user exists.
694
-	if ( $user_data ) {
693
+	if ($user_data) {
695 694
 		// Get password.
696
-		$user_pass = isset( $_POST['give_user_pass'] ) ? $_POST['give_user_pass'] : false;
695
+		$user_pass = isset($_POST['give_user_pass']) ? $_POST['give_user_pass'] : false;
697 696
 
698 697
 		// Check user_pass.
699
-		if ( $user_pass ) {
698
+		if ($user_pass) {
700 699
 			// Check if password is valid.
701
-			if ( ! wp_check_password( $user_pass, $user_data->user_pass, $user_data->ID ) ) {
700
+			if ( ! wp_check_password($user_pass, $user_data->user_pass, $user_data->ID)) {
702 701
 				// Incorrect password.
703 702
 				give_set_error(
704 703
 					'password_incorrect',
705 704
 					sprintf(
706 705
 						'%1$s <a href="%2$s">%3$s</a>',
707
-						__( 'The password you entered is incorrect.', 'give' ),
708
-						wp_lostpassword_url( "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ),
709
-						__( 'Reset Password', 'give' )
706
+						__('The password you entered is incorrect.', 'give'),
707
+						wp_lostpassword_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"),
708
+						__('Reset Password', 'give')
710 709
 					)
711 710
 				);
712 711
 				// All is correct.
@@ -723,11 +722,11 @@  discard block
 block discarded – undo
723 722
 			}
724 723
 		} else {
725 724
 			// Empty password.
726
-			give_set_error( 'password_empty', __( 'Enter a password.', 'give' ) );
725
+			give_set_error('password_empty', __('Enter a password.', 'give'));
727 726
 		}
728 727
 	} else {
729 728
 		// No username.
730
-		give_set_error( 'username_incorrect', __( 'The username you entered does not exist.', 'give' ) );
729
+		give_set_error('username_incorrect', __('The username you entered does not exist.', 'give'));
731 730
 	}// End if().
732 731
 
733 732
 	return $valid_user_data;
@@ -742,7 +741,7 @@  discard block
 block discarded – undo
742 741
  */
743 742
 function give_donation_form_validate_guest_user() {
744 743
 
745
-	$form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : '';
744
+	$form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : '';
746 745
 
747 746
 	// Start an array to collect valid user data.
748 747
 	$valid_user_data = array(
@@ -751,38 +750,38 @@  discard block
 block discarded – undo
751 750
 	);
752 751
 
753 752
 	// Show error message if user must be logged in.
754
-	if ( give_logged_in_only( $form_id ) ) {
755
-		give_set_error( 'logged_in_only', __( 'You must be logged in to donate.', 'give' ) );
753
+	if (give_logged_in_only($form_id)) {
754
+		give_set_error('logged_in_only', __('You must be logged in to donate.', 'give'));
756 755
 	}
757 756
 
758 757
 	// Get the guest email.
759
-	$guest_email = isset( $_POST['give_email'] ) ? $_POST['give_email'] : false;
758
+	$guest_email = isset($_POST['give_email']) ? $_POST['give_email'] : false;
760 759
 
761 760
 	// Check email.
762
-	if ( $guest_email && strlen( $guest_email ) > 0 ) {
761
+	if ($guest_email && strlen($guest_email) > 0) {
763 762
 		// Validate email.
764
-		if ( ! is_email( $guest_email ) ) {
763
+		if ( ! is_email($guest_email)) {
765 764
 			// Invalid email.
766
-			give_set_error( 'email_invalid', __( 'Invalid email.', 'give' ) );
765
+			give_set_error('email_invalid', __('Invalid email.', 'give'));
767 766
 		} else {
768 767
 			// All is good to go.
769 768
 			$valid_user_data['user_email'] = $guest_email;
770 769
 
771 770
 			// Get user_id from donor if exist.
772
-			$donor = new Give_Donor( $guest_email );
773
-			if ( $donor->id && $donor->user_id ) {
771
+			$donor = new Give_Donor($guest_email);
772
+			if ($donor->id && $donor->user_id) {
774 773
 				$valid_user_data['user_id'] = $donor->user_id;
775 774
 			}
776 775
 		}
777 776
 	} else {
778 777
 		// No email.
779
-		give_set_error( 'email_empty', __( 'Enter an email.', 'give' ) );
778
+		give_set_error('email_empty', __('Enter an email.', 'give'));
780 779
 	}
781 780
 
782 781
 	// Loop through required fields and show error messages.
783
-	foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) {
784
-		if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) {
785
-			give_set_error( $value['error_id'], $value['error_message'] );
782
+	foreach (give_get_required_fields($form_id) as $field_name => $value) {
783
+		if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) {
784
+			give_set_error($value['error_id'], $value['error_message']);
786 785
 		}
787 786
 	}
788 787
 
@@ -798,36 +797,36 @@  discard block
 block discarded – undo
798 797
  * @since   1.0
799 798
  * @return  integer
800 799
  */
801
-function give_register_and_login_new_user( $user_data = array() ) {
800
+function give_register_and_login_new_user($user_data = array()) {
802 801
 	// Verify the array.
803
-	if ( empty( $user_data ) ) {
804
-		return - 1;
802
+	if (empty($user_data)) {
803
+		return -1;
805 804
 	}
806 805
 
807
-	if ( give_get_errors() ) {
808
-		return - 1;
806
+	if (give_get_errors()) {
807
+		return -1;
809 808
 	}
810 809
 
811
-	$user_args = apply_filters( 'give_insert_user_args', array(
812
-		'user_login'      => isset( $user_data['user_login'] ) ? $user_data['user_login'] : '',
813
-		'user_pass'       => isset( $user_data['user_pass'] ) ? $user_data['user_pass'] : '',
814
-		'user_email'      => isset( $user_data['user_email'] ) ? $user_data['user_email'] : '',
815
-		'first_name'      => isset( $user_data['user_first'] ) ? $user_data['user_first'] : '',
816
-		'last_name'       => isset( $user_data['user_last'] ) ? $user_data['user_last'] : '',
817
-		'user_registered' => date( 'Y-m-d H:i:s' ),
818
-		'role'            => give_get_option( 'donor_default_user_role', 'give_donor' ),
819
-	), $user_data );
810
+	$user_args = apply_filters('give_insert_user_args', array(
811
+		'user_login'      => isset($user_data['user_login']) ? $user_data['user_login'] : '',
812
+		'user_pass'       => isset($user_data['user_pass']) ? $user_data['user_pass'] : '',
813
+		'user_email'      => isset($user_data['user_email']) ? $user_data['user_email'] : '',
814
+		'first_name'      => isset($user_data['user_first']) ? $user_data['user_first'] : '',
815
+		'last_name'       => isset($user_data['user_last']) ? $user_data['user_last'] : '',
816
+		'user_registered' => date('Y-m-d H:i:s'),
817
+		'role'            => give_get_option('donor_default_user_role', 'give_donor'),
818
+	), $user_data);
820 819
 
821 820
 	// Insert new user.
822
-	$user_id = wp_insert_user( $user_args );
821
+	$user_id = wp_insert_user($user_args);
823 822
 
824 823
 	// Validate inserted user.
825
-	if ( is_wp_error( $user_id ) ) {
826
-		return - 1;
824
+	if (is_wp_error($user_id)) {
825
+		return -1;
827 826
 	}
828 827
 
829 828
 	// Allow themes and plugins to filter the user data.
830
-	$user_data = apply_filters( 'give_insert_user_data', $user_data, $user_args );
829
+	$user_data = apply_filters('give_insert_user_data', $user_data, $user_args);
831 830
 
832 831
 	/**
833 832
 	 * Fires after inserting user.
@@ -837,7 +836,7 @@  discard block
 block discarded – undo
837 836
 	 * @param int $user_id User id.
838 837
 	 * @param array $user_data Array containing user data.
839 838
 	 */
840
-	do_action( 'give_insert_user', $user_id, $user_data );
839
+	do_action('give_insert_user', $user_id, $user_data);
841 840
 
842 841
 	/**
843 842
 	 * Filter allow user to alter if user when to login or not when user is register for the first time.
@@ -846,9 +845,9 @@  discard block
 block discarded – undo
846 845
 	 *
847 846
 	 * return bool True if login with registration and False if only want to register.
848 847
 	 */
849
-	if ( true === (bool) apply_filters( 'give_log_user_in_on_register', true ) ) {
848
+	if (true === (bool) apply_filters('give_log_user_in_on_register', true)) {
850 849
 		// Login new user.
851
-		give_log_user_in( $user_id, $user_data['user_login'], $user_data['user_pass'] );
850
+		give_log_user_in($user_id, $user_data['user_login'], $user_data['user_pass']);
852 851
 	}
853 852
 
854 853
 	// Return user id.
@@ -864,27 +863,27 @@  discard block
 block discarded – undo
864 863
  * @since   1.0
865 864
  * @return  array|bool
866 865
  */
867
-function give_get_donation_form_user( $valid_data = array() ) {
866
+function give_get_donation_form_user($valid_data = array()) {
868 867
 
869 868
 	// Initialize user.
870 869
 	$user    = false;
871
-	$is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
870
+	$is_ajax = defined('DOING_AJAX') && DOING_AJAX;
872 871
 
873
-	if ( $is_ajax ) {
872
+	if ($is_ajax) {
874 873
 		// Do not create or login the user during the ajax submission (check for errors only).
875 874
 		return true;
876
-	} elseif ( is_user_logged_in() ) {
875
+	} elseif (is_user_logged_in()) {
877 876
 		// Set the valid user as the logged in collected data.
878 877
 		$user = $valid_data['logged_in_user'];
879
-	} elseif ( $valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true ) {
878
+	} elseif ($valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true) {
880 879
 		// New user registration.
881
-		if ( $valid_data['need_new_user'] === true ) {
880
+		if ($valid_data['need_new_user'] === true) {
882 881
 			// Set user.
883 882
 			$user = $valid_data['new_user_data'];
884 883
 			// Register and login new user.
885
-			$user['user_id'] = give_register_and_login_new_user( $user );
884
+			$user['user_id'] = give_register_and_login_new_user($user);
886 885
 			// User login
887
-		} elseif ( $valid_data['need_user_login'] === true && ! $is_ajax ) {
886
+		} elseif ($valid_data['need_user_login'] === true && ! $is_ajax) {
888 887
 
889 888
 			/**
890 889
 			 * The login form is now processed in the give_process_donation_login() function.
@@ -896,48 +895,48 @@  discard block
 block discarded – undo
896 895
 			// Set user.
897 896
 			$user = $valid_data['login_user_data'];
898 897
 			// Login user.
899
-			give_log_user_in( $user['user_id'], $user['user_login'], $user['user_pass'] );
898
+			give_log_user_in($user['user_id'], $user['user_login'], $user['user_pass']);
900 899
 		}
901 900
 	}
902 901
 
903 902
 	// Check guest checkout.
904
-	if ( false === $user && false === give_logged_in_only( $_POST['give-form-id'] ) ) {
903
+	if (false === $user && false === give_logged_in_only($_POST['give-form-id'])) {
905 904
 		// Set user
906 905
 		$user = $valid_data['guest_user_data'];
907 906
 	}
908 907
 
909 908
 	// Verify we have an user.
910
-	if ( false === $user || empty( $user ) ) {
909
+	if (false === $user || empty($user)) {
911 910
 		// Return false.
912 911
 		return false;
913 912
 	}
914 913
 
915 914
 	// Get user first name.
916
-	if ( ! isset( $user['user_first'] ) || strlen( trim( $user['user_first'] ) ) < 1 ) {
917
-		$user['user_first'] = isset( $_POST['give_first'] ) ? strip_tags( trim( $_POST['give_first'] ) ) : '';
915
+	if ( ! isset($user['user_first']) || strlen(trim($user['user_first'])) < 1) {
916
+		$user['user_first'] = isset($_POST['give_first']) ? strip_tags(trim($_POST['give_first'])) : '';
918 917
 	}
919 918
 
920 919
 	// Get user last name.
921
-	if ( ! isset( $user['user_last'] ) || strlen( trim( $user['user_last'] ) ) < 1 ) {
922
-		$user['user_last'] = isset( $_POST['give_last'] ) ? strip_tags( trim( $_POST['give_last'] ) ) : '';
920
+	if ( ! isset($user['user_last']) || strlen(trim($user['user_last'])) < 1) {
921
+		$user['user_last'] = isset($_POST['give_last']) ? strip_tags(trim($_POST['give_last'])) : '';
923 922
 	}
924 923
 
925 924
 	// Get the user's billing address details.
926 925
 	$user['address']            = array();
927
-	$user['address']['line1']   = ! empty( $_POST['card_address'] ) ? give_clean( $_POST['card_address'] ) : false;
928
-	$user['address']['line2']   = ! empty( $_POST['card_address_2'] ) ? give_clean( $_POST['card_address_2'] ) : false;
929
-	$user['address']['city']    = ! empty( $_POST['card_city'] ) ? give_clean( $_POST['card_city'] ) : false;
930
-	$user['address']['state']   = ! empty( $_POST['card_state'] ) ? give_clean( $_POST['card_state'] ) : false;
931
-	$user['address']['zip']     = ! empty( $_POST['card_zip'] ) ? give_clean( $_POST['card_zip'] ) : false;
932
-	$user['address']['country'] = ! empty( $_POST['billing_country'] ) ? give_clean( $_POST['billing_country'] ) : false;
933
-
934
-	if ( empty( $user['address']['country'] ) ) {
926
+	$user['address']['line1']   = ! empty($_POST['card_address']) ? give_clean($_POST['card_address']) : false;
927
+	$user['address']['line2']   = ! empty($_POST['card_address_2']) ? give_clean($_POST['card_address_2']) : false;
928
+	$user['address']['city']    = ! empty($_POST['card_city']) ? give_clean($_POST['card_city']) : false;
929
+	$user['address']['state']   = ! empty($_POST['card_state']) ? give_clean($_POST['card_state']) : false;
930
+	$user['address']['zip']     = ! empty($_POST['card_zip']) ? give_clean($_POST['card_zip']) : false;
931
+	$user['address']['country'] = ! empty($_POST['billing_country']) ? give_clean($_POST['billing_country']) : false;
932
+
933
+	if (empty($user['address']['country'])) {
935 934
 		$user['address'] = false;
936 935
 	} // End if().
937 936
 
938
-	if ( ! empty( $user['user_id'] ) && $user['user_id'] > 0 && ! empty( $user['address'] ) ) {
937
+	if ( ! empty($user['user_id']) && $user['user_id'] > 0 && ! empty($user['address'])) {
939 938
 		// Store the address in the user's meta so the donation form can be pre-populated with it on return donation.
940
-		update_user_meta( $user['user_id'], '_give_user_address', $user['address'] );
939
+		update_user_meta($user['user_id'], '_give_user_address', $user['address']);
941 940
 	}
942 941
 
943 942
 	// Return valid user.
@@ -956,16 +955,16 @@  discard block
 block discarded – undo
956 955
 	$card_data = give_get_donation_cc_info();
957 956
 
958 957
 	// Validate the card zip.
959
-	if ( ! empty( $card_data['card_zip'] ) ) {
960
-		if ( ! give_donation_form_validate_cc_zip( $card_data['card_zip'], $card_data['card_country'] ) ) {
961
-			give_set_error( 'invalid_cc_zip', __( 'The zip / postal code you entered for your billing address is invalid.', 'give' ) );
958
+	if ( ! empty($card_data['card_zip'])) {
959
+		if ( ! give_donation_form_validate_cc_zip($card_data['card_zip'], $card_data['card_country'])) {
960
+			give_set_error('invalid_cc_zip', __('The zip / postal code you entered for your billing address is invalid.', 'give'));
962 961
 		}
963 962
 	}
964 963
 
965 964
 	// Ensure no spaces.
966
-	if ( ! empty( $card_data['card_number'] ) ) {
967
-		$card_data['card_number'] = str_replace( '+', '', $card_data['card_number'] ); // no "+" signs
968
-		$card_data['card_number'] = str_replace( ' ', '', $card_data['card_number'] ); // No spaces
965
+	if ( ! empty($card_data['card_number'])) {
966
+		$card_data['card_number'] = str_replace('+', '', $card_data['card_number']); // no "+" signs
967
+		$card_data['card_number'] = str_replace(' ', '', $card_data['card_number']); // No spaces
969 968
 	}
970 969
 
971 970
 	// This should validate card numbers at some point too.
@@ -982,17 +981,17 @@  discard block
 block discarded – undo
982 981
 function give_get_donation_cc_info() {
983 982
 
984 983
 	$cc_info                   = array();
985
-	$cc_info['card_name']      = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : '';
986
-	$cc_info['card_number']    = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : '';
987
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : '';
988
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : '';
989
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : '';
990
-	$cc_info['card_address']   = isset( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : '';
991
-	$cc_info['card_address_2'] = isset( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : '';
992
-	$cc_info['card_city']      = isset( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : '';
993
-	$cc_info['card_state']     = isset( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : '';
994
-	$cc_info['card_country']   = isset( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : '';
995
-	$cc_info['card_zip']       = isset( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : '';
984
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
985
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
986
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
987
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
988
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
989
+	$cc_info['card_address']   = isset($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : '';
990
+	$cc_info['card_address_2'] = isset($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : '';
991
+	$cc_info['card_city']      = isset($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : '';
992
+	$cc_info['card_state']     = isset($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : '';
993
+	$cc_info['card_country']   = isset($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : '';
994
+	$cc_info['card_zip']       = isset($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : '';
996 995
 
997 996
 	// Return cc info.
998 997
 	return $cc_info;
@@ -1008,14 +1007,14 @@  discard block
 block discarded – undo
1008 1007
  *
1009 1008
  * @return bool|mixed
1010 1009
  */
1011
-function give_donation_form_validate_cc_zip( $zip = 0, $country_code = '' ) {
1010
+function give_donation_form_validate_cc_zip($zip = 0, $country_code = '') {
1012 1011
 	$ret = false;
1013 1012
 
1014
-	if ( empty( $zip ) || empty( $country_code ) ) {
1013
+	if (empty($zip) || empty($country_code)) {
1015 1014
 		return $ret;
1016 1015
 	}
1017 1016
 
1018
-	$country_code = strtoupper( $country_code );
1017
+	$country_code = strtoupper($country_code);
1019 1018
 
1020 1019
 	$zip_regex = array(
1021 1020
 		'AD' => 'AD\d{3}',
@@ -1175,11 +1174,11 @@  discard block
 block discarded – undo
1175 1174
 		'ZM' => '\d{5}',
1176 1175
 	);
1177 1176
 
1178
-	if ( ! isset( $zip_regex[ $country_code ] ) || preg_match( '/' . $zip_regex[ $country_code ] . '/i', $zip ) ) {
1177
+	if ( ! isset($zip_regex[$country_code]) || preg_match('/'.$zip_regex[$country_code].'/i', $zip)) {
1179 1178
 		$ret = true;
1180 1179
 	}
1181 1180
 
1182
-	return apply_filters( 'give_is_zip_valid', $ret, $zip, $country_code );
1181
+	return apply_filters('give_is_zip_valid', $ret, $zip, $country_code);
1183 1182
 }
1184 1183
 
1185 1184
 
@@ -1193,33 +1192,33 @@  discard block
 block discarded – undo
1193 1192
  *
1194 1193
  * @return bool
1195 1194
  */
1196
-function give_validate_multi_donation_form_level( $valid_data, $data ) {
1195
+function give_validate_multi_donation_form_level($valid_data, $data) {
1197 1196
 	/* @var Give_Donate_Form $form */
1198
-	$form = new Give_Donate_Form( $data['give-form-id'] );
1197
+	$form = new Give_Donate_Form($data['give-form-id']);
1199 1198
 
1200 1199
 	$donation_level_matched = false;
1201 1200
 
1202
-	if ( $form->is_multi_type_donation_form() ) {
1201
+	if ($form->is_multi_type_donation_form()) {
1203 1202
 
1204 1203
 		// Bailout.
1205
-		if ( ! ( $variable_prices = $form->get_prices() ) ) {
1204
+		if ( ! ($variable_prices = $form->get_prices())) {
1206 1205
 			return false;
1207 1206
 		}
1208 1207
 
1209 1208
 		// Sanitize donation amount.
1210
-		$data['give-amount'] = give_maybe_sanitize_amount( $data['give-amount'] );
1209
+		$data['give-amount'] = give_maybe_sanitize_amount($data['give-amount']);
1211 1210
 
1212
-		if ( $data['give-amount'] === give_maybe_sanitize_amount( give_get_price_option_amount( $data['give-form-id'], $data['give-price-id'] ) ) ) {
1211
+		if ($data['give-amount'] === give_maybe_sanitize_amount(give_get_price_option_amount($data['give-form-id'], $data['give-price-id']))) {
1213 1212
 			return true;
1214 1213
 		}
1215 1214
 
1216 1215
 		// Find correct donation level from all donation levels.
1217
-		foreach ( $variable_prices as $variable_price ) {
1216
+		foreach ($variable_prices as $variable_price) {
1218 1217
 			// Sanitize level amount.
1219
-			$variable_price['_give_amount'] = give_maybe_sanitize_amount( $variable_price['_give_amount'] );
1218
+			$variable_price['_give_amount'] = give_maybe_sanitize_amount($variable_price['_give_amount']);
1220 1219
 
1221 1220
 			// Set first match donation level ID.
1222
-			if ( $data['give-amount'] === $variable_price['_give_amount'] ) {
1221
+			if ($data['give-amount'] === $variable_price['_give_amount']) {
1223 1222
 				$_POST['give-price-id'] = $variable_price['_give_id']['level_id'];
1224 1223
 				$donation_level_matched = true;
1225 1224
 				break;
@@ -1230,19 +1229,19 @@  discard block
 block discarded – undo
1230 1229
 		// If yes then set price id to custom if amount is greater then custom minimum amount (if any).
1231 1230
 		if (
1232 1231
 			! $donation_level_matched
1233
-			&& ( give_is_setting_enabled( give_get_meta( $data['give-form-id'], '_give_custom_amount', true ) ) )
1232
+			&& (give_is_setting_enabled(give_get_meta($data['give-form-id'], '_give_custom_amount', true)))
1234 1233
 		) {
1235 1234
 			// Sanitize custom minimum amount.
1236
-			$custom_minimum_amount = give_maybe_sanitize_amount( give_get_meta( $data['give-form-id'], '_give_custom_amount_minimum', true ) );
1235
+			$custom_minimum_amount = give_maybe_sanitize_amount(give_get_meta($data['give-form-id'], '_give_custom_amount_minimum', true));
1237 1236
 
1238
-			if ( $data['give-amount'] >= $custom_minimum_amount ) {
1237
+			if ($data['give-amount'] >= $custom_minimum_amount) {
1239 1238
 				$_POST['give-price-id'] = 'custom';
1240 1239
 				$donation_level_matched = true;
1241 1240
 			}
1242 1241
 		}
1243 1242
 	}// End if().
1244 1243
 
1245
-	return ( $donation_level_matched ? true : false );
1244
+	return ($donation_level_matched ? true : false);
1246 1245
 }
1247 1246
 
1248
-add_action( 'give_checkout_error_checks', 'give_validate_multi_donation_form_level', 10, 2 );
1247
+add_action('give_checkout_error_checks', 'give_validate_multi_donation_form_level', 10, 2);
Please login to merge, or discard this patch.