@@ -10,7 +10,7 @@ discard block |
||
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 | |
@@ -25,27 +25,27 @@ discard block |
||
25 | 25 | */ |
26 | 26 | function give_process_purchase_form() { |
27 | 27 | |
28 | - do_action( 'give_pre_process_purchase' ); |
|
28 | + do_action('give_pre_process_purchase'); |
|
29 | 29 | |
30 | 30 | // Validate the form $_POST data |
31 | 31 | $valid_data = give_purchase_form_validate_fields(); |
32 | 32 | |
33 | 33 | // Allow themes and plugins to hook to errors |
34 | - do_action( 'give_checkout_error_checks', $valid_data, $_POST ); |
|
34 | + do_action('give_checkout_error_checks', $valid_data, $_POST); |
|
35 | 35 | |
36 | - $is_ajax = isset( $_POST['give_ajax'] ); |
|
36 | + $is_ajax = isset($_POST['give_ajax']); |
|
37 | 37 | |
38 | 38 | // Process the login form |
39 | - if ( isset( $_POST['give_login_submit'] ) ) { |
|
39 | + if (isset($_POST['give_login_submit'])) { |
|
40 | 40 | give_process_form_login(); |
41 | 41 | } |
42 | 42 | |
43 | 43 | // Validate the user |
44 | - $user = give_get_purchase_form_user( $valid_data ); |
|
44 | + $user = give_get_purchase_form_user($valid_data); |
|
45 | 45 | |
46 | - if ( give_get_errors() || ! $user ) { |
|
47 | - if ( $is_ajax ) { |
|
48 | - do_action( 'give_ajax_checkout_errors' ); |
|
46 | + if (give_get_errors() || ! $user) { |
|
47 | + if ($is_ajax) { |
|
48 | + do_action('give_ajax_checkout_errors'); |
|
49 | 49 | give_die(); |
50 | 50 | } else { |
51 | 51 | return false; |
@@ -53,17 +53,17 @@ discard block |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | //If AJAX send back success to proceed with form submission |
56 | - if ( $is_ajax ) { |
|
56 | + if ($is_ajax) { |
|
57 | 57 | echo 'success'; |
58 | 58 | give_die(); |
59 | 59 | } |
60 | 60 | |
61 | 61 | //After AJAX: Setup session if not using php_sessions |
62 | - if ( ! Give()->session->use_php_sessions() ) { |
|
62 | + if ( ! Give()->session->use_php_sessions()) { |
|
63 | 63 | //Double-check that set_cookie is publicly accessible; |
64 | 64 | // we're using a slightly modified class-wp-sessions.php |
65 | - $session_reflection = new ReflectionMethod( 'WP_Session', 'set_cookie' ); |
|
66 | - if ( $session_reflection->isPublic() ) { |
|
65 | + $session_reflection = new ReflectionMethod('WP_Session', 'set_cookie'); |
|
66 | + if ($session_reflection->isPublic()) { |
|
67 | 67 | // Manually set the cookie. |
68 | 68 | Give()->session->init()->set_cookie(); |
69 | 69 | } |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | 'address' => $user['address'] |
79 | 79 | ); |
80 | 80 | |
81 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
81 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
82 | 82 | |
83 | 83 | // Setup purchase information |
84 | 84 | $purchase_data = array( |
85 | - 'price' => ( isset( $_POST['give-amount'] ) ? (float) apply_filters( 'give_donation_total', give_sanitize_amount( give_format_amount( $_POST['give-amount'] ) ) ) : '0.00' ), |
|
86 | - 'purchase_key' => strtolower( md5( $user['user_email'] . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'give', true ) ) ), |
|
85 | + 'price' => (isset($_POST['give-amount']) ? (float) apply_filters('give_donation_total', give_sanitize_amount(give_format_amount($_POST['give-amount']))) : '0.00'), |
|
86 | + 'purchase_key' => strtolower(md5($user['user_email'].date('Y-m-d H:i:s').$auth_key.uniqid('give', true))), |
|
87 | 87 | 'user_email' => $user['user_email'], |
88 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
89 | - 'user_info' => stripslashes_deep( $user_info ), |
|
88 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
89 | + 'user_info' => stripslashes_deep($user_info), |
|
90 | 90 | 'post_data' => $_POST, |
91 | 91 | 'gateway' => $valid_data['gateway'], |
92 | 92 | 'card_info' => $valid_data['cc_info'] |
@@ -96,37 +96,37 @@ discard block |
||
96 | 96 | $valid_data['user'] = $user; |
97 | 97 | |
98 | 98 | // Allow themes and plugins to hook before the gateway |
99 | - do_action( 'give_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
99 | + do_action('give_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
100 | 100 | |
101 | 101 | //Sanity check for price |
102 | - if ( ! $purchase_data['price'] ) { |
|
102 | + if ( ! $purchase_data['price']) { |
|
103 | 103 | // Revert to manual |
104 | 104 | $purchase_data['gateway'] = 'manual'; |
105 | 105 | $_POST['give-gateway'] = 'manual'; |
106 | 106 | } |
107 | 107 | |
108 | 108 | // Allow the purchase data to be modified before it is sent to the gateway |
109 | - $purchase_data = apply_filters( 'give_purchase_data_before_gateway', $purchase_data, $valid_data ); |
|
109 | + $purchase_data = apply_filters('give_purchase_data_before_gateway', $purchase_data, $valid_data); |
|
110 | 110 | |
111 | 111 | // Setup the data we're storing in the purchase session |
112 | 112 | $session_data = $purchase_data; |
113 | 113 | |
114 | 114 | // Make sure credit card numbers are never stored in sessions |
115 | - unset( $session_data['card_info']['card_number'] ); |
|
116 | - unset( $session_data['post_data']['card_number'] ); |
|
115 | + unset($session_data['card_info']['card_number']); |
|
116 | + unset($session_data['post_data']['card_number']); |
|
117 | 117 | |
118 | 118 | // Used for showing data to non logged-in users after purchase, and for other plugins needing purchase data. |
119 | - give_set_purchase_session( $session_data ); |
|
119 | + give_set_purchase_session($session_data); |
|
120 | 120 | |
121 | 121 | // Send info to the gateway for payment processing |
122 | - give_send_to_gateway( $purchase_data['gateway'], $purchase_data ); |
|
122 | + give_send_to_gateway($purchase_data['gateway'], $purchase_data); |
|
123 | 123 | give_die(); |
124 | 124 | |
125 | 125 | } |
126 | 126 | |
127 | -add_action( 'give_purchase', 'give_process_purchase_form' ); |
|
128 | -add_action( 'wp_ajax_give_process_checkout', 'give_process_purchase_form' ); |
|
129 | -add_action( 'wp_ajax_nopriv_give_process_checkout', 'give_process_purchase_form' ); |
|
127 | +add_action('give_purchase', 'give_process_purchase_form'); |
|
128 | +add_action('wp_ajax_give_process_checkout', 'give_process_purchase_form'); |
|
129 | +add_action('wp_ajax_nopriv_give_process_checkout', 'give_process_purchase_form'); |
|
130 | 130 | |
131 | 131 | /** |
132 | 132 | * Process the checkout login form |
@@ -137,32 +137,32 @@ discard block |
||
137 | 137 | */ |
138 | 138 | function give_process_form_login() { |
139 | 139 | |
140 | - $is_ajax = isset( $_POST['give_ajax'] ); |
|
140 | + $is_ajax = isset($_POST['give_ajax']); |
|
141 | 141 | |
142 | 142 | $user_data = give_purchase_form_validate_user_login(); |
143 | 143 | |
144 | - if ( give_get_errors() || $user_data['user_id'] < 1 ) { |
|
145 | - if ( $is_ajax ) { |
|
146 | - do_action( 'give_ajax_checkout_errors' ); |
|
144 | + if (give_get_errors() || $user_data['user_id'] < 1) { |
|
145 | + if ($is_ajax) { |
|
146 | + do_action('give_ajax_checkout_errors'); |
|
147 | 147 | give_die(); |
148 | 148 | } else { |
149 | - wp_redirect( $_SERVER['HTTP_REFERER'] ); |
|
149 | + wp_redirect($_SERVER['HTTP_REFERER']); |
|
150 | 150 | exit; |
151 | 151 | } |
152 | 152 | } |
153 | 153 | |
154 | - give_log_user_in( $user_data['user_id'], $user_data['user_login'], $user_data['user_pass'] ); |
|
154 | + give_log_user_in($user_data['user_id'], $user_data['user_login'], $user_data['user_pass']); |
|
155 | 155 | |
156 | - if ( $is_ajax ) { |
|
156 | + if ($is_ajax) { |
|
157 | 157 | echo 'success'; |
158 | 158 | give_die(); |
159 | 159 | } else { |
160 | - wp_redirect( $_SERVER['HTTP_REFERER'] ); |
|
160 | + wp_redirect($_SERVER['HTTP_REFERER']); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
164 | -add_action( 'wp_ajax_give_process_checkout_login', 'give_process_form_login' ); |
|
165 | -add_action( 'wp_ajax_nopriv_give_process_checkout_login', 'give_process_form_login' ); |
|
164 | +add_action('wp_ajax_give_process_checkout_login', 'give_process_form_login'); |
|
165 | +add_action('wp_ajax_nopriv_give_process_checkout_login', 'give_process_form_login'); |
|
166 | 166 | |
167 | 167 | /** |
168 | 168 | * Purchase Form Validate Fields |
@@ -174,40 +174,40 @@ discard block |
||
174 | 174 | function give_purchase_form_validate_fields() { |
175 | 175 | |
176 | 176 | // Check if there is $_POST |
177 | - if ( empty( $_POST ) ) { |
|
177 | + if (empty($_POST)) { |
|
178 | 178 | return false; |
179 | 179 | } |
180 | 180 | |
181 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
181 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
182 | 182 | |
183 | 183 | // Start an array to collect valid data |
184 | 184 | $valid_data = array( |
185 | 185 | 'gateway' => give_purchase_form_validate_gateway(), // Gateway fallback (amount is validated here) |
186 | - 'need_new_user' => false, // New user flag |
|
187 | - 'need_user_login' => false, // Login user flag |
|
188 | - 'logged_user_data' => array(), // Logged user collected data |
|
189 | - 'new_user_data' => array(), // New user collected data |
|
190 | - 'login_user_data' => array(), // Login user collected data |
|
191 | - 'guest_user_data' => array(), // Guest user collected data |
|
186 | + 'need_new_user' => false, // New user flag |
|
187 | + 'need_user_login' => false, // Login user flag |
|
188 | + 'logged_user_data' => array(), // Logged user collected data |
|
189 | + 'new_user_data' => array(), // New user collected data |
|
190 | + 'login_user_data' => array(), // Login user collected data |
|
191 | + 'guest_user_data' => array(), // Guest user collected data |
|
192 | 192 | 'cc_info' => give_purchase_form_validate_cc() // Credit card info |
193 | 193 | ); |
194 | 194 | |
195 | 195 | // Validate agree to terms |
196 | - $terms_option = get_post_meta( $form_id, '_give_terms_option', true ); |
|
197 | - if ( isset( $terms_option ) && $terms_option === 'yes' ) { |
|
196 | + $terms_option = get_post_meta($form_id, '_give_terms_option', true); |
|
197 | + if (isset($terms_option) && $terms_option === 'yes') { |
|
198 | 198 | give_purchase_form_validate_agree_to_terms(); |
199 | 199 | } |
200 | 200 | |
201 | - if ( is_user_logged_in() ) { |
|
201 | + if (is_user_logged_in()) { |
|
202 | 202 | // Collect logged in user data |
203 | 203 | $valid_data['logged_in_user'] = give_purchase_form_validate_logged_in_user(); |
204 | - } else if ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-register' ) { |
|
204 | + } else if (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-register') { |
|
205 | 205 | // Set new user registration as required |
206 | 206 | $valid_data['need_new_user'] = true; |
207 | 207 | // Validate new user data |
208 | 208 | $valid_data['new_user_data'] = give_purchase_form_validate_new_user(); |
209 | 209 | // Check if login validation is needed |
210 | - } else if ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-login' ) { |
|
210 | + } else if (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-login') { |
|
211 | 211 | // Set user login as required |
212 | 212 | $valid_data['need_user_login'] = true; |
213 | 213 | // Validate users login info |
@@ -232,37 +232,37 @@ discard block |
||
232 | 232 | */ |
233 | 233 | function give_purchase_form_validate_gateway() { |
234 | 234 | |
235 | - $form_id = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0; |
|
236 | - $amount = isset( $_REQUEST['give-amount'] ) ? give_sanitize_amount( $_REQUEST['give-amount'] ) : 0; |
|
237 | - $gateway = give_get_default_gateway( $form_id ); |
|
235 | + $form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0; |
|
236 | + $amount = isset($_REQUEST['give-amount']) ? give_sanitize_amount($_REQUEST['give-amount']) : 0; |
|
237 | + $gateway = give_get_default_gateway($form_id); |
|
238 | 238 | |
239 | 239 | // Check if a gateway value is present |
240 | - if ( ! empty( $_REQUEST['give-gateway'] ) ) { |
|
240 | + if ( ! empty($_REQUEST['give-gateway'])) { |
|
241 | 241 | |
242 | - $gateway = sanitize_text_field( $_REQUEST['give-gateway'] ); |
|
242 | + $gateway = sanitize_text_field($_REQUEST['give-gateway']); |
|
243 | 243 | |
244 | 244 | //Is amount being donated in LIVE mode 0.00? If so, error: |
245 | - if ( $amount == 0 && ! give_is_test_mode() ) { |
|
245 | + if ($amount == 0 && ! give_is_test_mode()) { |
|
246 | 246 | |
247 | - give_set_error( 'invalid_donation_amount', __( 'Please insert a valid donation amount.', 'give' ) ); |
|
247 | + give_set_error('invalid_donation_amount', __('Please insert a valid donation amount.', 'give')); |
|
248 | 248 | |
249 | 249 | } //Check for a minimum custom amount |
250 | - elseif ( ! give_verify_minimum_price() ) { |
|
250 | + elseif ( ! give_verify_minimum_price()) { |
|
251 | 251 | |
252 | - $minimum = give_currency_filter( give_format_amount( give_get_form_minimum_price( $form_id ) ) ); |
|
253 | - $error_message = __( 'This form has a minimum donation amount of %s', 'give' ); |
|
252 | + $minimum = give_currency_filter(give_format_amount(give_get_form_minimum_price($form_id))); |
|
253 | + $error_message = __('This form has a minimum donation amount of %s', 'give'); |
|
254 | 254 | |
255 | - give_set_error( 'invalid_donation_minimum', sprintf( $error_message, $minimum ) ); |
|
255 | + give_set_error('invalid_donation_minimum', sprintf($error_message, $minimum)); |
|
256 | 256 | |
257 | 257 | } //Is this test mode zero donation? Let it through but set to manual gateway |
258 | - elseif ( $amount == 0 && give_is_test_mode() ) { |
|
258 | + elseif ($amount == 0 && give_is_test_mode()) { |
|
259 | 259 | |
260 | 260 | $gateway = 'manual'; |
261 | 261 | |
262 | 262 | } //Check if this gateway is active |
263 | - elseif ( ! give_is_gateway_active( $gateway ) ) { |
|
263 | + elseif ( ! give_is_gateway_active($gateway)) { |
|
264 | 264 | |
265 | - give_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'give' ) ); |
|
265 | + give_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'give')); |
|
266 | 266 | |
267 | 267 | } |
268 | 268 | |
@@ -281,23 +281,23 @@ discard block |
||
281 | 281 | */ |
282 | 282 | function give_verify_minimum_price() { |
283 | 283 | |
284 | - $amount = give_sanitize_amount( $_REQUEST['give-amount'] ); |
|
285 | - $form_id = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0; |
|
286 | - $price_id = isset( $_REQUEST['give-price-id'] ) ? $_REQUEST['give-price-id'] : 0; |
|
287 | - $variable_prices = give_has_variable_prices( $form_id ); |
|
284 | + $amount = give_sanitize_amount($_REQUEST['give-amount']); |
|
285 | + $form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0; |
|
286 | + $price_id = isset($_REQUEST['give-price-id']) ? $_REQUEST['give-price-id'] : 0; |
|
287 | + $variable_prices = give_has_variable_prices($form_id); |
|
288 | 288 | |
289 | - if ( $variable_prices && ! empty( $price_id ) ) { |
|
289 | + if ($variable_prices && ! empty($price_id)) { |
|
290 | 290 | |
291 | - $price_level_amount = give_get_price_option_amount( $form_id, $price_id ); |
|
291 | + $price_level_amount = give_get_price_option_amount($form_id, $price_id); |
|
292 | 292 | |
293 | - if ( $price_level_amount == $amount ) { |
|
293 | + if ($price_level_amount == $amount) { |
|
294 | 294 | return true; |
295 | 295 | } |
296 | 296 | } |
297 | 297 | |
298 | - $minimum = give_get_form_minimum_price( $form_id ); |
|
298 | + $minimum = give_get_form_minimum_price($form_id); |
|
299 | 299 | |
300 | - if ( $minimum > $amount ) { |
|
300 | + if ($minimum > $amount) { |
|
301 | 301 | return false; |
302 | 302 | } |
303 | 303 | |
@@ -313,9 +313,9 @@ discard block |
||
313 | 313 | */ |
314 | 314 | function give_purchase_form_validate_agree_to_terms() { |
315 | 315 | // Validate agree to terms |
316 | - if ( ! isset( $_POST['give_agree_to_terms'] ) || $_POST['give_agree_to_terms'] != 1 ) { |
|
316 | + if ( ! isset($_POST['give_agree_to_terms']) || $_POST['give_agree_to_terms'] != 1) { |
|
317 | 317 | // User did not agree |
318 | - give_set_error( 'agree_to_terms', apply_filters( 'give_agree_to_terms_text', __( 'You must agree to the terms of use', 'give' ) ) ); |
|
318 | + give_set_error('agree_to_terms', apply_filters('give_agree_to_terms_text', __('You must agree to the terms of use', 'give'))); |
|
319 | 319 | } |
320 | 320 | } |
321 | 321 | |
@@ -329,47 +329,47 @@ discard block |
||
329 | 329 | * |
330 | 330 | * @return array |
331 | 331 | */ |
332 | -function give_purchase_form_required_fields( $form_id ) { |
|
332 | +function give_purchase_form_required_fields($form_id) { |
|
333 | 333 | |
334 | - $payment_mode = give_get_chosen_gateway( $form_id ); |
|
334 | + $payment_mode = give_get_chosen_gateway($form_id); |
|
335 | 335 | |
336 | 336 | $required_fields = array( |
337 | 337 | 'give_email' => array( |
338 | 338 | 'error_id' => 'invalid_email', |
339 | - 'error_message' => __( 'Please enter a valid email address', 'give' ) |
|
339 | + 'error_message' => __('Please enter a valid email address', 'give') |
|
340 | 340 | ), |
341 | 341 | 'give_first' => array( |
342 | 342 | 'error_id' => 'invalid_first_name', |
343 | - 'error_message' => __( 'Please enter your first name', 'give' ) |
|
343 | + 'error_message' => __('Please enter your first name', 'give') |
|
344 | 344 | ) |
345 | 345 | ); |
346 | 346 | |
347 | - $require_address = give_require_billing_address( $payment_mode ); |
|
347 | + $require_address = give_require_billing_address($payment_mode); |
|
348 | 348 | |
349 | - if ( $require_address ) { |
|
350 | - $required_fields['card_address'] = array( |
|
349 | + if ($require_address) { |
|
350 | + $required_fields['card_address'] = array( |
|
351 | 351 | 'error_id' => 'invalid_card_address', |
352 | - 'error_message' => __( 'Please enter your primary billing address', 'give' ) |
|
352 | + 'error_message' => __('Please enter your primary billing address', 'give') |
|
353 | 353 | ); |
354 | - $required_fields['card_zip'] = array( |
|
354 | + $required_fields['card_zip'] = array( |
|
355 | 355 | 'error_id' => 'invalid_zip_code', |
356 | - 'error_message' => __( 'Please enter your zip / postal code', 'give' ) |
|
356 | + 'error_message' => __('Please enter your zip / postal code', 'give') |
|
357 | 357 | ); |
358 | - $required_fields['card_city'] = array( |
|
358 | + $required_fields['card_city'] = array( |
|
359 | 359 | 'error_id' => 'invalid_city', |
360 | - 'error_message' => __( 'Please enter your billing city', 'give' ) |
|
360 | + 'error_message' => __('Please enter your billing city', 'give') |
|
361 | 361 | ); |
362 | 362 | $required_fields['billing_country'] = array( |
363 | 363 | 'error_id' => 'invalid_country', |
364 | - 'error_message' => __( 'Please select your billing country', 'give' ) |
|
364 | + 'error_message' => __('Please select your billing country', 'give') |
|
365 | 365 | ); |
366 | - $required_fields['card_state'] = array( |
|
366 | + $required_fields['card_state'] = array( |
|
367 | 367 | 'error_id' => 'invalid_state', |
368 | - 'error_message' => __( 'Please enter billing state / province', 'give' ) |
|
368 | + 'error_message' => __('Please enter billing state / province', 'give') |
|
369 | 369 | ); |
370 | 370 | } |
371 | 371 | |
372 | - return apply_filters( 'give_purchase_form_required_fields', $required_fields, $form_id ); |
|
372 | + return apply_filters('give_purchase_form_required_fields', $required_fields, $form_id); |
|
373 | 373 | |
374 | 374 | } |
375 | 375 | |
@@ -382,16 +382,16 @@ discard block |
||
382 | 382 | * |
383 | 383 | * @return mixed|void |
384 | 384 | */ |
385 | -function give_require_billing_address( $payment_mode ) { |
|
385 | +function give_require_billing_address($payment_mode) { |
|
386 | 386 | |
387 | 387 | $return = false; |
388 | 388 | |
389 | - if ( isset( $_POST['billing_country'] ) || did_action( "give_{$payment_mode}_cc_form" ) || did_action( 'give_cc_form' ) ) { |
|
389 | + if (isset($_POST['billing_country']) || did_action("give_{$payment_mode}_cc_form") || did_action('give_cc_form')) { |
|
390 | 390 | $return = true; |
391 | 391 | } |
392 | 392 | |
393 | 393 | // Let payment gateways and other extensions determine if address fields should be required |
394 | - return apply_filters( 'give_require_billing_address', $return ); |
|
394 | + return apply_filters('give_require_billing_address', $return); |
|
395 | 395 | |
396 | 396 | } |
397 | 397 | |
@@ -405,43 +405,43 @@ discard block |
||
405 | 405 | function give_purchase_form_validate_logged_in_user() { |
406 | 406 | global $user_ID; |
407 | 407 | |
408 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
408 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
409 | 409 | |
410 | 410 | // Start empty array to collect valid user data |
411 | 411 | $valid_user_data = array( |
412 | 412 | // Assume there will be errors |
413 | - 'user_id' => - 1 |
|
413 | + 'user_id' => -1 |
|
414 | 414 | ); |
415 | 415 | |
416 | 416 | // Verify there is a user_ID |
417 | - if ( $user_ID > 0 ) { |
|
417 | + if ($user_ID > 0) { |
|
418 | 418 | // Get the logged in user data |
419 | - $user_data = get_userdata( $user_ID ); |
|
419 | + $user_data = get_userdata($user_ID); |
|
420 | 420 | |
421 | 421 | // Loop through required fields and show error messages |
422 | - foreach ( give_purchase_form_required_fields( $form_id ) as $field_name => $value ) { |
|
423 | - if ( in_array( $value, give_purchase_form_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
424 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
422 | + foreach (give_purchase_form_required_fields($form_id) as $field_name => $value) { |
|
423 | + if (in_array($value, give_purchase_form_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
424 | + give_set_error($value['error_id'], $value['error_message']); |
|
425 | 425 | } |
426 | 426 | } |
427 | 427 | |
428 | 428 | // Verify data |
429 | - if ( $user_data ) { |
|
429 | + if ($user_data) { |
|
430 | 430 | // Collected logged in user data |
431 | 431 | $valid_user_data = array( |
432 | 432 | 'user_id' => $user_ID, |
433 | - 'user_email' => isset( $_POST['give_email'] ) ? sanitize_email( $_POST['give_email'] ) : $user_data->user_email, |
|
434 | - 'user_first' => isset( $_POST['give_first'] ) && ! empty( $_POST['give_first'] ) ? sanitize_text_field( $_POST['give_first'] ) : $user_data->first_name, |
|
435 | - 'user_last' => isset( $_POST['give_last'] ) && ! empty( $_POST['give_last'] ) ? sanitize_text_field( $_POST['give_last'] ) : $user_data->last_name, |
|
433 | + 'user_email' => isset($_POST['give_email']) ? sanitize_email($_POST['give_email']) : $user_data->user_email, |
|
434 | + 'user_first' => isset($_POST['give_first']) && ! empty($_POST['give_first']) ? sanitize_text_field($_POST['give_first']) : $user_data->first_name, |
|
435 | + 'user_last' => isset($_POST['give_last']) && ! empty($_POST['give_last']) ? sanitize_text_field($_POST['give_last']) : $user_data->last_name, |
|
436 | 436 | ); |
437 | 437 | |
438 | - if ( ! is_email( $valid_user_data['user_email'] ) ) { |
|
439 | - give_set_error( 'email_invalid', __( 'Invalid email', 'give' ) ); |
|
438 | + if ( ! is_email($valid_user_data['user_email'])) { |
|
439 | + give_set_error('email_invalid', __('Invalid email', 'give')); |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | } else { |
443 | 443 | // Set invalid user error |
444 | - give_set_error( 'invalid_user', __( 'The user information is invalid', 'give' ) ); |
|
444 | + give_set_error('invalid_user', __('The user information is invalid', 'give')); |
|
445 | 445 | } |
446 | 446 | } |
447 | 447 | |
@@ -459,90 +459,90 @@ discard block |
||
459 | 459 | function give_purchase_form_validate_new_user() { |
460 | 460 | |
461 | 461 | $registering_new_user = false; |
462 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
462 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
463 | 463 | |
464 | 464 | // Start an empty array to collect valid user data |
465 | 465 | $valid_user_data = array( |
466 | 466 | // Assume there will be errors |
467 | - 'user_id' => - 1, |
|
467 | + 'user_id' => -1, |
|
468 | 468 | // Get first name |
469 | - 'user_first' => isset( $_POST['give_first'] ) ? sanitize_text_field( $_POST['give_first'] ) : '', |
|
469 | + 'user_first' => isset($_POST['give_first']) ? sanitize_text_field($_POST['give_first']) : '', |
|
470 | 470 | // Get last name |
471 | - 'user_last' => isset( $_POST['give_last'] ) ? sanitize_text_field( $_POST['give_last'] ) : '', |
|
471 | + 'user_last' => isset($_POST['give_last']) ? sanitize_text_field($_POST['give_last']) : '', |
|
472 | 472 | ); |
473 | 473 | |
474 | 474 | // Check the new user's credentials against existing ones |
475 | - $user_login = isset( $_POST['give_user_login'] ) ? trim( $_POST['give_user_login'] ) : false; |
|
476 | - $user_email = isset( $_POST['give_email'] ) ? trim( $_POST['give_email'] ) : false; |
|
477 | - $user_pass = isset( $_POST['give_user_pass'] ) ? trim( $_POST['give_user_pass'] ) : false; |
|
478 | - $pass_confirm = isset( $_POST['give_user_pass_confirm'] ) ? trim( $_POST['give_user_pass_confirm'] ) : false; |
|
475 | + $user_login = isset($_POST['give_user_login']) ? trim($_POST['give_user_login']) : false; |
|
476 | + $user_email = isset($_POST['give_email']) ? trim($_POST['give_email']) : false; |
|
477 | + $user_pass = isset($_POST['give_user_pass']) ? trim($_POST['give_user_pass']) : false; |
|
478 | + $pass_confirm = isset($_POST['give_user_pass_confirm']) ? trim($_POST['give_user_pass_confirm']) : false; |
|
479 | 479 | |
480 | 480 | // Loop through required fields and show error messages |
481 | - foreach ( give_purchase_form_required_fields( $form_id ) as $field_name => $value ) { |
|
482 | - if ( in_array( $value, give_purchase_form_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
483 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
481 | + foreach (give_purchase_form_required_fields($form_id) as $field_name => $value) { |
|
482 | + if (in_array($value, give_purchase_form_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
483 | + give_set_error($value['error_id'], $value['error_message']); |
|
484 | 484 | } |
485 | 485 | } |
486 | 486 | |
487 | 487 | // Check if we have an username to register |
488 | - if ( $user_login && strlen( $user_login ) > 0 ) { |
|
488 | + if ($user_login && strlen($user_login) > 0) { |
|
489 | 489 | $registering_new_user = true; |
490 | 490 | |
491 | 491 | // We have an user name, check if it already exists |
492 | - if ( username_exists( $user_login ) ) { |
|
492 | + if (username_exists($user_login)) { |
|
493 | 493 | // Username already registered |
494 | - give_set_error( 'username_unavailable', __( 'Username already taken', 'give' ) ); |
|
494 | + give_set_error('username_unavailable', __('Username already taken', 'give')); |
|
495 | 495 | // Check if it's valid |
496 | - } else if ( ! give_validate_username( $user_login ) ) { |
|
496 | + } else if ( ! give_validate_username($user_login)) { |
|
497 | 497 | // Invalid username |
498 | - if ( is_multisite() ) { |
|
499 | - give_set_error( 'username_invalid', __( 'Invalid username. Only lowercase letters (a-z) and numbers are allowed', 'give' ) ); |
|
498 | + if (is_multisite()) { |
|
499 | + give_set_error('username_invalid', __('Invalid username. Only lowercase letters (a-z) and numbers are allowed', 'give')); |
|
500 | 500 | } else { |
501 | - give_set_error( 'username_invalid', __( 'Invalid username', 'give' ) ); |
|
501 | + give_set_error('username_invalid', __('Invalid username', 'give')); |
|
502 | 502 | } |
503 | 503 | } else { |
504 | 504 | // All the checks have run and it's good to go |
505 | 505 | $valid_user_data['user_login'] = $user_login; |
506 | 506 | } |
507 | - } elseif ( give_logged_in_only( $form_id ) ) { |
|
508 | - give_set_error( 'registration_required', esc_html__( 'You must register or login to complete your donation', 'give' ) ); |
|
507 | + } elseif (give_logged_in_only($form_id)) { |
|
508 | + give_set_error('registration_required', esc_html__('You must register or login to complete your donation', 'give')); |
|
509 | 509 | } |
510 | 510 | |
511 | 511 | // Check if we have an email to verify |
512 | - if ( $user_email && strlen( $user_email ) > 0 ) { |
|
512 | + if ($user_email && strlen($user_email) > 0) { |
|
513 | 513 | // Validate email |
514 | - if ( ! is_email( $user_email ) ) { |
|
515 | - give_set_error( 'email_invalid', __( 'Sorry, that email is invalid', 'give' ) ); |
|
514 | + if ( ! is_email($user_email)) { |
|
515 | + give_set_error('email_invalid', __('Sorry, that email is invalid', 'give')); |
|
516 | 516 | // Check if email exists |
517 | - } else if ( email_exists( $user_email ) && $registering_new_user ) { |
|
518 | - give_set_error( 'email_used', __( 'Sorry, that email already active for another user', 'give' ) ); |
|
517 | + } else if (email_exists($user_email) && $registering_new_user) { |
|
518 | + give_set_error('email_used', __('Sorry, that email already active for another user', 'give')); |
|
519 | 519 | } else { |
520 | 520 | // All the checks have run and it's good to go |
521 | 521 | $valid_user_data['user_email'] = $user_email; |
522 | 522 | } |
523 | 523 | } else { |
524 | 524 | // No email |
525 | - give_set_error( 'email_empty', __( 'Enter an email', 'give' ) ); |
|
525 | + give_set_error('email_empty', __('Enter an email', 'give')); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | // Check password |
529 | - if ( $user_pass && $pass_confirm ) { |
|
529 | + if ($user_pass && $pass_confirm) { |
|
530 | 530 | // Verify confirmation matches |
531 | - if ( $user_pass != $pass_confirm ) { |
|
531 | + if ($user_pass != $pass_confirm) { |
|
532 | 532 | // Passwords do not match |
533 | - give_set_error( 'password_mismatch', __( 'Passwords don\'t match', 'give' ) ); |
|
533 | + give_set_error('password_mismatch', __('Passwords don\'t match', 'give')); |
|
534 | 534 | } else { |
535 | 535 | // All is good to go |
536 | 536 | $valid_user_data['user_pass'] = $user_pass; |
537 | 537 | } |
538 | 538 | } else { |
539 | 539 | // Password or confirmation missing |
540 | - if ( ! $user_pass && $registering_new_user ) { |
|
540 | + if ( ! $user_pass && $registering_new_user) { |
|
541 | 541 | // The password is invalid |
542 | - give_set_error( 'password_empty', __( 'Enter a password', 'give' ) ); |
|
543 | - } else if ( ! $pass_confirm && $registering_new_user ) { |
|
542 | + give_set_error('password_empty', __('Enter a password', 'give')); |
|
543 | + } else if ( ! $pass_confirm && $registering_new_user) { |
|
544 | 544 | // Confirmation password is invalid |
545 | - give_set_error( 'confirmation_empty', __( 'Enter the password confirmation', 'give' ) ); |
|
545 | + give_set_error('confirmation_empty', __('Enter the password confirmation', 'give')); |
|
546 | 546 | } |
547 | 547 | } |
548 | 548 | |
@@ -561,34 +561,34 @@ discard block |
||
561 | 561 | // Start an array to collect valid user data |
562 | 562 | $valid_user_data = array( |
563 | 563 | // Assume there will be errors |
564 | - 'user_id' => - 1 |
|
564 | + 'user_id' => -1 |
|
565 | 565 | ); |
566 | 566 | |
567 | 567 | // Username |
568 | - if ( ! isset( $_POST['give_user_login'] ) || $_POST['give_user_login'] == '' ) { |
|
569 | - give_set_error( 'must_log_in', __( 'You must login or register to complete your donation', 'give' ) ); |
|
568 | + if ( ! isset($_POST['give_user_login']) || $_POST['give_user_login'] == '') { |
|
569 | + give_set_error('must_log_in', __('You must login or register to complete your donation', 'give')); |
|
570 | 570 | |
571 | 571 | return $valid_user_data; |
572 | 572 | } |
573 | 573 | |
574 | 574 | // Get the user by login |
575 | - $user_data = get_user_by( 'login', strip_tags( $_POST['give_user_login'] ) ); |
|
575 | + $user_data = get_user_by('login', strip_tags($_POST['give_user_login'])); |
|
576 | 576 | |
577 | 577 | // Check if user exists |
578 | - if ( $user_data ) { |
|
578 | + if ($user_data) { |
|
579 | 579 | // Get password |
580 | - $user_pass = isset( $_POST['give_user_pass'] ) ? $_POST['give_user_pass'] : false; |
|
580 | + $user_pass = isset($_POST['give_user_pass']) ? $_POST['give_user_pass'] : false; |
|
581 | 581 | |
582 | 582 | // Check user_pass |
583 | - if ( $user_pass ) { |
|
583 | + if ($user_pass) { |
|
584 | 584 | // Check if password is valid |
585 | - if ( ! wp_check_password( $user_pass, $user_data->user_pass, $user_data->ID ) ) { |
|
585 | + if ( ! wp_check_password($user_pass, $user_data->user_pass, $user_data->ID)) { |
|
586 | 586 | // Incorrect password |
587 | 587 | give_set_error( |
588 | 588 | 'password_incorrect', |
589 | 589 | sprintf( |
590 | - __( 'The password you entered is incorrect. %sReset Password%s', 'give' ), |
|
591 | - '<a href="' . wp_lostpassword_url( "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ) . '" title="' . __( 'Lost Password', 'give' ) . '">', |
|
590 | + __('The password you entered is incorrect. %sReset Password%s', 'give'), |
|
591 | + '<a href="'.wp_lostpassword_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]").'" title="'.__('Lost Password', 'give').'">', |
|
592 | 592 | '</a>' |
593 | 593 | ) |
594 | 594 | ); |
@@ -606,11 +606,11 @@ discard block |
||
606 | 606 | } |
607 | 607 | } else { |
608 | 608 | // Empty password |
609 | - give_set_error( 'password_empty', __( 'Enter a password', 'give' ) ); |
|
609 | + give_set_error('password_empty', __('Enter a password', 'give')); |
|
610 | 610 | } |
611 | 611 | } else { |
612 | 612 | // no username |
613 | - give_set_error( 'username_incorrect', __( 'The username you entered does not exist', 'give' ) ); |
|
613 | + give_set_error('username_incorrect', __('The username you entered does not exist', 'give')); |
|
614 | 614 | } |
615 | 615 | |
616 | 616 | return $valid_user_data; |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | */ |
626 | 626 | function give_purchase_form_validate_guest_user() { |
627 | 627 | |
628 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
628 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
629 | 629 | |
630 | 630 | // Start an array to collect valid user data |
631 | 631 | $valid_user_data = array( |
@@ -634,32 +634,32 @@ discard block |
||
634 | 634 | ); |
635 | 635 | |
636 | 636 | // Show error message if user must be logged in |
637 | - if ( give_logged_in_only( $form_id ) ) { |
|
638 | - give_set_error( 'logged_in_only', __( 'You must be logged into to donate', 'give' ) ); |
|
637 | + if (give_logged_in_only($form_id)) { |
|
638 | + give_set_error('logged_in_only', __('You must be logged into to donate', 'give')); |
|
639 | 639 | } |
640 | 640 | |
641 | 641 | // Get the guest email |
642 | - $guest_email = isset( $_POST['give_email'] ) ? $_POST['give_email'] : false; |
|
642 | + $guest_email = isset($_POST['give_email']) ? $_POST['give_email'] : false; |
|
643 | 643 | |
644 | 644 | // Check email |
645 | - if ( $guest_email && strlen( $guest_email ) > 0 ) { |
|
645 | + if ($guest_email && strlen($guest_email) > 0) { |
|
646 | 646 | // Validate email |
647 | - if ( ! is_email( $guest_email ) ) { |
|
647 | + if ( ! is_email($guest_email)) { |
|
648 | 648 | // Invalid email |
649 | - give_set_error( 'email_invalid', __( 'Invalid email', 'give' ) ); |
|
649 | + give_set_error('email_invalid', __('Invalid email', 'give')); |
|
650 | 650 | } else { |
651 | 651 | // All is good to go |
652 | 652 | $valid_user_data['user_email'] = $guest_email; |
653 | 653 | } |
654 | 654 | } else { |
655 | 655 | // No email |
656 | - give_set_error( 'email_empty', __( 'Enter an email', 'give' ) ); |
|
656 | + give_set_error('email_empty', __('Enter an email', 'give')); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | // Loop through required fields and show error messages |
660 | - foreach ( give_purchase_form_required_fields( $form_id ) as $field_name => $value ) { |
|
661 | - if ( in_array( $value, give_purchase_form_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
662 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
660 | + foreach (give_purchase_form_required_fields($form_id) as $field_name => $value) { |
|
661 | + if (in_array($value, give_purchase_form_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
662 | + give_set_error($value['error_id'], $value['error_message']); |
|
663 | 663 | } |
664 | 664 | } |
665 | 665 | |
@@ -675,42 +675,42 @@ discard block |
||
675 | 675 | * @since 1.0 |
676 | 676 | * @return integer |
677 | 677 | */ |
678 | -function give_register_and_login_new_user( $user_data = array() ) { |
|
678 | +function give_register_and_login_new_user($user_data = array()) { |
|
679 | 679 | // Verify the array |
680 | - if ( empty( $user_data ) ) { |
|
681 | - return - 1; |
|
680 | + if (empty($user_data)) { |
|
681 | + return -1; |
|
682 | 682 | } |
683 | 683 | |
684 | - if ( give_get_errors() ) { |
|
685 | - return - 1; |
|
684 | + if (give_get_errors()) { |
|
685 | + return -1; |
|
686 | 686 | } |
687 | 687 | |
688 | - $user_args = apply_filters( 'give_insert_user_args', array( |
|
689 | - 'user_login' => isset( $user_data['user_login'] ) ? $user_data['user_login'] : '', |
|
690 | - 'user_pass' => isset( $user_data['user_pass'] ) ? $user_data['user_pass'] : '', |
|
691 | - 'user_email' => isset( $user_data['user_email'] ) ? $user_data['user_email'] : '', |
|
692 | - 'first_name' => isset( $user_data['user_first'] ) ? $user_data['user_first'] : '', |
|
693 | - 'last_name' => isset( $user_data['user_last'] ) ? $user_data['user_last'] : '', |
|
694 | - 'user_registered' => date( 'Y-m-d H:i:s' ), |
|
695 | - 'role' => get_option( 'default_role' ) |
|
696 | - ), $user_data ); |
|
688 | + $user_args = apply_filters('give_insert_user_args', array( |
|
689 | + 'user_login' => isset($user_data['user_login']) ? $user_data['user_login'] : '', |
|
690 | + 'user_pass' => isset($user_data['user_pass']) ? $user_data['user_pass'] : '', |
|
691 | + 'user_email' => isset($user_data['user_email']) ? $user_data['user_email'] : '', |
|
692 | + 'first_name' => isset($user_data['user_first']) ? $user_data['user_first'] : '', |
|
693 | + 'last_name' => isset($user_data['user_last']) ? $user_data['user_last'] : '', |
|
694 | + 'user_registered' => date('Y-m-d H:i:s'), |
|
695 | + 'role' => get_option('default_role') |
|
696 | + ), $user_data); |
|
697 | 697 | |
698 | 698 | // Insert new user |
699 | - $user_id = wp_insert_user( $user_args ); |
|
699 | + $user_id = wp_insert_user($user_args); |
|
700 | 700 | |
701 | 701 | // Validate inserted user |
702 | - if ( is_wp_error( $user_id ) ) { |
|
703 | - return - 1; |
|
702 | + if (is_wp_error($user_id)) { |
|
703 | + return -1; |
|
704 | 704 | } |
705 | 705 | |
706 | 706 | // Allow themes and plugins to filter the user data |
707 | - $user_data = apply_filters( 'give_insert_user_data', $user_data, $user_args ); |
|
707 | + $user_data = apply_filters('give_insert_user_data', $user_data, $user_args); |
|
708 | 708 | |
709 | 709 | // Allow themes and plugins to hook |
710 | - do_action( 'give_insert_user', $user_id, $user_data ); |
|
710 | + do_action('give_insert_user', $user_id, $user_data); |
|
711 | 711 | |
712 | 712 | // Login new user |
713 | - give_log_user_in( $user_id, $user_data['user_login'], $user_data['user_pass'] ); |
|
713 | + give_log_user_in($user_id, $user_data['user_login'], $user_data['user_pass']); |
|
714 | 714 | |
715 | 715 | // Return user id |
716 | 716 | return $user_id; |
@@ -725,27 +725,27 @@ discard block |
||
725 | 725 | * @since 1.0 |
726 | 726 | * @return array |
727 | 727 | */ |
728 | -function give_get_purchase_form_user( $valid_data = array() ) { |
|
728 | +function give_get_purchase_form_user($valid_data = array()) { |
|
729 | 729 | |
730 | 730 | // Initialize user |
731 | 731 | $user = false; |
732 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
732 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
733 | 733 | |
734 | - if ( $is_ajax ) { |
|
734 | + if ($is_ajax) { |
|
735 | 735 | // Do not create or login the user during the ajax submission (check for errors only) |
736 | 736 | return true; |
737 | - } else if ( is_user_logged_in() ) { |
|
737 | + } else if (is_user_logged_in()) { |
|
738 | 738 | // Set the valid user as the logged in collected data |
739 | 739 | $user = $valid_data['logged_in_user']; |
740 | - } else if ( $valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true ) { |
|
740 | + } else if ($valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true) { |
|
741 | 741 | // New user registration |
742 | - if ( $valid_data['need_new_user'] === true ) { |
|
742 | + if ($valid_data['need_new_user'] === true) { |
|
743 | 743 | // Set user |
744 | 744 | $user = $valid_data['new_user_data']; |
745 | 745 | // Register and login new user |
746 | - $user['user_id'] = give_register_and_login_new_user( $user ); |
|
746 | + $user['user_id'] = give_register_and_login_new_user($user); |
|
747 | 747 | // User login |
748 | - } else if ( $valid_data['need_user_login'] === true && ! $is_ajax ) { |
|
748 | + } else if ($valid_data['need_user_login'] === true && ! $is_ajax) { |
|
749 | 749 | |
750 | 750 | /* |
751 | 751 | * The login form is now processed in the give_process_purchase_login() function. |
@@ -760,48 +760,48 @@ discard block |
||
760 | 760 | // Set user |
761 | 761 | $user = $valid_data['login_user_data']; |
762 | 762 | // Login user |
763 | - give_log_user_in( $user['user_id'], $user['user_login'], $user['user_pass'] ); |
|
763 | + give_log_user_in($user['user_id'], $user['user_login'], $user['user_pass']); |
|
764 | 764 | } |
765 | 765 | } |
766 | 766 | |
767 | 767 | // Check guest checkout |
768 | - if ( false === $user && false === give_logged_in_only( $_POST['give-form-id'] ) ) { |
|
768 | + if (false === $user && false === give_logged_in_only($_POST['give-form-id'])) { |
|
769 | 769 | // Set user |
770 | 770 | $user = $valid_data['guest_user_data']; |
771 | 771 | } |
772 | 772 | |
773 | 773 | // Verify we have an user |
774 | - if ( false === $user || empty( $user ) ) { |
|
774 | + if (false === $user || empty($user)) { |
|
775 | 775 | // Return false |
776 | 776 | return false; |
777 | 777 | } |
778 | 778 | |
779 | 779 | // Get user first name |
780 | - if ( ! isset( $user['user_first'] ) || strlen( trim( $user['user_first'] ) ) < 1 ) { |
|
781 | - $user['user_first'] = isset( $_POST["give_first"] ) ? strip_tags( trim( $_POST["give_first"] ) ) : ''; |
|
780 | + if ( ! isset($user['user_first']) || strlen(trim($user['user_first'])) < 1) { |
|
781 | + $user['user_first'] = isset($_POST["give_first"]) ? strip_tags(trim($_POST["give_first"])) : ''; |
|
782 | 782 | } |
783 | 783 | |
784 | 784 | // Get user last name |
785 | - if ( ! isset( $user['user_last'] ) || strlen( trim( $user['user_last'] ) ) < 1 ) { |
|
786 | - $user['user_last'] = isset( $_POST["give_last"] ) ? strip_tags( trim( $_POST["give_last"] ) ) : ''; |
|
785 | + if ( ! isset($user['user_last']) || strlen(trim($user['user_last'])) < 1) { |
|
786 | + $user['user_last'] = isset($_POST["give_last"]) ? strip_tags(trim($_POST["give_last"])) : ''; |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | // Get the user's billing address details |
790 | 790 | $user['address'] = array(); |
791 | - $user['address']['line1'] = ! empty( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : false; |
|
792 | - $user['address']['line2'] = ! empty( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : false; |
|
793 | - $user['address']['city'] = ! empty( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : false; |
|
794 | - $user['address']['state'] = ! empty( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : false; |
|
795 | - $user['address']['country'] = ! empty( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : false; |
|
796 | - $user['address']['zip'] = ! empty( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : false; |
|
797 | - |
|
798 | - if ( empty( $user['address']['country'] ) ) { |
|
791 | + $user['address']['line1'] = ! empty($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : false; |
|
792 | + $user['address']['line2'] = ! empty($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : false; |
|
793 | + $user['address']['city'] = ! empty($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : false; |
|
794 | + $user['address']['state'] = ! empty($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : false; |
|
795 | + $user['address']['country'] = ! empty($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : false; |
|
796 | + $user['address']['zip'] = ! empty($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : false; |
|
797 | + |
|
798 | + if (empty($user['address']['country'])) { |
|
799 | 799 | $user['address'] = false; |
800 | 800 | } // Country will always be set if address fields are present |
801 | 801 | |
802 | - if ( ! empty( $user['user_id'] ) && $user['user_id'] > 0 && ! empty( $user['address'] ) ) { |
|
802 | + if ( ! empty($user['user_id']) && $user['user_id'] > 0 && ! empty($user['address'])) { |
|
803 | 803 | // Store the address in the user's meta so the donation form can be pre-populated with it on return purchases |
804 | - update_user_meta( $user['user_id'], '_give_user_address', $user['address'] ); |
|
804 | + update_user_meta($user['user_id'], '_give_user_address', $user['address']); |
|
805 | 805 | } |
806 | 806 | |
807 | 807 | // Return valid user |
@@ -820,16 +820,16 @@ discard block |
||
820 | 820 | $card_data = give_get_purchase_cc_info(); |
821 | 821 | |
822 | 822 | // Validate the card zip |
823 | - if ( ! empty( $card_data['card_zip'] ) ) { |
|
824 | - if ( ! give_purchase_form_validate_cc_zip( $card_data['card_zip'], $card_data['card_country'] ) ) { |
|
825 | - give_set_error( 'invalid_cc_zip', __( 'The zip / postal code you entered for your billing address is invalid', 'give' ) ); |
|
823 | + if ( ! empty($card_data['card_zip'])) { |
|
824 | + if ( ! give_purchase_form_validate_cc_zip($card_data['card_zip'], $card_data['card_country'])) { |
|
825 | + give_set_error('invalid_cc_zip', __('The zip / postal code you entered for your billing address is invalid', 'give')); |
|
826 | 826 | } |
827 | 827 | } |
828 | 828 | |
829 | 829 | //Ensure no spaces |
830 | - if ( ! empty( $card_data['card_number'] ) ) { |
|
831 | - $card_data['card_number'] = str_replace( '+', '', $card_data['card_number'] ); //no "+" signs |
|
832 | - $card_data['card_number'] = str_replace( ' ', '', $card_data['card_number'] ); // No spaces |
|
830 | + if ( ! empty($card_data['card_number'])) { |
|
831 | + $card_data['card_number'] = str_replace('+', '', $card_data['card_number']); //no "+" signs |
|
832 | + $card_data['card_number'] = str_replace(' ', '', $card_data['card_number']); // No spaces |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | // This should validate card numbers at some point too |
@@ -845,17 +845,17 @@ discard block |
||
845 | 845 | */ |
846 | 846 | function give_get_purchase_cc_info() { |
847 | 847 | $cc_info = array(); |
848 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
849 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
850 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
851 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
852 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
853 | - $cc_info['card_address'] = isset( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : ''; |
|
854 | - $cc_info['card_address_2'] = isset( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : ''; |
|
855 | - $cc_info['card_city'] = isset( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : ''; |
|
856 | - $cc_info['card_state'] = isset( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : ''; |
|
857 | - $cc_info['card_country'] = isset( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : ''; |
|
858 | - $cc_info['card_zip'] = isset( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : ''; |
|
848 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
849 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
850 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
851 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
852 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
853 | + $cc_info['card_address'] = isset($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : ''; |
|
854 | + $cc_info['card_address_2'] = isset($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : ''; |
|
855 | + $cc_info['card_city'] = isset($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : ''; |
|
856 | + $cc_info['card_state'] = isset($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : ''; |
|
857 | + $cc_info['card_country'] = isset($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : ''; |
|
858 | + $cc_info['card_zip'] = isset($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : ''; |
|
859 | 859 | |
860 | 860 | // Return cc info |
861 | 861 | return $cc_info; |
@@ -871,14 +871,14 @@ discard block |
||
871 | 871 | * |
872 | 872 | * @return bool|mixed|void |
873 | 873 | */ |
874 | -function give_purchase_form_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
874 | +function give_purchase_form_validate_cc_zip($zip = 0, $country_code = '') { |
|
875 | 875 | $ret = false; |
876 | 876 | |
877 | - if ( empty( $zip ) || empty( $country_code ) ) { |
|
877 | + if (empty($zip) || empty($country_code)) { |
|
878 | 878 | return $ret; |
879 | 879 | } |
880 | 880 | |
881 | - $country_code = strtoupper( $country_code ); |
|
881 | + $country_code = strtoupper($country_code); |
|
882 | 882 | |
883 | 883 | $zip_regex = array( |
884 | 884 | "AD" => "AD\d{3}", |
@@ -1038,11 +1038,11 @@ discard block |
||
1038 | 1038 | "ZM" => "\d{5}" |
1039 | 1039 | ); |
1040 | 1040 | |
1041 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) { |
|
1041 | + if ( ! isset ($zip_regex[$country_code]) || preg_match("/".$zip_regex[$country_code]."/i", $zip)) { |
|
1042 | 1042 | $ret = true; |
1043 | 1043 | } |
1044 | 1044 | |
1045 | - return apply_filters( 'give_is_zip_valid', $ret, $zip, $country_code ); |
|
1045 | + return apply_filters('give_is_zip_valid', $ret, $zip, $country_code); |
|
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | |
@@ -1052,48 +1052,48 @@ discard block |
||
1052 | 1052 | * @since 1.0 |
1053 | 1053 | * @return void |
1054 | 1054 | */ |
1055 | -function give_check_purchase_email( $valid_data, $posted ) { |
|
1055 | +function give_check_purchase_email($valid_data, $posted) { |
|
1056 | 1056 | $is_banned = false; |
1057 | 1057 | $banned = give_get_banned_emails(); |
1058 | 1058 | |
1059 | - if ( empty( $banned ) ) { |
|
1059 | + if (empty($banned)) { |
|
1060 | 1060 | return; |
1061 | 1061 | } |
1062 | 1062 | |
1063 | - if ( is_user_logged_in() ) { |
|
1063 | + if (is_user_logged_in()) { |
|
1064 | 1064 | |
1065 | 1065 | // The user is logged in, check that their account email is not banned |
1066 | - $user_data = get_userdata( get_current_user_id() ); |
|
1067 | - if ( give_is_email_banned( $user_data->user_email ) ) { |
|
1066 | + $user_data = get_userdata(get_current_user_id()); |
|
1067 | + if (give_is_email_banned($user_data->user_email)) { |
|
1068 | 1068 | |
1069 | 1069 | $is_banned = true; |
1070 | 1070 | } |
1071 | 1071 | |
1072 | - if ( give_is_email_banned( $posted['give_email'] ) ) { |
|
1072 | + if (give_is_email_banned($posted['give_email'])) { |
|
1073 | 1073 | $is_banned = true; |
1074 | 1074 | } |
1075 | 1075 | |
1076 | - } elseif ( isset( $posted['give-purchase-var'] ) && $posted['give-purchase-var'] == 'needs-to-login' ) { |
|
1076 | + } elseif (isset($posted['give-purchase-var']) && $posted['give-purchase-var'] == 'needs-to-login') { |
|
1077 | 1077 | |
1078 | 1078 | // The user is logging in, check that their email is not banned |
1079 | - $user_data = get_user_by( 'login', $posted['give_user_login'] ); |
|
1080 | - if ( $user_data && give_is_email_banned( $user_data->user_email ) ) { |
|
1079 | + $user_data = get_user_by('login', $posted['give_user_login']); |
|
1080 | + if ($user_data && give_is_email_banned($user_data->user_email)) { |
|
1081 | 1081 | $is_banned = true; |
1082 | 1082 | } |
1083 | 1083 | |
1084 | 1084 | } else { |
1085 | 1085 | |
1086 | 1086 | // Guest purchase, check that the email is not banned |
1087 | - if ( give_is_email_banned( $posted['give_email'] ) ) { |
|
1087 | + if (give_is_email_banned($posted['give_email'])) { |
|
1088 | 1088 | $is_banned = true; |
1089 | 1089 | } |
1090 | 1090 | |
1091 | 1091 | } |
1092 | 1092 | |
1093 | - if ( $is_banned ) { |
|
1093 | + if ($is_banned) { |
|
1094 | 1094 | // Set an error and give the donor a general error (don't alert them that they were banned) |
1095 | - give_set_error( 'email_banned', __( 'An internal error has occurred, please try again or contact support.', 'give' ) ); |
|
1095 | + give_set_error('email_banned', __('An internal error has occurred, please try again or contact support.', 'give')); |
|
1096 | 1096 | } |
1097 | 1097 | } |
1098 | 1098 | |
1099 | -add_action( 'give_checkout_error_checks', 'give_check_purchase_email', 10, 2 ); |
|
1099 | +add_action('give_checkout_error_checks', 'give_check_purchase_email', 10, 2); |