@@ -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 | |
@@ -29,20 +29,20 @@ discard block |
||
| 29 | 29 | function give_process_donation_form() { |
| 30 | 30 | |
| 31 | 31 | // Sanitize Posted Data. |
| 32 | - $post_data = give_clean( $_POST ); // WPCS: input var ok, CSRF ok. |
|
| 32 | + $post_data = give_clean($_POST); // WPCS: input var ok, CSRF ok. |
|
| 33 | 33 | |
| 34 | 34 | // Check whether the form submitted via AJAX or not. |
| 35 | - $is_ajax = isset( $post_data['give_ajax'] ); |
|
| 35 | + $is_ajax = isset($post_data['give_ajax']); |
|
| 36 | 36 | |
| 37 | 37 | // Verify donation form nonce. |
| 38 | - if ( ! give_verify_donation_form_nonce( $post_data['give-form-hash'], $post_data['give-form-id'] ) ) { |
|
| 39 | - if ( $is_ajax ) { |
|
| 38 | + if ( ! give_verify_donation_form_nonce($post_data['give-form-hash'], $post_data['give-form-id'])) { |
|
| 39 | + if ($is_ajax) { |
|
| 40 | 40 | /** |
| 41 | 41 | * Fires when AJAX sends back errors from the donation form. |
| 42 | 42 | * |
| 43 | 43 | * @since 1.0 |
| 44 | 44 | */ |
| 45 | - do_action( 'give_ajax_donation_errors' ); |
|
| 45 | + do_action('give_ajax_donation_errors'); |
|
| 46 | 46 | give_die(); |
| 47 | 47 | } else { |
| 48 | 48 | give_send_back_to_checkout(); |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * |
| 55 | 55 | * @since 1.0 |
| 56 | 56 | */ |
| 57 | - do_action( 'give_pre_process_donation' ); |
|
| 57 | + do_action('give_pre_process_donation'); |
|
| 58 | 58 | |
| 59 | 59 | // Validate the form $_POST data. |
| 60 | 60 | $valid_data = give_donation_form_validate_fields(); |
@@ -70,24 +70,24 @@ discard block |
||
| 70 | 70 | * @param array $deprecated Deprecated Since 2.0.2. Use $_POST instead. |
| 71 | 71 | */ |
| 72 | 72 | $deprecated = $post_data; |
| 73 | - do_action( 'give_checkout_error_checks', $valid_data, $deprecated ); |
|
| 73 | + do_action('give_checkout_error_checks', $valid_data, $deprecated); |
|
| 74 | 74 | |
| 75 | 75 | // Process the login form. |
| 76 | - if ( isset( $post_data['give_login_submit'] ) ) { |
|
| 76 | + if (isset($post_data['give_login_submit'])) { |
|
| 77 | 77 | give_process_form_login(); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Validate the user. |
| 81 | - $user = give_get_donation_form_user( $valid_data ); |
|
| 81 | + $user = give_get_donation_form_user($valid_data); |
|
| 82 | 82 | |
| 83 | - if ( false === $valid_data || give_get_errors() || ! $user ) { |
|
| 84 | - if ( $is_ajax ) { |
|
| 83 | + if (false === $valid_data || give_get_errors() || ! $user) { |
|
| 84 | + if ($is_ajax) { |
|
| 85 | 85 | /** |
| 86 | 86 | * Fires when AJAX sends back errors from the donation form. |
| 87 | 87 | * |
| 88 | 88 | * @since 1.0 |
| 89 | 89 | */ |
| 90 | - do_action( 'give_ajax_donation_errors' ); |
|
| 90 | + do_action('give_ajax_donation_errors'); |
|
| 91 | 91 | give_die(); |
| 92 | 92 | } else { |
| 93 | 93 | return false; |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | // If AJAX send back success to proceed with form submission. |
| 98 | - if ( $is_ajax ) { |
|
| 98 | + if ($is_ajax) { |
|
| 99 | 99 | echo 'success'; |
| 100 | 100 | give_die(); |
| 101 | 101 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * |
| 106 | 106 | * @since 2.2.0 |
| 107 | 107 | */ |
| 108 | - do_action( 'give_process_donation_after_validation' ); |
|
| 108 | + do_action('give_process_donation_after_validation'); |
|
| 109 | 109 | |
| 110 | 110 | // Setup user information. |
| 111 | 111 | $user_info = array( |
@@ -117,15 +117,14 @@ discard block |
||
| 117 | 117 | 'address' => $user['address'], |
| 118 | 118 | ); |
| 119 | 119 | |
| 120 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
| 120 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
| 121 | 121 | |
| 122 | 122 | // Donation form ID. |
| 123 | - $form_id = isset( $post_data['give-form-id'] ) ? absint( $post_data['give-form-id'] ) : 0; |
|
| 123 | + $form_id = isset($post_data['give-form-id']) ? absint($post_data['give-form-id']) : 0; |
|
| 124 | 124 | |
| 125 | - $price = isset( $post_data['give-amount'] ) ? |
|
| 126 | - (float) apply_filters( 'give_donation_total', give_maybe_sanitize_amount( $post_data['give-amount'], array( 'currency' => give_get_currency( $form_id ) ) ) ) : |
|
| 127 | - '0.00'; |
|
| 128 | - $purchase_key = strtolower( md5( $user['user_email'] . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'give', true ) ) ); |
|
| 125 | + $price = isset($post_data['give-amount']) ? |
|
| 126 | + (float) apply_filters('give_donation_total', give_maybe_sanitize_amount($post_data['give-amount'], array('currency' => give_get_currency($form_id)))) : '0.00'; |
|
| 127 | + $purchase_key = strtolower(md5($user['user_email'].date('Y-m-d H:i:s').$auth_key.uniqid('give', true))); |
|
| 129 | 128 | |
| 130 | 129 | /** |
| 131 | 130 | * Update donation Purchase key. |
@@ -155,8 +154,8 @@ discard block |
||
| 155 | 154 | 'price' => $price, |
| 156 | 155 | 'purchase_key' => $purchase_key, |
| 157 | 156 | 'user_email' => $user['user_email'], |
| 158 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
| 159 | - 'user_info' => stripslashes_deep( $user_info ), |
|
| 157 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
| 158 | + 'user_info' => stripslashes_deep($user_info), |
|
| 160 | 159 | 'post_data' => $post_data, |
| 161 | 160 | 'gateway' => $valid_data['gateway'], |
| 162 | 161 | 'card_info' => $valid_data['cc_info'], |
@@ -176,10 +175,10 @@ discard block |
||
| 176 | 175 | * @param array $user_info Array containing basic user information. |
| 177 | 176 | * @param bool|array $valid_data Validate fields. |
| 178 | 177 | */ |
| 179 | - do_action( 'give_checkout_before_gateway', $post_data, $user_info, $valid_data ); |
|
| 178 | + do_action('give_checkout_before_gateway', $post_data, $user_info, $valid_data); |
|
| 180 | 179 | |
| 181 | 180 | // Sanity check for price. |
| 182 | - if ( ! $donation_data['price'] ) { |
|
| 181 | + if ( ! $donation_data['price']) { |
|
| 183 | 182 | // Revert to manual. |
| 184 | 183 | $donation_data['gateway'] = 'manual'; |
| 185 | 184 | $_POST['give-gateway'] = 'manual'; |
@@ -190,26 +189,26 @@ discard block |
||
| 190 | 189 | * |
| 191 | 190 | * @since 1.7 |
| 192 | 191 | */ |
| 193 | - $donation_data = apply_filters( 'give_donation_data_before_gateway', $donation_data, $valid_data ); |
|
| 192 | + $donation_data = apply_filters('give_donation_data_before_gateway', $donation_data, $valid_data); |
|
| 194 | 193 | |
| 195 | 194 | // Setup the data we're storing in the donation session. |
| 196 | 195 | $session_data = $donation_data; |
| 197 | 196 | |
| 198 | 197 | // Make sure credit card numbers are never stored in sessions. |
| 199 | - unset( $session_data['card_info']['card_number'] ); |
|
| 200 | - unset( $session_data['post_data']['card_number'] ); |
|
| 198 | + unset($session_data['card_info']['card_number']); |
|
| 199 | + unset($session_data['post_data']['card_number']); |
|
| 201 | 200 | |
| 202 | 201 | // Used for showing data to non logged-in users after donation, and for other plugins needing donation data. |
| 203 | - give_set_purchase_session( $session_data ); |
|
| 202 | + give_set_purchase_session($session_data); |
|
| 204 | 203 | |
| 205 | 204 | // Send info to the gateway for payment processing. |
| 206 | - give_send_to_gateway( $donation_data['gateway'], $donation_data ); |
|
| 205 | + give_send_to_gateway($donation_data['gateway'], $donation_data); |
|
| 207 | 206 | give_die(); |
| 208 | 207 | } |
| 209 | 208 | |
| 210 | -add_action( 'give_purchase', 'give_process_donation_form' ); |
|
| 211 | -add_action( 'wp_ajax_give_process_donation', 'give_process_donation_form' ); |
|
| 212 | -add_action( 'wp_ajax_nopriv_give_process_donation', 'give_process_donation_form' ); |
|
| 209 | +add_action('give_purchase', 'give_process_donation_form'); |
|
| 210 | +add_action('wp_ajax_give_process_donation', 'give_process_donation_form'); |
|
| 211 | +add_action('wp_ajax_nopriv_give_process_donation', 'give_process_donation_form'); |
|
| 213 | 212 | |
| 214 | 213 | /** |
| 215 | 214 | * Verify that when a logged in user makes a donation that the email address used doesn't belong to a different customer. |
@@ -220,27 +219,27 @@ discard block |
||
| 220 | 219 | * |
| 221 | 220 | * @return void |
| 222 | 221 | */ |
| 223 | -function give_check_logged_in_user_for_existing_email( $valid_data ) { |
|
| 222 | +function give_check_logged_in_user_for_existing_email($valid_data) { |
|
| 224 | 223 | |
| 225 | 224 | // Verify that the email address belongs to this customer. |
| 226 | - if ( is_user_logged_in() ) { |
|
| 225 | + if (is_user_logged_in()) { |
|
| 227 | 226 | |
| 228 | 227 | $submitted_email = $valid_data['logged_in_user']['user_email']; |
| 229 | - $donor = new Give_Donor( get_current_user_id(), true ); |
|
| 228 | + $donor = new Give_Donor(get_current_user_id(), true); |
|
| 230 | 229 | |
| 231 | 230 | // If this email address is not registered with this customer, see if it belongs to any other customer. |
| 232 | 231 | if ( |
| 233 | 232 | $submitted_email !== $donor->email |
| 234 | - && ( is_array( $donor->emails ) && ! in_array( $submitted_email, $donor->emails, true ) ) |
|
| 233 | + && (is_array($donor->emails) && ! in_array($submitted_email, $donor->emails, true)) |
|
| 235 | 234 | ) { |
| 236 | - $found_donor = new Give_Donor( $submitted_email ); |
|
| 235 | + $found_donor = new Give_Donor($submitted_email); |
|
| 237 | 236 | |
| 238 | - if ( $found_donor->id > 0 ) { |
|
| 237 | + if ($found_donor->id > 0) { |
|
| 239 | 238 | give_set_error( |
| 240 | 239 | 'give-customer-email-exists', |
| 241 | 240 | sprintf( |
| 242 | 241 | /* translators: 1. Donor Email, 2. Submitted Email */ |
| 243 | - __( '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' ), |
|
| 242 | + __('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'), |
|
| 244 | 243 | $donor->email, |
| 245 | 244 | $submitted_email |
| 246 | 245 | ) |
@@ -250,7 +249,7 @@ discard block |
||
| 250 | 249 | } |
| 251 | 250 | } |
| 252 | 251 | |
| 253 | -add_action( 'give_checkout_error_checks', 'give_check_logged_in_user_for_existing_email', 10, 1 ); |
|
| 252 | +add_action('give_checkout_error_checks', 'give_check_logged_in_user_for_existing_email', 10, 1); |
|
| 254 | 253 | |
| 255 | 254 | /** |
| 256 | 255 | * Process the checkout login form |
@@ -262,49 +261,49 @@ discard block |
||
| 262 | 261 | */ |
| 263 | 262 | function give_process_form_login() { |
| 264 | 263 | |
| 265 | - $is_ajax = ! empty( $_POST['give_ajax'] ) ? give_clean( $_POST['give_ajax'] ) : 0; // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 264 | + $is_ajax = ! empty($_POST['give_ajax']) ? give_clean($_POST['give_ajax']) : 0; // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 266 | 265 | $referrer = wp_get_referer(); |
| 267 | 266 | $user_data = give_donation_form_validate_user_login(); |
| 268 | 267 | |
| 269 | - if ( give_get_errors() || $user_data['user_id'] < 1 ) { |
|
| 270 | - if ( $is_ajax ) { |
|
| 268 | + if (give_get_errors() || $user_data['user_id'] < 1) { |
|
| 269 | + if ($is_ajax) { |
|
| 271 | 270 | /** |
| 272 | 271 | * Fires when AJAX sends back errors from the donation form. |
| 273 | 272 | * |
| 274 | 273 | * @since 1.0 |
| 275 | 274 | */ |
| 276 | 275 | ob_start(); |
| 277 | - do_action( 'give_ajax_donation_errors' ); |
|
| 276 | + do_action('give_ajax_donation_errors'); |
|
| 278 | 277 | $message = ob_get_contents(); |
| 279 | 278 | ob_end_clean(); |
| 280 | - wp_send_json_error( $message ); |
|
| 279 | + wp_send_json_error($message); |
|
| 281 | 280 | } else { |
| 282 | - wp_safe_redirect( $referrer ); |
|
| 281 | + wp_safe_redirect($referrer); |
|
| 283 | 282 | exit; |
| 284 | 283 | } |
| 285 | 284 | } |
| 286 | 285 | |
| 287 | - give_log_user_in( $user_data['user_id'], $user_data['user_login'], $user_data['user_pass'] ); |
|
| 286 | + give_log_user_in($user_data['user_id'], $user_data['user_login'], $user_data['user_pass']); |
|
| 288 | 287 | |
| 289 | - if ( $is_ajax ) { |
|
| 288 | + if ($is_ajax) { |
|
| 290 | 289 | $message = Give()->notices->print_frontend_notice( |
| 291 | 290 | sprintf( |
| 292 | 291 | /* translators: %s: user first name */ |
| 293 | - esc_html__( 'Welcome %s! You have successfully logged into your account.', 'give' ), |
|
| 294 | - ( ! empty( $user_data['user_first'] ) ) ? $user_data['user_first'] : $user_data['user_login'] |
|
| 292 | + esc_html__('Welcome %s! You have successfully logged into your account.', 'give'), |
|
| 293 | + ( ! empty($user_data['user_first'])) ? $user_data['user_first'] : $user_data['user_login'] |
|
| 295 | 294 | ), |
| 296 | 295 | false, |
| 297 | 296 | 'success' |
| 298 | 297 | ); |
| 299 | 298 | |
| 300 | - wp_send_json_success( $message ); |
|
| 299 | + wp_send_json_success($message); |
|
| 301 | 300 | } else { |
| 302 | - wp_safe_redirect( $referrer ); |
|
| 301 | + wp_safe_redirect($referrer); |
|
| 303 | 302 | } |
| 304 | 303 | } |
| 305 | 304 | |
| 306 | -add_action( 'wp_ajax_give_process_donation_login', 'give_process_form_login' ); |
|
| 307 | -add_action( 'wp_ajax_nopriv_give_process_donation_login', 'give_process_form_login' ); |
|
| 305 | +add_action('wp_ajax_give_process_donation_login', 'give_process_form_login'); |
|
| 306 | +add_action('wp_ajax_nopriv_give_process_donation_login', 'give_process_form_login'); |
|
| 308 | 307 | |
| 309 | 308 | /** |
| 310 | 309 | * Donation Form Validate Fields. |
@@ -316,49 +315,49 @@ discard block |
||
| 316 | 315 | */ |
| 317 | 316 | function give_donation_form_validate_fields() { |
| 318 | 317 | |
| 319 | - $post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 318 | + $post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 320 | 319 | |
| 321 | 320 | // Validate Honeypot First. |
| 322 | - if ( ! empty( $post_data['give-honeypot'] ) ) { |
|
| 323 | - give_set_error( 'invalid_honeypot', esc_html__( 'Honeypot field detected. Go away bad bot!', 'give' ) ); |
|
| 321 | + if ( ! empty($post_data['give-honeypot'])) { |
|
| 322 | + give_set_error('invalid_honeypot', esc_html__('Honeypot field detected. Go away bad bot!', 'give')); |
|
| 324 | 323 | } |
| 325 | 324 | |
| 326 | 325 | // Check spam detect. |
| 327 | 326 | if ( |
| 328 | - isset( $post_data['action'] ) && |
|
| 329 | - give_is_setting_enabled( give_get_option( 'akismet_spam_protection' ) ) && |
|
| 327 | + isset($post_data['action']) && |
|
| 328 | + give_is_setting_enabled(give_get_option('akismet_spam_protection')) && |
|
| 330 | 329 | give_is_spam_donation() |
| 331 | 330 | ) { |
| 332 | - give_set_error( 'spam_donation', __( 'This donation has been flagged as spam. Please try again.', 'give' ) ); |
|
| 331 | + give_set_error('spam_donation', __('This donation has been flagged as spam. Please try again.', 'give')); |
|
| 333 | 332 | } |
| 334 | 333 | |
| 335 | 334 | // Start an array to collect valid data. |
| 336 | 335 | $valid_data = array( |
| 337 | 336 | 'gateway' => give_donation_form_validate_gateway(), // Gateway fallback (amount is validated here). |
| 338 | - 'need_new_user' => false, // New user flag. |
|
| 339 | - 'need_user_login' => false, // Login user flag. |
|
| 340 | - 'logged_user_data' => array(), // Logged user collected data. |
|
| 341 | - 'new_user_data' => array(), // New user collected data. |
|
| 342 | - 'login_user_data' => array(), // Login user collected data. |
|
| 343 | - 'guest_user_data' => array(), // Guest user collected data. |
|
| 337 | + 'need_new_user' => false, // New user flag. |
|
| 338 | + 'need_user_login' => false, // Login user flag. |
|
| 339 | + 'logged_user_data' => array(), // Logged user collected data. |
|
| 340 | + 'new_user_data' => array(), // New user collected data. |
|
| 341 | + 'login_user_data' => array(), // Login user collected data. |
|
| 342 | + 'guest_user_data' => array(), // Guest user collected data. |
|
| 344 | 343 | 'cc_info' => give_donation_form_validate_cc(), // Credit card info. |
| 345 | 344 | ); |
| 346 | 345 | |
| 347 | - $form_id = intval( $post_data['give-form-id'] ); |
|
| 346 | + $form_id = intval($post_data['give-form-id']); |
|
| 348 | 347 | |
| 349 | 348 | // Validate agree to terms. |
| 350 | - if ( give_is_terms_enabled( $form_id ) ) { |
|
| 349 | + if (give_is_terms_enabled($form_id)) { |
|
| 351 | 350 | give_donation_form_validate_agree_to_terms(); |
| 352 | 351 | } |
| 353 | 352 | |
| 354 | - if ( is_user_logged_in() ) { |
|
| 353 | + if (is_user_logged_in()) { |
|
| 355 | 354 | |
| 356 | 355 | // Collect logged in user data. |
| 357 | 356 | $valid_data['logged_in_user'] = give_donation_form_validate_logged_in_user(); |
| 358 | 357 | } elseif ( |
| 359 | - isset( $post_data['give-purchase-var'] ) && |
|
| 358 | + isset($post_data['give-purchase-var']) && |
|
| 360 | 359 | 'needs-to-register' === $post_data['give-purchase-var'] && |
| 361 | - ! empty( $post_data['give_create_account'] ) |
|
| 360 | + ! empty($post_data['give_create_account']) |
|
| 362 | 361 | ) { |
| 363 | 362 | |
| 364 | 363 | // Set new user registration as required. |
@@ -367,7 +366,7 @@ discard block |
||
| 367 | 366 | // Validate new user data. |
| 368 | 367 | $valid_data['new_user_data'] = give_donation_form_validate_new_user(); |
| 369 | 368 | } elseif ( |
| 370 | - isset( $post_data['give-purchase-var'] ) && |
|
| 369 | + isset($post_data['give-purchase-var']) && |
|
| 371 | 370 | 'needs-to-login' === $post_data['give-purchase-var'] |
| 372 | 371 | ) { |
| 373 | 372 | |
@@ -396,14 +395,14 @@ discard block |
||
| 396 | 395 | function give_is_spam_donation() { |
| 397 | 396 | $spam = false; |
| 398 | 397 | |
| 399 | - $user_agent = (string) isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : ''; |
|
| 398 | + $user_agent = (string) isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; |
|
| 400 | 399 | |
| 401 | - if ( strlen( $user_agent ) < 2 ) { |
|
| 400 | + if (strlen($user_agent) < 2) { |
|
| 402 | 401 | $spam = true; |
| 403 | 402 | } |
| 404 | 403 | |
| 405 | 404 | // Allow developer to customized Akismet spam detect API call and it's response. |
| 406 | - return apply_filters( 'give_spam', $spam ); |
|
| 405 | + return apply_filters('give_spam', $spam); |
|
| 407 | 406 | } |
| 408 | 407 | |
| 409 | 408 | /** |
@@ -418,33 +417,33 @@ discard block |
||
| 418 | 417 | */ |
| 419 | 418 | function give_donation_form_validate_gateway() { |
| 420 | 419 | |
| 421 | - $post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 422 | - $form_id = ! empty( $post_data['give-form-id'] ) ? $post_data['give-form-id'] : 0; |
|
| 423 | - $amount = ! empty( $post_data['give-amount'] ) ? give_maybe_sanitize_amount( $post_data['give-amount'] ) : 0; |
|
| 424 | - $gateway = ! empty( $post_data['give-gateway'] ) ? $post_data['give-gateway'] : 0; |
|
| 420 | + $post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 421 | + $form_id = ! empty($post_data['give-form-id']) ? $post_data['give-form-id'] : 0; |
|
| 422 | + $amount = ! empty($post_data['give-amount']) ? give_maybe_sanitize_amount($post_data['give-amount']) : 0; |
|
| 423 | + $gateway = ! empty($post_data['give-gateway']) ? $post_data['give-gateway'] : 0; |
|
| 425 | 424 | |
| 426 | 425 | // Bailout, if payment gateway is not submitted with donation form data. |
| 427 | - if ( empty( $gateway ) ) { |
|
| 426 | + if (empty($gateway)) { |
|
| 428 | 427 | |
| 429 | - give_set_error( 'empty_gateway', __( 'The donation form will process with a valid payment gateway.', 'give' ) ); |
|
| 428 | + give_set_error('empty_gateway', __('The donation form will process with a valid payment gateway.', 'give')); |
|
| 430 | 429 | |
| 431 | - } elseif ( ! give_is_gateway_active( $gateway ) ) { |
|
| 430 | + } elseif ( ! give_is_gateway_active($gateway)) { |
|
| 432 | 431 | |
| 433 | - give_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled.', 'give' ) ); |
|
| 432 | + give_set_error('invalid_gateway', __('The selected payment gateway is not enabled.', 'give')); |
|
| 434 | 433 | |
| 435 | - } elseif ( empty( $amount ) ) { |
|
| 434 | + } elseif (empty($amount)) { |
|
| 436 | 435 | |
| 437 | - give_set_error( 'invalid_donation_amount', __( 'Please insert a valid donation amount.', 'give' ) ); |
|
| 436 | + give_set_error('invalid_donation_amount', __('Please insert a valid donation amount.', 'give')); |
|
| 438 | 437 | |
| 439 | - } elseif ( ! give_verify_minimum_price( 'minimum' ) ) { |
|
| 438 | + } elseif ( ! give_verify_minimum_price('minimum')) { |
|
| 440 | 439 | |
| 441 | 440 | give_set_error( |
| 442 | 441 | 'invalid_donation_minimum', |
| 443 | 442 | sprintf( |
| 444 | 443 | /* translators: %s: minimum donation amount */ |
| 445 | - __( 'This form has a minimum donation amount of %s.', 'give' ), |
|
| 444 | + __('This form has a minimum donation amount of %s.', 'give'), |
|
| 446 | 445 | give_currency_filter( |
| 447 | - give_format_amount( give_get_form_minimum_price( $form_id ), |
|
| 446 | + give_format_amount(give_get_form_minimum_price($form_id), |
|
| 448 | 447 | array( |
| 449 | 448 | 'sanitize' => false, |
| 450 | 449 | ) |
@@ -452,15 +451,15 @@ discard block |
||
| 452 | 451 | ) |
| 453 | 452 | ) |
| 454 | 453 | ); |
| 455 | - } elseif ( ! give_verify_minimum_price( 'maximum' ) ) { |
|
| 454 | + } elseif ( ! give_verify_minimum_price('maximum')) { |
|
| 456 | 455 | |
| 457 | 456 | give_set_error( |
| 458 | 457 | 'invalid_donation_maximum', |
| 459 | 458 | sprintf( |
| 460 | 459 | /* translators: %s: Maximum donation amount */ |
| 461 | - __( 'This form has a maximum donation amount of %s.', 'give' ), |
|
| 460 | + __('This form has a maximum donation amount of %s.', 'give'), |
|
| 462 | 461 | give_currency_filter( |
| 463 | - give_format_amount( give_get_form_maximum_price( $form_id ), |
|
| 462 | + give_format_amount(give_get_form_maximum_price($form_id), |
|
| 464 | 463 | array( |
| 465 | 464 | 'sanitize' => false, |
| 466 | 465 | ) |
@@ -486,33 +485,33 @@ discard block |
||
| 486 | 485 | * |
| 487 | 486 | * @return bool |
| 488 | 487 | */ |
| 489 | -function give_verify_minimum_price( $amount_range = 'minimum' ) { |
|
| 488 | +function give_verify_minimum_price($amount_range = 'minimum') { |
|
| 490 | 489 | |
| 491 | - $post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 492 | - $form_id = ! empty( $post_data['give-form-id'] ) ? $post_data['give-form-id'] : 0; |
|
| 493 | - $amount = ! empty( $post_data['give-amount'] ) ? give_maybe_sanitize_amount( $post_data['give-amount'], array( 'currency' => give_get_currency( $form_id ) ) ) : 0; |
|
| 494 | - $price_id = isset( $post_data['give-price-id'] ) ? absint( $post_data['give-price-id'] ) : ''; |
|
| 490 | + $post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 491 | + $form_id = ! empty($post_data['give-form-id']) ? $post_data['give-form-id'] : 0; |
|
| 492 | + $amount = ! empty($post_data['give-amount']) ? give_maybe_sanitize_amount($post_data['give-amount'], array('currency' => give_get_currency($form_id))) : 0; |
|
| 493 | + $price_id = isset($post_data['give-price-id']) ? absint($post_data['give-price-id']) : ''; |
|
| 495 | 494 | |
| 496 | - $variable_prices = give_has_variable_prices( $form_id ); |
|
| 497 | - $price_ids = array_map( 'absint', give_get_variable_price_ids( $form_id ) ); |
|
| 495 | + $variable_prices = give_has_variable_prices($form_id); |
|
| 496 | + $price_ids = array_map('absint', give_get_variable_price_ids($form_id)); |
|
| 498 | 497 | $verified_stat = false; |
| 499 | 498 | |
| 500 | - if ( $variable_prices && in_array( $price_id, $price_ids, true ) ) { |
|
| 499 | + if ($variable_prices && in_array($price_id, $price_ids, true)) { |
|
| 501 | 500 | |
| 502 | - $price_level_amount = give_get_price_option_amount( $form_id, $price_id ); |
|
| 501 | + $price_level_amount = give_get_price_option_amount($form_id, $price_id); |
|
| 503 | 502 | |
| 504 | - if ( $price_level_amount == $amount ) { |
|
| 503 | + if ($price_level_amount == $amount) { |
|
| 505 | 504 | $verified_stat = true; |
| 506 | 505 | } |
| 507 | 506 | } |
| 508 | 507 | |
| 509 | - if ( ! $verified_stat ) { |
|
| 510 | - switch ( $amount_range ) { |
|
| 508 | + if ( ! $verified_stat) { |
|
| 509 | + switch ($amount_range) { |
|
| 511 | 510 | case 'minimum' : |
| 512 | - $verified_stat = ( give_get_form_minimum_price( $form_id ) > $amount ) ? false : true; |
|
| 511 | + $verified_stat = (give_get_form_minimum_price($form_id) > $amount) ? false : true; |
|
| 513 | 512 | break; |
| 514 | 513 | case 'maximum' : |
| 515 | - $verified_stat = ( give_get_form_maximum_price( $form_id ) < $amount ) ? false : true; |
|
| 514 | + $verified_stat = (give_get_form_maximum_price($form_id) < $amount) ? false : true; |
|
| 516 | 515 | break; |
| 517 | 516 | } |
| 518 | 517 | } |
@@ -526,7 +525,7 @@ discard block |
||
| 526 | 525 | * @param string $amount_range Type of the amount. |
| 527 | 526 | * @param integer $form_id Give Donation Form ID. |
| 528 | 527 | */ |
| 529 | - return apply_filters( 'give_verify_minimum_maximum_price', $verified_stat, $amount_range, $form_id ); |
|
| 528 | + return apply_filters('give_verify_minimum_maximum_price', $verified_stat, $amount_range, $form_id); |
|
| 530 | 529 | } |
| 531 | 530 | |
| 532 | 531 | /** |
@@ -539,13 +538,13 @@ discard block |
||
| 539 | 538 | */ |
| 540 | 539 | function give_donation_form_validate_agree_to_terms() { |
| 541 | 540 | |
| 542 | - $agree_to_terms = ! empty( $_POST['give_agree_to_terms'] ) ? give_clean( $_POST['give_agree_to_terms'] ) : 0; // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 541 | + $agree_to_terms = ! empty($_POST['give_agree_to_terms']) ? give_clean($_POST['give_agree_to_terms']) : 0; // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 543 | 542 | |
| 544 | 543 | // Proceed only, if donor agreed to terms. |
| 545 | - if ( ! $agree_to_terms ) { |
|
| 544 | + if ( ! $agree_to_terms) { |
|
| 546 | 545 | |
| 547 | 546 | // User did not agree. |
| 548 | - give_set_error( 'agree_to_terms', apply_filters( 'give_agree_to_terms_text', __( 'You must agree to the terms and conditions.', 'give' ) ) ); |
|
| 547 | + give_set_error('agree_to_terms', apply_filters('give_agree_to_terms_text', __('You must agree to the terms and conditions.', 'give'))); |
|
| 549 | 548 | } |
| 550 | 549 | } |
| 551 | 550 | |
@@ -559,92 +558,92 @@ discard block |
||
| 559 | 558 | * |
| 560 | 559 | * @return array |
| 561 | 560 | */ |
| 562 | -function give_get_required_fields( $form_id ) { |
|
| 561 | +function give_get_required_fields($form_id) { |
|
| 563 | 562 | |
| 564 | - $payment_mode = give_get_chosen_gateway( $form_id ); |
|
| 563 | + $payment_mode = give_get_chosen_gateway($form_id); |
|
| 565 | 564 | |
| 566 | 565 | $required_fields = array( |
| 567 | 566 | 'give_email' => array( |
| 568 | 567 | 'error_id' => 'invalid_email', |
| 569 | - 'error_message' => __( 'Please enter a valid email address.', 'give' ), |
|
| 568 | + 'error_message' => __('Please enter a valid email address.', 'give'), |
|
| 570 | 569 | ), |
| 571 | 570 | 'give_first' => array( |
| 572 | 571 | 'error_id' => 'invalid_first_name', |
| 573 | - 'error_message' => __( 'Please enter your first name.', 'give' ), |
|
| 572 | + 'error_message' => __('Please enter your first name.', 'give'), |
|
| 574 | 573 | ), |
| 575 | 574 | ); |
| 576 | 575 | |
| 577 | - $name_title_prefix = give_is_name_title_prefix_required( $form_id ); |
|
| 578 | - if ( $name_title_prefix ) { |
|
| 576 | + $name_title_prefix = give_is_name_title_prefix_required($form_id); |
|
| 577 | + if ($name_title_prefix) { |
|
| 579 | 578 | $required_fields['give_title'] = array( |
| 580 | 579 | 'error_id' => 'invalid_title', |
| 581 | - 'error_message' => __( 'Please enter your title.', 'give' ), |
|
| 580 | + 'error_message' => __('Please enter your title.', 'give'), |
|
| 582 | 581 | ); |
| 583 | 582 | } |
| 584 | 583 | |
| 585 | - $require_address = give_require_billing_address( $payment_mode ); |
|
| 584 | + $require_address = give_require_billing_address($payment_mode); |
|
| 586 | 585 | |
| 587 | - if ( $require_address ) { |
|
| 588 | - $required_fields['card_address'] = array( |
|
| 586 | + if ($require_address) { |
|
| 587 | + $required_fields['card_address'] = array( |
|
| 589 | 588 | 'error_id' => 'invalid_card_address', |
| 590 | - 'error_message' => __( 'Please enter your primary billing address.', 'give' ), |
|
| 589 | + 'error_message' => __('Please enter your primary billing address.', 'give'), |
|
| 591 | 590 | ); |
| 592 | - $required_fields['card_zip'] = array( |
|
| 591 | + $required_fields['card_zip'] = array( |
|
| 593 | 592 | 'error_id' => 'invalid_zip_code', |
| 594 | - 'error_message' => __( 'Please enter your zip / postal code.', 'give' ), |
|
| 593 | + 'error_message' => __('Please enter your zip / postal code.', 'give'), |
|
| 595 | 594 | ); |
| 596 | - $required_fields['card_city'] = array( |
|
| 595 | + $required_fields['card_city'] = array( |
|
| 597 | 596 | 'error_id' => 'invalid_city', |
| 598 | - 'error_message' => __( 'Please enter your billing city.', 'give' ), |
|
| 597 | + 'error_message' => __('Please enter your billing city.', 'give'), |
|
| 599 | 598 | ); |
| 600 | 599 | $required_fields['billing_country'] = array( |
| 601 | 600 | 'error_id' => 'invalid_country', |
| 602 | - 'error_message' => __( 'Please select your billing country.', 'give' ), |
|
| 601 | + 'error_message' => __('Please select your billing country.', 'give'), |
|
| 603 | 602 | ); |
| 604 | 603 | |
| 605 | 604 | |
| 606 | 605 | $required_fields['card_state'] = array( |
| 607 | 606 | 'error_id' => 'invalid_state', |
| 608 | - 'error_message' => __( 'Please enter billing state / province / County.', 'give' ), |
|
| 607 | + 'error_message' => __('Please enter billing state / province / County.', 'give'), |
|
| 609 | 608 | ); |
| 610 | 609 | |
| 611 | - $country = ! empty( $_POST['billing_country'] ) ? give_clean( $_POST['billing_country'] ) : 0; // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 610 | + $country = ! empty($_POST['billing_country']) ? give_clean($_POST['billing_country']) : 0; // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 612 | 611 | |
| 613 | 612 | // Check if billing country already exists. |
| 614 | - if ( $country ) { |
|
| 613 | + if ($country) { |
|
| 615 | 614 | |
| 616 | 615 | // Get the country list that does not required any states init. |
| 617 | 616 | $states_country = give_states_not_required_country_list(); |
| 618 | 617 | |
| 619 | 618 | // Check if states is empty or not. |
| 620 | - if ( array_key_exists( $country, $states_country ) ) { |
|
| 619 | + if (array_key_exists($country, $states_country)) { |
|
| 621 | 620 | // If states is empty remove the required fields of state in billing cart. |
| 622 | - unset( $required_fields['card_state'] ); |
|
| 621 | + unset($required_fields['card_state']); |
|
| 623 | 622 | } |
| 624 | 623 | } |
| 625 | 624 | } // End if(). |
| 626 | 625 | |
| 627 | - if ( give_is_company_field_enabled( $form_id ) ) { |
|
| 628 | - $form_option = give_get_meta( $form_id, '_give_company_field', true ); |
|
| 629 | - $global_setting = give_get_option( 'company_field' ); |
|
| 626 | + if (give_is_company_field_enabled($form_id)) { |
|
| 627 | + $form_option = give_get_meta($form_id, '_give_company_field', true); |
|
| 628 | + $global_setting = give_get_option('company_field'); |
|
| 630 | 629 | |
| 631 | 630 | $is_company_field_required = false; |
| 632 | 631 | |
| 633 | - if ( ! empty( $form_option ) && give_is_setting_enabled( $form_option, array( 'required' ) ) ) { |
|
| 632 | + if ( ! empty($form_option) && give_is_setting_enabled($form_option, array('required'))) { |
|
| 634 | 633 | $is_company_field_required = true; |
| 635 | 634 | |
| 636 | - } elseif ( 'global' === $form_option && give_is_setting_enabled( $global_setting, array( 'required' ) ) ) { |
|
| 635 | + } elseif ('global' === $form_option && give_is_setting_enabled($global_setting, array('required'))) { |
|
| 637 | 636 | $is_company_field_required = true; |
| 638 | 637 | |
| 639 | - } elseif ( empty( $form_option ) && give_is_setting_enabled( $global_setting, array( 'required' ) ) ) { |
|
| 638 | + } elseif (empty($form_option) && give_is_setting_enabled($global_setting, array('required'))) { |
|
| 640 | 639 | $is_company_field_required = true; |
| 641 | 640 | |
| 642 | 641 | } |
| 643 | 642 | |
| 644 | - if ( $is_company_field_required ) { |
|
| 643 | + if ($is_company_field_required) { |
|
| 645 | 644 | $required_fields['give_company_name'] = array( |
| 646 | 645 | 'error_id' => 'invalid_company', |
| 647 | - 'error_message' => __( 'Please enter Company Name.', 'give' ), |
|
| 646 | + 'error_message' => __('Please enter Company Name.', 'give'), |
|
| 648 | 647 | ); |
| 649 | 648 | } |
| 650 | 649 | } |
@@ -654,7 +653,7 @@ discard block |
||
| 654 | 653 | * |
| 655 | 654 | * @since 1.7 |
| 656 | 655 | */ |
| 657 | - $required_fields = apply_filters( 'give_donation_form_required_fields', $required_fields, $form_id ); |
|
| 656 | + $required_fields = apply_filters('give_donation_form_required_fields', $required_fields, $form_id); |
|
| 658 | 657 | |
| 659 | 658 | return $required_fields; |
| 660 | 659 | |
@@ -669,17 +668,17 @@ discard block |
||
| 669 | 668 | * |
| 670 | 669 | * @return bool |
| 671 | 670 | */ |
| 672 | -function give_require_billing_address( $payment_mode ) { |
|
| 671 | +function give_require_billing_address($payment_mode) { |
|
| 673 | 672 | |
| 674 | 673 | $return = false; |
| 675 | - $billing_country = ! empty( $_POST['billing_country'] ) ? give_clean( $_POST['billing_country'] ) : 0; // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 674 | + $billing_country = ! empty($_POST['billing_country']) ? give_clean($_POST['billing_country']) : 0; // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 676 | 675 | |
| 677 | - if ( $billing_country || did_action( "give_{$payment_mode}_cc_form" ) || did_action( 'give_cc_form' ) ) { |
|
| 676 | + if ($billing_country || did_action("give_{$payment_mode}_cc_form") || did_action('give_cc_form')) { |
|
| 678 | 677 | $return = true; |
| 679 | 678 | } |
| 680 | 679 | |
| 681 | 680 | // Let payment gateways and other extensions determine if address fields should be required. |
| 682 | - return apply_filters( 'give_require_billing_address', $return ); |
|
| 681 | + return apply_filters('give_require_billing_address', $return); |
|
| 683 | 682 | |
| 684 | 683 | } |
| 685 | 684 | |
@@ -693,47 +692,47 @@ discard block |
||
| 693 | 692 | */ |
| 694 | 693 | function give_donation_form_validate_logged_in_user() { |
| 695 | 694 | |
| 696 | - $post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 695 | + $post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 697 | 696 | $user_id = get_current_user_id(); |
| 698 | - $form_id = ! empty( $post_data['give-form-id'] ) ? $post_data['give-form-id'] : 0; |
|
| 697 | + $form_id = ! empty($post_data['give-form-id']) ? $post_data['give-form-id'] : 0; |
|
| 699 | 698 | |
| 700 | 699 | // Start empty array to collect valid user data. |
| 701 | 700 | $valid_user_data = array( |
| 702 | 701 | |
| 703 | 702 | // Assume there will be errors. |
| 704 | - 'user_id' => - 1, |
|
| 703 | + 'user_id' => -1, |
|
| 705 | 704 | ); |
| 706 | 705 | |
| 707 | 706 | // Proceed on;y, if valid $user_id found. |
| 708 | - if ( $user_id > 0 ) { |
|
| 707 | + if ($user_id > 0) { |
|
| 709 | 708 | |
| 710 | 709 | // Get the logged in user data. |
| 711 | - $user_data = get_userdata( $user_id ); |
|
| 710 | + $user_data = get_userdata($user_id); |
|
| 712 | 711 | |
| 713 | 712 | // Validate Required Form Fields. |
| 714 | - give_validate_required_form_fields( $form_id ); |
|
| 713 | + give_validate_required_form_fields($form_id); |
|
| 715 | 714 | |
| 716 | 715 | // Verify data. |
| 717 | - if ( is_object( $user_data ) && $user_data->ID > 0 ) { |
|
| 716 | + if (is_object($user_data) && $user_data->ID > 0) { |
|
| 718 | 717 | |
| 719 | 718 | // Collected logged in user data. |
| 720 | 719 | $valid_user_data = array( |
| 721 | 720 | 'user_id' => $user_id, |
| 722 | - 'user_email' => ! empty( $post_data['give_email'] ) ? sanitize_email( $post_data['give_email'] ) : $user_data->user_email, |
|
| 723 | - 'user_first' => ! empty( $post_data['give_first'] ) ? $post_data['give_first'] : $user_data->first_name, |
|
| 724 | - 'user_last' => ! empty( $post_data['give_last'] ) ? $post_data['give_last'] : $user_data->last_name, |
|
| 721 | + 'user_email' => ! empty($post_data['give_email']) ? sanitize_email($post_data['give_email']) : $user_data->user_email, |
|
| 722 | + 'user_first' => ! empty($post_data['give_first']) ? $post_data['give_first'] : $user_data->first_name, |
|
| 723 | + 'user_last' => ! empty($post_data['give_last']) ? $post_data['give_last'] : $user_data->last_name, |
|
| 725 | 724 | ); |
| 726 | 725 | |
| 727 | 726 | // Validate essential form fields. |
| 728 | - give_donation_form_validate_name_fields( $post_data ); |
|
| 727 | + give_donation_form_validate_name_fields($post_data); |
|
| 729 | 728 | |
| 730 | - if ( ! is_email( $valid_user_data['user_email'] ) ) { |
|
| 731 | - give_set_error( 'email_invalid', esc_html__( 'Invalid email.', 'give' ) ); |
|
| 729 | + if ( ! is_email($valid_user_data['user_email'])) { |
|
| 730 | + give_set_error('email_invalid', esc_html__('Invalid email.', 'give')); |
|
| 732 | 731 | } |
| 733 | 732 | } else { |
| 734 | 733 | |
| 735 | 734 | // Set invalid user information error. |
| 736 | - give_set_error( 'invalid_user', esc_html__( 'The user information is invalid.', 'give' ) ); |
|
| 735 | + give_set_error('invalid_user', esc_html__('The user information is invalid.', 'give')); |
|
| 737 | 736 | } |
| 738 | 737 | } |
| 739 | 738 | |
@@ -754,7 +753,7 @@ discard block |
||
| 754 | 753 | $auto_generated_password = wp_generate_password(); |
| 755 | 754 | $default_user_data = array( |
| 756 | 755 | 'give-form-id' => '', |
| 757 | - 'user_id' => - 1, // Assume there will be errors. |
|
| 756 | + 'user_id' => -1, // Assume there will be errors. |
|
| 758 | 757 | 'user_first' => '', |
| 759 | 758 | 'user_last' => '', |
| 760 | 759 | 'give_user_login' => false, |
@@ -764,26 +763,26 @@ discard block |
||
| 764 | 763 | ); |
| 765 | 764 | |
| 766 | 765 | // Get data. |
| 767 | - $post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 768 | - $user_data = wp_parse_args( $post_data, $default_user_data ); |
|
| 766 | + $post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 767 | + $user_data = wp_parse_args($post_data, $default_user_data); |
|
| 769 | 768 | |
| 770 | - $form_id = absint( $user_data['give-form-id'] ); |
|
| 771 | - $nonce = ! empty( $post_data['give-form-user-register-hash'] ) ? $post_data['give-form-user-register-hash'] : ''; |
|
| 769 | + $form_id = absint($user_data['give-form-id']); |
|
| 770 | + $nonce = ! empty($post_data['give-form-user-register-hash']) ? $post_data['give-form-user-register-hash'] : ''; |
|
| 772 | 771 | |
| 773 | 772 | // Validate user creation nonce. |
| 774 | - if ( ! wp_verify_nonce( $nonce, "give_form_create_user_nonce_{$form_id}" ) ) { |
|
| 775 | - give_set_error( 'invalid_nonce', __( 'Nonce verification has failed.', 'give' ) ); |
|
| 773 | + if ( ! wp_verify_nonce($nonce, "give_form_create_user_nonce_{$form_id}")) { |
|
| 774 | + give_set_error('invalid_nonce', __('Nonce verification has failed.', 'give')); |
|
| 776 | 775 | } |
| 777 | 776 | |
| 778 | 777 | $registering_new_user = false; |
| 779 | 778 | |
| 780 | - give_donation_form_validate_name_fields( $user_data ); |
|
| 779 | + give_donation_form_validate_name_fields($user_data); |
|
| 781 | 780 | |
| 782 | 781 | // Start an empty array to collect valid user data. |
| 783 | 782 | $valid_user_data = array( |
| 784 | 783 | |
| 785 | 784 | // Assume there will be errors. |
| 786 | - 'user_id' => - 1, |
|
| 785 | + 'user_id' => -1, |
|
| 787 | 786 | |
| 788 | 787 | // Get first name. |
| 789 | 788 | 'user_first' => $user_data['give_first'], |
@@ -796,13 +795,13 @@ discard block |
||
| 796 | 795 | ); |
| 797 | 796 | |
| 798 | 797 | // Validate Required Form Fields. |
| 799 | - give_validate_required_form_fields( $form_id ); |
|
| 798 | + give_validate_required_form_fields($form_id); |
|
| 800 | 799 | |
| 801 | 800 | // Set Email as Username. |
| 802 | 801 | $valid_user_data['user_login'] = $user_data['give_email']; |
| 803 | 802 | |
| 804 | 803 | // Check if we have an email to verify. |
| 805 | - if ( give_validate_user_email( $user_data['give_email'], $registering_new_user ) ) { |
|
| 804 | + if (give_validate_user_email($user_data['give_email'], $registering_new_user)) { |
|
| 806 | 805 | $valid_user_data['user_email'] = $user_data['give_email']; |
| 807 | 806 | } |
| 808 | 807 | |
@@ -819,47 +818,47 @@ discard block |
||
| 819 | 818 | */ |
| 820 | 819 | function give_donation_form_validate_user_login() { |
| 821 | 820 | |
| 822 | - $post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 821 | + $post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 823 | 822 | |
| 824 | 823 | // Start an array to collect valid user data. |
| 825 | 824 | $valid_user_data = array( |
| 826 | 825 | |
| 827 | 826 | // Assume there will be errors. |
| 828 | - 'user_id' => - 1, |
|
| 827 | + 'user_id' => -1, |
|
| 829 | 828 | ); |
| 830 | 829 | |
| 831 | 830 | // Bailout, if Username is empty. |
| 832 | - if ( empty( $post_data['give_user_login'] ) ) { |
|
| 833 | - give_set_error( 'must_log_in', __( 'You must register or login to complete your donation.', 'give' ) ); |
|
| 831 | + if (empty($post_data['give_user_login'])) { |
|
| 832 | + give_set_error('must_log_in', __('You must register or login to complete your donation.', 'give')); |
|
| 834 | 833 | |
| 835 | 834 | return $valid_user_data; |
| 836 | 835 | } |
| 837 | 836 | |
| 838 | 837 | // Get the user by login. |
| 839 | - $user_data = get_user_by( 'login', strip_tags( $post_data['give_user_login'] ) ); |
|
| 838 | + $user_data = get_user_by('login', strip_tags($post_data['give_user_login'])); |
|
| 840 | 839 | |
| 841 | 840 | // Check if user exists. |
| 842 | - if ( $user_data ) { |
|
| 841 | + if ($user_data) { |
|
| 843 | 842 | |
| 844 | 843 | // Get password. |
| 845 | - $user_pass = ! empty( $post_data['give_user_pass'] ) ? $post_data['give_user_pass'] : false; |
|
| 844 | + $user_pass = ! empty($post_data['give_user_pass']) ? $post_data['give_user_pass'] : false; |
|
| 846 | 845 | |
| 847 | 846 | // Check user_pass. |
| 848 | - if ( $user_pass ) { |
|
| 847 | + if ($user_pass) { |
|
| 849 | 848 | |
| 850 | 849 | // Check if password is valid. |
| 851 | - if ( ! wp_check_password( $user_pass, $user_data->user_pass, $user_data->ID ) ) { |
|
| 850 | + if ( ! wp_check_password($user_pass, $user_data->user_pass, $user_data->ID)) { |
|
| 852 | 851 | |
| 853 | - $current_page_url = site_url() . '/' . get_page_uri(); |
|
| 852 | + $current_page_url = site_url().'/'.get_page_uri(); |
|
| 854 | 853 | |
| 855 | 854 | // Incorrect password. |
| 856 | 855 | give_set_error( |
| 857 | 856 | 'password_incorrect', |
| 858 | 857 | sprintf( |
| 859 | 858 | '%1$s <a href="%2$s">%3$s</a>', |
| 860 | - __( 'The password you entered is incorrect.', 'give' ), |
|
| 861 | - wp_lostpassword_url( $current_page_url ), |
|
| 862 | - __( 'Reset Password', 'give' ) |
|
| 859 | + __('The password you entered is incorrect.', 'give'), |
|
| 860 | + wp_lostpassword_url($current_page_url), |
|
| 861 | + __('Reset Password', 'give') |
|
| 863 | 862 | ) |
| 864 | 863 | ); |
| 865 | 864 | |
@@ -877,11 +876,11 @@ discard block |
||
| 877 | 876 | } |
| 878 | 877 | } else { |
| 879 | 878 | // Empty password. |
| 880 | - give_set_error( 'password_empty', __( 'Enter a password.', 'give' ) ); |
|
| 879 | + give_set_error('password_empty', __('Enter a password.', 'give')); |
|
| 881 | 880 | } |
| 882 | 881 | } else { |
| 883 | 882 | // No username. |
| 884 | - give_set_error( 'username_incorrect', __( 'The username you entered does not exist.', 'give' ) ); |
|
| 883 | + give_set_error('username_incorrect', __('The username you entered does not exist.', 'give')); |
|
| 885 | 884 | } // End if(). |
| 886 | 885 | |
| 887 | 886 | return $valid_user_data; |
@@ -897,8 +896,8 @@ discard block |
||
| 897 | 896 | */ |
| 898 | 897 | function give_donation_form_validate_guest_user() { |
| 899 | 898 | |
| 900 | - $post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 901 | - $form_id = ! empty( $post_data['give-form-id'] ) ? $post_data['give-form-id'] : 0; |
|
| 899 | + $post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 900 | + $form_id = ! empty($post_data['give-form-id']) ? $post_data['give-form-id'] : 0; |
|
| 902 | 901 | |
| 903 | 902 | // Start an array to collect valid user data. |
| 904 | 903 | $valid_user_data = array( |
@@ -907,22 +906,22 @@ discard block |
||
| 907 | 906 | ); |
| 908 | 907 | |
| 909 | 908 | // Validate name fields. |
| 910 | - give_donation_form_validate_name_fields( $post_data ); |
|
| 909 | + give_donation_form_validate_name_fields($post_data); |
|
| 911 | 910 | |
| 912 | 911 | // Validate Required Form Fields. |
| 913 | - give_validate_required_form_fields( $form_id ); |
|
| 912 | + give_validate_required_form_fields($form_id); |
|
| 914 | 913 | |
| 915 | 914 | // Get the guest email. |
| 916 | - $guest_email = ! empty( $post_data['give_email'] ) ? $post_data['give_email'] : false; |
|
| 915 | + $guest_email = ! empty($post_data['give_email']) ? $post_data['give_email'] : false; |
|
| 917 | 916 | |
| 918 | 917 | // Check email. |
| 919 | - if ( $guest_email && strlen( $guest_email ) > 0 ) { |
|
| 918 | + if ($guest_email && strlen($guest_email) > 0) { |
|
| 920 | 919 | |
| 921 | 920 | // Validate email. |
| 922 | - if ( ! is_email( $guest_email ) ) { |
|
| 921 | + if ( ! is_email($guest_email)) { |
|
| 923 | 922 | |
| 924 | 923 | // Invalid email. |
| 925 | - give_set_error( 'email_invalid', __( 'Invalid email.', 'give' ) ); |
|
| 924 | + give_set_error('email_invalid', __('Invalid email.', 'give')); |
|
| 926 | 925 | |
| 927 | 926 | } else { |
| 928 | 927 | |
@@ -930,15 +929,15 @@ discard block |
||
| 930 | 929 | $valid_user_data['user_email'] = $guest_email; |
| 931 | 930 | |
| 932 | 931 | // Get user_id from donor if exist. |
| 933 | - $donor = new Give_Donor( $guest_email ); |
|
| 932 | + $donor = new Give_Donor($guest_email); |
|
| 934 | 933 | |
| 935 | - if ( $donor->id && $donor->user_id ) { |
|
| 934 | + if ($donor->id && $donor->user_id) { |
|
| 936 | 935 | $valid_user_data['user_id'] = $donor->user_id; |
| 937 | 936 | } |
| 938 | 937 | } |
| 939 | 938 | } else { |
| 940 | 939 | // No email. |
| 941 | - give_set_error( 'email_empty', __( 'Enter an email.', 'give' ) ); |
|
| 940 | + give_set_error('email_empty', __('Enter an email.', 'give')); |
|
| 942 | 941 | } |
| 943 | 942 | |
| 944 | 943 | return $valid_user_data; |
@@ -954,36 +953,36 @@ discard block |
||
| 954 | 953 | * |
| 955 | 954 | * @return integer |
| 956 | 955 | */ |
| 957 | -function give_register_and_login_new_user( $user_data = array() ) { |
|
| 956 | +function give_register_and_login_new_user($user_data = array()) { |
|
| 958 | 957 | // Verify the array. |
| 959 | - if ( empty( $user_data ) ) { |
|
| 960 | - return - 1; |
|
| 958 | + if (empty($user_data)) { |
|
| 959 | + return -1; |
|
| 961 | 960 | } |
| 962 | 961 | |
| 963 | - if ( give_get_errors() ) { |
|
| 964 | - return - 1; |
|
| 962 | + if (give_get_errors()) { |
|
| 963 | + return -1; |
|
| 965 | 964 | } |
| 966 | 965 | |
| 967 | - $user_args = apply_filters( 'give_insert_user_args', array( |
|
| 968 | - 'user_login' => isset( $user_data['user_login'] ) ? $user_data['user_login'] : '', |
|
| 969 | - 'user_pass' => isset( $user_data['user_pass'] ) ? $user_data['user_pass'] : '', |
|
| 970 | - 'user_email' => isset( $user_data['user_email'] ) ? $user_data['user_email'] : '', |
|
| 971 | - 'first_name' => isset( $user_data['user_first'] ) ? $user_data['user_first'] : '', |
|
| 972 | - 'last_name' => isset( $user_data['user_last'] ) ? $user_data['user_last'] : '', |
|
| 973 | - 'user_registered' => date( 'Y-m-d H:i:s' ), |
|
| 974 | - 'role' => give_get_option( 'donor_default_user_role', 'give_donor' ), |
|
| 975 | - ), $user_data ); |
|
| 966 | + $user_args = apply_filters('give_insert_user_args', array( |
|
| 967 | + 'user_login' => isset($user_data['user_login']) ? $user_data['user_login'] : '', |
|
| 968 | + 'user_pass' => isset($user_data['user_pass']) ? $user_data['user_pass'] : '', |
|
| 969 | + 'user_email' => isset($user_data['user_email']) ? $user_data['user_email'] : '', |
|
| 970 | + 'first_name' => isset($user_data['user_first']) ? $user_data['user_first'] : '', |
|
| 971 | + 'last_name' => isset($user_data['user_last']) ? $user_data['user_last'] : '', |
|
| 972 | + 'user_registered' => date('Y-m-d H:i:s'), |
|
| 973 | + 'role' => give_get_option('donor_default_user_role', 'give_donor'), |
|
| 974 | + ), $user_data); |
|
| 976 | 975 | |
| 977 | 976 | // Insert new user. |
| 978 | - $user_id = wp_insert_user( $user_args ); |
|
| 977 | + $user_id = wp_insert_user($user_args); |
|
| 979 | 978 | |
| 980 | 979 | // Validate inserted user. |
| 981 | - if ( is_wp_error( $user_id ) ) { |
|
| 982 | - return - 1; |
|
| 980 | + if (is_wp_error($user_id)) { |
|
| 981 | + return -1; |
|
| 983 | 982 | } |
| 984 | 983 | |
| 985 | 984 | // Allow themes and plugins to filter the user data. |
| 986 | - $user_data = apply_filters( 'give_insert_user_data', $user_data, $user_args ); |
|
| 985 | + $user_data = apply_filters('give_insert_user_data', $user_data, $user_args); |
|
| 987 | 986 | |
| 988 | 987 | /** |
| 989 | 988 | * Fires after inserting user. |
@@ -993,7 +992,7 @@ discard block |
||
| 993 | 992 | * @param int $user_id User id. |
| 994 | 993 | * @param array $user_data Array containing user data. |
| 995 | 994 | */ |
| 996 | - do_action( 'give_insert_user', $user_id, $user_data ); |
|
| 995 | + do_action('give_insert_user', $user_id, $user_data); |
|
| 997 | 996 | |
| 998 | 997 | /** |
| 999 | 998 | * Filter allow user to alter if user when to login or not when user is register for the first time. |
@@ -1002,9 +1001,9 @@ discard block |
||
| 1002 | 1001 | * |
| 1003 | 1002 | * return bool True if login with registration and False if only want to register. |
| 1004 | 1003 | */ |
| 1005 | - if ( true === (bool) apply_filters( 'give_log_user_in_on_register', true ) ) { |
|
| 1004 | + if (true === (bool) apply_filters('give_log_user_in_on_register', true)) { |
|
| 1006 | 1005 | // Login new user. |
| 1007 | - give_log_user_in( $user_id, $user_data['user_login'], $user_data['user_pass'] ); |
|
| 1006 | + give_log_user_in($user_id, $user_data['user_login'], $user_data['user_pass']); |
|
| 1008 | 1007 | } |
| 1009 | 1008 | |
| 1010 | 1009 | // Return user id. |
@@ -1021,33 +1020,33 @@ discard block |
||
| 1021 | 1020 | * |
| 1022 | 1021 | * @return array|bool |
| 1023 | 1022 | */ |
| 1024 | -function give_get_donation_form_user( $valid_data = array() ) { |
|
| 1023 | +function give_get_donation_form_user($valid_data = array()) { |
|
| 1025 | 1024 | |
| 1026 | 1025 | // Initialize user. |
| 1027 | 1026 | $user = false; |
| 1028 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
| 1029 | - $post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 1027 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
| 1028 | + $post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 1030 | 1029 | |
| 1031 | - if ( $is_ajax ) { |
|
| 1030 | + if ($is_ajax) { |
|
| 1032 | 1031 | |
| 1033 | 1032 | // Do not create or login the user during the ajax submission (check for errors only). |
| 1034 | 1033 | return true; |
| 1035 | - } elseif ( is_user_logged_in() ) { |
|
| 1034 | + } elseif (is_user_logged_in()) { |
|
| 1036 | 1035 | |
| 1037 | 1036 | // Set the valid user as the logged in collected data. |
| 1038 | 1037 | $user = $valid_data['logged_in_user']; |
| 1039 | - } elseif ( true === $valid_data['need_new_user'] || true === $valid_data['need_user_login'] ) { |
|
| 1038 | + } elseif (true === $valid_data['need_new_user'] || true === $valid_data['need_user_login']) { |
|
| 1040 | 1039 | |
| 1041 | 1040 | // New user registration. |
| 1042 | - if ( true === $valid_data['need_new_user'] ) { |
|
| 1041 | + if (true === $valid_data['need_new_user']) { |
|
| 1043 | 1042 | |
| 1044 | 1043 | // Set user. |
| 1045 | 1044 | $user = $valid_data['new_user_data']; |
| 1046 | 1045 | |
| 1047 | 1046 | // Register and login new user. |
| 1048 | - $user['user_id'] = give_register_and_login_new_user( $user ); |
|
| 1047 | + $user['user_id'] = give_register_and_login_new_user($user); |
|
| 1049 | 1048 | |
| 1050 | - } elseif ( true === $valid_data['need_user_login'] && ! $is_ajax ) { |
|
| 1049 | + } elseif (true === $valid_data['need_user_login'] && ! $is_ajax) { |
|
| 1051 | 1050 | |
| 1052 | 1051 | /** |
| 1053 | 1052 | * The login form is now processed in the give_process_donation_login() function. |
@@ -1059,47 +1058,47 @@ discard block |
||
| 1059 | 1058 | $user = $valid_data['login_user_data']; |
| 1060 | 1059 | |
| 1061 | 1060 | // Login user. |
| 1062 | - give_log_user_in( $user['user_id'], $user['user_login'], $user['user_pass'] ); |
|
| 1061 | + give_log_user_in($user['user_id'], $user['user_login'], $user['user_pass']); |
|
| 1063 | 1062 | } |
| 1064 | 1063 | } // End if(). |
| 1065 | 1064 | |
| 1066 | 1065 | // Check guest checkout. |
| 1067 | - if ( false === $user && false === give_logged_in_only( $post_data['give-form-id'] ) ) { |
|
| 1066 | + if (false === $user && false === give_logged_in_only($post_data['give-form-id'])) { |
|
| 1068 | 1067 | |
| 1069 | 1068 | // Set user. |
| 1070 | 1069 | $user = $valid_data['guest_user_data']; |
| 1071 | 1070 | } |
| 1072 | 1071 | |
| 1073 | 1072 | // Verify we have an user. |
| 1074 | - if ( false === $user || empty( $user ) ) { |
|
| 1073 | + if (false === $user || empty($user)) { |
|
| 1075 | 1074 | return false; |
| 1076 | 1075 | } |
| 1077 | 1076 | |
| 1078 | 1077 | // Get user first name. |
| 1079 | - if ( ! isset( $user['user_first'] ) || strlen( trim( $user['user_first'] ) ) < 1 ) { |
|
| 1080 | - $user['user_first'] = isset( $post_data['give_first'] ) ? strip_tags( trim( $post_data['give_first'] ) ) : ''; |
|
| 1078 | + if ( ! isset($user['user_first']) || strlen(trim($user['user_first'])) < 1) { |
|
| 1079 | + $user['user_first'] = isset($post_data['give_first']) ? strip_tags(trim($post_data['give_first'])) : ''; |
|
| 1081 | 1080 | } |
| 1082 | 1081 | |
| 1083 | 1082 | // Get user last name. |
| 1084 | - if ( ! isset( $user['user_last'] ) || strlen( trim( $user['user_last'] ) ) < 1 ) { |
|
| 1085 | - $user['user_last'] = isset( $post_data['give_last'] ) ? strip_tags( trim( $post_data['give_last'] ) ) : ''; |
|
| 1083 | + if ( ! isset($user['user_last']) || strlen(trim($user['user_last'])) < 1) { |
|
| 1084 | + $user['user_last'] = isset($post_data['give_last']) ? strip_tags(trim($post_data['give_last'])) : ''; |
|
| 1086 | 1085 | } |
| 1087 | 1086 | |
| 1088 | 1087 | // Add Title Prefix to user information. |
| 1089 | - if ( empty( $user['user_title'] ) || strlen( trim( $user['user_title'] ) ) < 1 ) { |
|
| 1090 | - $user['user_title'] = ! empty( $post_data['give_title'] ) ? strip_tags( trim( $post_data['give_title'] ) ) : ''; |
|
| 1088 | + if (empty($user['user_title']) || strlen(trim($user['user_title'])) < 1) { |
|
| 1089 | + $user['user_title'] = ! empty($post_data['give_title']) ? strip_tags(trim($post_data['give_title'])) : ''; |
|
| 1091 | 1090 | } |
| 1092 | 1091 | |
| 1093 | 1092 | // Get the user's billing address details. |
| 1094 | 1093 | $user['address'] = array(); |
| 1095 | - $user['address']['line1'] = ! empty( $post_data['card_address'] ) ? $post_data['card_address'] : false; |
|
| 1096 | - $user['address']['line2'] = ! empty( $post_data['card_address_2'] ) ? $post_data['card_address_2'] : false; |
|
| 1097 | - $user['address']['city'] = ! empty( $post_data['card_city'] ) ? $post_data['card_city'] : false; |
|
| 1098 | - $user['address']['state'] = ! empty( $post_data['card_state'] ) ? $post_data['card_state'] : false; |
|
| 1099 | - $user['address']['zip'] = ! empty( $post_data['card_zip'] ) ? $post_data['card_zip'] : false; |
|
| 1100 | - $user['address']['country'] = ! empty( $post_data['billing_country'] ) ? $post_data['billing_country'] : false; |
|
| 1101 | - |
|
| 1102 | - if ( empty( $user['address']['country'] ) ) { |
|
| 1094 | + $user['address']['line1'] = ! empty($post_data['card_address']) ? $post_data['card_address'] : false; |
|
| 1095 | + $user['address']['line2'] = ! empty($post_data['card_address_2']) ? $post_data['card_address_2'] : false; |
|
| 1096 | + $user['address']['city'] = ! empty($post_data['card_city']) ? $post_data['card_city'] : false; |
|
| 1097 | + $user['address']['state'] = ! empty($post_data['card_state']) ? $post_data['card_state'] : false; |
|
| 1098 | + $user['address']['zip'] = ! empty($post_data['card_zip']) ? $post_data['card_zip'] : false; |
|
| 1099 | + $user['address']['country'] = ! empty($post_data['billing_country']) ? $post_data['billing_country'] : false; |
|
| 1100 | + |
|
| 1101 | + if (empty($user['address']['country'])) { |
|
| 1103 | 1102 | $user['address'] = false; |
| 1104 | 1103 | } // End if(). |
| 1105 | 1104 | |
@@ -1120,16 +1119,16 @@ discard block |
||
| 1120 | 1119 | $card_data = give_get_donation_cc_info(); |
| 1121 | 1120 | |
| 1122 | 1121 | // Validate the card zip. |
| 1123 | - if ( ! empty( $card_data['card_zip'] ) ) { |
|
| 1124 | - if ( ! give_donation_form_validate_cc_zip( $card_data['card_zip'], $card_data['card_country'] ) ) { |
|
| 1125 | - give_set_error( 'invalid_cc_zip', __( 'The zip / postal code you entered for your billing address is invalid.', 'give' ) ); |
|
| 1122 | + if ( ! empty($card_data['card_zip'])) { |
|
| 1123 | + if ( ! give_donation_form_validate_cc_zip($card_data['card_zip'], $card_data['card_country'])) { |
|
| 1124 | + give_set_error('invalid_cc_zip', __('The zip / postal code you entered for your billing address is invalid.', 'give')); |
|
| 1126 | 1125 | } |
| 1127 | 1126 | } |
| 1128 | 1127 | |
| 1129 | 1128 | // Ensure no spaces. |
| 1130 | - if ( ! empty( $card_data['card_number'] ) ) { |
|
| 1131 | - $card_data['card_number'] = str_replace( '+', '', $card_data['card_number'] ); // no "+" signs. |
|
| 1132 | - $card_data['card_number'] = str_replace( ' ', '', $card_data['card_number'] ); // No spaces. |
|
| 1129 | + if ( ! empty($card_data['card_number'])) { |
|
| 1130 | + $card_data['card_number'] = str_replace('+', '', $card_data['card_number']); // no "+" signs. |
|
| 1131 | + $card_data['card_number'] = str_replace(' ', '', $card_data['card_number']); // No spaces. |
|
| 1133 | 1132 | } |
| 1134 | 1133 | |
| 1135 | 1134 | // This should validate card numbers at some point too. |
@@ -1147,20 +1146,20 @@ discard block |
||
| 1147 | 1146 | function give_get_donation_cc_info() { |
| 1148 | 1147 | |
| 1149 | 1148 | // Sanitize the values submitted with donation form. |
| 1150 | - $post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 1149 | + $post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 1151 | 1150 | |
| 1152 | 1151 | $cc_info = array(); |
| 1153 | - $cc_info['card_name'] = ! empty( $post_data['card_name'] ) ? $post_data['card_name'] : ''; |
|
| 1154 | - $cc_info['card_number'] = ! empty( $post_data['card_number'] ) ? $post_data['card_number'] : ''; |
|
| 1155 | - $cc_info['card_cvc'] = ! empty( $post_data['card_cvc'] ) ? $post_data['card_cvc'] : ''; |
|
| 1156 | - $cc_info['card_exp_month'] = ! empty( $post_data['card_exp_month'] ) ? $post_data['card_exp_month'] : ''; |
|
| 1157 | - $cc_info['card_exp_year'] = ! empty( $post_data['card_exp_year'] ) ? $post_data['card_exp_year'] : ''; |
|
| 1158 | - $cc_info['card_address'] = ! empty( $post_data['card_address'] ) ? $post_data['card_address'] : ''; |
|
| 1159 | - $cc_info['card_address_2'] = ! empty( $post_data['card_address_2'] ) ? $post_data['card_address_2'] : ''; |
|
| 1160 | - $cc_info['card_city'] = ! empty( $post_data['card_city'] ) ? $post_data['card_city'] : ''; |
|
| 1161 | - $cc_info['card_state'] = ! empty( $post_data['card_state'] ) ? $post_data['card_state'] : ''; |
|
| 1162 | - $cc_info['card_country'] = ! empty( $post_data['billing_country'] ) ? $post_data['billing_country'] : ''; |
|
| 1163 | - $cc_info['card_zip'] = ! empty( $post_data['card_zip'] ) ? $post_data['card_zip'] : ''; |
|
| 1152 | + $cc_info['card_name'] = ! empty($post_data['card_name']) ? $post_data['card_name'] : ''; |
|
| 1153 | + $cc_info['card_number'] = ! empty($post_data['card_number']) ? $post_data['card_number'] : ''; |
|
| 1154 | + $cc_info['card_cvc'] = ! empty($post_data['card_cvc']) ? $post_data['card_cvc'] : ''; |
|
| 1155 | + $cc_info['card_exp_month'] = ! empty($post_data['card_exp_month']) ? $post_data['card_exp_month'] : ''; |
|
| 1156 | + $cc_info['card_exp_year'] = ! empty($post_data['card_exp_year']) ? $post_data['card_exp_year'] : ''; |
|
| 1157 | + $cc_info['card_address'] = ! empty($post_data['card_address']) ? $post_data['card_address'] : ''; |
|
| 1158 | + $cc_info['card_address_2'] = ! empty($post_data['card_address_2']) ? $post_data['card_address_2'] : ''; |
|
| 1159 | + $cc_info['card_city'] = ! empty($post_data['card_city']) ? $post_data['card_city'] : ''; |
|
| 1160 | + $cc_info['card_state'] = ! empty($post_data['card_state']) ? $post_data['card_state'] : ''; |
|
| 1161 | + $cc_info['card_country'] = ! empty($post_data['billing_country']) ? $post_data['billing_country'] : ''; |
|
| 1162 | + $cc_info['card_zip'] = ! empty($post_data['card_zip']) ? $post_data['card_zip'] : ''; |
|
| 1164 | 1163 | |
| 1165 | 1164 | // Return cc info. |
| 1166 | 1165 | return $cc_info; |
@@ -1176,14 +1175,14 @@ discard block |
||
| 1176 | 1175 | * |
| 1177 | 1176 | * @return bool|mixed |
| 1178 | 1177 | */ |
| 1179 | -function give_donation_form_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
| 1178 | +function give_donation_form_validate_cc_zip($zip = 0, $country_code = '') { |
|
| 1180 | 1179 | $ret = false; |
| 1181 | 1180 | |
| 1182 | - if ( empty( $zip ) || empty( $country_code ) ) { |
|
| 1181 | + if (empty($zip) || empty($country_code)) { |
|
| 1183 | 1182 | return $ret; |
| 1184 | 1183 | } |
| 1185 | 1184 | |
| 1186 | - $country_code = strtoupper( $country_code ); |
|
| 1185 | + $country_code = strtoupper($country_code); |
|
| 1187 | 1186 | |
| 1188 | 1187 | $zip_regex = array( |
| 1189 | 1188 | 'AD' => 'AD\d{3}', |
@@ -1343,11 +1342,11 @@ discard block |
||
| 1343 | 1342 | 'ZM' => '\d{5}', |
| 1344 | 1343 | ); |
| 1345 | 1344 | |
| 1346 | - if ( ! isset( $zip_regex[ $country_code ] ) || preg_match( '/' . $zip_regex[ $country_code ] . '/i', $zip ) ) { |
|
| 1345 | + if ( ! isset($zip_regex[$country_code]) || preg_match('/'.$zip_regex[$country_code].'/i', $zip)) { |
|
| 1347 | 1346 | $ret = true; |
| 1348 | 1347 | } |
| 1349 | 1348 | |
| 1350 | - return apply_filters( 'give_is_zip_valid', $ret, $zip, $country_code ); |
|
| 1349 | + return apply_filters('give_is_zip_valid', $ret, $zip, $country_code); |
|
| 1351 | 1350 | } |
| 1352 | 1351 | |
| 1353 | 1352 | /** |
@@ -1359,60 +1358,60 @@ discard block |
||
| 1359 | 1358 | * |
| 1360 | 1359 | * @return bool |
| 1361 | 1360 | */ |
| 1362 | -function give_validate_donation_amount( $valid_data ) { |
|
| 1361 | +function give_validate_donation_amount($valid_data) { |
|
| 1363 | 1362 | |
| 1364 | - $post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 1363 | + $post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 1365 | 1364 | |
| 1366 | 1365 | /* @var Give_Donate_Form $form */ |
| 1367 | - $form = new Give_Donate_Form( $post_data['give-form-id'] ); |
|
| 1366 | + $form = new Give_Donate_Form($post_data['give-form-id']); |
|
| 1368 | 1367 | |
| 1369 | 1368 | // Get the form currency. |
| 1370 | - $form_currency = give_get_currency( $post_data['give-form-id'] ); |
|
| 1369 | + $form_currency = give_get_currency($post_data['give-form-id']); |
|
| 1371 | 1370 | |
| 1372 | 1371 | $donation_level_matched = false; |
| 1373 | 1372 | |
| 1374 | - if ( $form->is_set_type_donation_form() ) { |
|
| 1373 | + if ($form->is_set_type_donation_form()) { |
|
| 1375 | 1374 | |
| 1376 | 1375 | // Sanitize donation amount. |
| 1377 | - $post_data['give-amount'] = give_maybe_sanitize_amount( $post_data['give-amount'], array( 'currency' => $form_currency ) ); |
|
| 1376 | + $post_data['give-amount'] = give_maybe_sanitize_amount($post_data['give-amount'], array('currency' => $form_currency)); |
|
| 1378 | 1377 | |
| 1379 | 1378 | // Backward compatibility. |
| 1380 | - if ( $form->is_custom_price( $post_data['give-amount'] ) ) { |
|
| 1379 | + if ($form->is_custom_price($post_data['give-amount'])) { |
|
| 1381 | 1380 | $post_data['give-price-id'] = 'custom'; |
| 1382 | 1381 | } |
| 1383 | 1382 | |
| 1384 | 1383 | $donation_level_matched = true; |
| 1385 | 1384 | |
| 1386 | - } elseif ( $form->is_multi_type_donation_form() ) { |
|
| 1385 | + } elseif ($form->is_multi_type_donation_form()) { |
|
| 1387 | 1386 | |
| 1388 | 1387 | $variable_prices = $form->get_prices(); |
| 1389 | 1388 | |
| 1390 | 1389 | // Bailout. |
| 1391 | - if ( ! $variable_prices ) { |
|
| 1390 | + if ( ! $variable_prices) { |
|
| 1392 | 1391 | return false; |
| 1393 | 1392 | } |
| 1394 | 1393 | |
| 1395 | 1394 | // Sanitize donation amount. |
| 1396 | - $post_data['give-amount'] = give_maybe_sanitize_amount( $post_data['give-amount'], array( 'currency' => $form_currency ) ); |
|
| 1397 | - $variable_price_option_amount = give_maybe_sanitize_amount( give_get_price_option_amount( $post_data['give-form-id'], $post_data['give-price-id'] ), array( 'currency' => $form_currency ) ); |
|
| 1395 | + $post_data['give-amount'] = give_maybe_sanitize_amount($post_data['give-amount'], array('currency' => $form_currency)); |
|
| 1396 | + $variable_price_option_amount = give_maybe_sanitize_amount(give_get_price_option_amount($post_data['give-form-id'], $post_data['give-price-id']), array('currency' => $form_currency)); |
|
| 1398 | 1397 | $new_price_id = ''; |
| 1399 | 1398 | |
| 1400 | - if ( $post_data['give-amount'] === $variable_price_option_amount ) { |
|
| 1399 | + if ($post_data['give-amount'] === $variable_price_option_amount) { |
|
| 1401 | 1400 | return true; |
| 1402 | 1401 | } |
| 1403 | 1402 | |
| 1404 | - if ( $form->is_custom_price( $post_data['give-amount'] ) ) { |
|
| 1403 | + if ($form->is_custom_price($post_data['give-amount'])) { |
|
| 1405 | 1404 | $new_price_id = 'custom'; |
| 1406 | 1405 | } else { |
| 1407 | 1406 | |
| 1408 | 1407 | // Find correct donation level from all donation levels. |
| 1409 | - foreach ( $variable_prices as $variable_price ) { |
|
| 1408 | + foreach ($variable_prices as $variable_price) { |
|
| 1410 | 1409 | |
| 1411 | 1410 | // Sanitize level amount. |
| 1412 | - $variable_price['_give_amount'] = give_maybe_sanitize_amount( $variable_price['_give_amount'] ); |
|
| 1411 | + $variable_price['_give_amount'] = give_maybe_sanitize_amount($variable_price['_give_amount']); |
|
| 1413 | 1412 | |
| 1414 | 1413 | // Set first match donation level ID. |
| 1415 | - if ( $post_data['give-amount'] === $variable_price['_give_amount'] ) { |
|
| 1414 | + if ($post_data['give-amount'] === $variable_price['_give_amount']) { |
|
| 1416 | 1415 | $new_price_id = $variable_price['_give_id']['level_id']; |
| 1417 | 1416 | break; |
| 1418 | 1417 | } |
@@ -1421,26 +1420,26 @@ discard block |
||
| 1421 | 1420 | |
| 1422 | 1421 | // If donation amount is not find in donation levels then check if form has custom donation feature enable or not. |
| 1423 | 1422 | // If yes then set price id to custom if amount is greater then custom minimum amount (if any). |
| 1424 | - if ( $post_data['give-price-id'] === $new_price_id ) { |
|
| 1423 | + if ($post_data['give-price-id'] === $new_price_id) { |
|
| 1425 | 1424 | $donation_level_matched = true; |
| 1426 | 1425 | } |
| 1427 | 1426 | } // End if(). |
| 1428 | 1427 | |
| 1429 | - if ( ! $donation_level_matched ) { |
|
| 1428 | + if ( ! $donation_level_matched) { |
|
| 1430 | 1429 | give_set_error( |
| 1431 | 1430 | 'invalid_donation_amount', |
| 1432 | 1431 | sprintf( |
| 1433 | 1432 | /* translators: %s: invalid donation amount */ |
| 1434 | - __( 'Donation amount %s is invalid.', 'give' ), |
|
| 1433 | + __('Donation amount %s is invalid.', 'give'), |
|
| 1435 | 1434 | give_currency_filter( |
| 1436 | - give_format_amount( $post_data['give-amount'], array( 'sanitize' => false, ) ) |
|
| 1435 | + give_format_amount($post_data['give-amount'], array('sanitize' => false,)) |
|
| 1437 | 1436 | ) |
| 1438 | 1437 | ) |
| 1439 | 1438 | ); |
| 1440 | 1439 | } |
| 1441 | 1440 | } |
| 1442 | 1441 | |
| 1443 | -add_action( 'give_checkout_error_checks', 'give_validate_donation_amount', 10, 1 ); |
|
| 1442 | +add_action('give_checkout_error_checks', 'give_validate_donation_amount', 10, 1); |
|
| 1444 | 1443 | |
| 1445 | 1444 | /** |
| 1446 | 1445 | * Validate Required Form Fields. |
@@ -1449,20 +1448,20 @@ discard block |
||
| 1449 | 1448 | * |
| 1450 | 1449 | * @since 2.0 |
| 1451 | 1450 | */ |
| 1452 | -function give_validate_required_form_fields( $form_id ) { |
|
| 1451 | +function give_validate_required_form_fields($form_id) { |
|
| 1453 | 1452 | |
| 1454 | 1453 | // Sanitize values submitted with donation form. |
| 1455 | - $post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 1454 | + $post_data = give_clean($_POST); // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 1456 | 1455 | |
| 1457 | 1456 | // Loop through required fields and show error messages. |
| 1458 | - foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) { |
|
| 1457 | + foreach (give_get_required_fields($form_id) as $field_name => $value) { |
|
| 1459 | 1458 | |
| 1460 | 1459 | // Clean Up Data of the input fields. |
| 1461 | - $field_value = $post_data[ $field_name ]; |
|
| 1460 | + $field_value = $post_data[$field_name]; |
|
| 1462 | 1461 | |
| 1463 | 1462 | // Check whether the required field is empty, then show the error message. |
| 1464 | - if ( in_array( $value, give_get_required_fields( $form_id ), true ) && empty( $field_value ) ) { |
|
| 1465 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
| 1463 | + if (in_array($value, give_get_required_fields($form_id), true) && empty($field_value)) { |
|
| 1464 | + give_set_error($value['error_id'], $value['error_message']); |
|
| 1466 | 1465 | } |
| 1467 | 1466 | } |
| 1468 | 1467 | } |
@@ -1476,12 +1475,12 @@ discard block |
||
| 1476 | 1475 | * |
| 1477 | 1476 | * @return void |
| 1478 | 1477 | */ |
| 1479 | -function give_donation_form_validate_name_fields( $post_data ) { |
|
| 1478 | +function give_donation_form_validate_name_fields($post_data) { |
|
| 1480 | 1479 | |
| 1481 | - $is_alpha_first_name = ( ! is_email( $post_data['give_first'] ) && ! preg_match( '~[0-9]~', $post_data['give_first'] ) ); |
|
| 1482 | - $is_alpha_last_name = ( ! is_email( $post_data['give_last'] ) && ! preg_match( '~[0-9]~', $post_data['give_last'] ) ); |
|
| 1480 | + $is_alpha_first_name = ( ! is_email($post_data['give_first']) && ! preg_match('~[0-9]~', $post_data['give_first'])); |
|
| 1481 | + $is_alpha_last_name = ( ! is_email($post_data['give_last']) && ! preg_match('~[0-9]~', $post_data['give_last'])); |
|
| 1483 | 1482 | |
| 1484 | - if ( ! $is_alpha_first_name || ( ! empty( $post_data['give_last'] ) && ! $is_alpha_last_name ) ) { |
|
| 1485 | - give_set_error( 'invalid_name', esc_html__( 'The First Name and Last Name fields cannot contain an email address or numbers.', 'give' ) ); |
|
| 1483 | + if ( ! $is_alpha_first_name || ( ! empty($post_data['give_last']) && ! $is_alpha_last_name)) { |
|
| 1484 | + give_set_error('invalid_name', esc_html__('The First Name and Last Name fields cannot contain an email address or numbers.', 'give')); |
|
| 1486 | 1485 | } |
| 1487 | 1486 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * @since 1.0 |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 12 | +if ( ! defined('ABSPATH')) { |
|
| 13 | 13 | exit; |
| 14 | 14 | } |
| 15 | 15 | |
@@ -22,10 +22,10 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @return bool |
| 24 | 24 | */ |
| 25 | -function give_paypal_standard_billing_fields( $form_id ) { |
|
| 25 | +function give_paypal_standard_billing_fields($form_id) { |
|
| 26 | 26 | |
| 27 | - if ( give_is_setting_enabled( give_get_option( 'paypal_standard_billing_details' ) ) ) { |
|
| 28 | - give_default_cc_address_fields( $form_id ); |
|
| 27 | + if (give_is_setting_enabled(give_get_option('paypal_standard_billing_details'))) { |
|
| 28 | + give_default_cc_address_fields($form_id); |
|
| 29 | 29 | |
| 30 | 30 | return true; |
| 31 | 31 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | -add_action( 'give_paypal_cc_form', 'give_paypal_standard_billing_fields' ); |
|
| 37 | +add_action('give_paypal_cc_form', 'give_paypal_standard_billing_fields'); |
|
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * Process PayPal Payment. |
@@ -45,28 +45,28 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return void |
| 47 | 47 | */ |
| 48 | -function give_process_paypal_payment( $payment_data ) { |
|
| 48 | +function give_process_paypal_payment($payment_data) { |
|
| 49 | 49 | |
| 50 | 50 | // Validate nonce. |
| 51 | - give_validate_nonce( $payment_data['gateway_nonce'], 'give-gateway' ); |
|
| 51 | + give_validate_nonce($payment_data['gateway_nonce'], 'give-gateway'); |
|
| 52 | 52 | |
| 53 | - $payment_id = give_create_payment( $payment_data ); |
|
| 53 | + $payment_id = give_create_payment($payment_data); |
|
| 54 | 54 | |
| 55 | 55 | // Check payment. |
| 56 | - if ( empty( $payment_id ) ) { |
|
| 56 | + if (empty($payment_id)) { |
|
| 57 | 57 | // Record the error. |
| 58 | - give_record_gateway_error( __( 'Payment Error', 'give' ), sprintf( /* translators: %s: payment data */ |
|
| 59 | - __( 'Payment creation failed before sending donor to PayPal. Payment data: %s', 'give' ), json_encode( $payment_data ) ), $payment_id ); |
|
| 58 | + give_record_gateway_error(__('Payment Error', 'give'), sprintf( /* translators: %s: payment data */ |
|
| 59 | + __('Payment creation failed before sending donor to PayPal. Payment data: %s', 'give'), json_encode($payment_data) ), $payment_id); |
|
| 60 | 60 | // Problems? Send back. |
| 61 | - give_send_back_to_checkout( '?payment-mode=' . $payment_data['post_data']['give-gateway'] ); |
|
| 61 | + give_send_back_to_checkout('?payment-mode='.$payment_data['post_data']['give-gateway']); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | // Redirect to PayPal. |
| 65 | - wp_redirect( give_build_paypal_url( $payment_id, $payment_data ) ); |
|
| 65 | + wp_redirect(give_build_paypal_url($payment_id, $payment_data)); |
|
| 66 | 66 | exit; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | -add_action( 'give_gateway_paypal', 'give_process_paypal_payment' ); |
|
| 69 | +add_action('give_gateway_paypal', 'give_process_paypal_payment'); |
|
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * Listens for a PayPal IPN requests and then sends to the processing function. |
@@ -77,17 +77,17 @@ discard block |
||
| 77 | 77 | function give_listen_for_paypal_ipn() { |
| 78 | 78 | |
| 79 | 79 | // Regular PayPal IPN. |
| 80 | - if ( isset( $_GET['give-listener'] ) && 'IPN' === $_GET['give-listener'] ) { |
|
| 80 | + if (isset($_GET['give-listener']) && 'IPN' === $_GET['give-listener']) { |
|
| 81 | 81 | /** |
| 82 | 82 | * Fires while verifying PayPal IPN |
| 83 | 83 | * |
| 84 | 84 | * @since 1.0 |
| 85 | 85 | */ |
| 86 | - do_action( 'give_verify_paypal_ipn' ); |
|
| 86 | + do_action('give_verify_paypal_ipn'); |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | -add_action( 'init', 'give_listen_for_paypal_ipn' ); |
|
| 90 | +add_action('init', 'give_listen_for_paypal_ipn'); |
|
| 91 | 91 | |
| 92 | 92 | /** |
| 93 | 93 | * Process PayPal IPN |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | function give_process_paypal_ipn() { |
| 99 | 99 | |
| 100 | 100 | // Check the request method is POST. |
| 101 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' !== $_SERVER['REQUEST_METHOD'] ) { |
|
| 101 | + if (isset($_SERVER['REQUEST_METHOD']) && 'POST' !== $_SERVER['REQUEST_METHOD']) { |
|
| 102 | 102 | return; |
| 103 | 103 | } |
| 104 | 104 | |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | $post_data = ''; |
| 107 | 107 | |
| 108 | 108 | // Fallback just in case post_max_size is lower than needed. |
| 109 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
| 110 | - $post_data = file_get_contents( 'php://input' ); |
|
| 109 | + if (ini_get('allow_url_fopen')) { |
|
| 110 | + $post_data = file_get_contents('php://input'); |
|
| 111 | 111 | } else { |
| 112 | 112 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough. |
| 113 | - ini_set( 'post_max_size', '12M' ); |
|
| 113 | + ini_set('post_max_size', '12M'); |
|
| 114 | 114 | } |
| 115 | 115 | // Start the encoded data collection with notification command. |
| 116 | 116 | $encoded_data = 'cmd=_notify-validate'; |
@@ -119,41 +119,41 @@ discard block |
||
| 119 | 119 | $arg_separator = give_get_php_arg_separator_output(); |
| 120 | 120 | |
| 121 | 121 | // Verify there is a post_data. |
| 122 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
| 122 | + if ($post_data || strlen($post_data) > 0) { |
|
| 123 | 123 | // Append the data. |
| 124 | - $encoded_data .= $arg_separator . $post_data; |
|
| 124 | + $encoded_data .= $arg_separator.$post_data; |
|
| 125 | 125 | } else { |
| 126 | 126 | // Check if POST is empty. |
| 127 | - if ( empty( $_POST ) ) { |
|
| 127 | + if (empty($_POST)) { |
|
| 128 | 128 | // Nothing to do. |
| 129 | 129 | return; |
| 130 | 130 | } else { |
| 131 | 131 | // Loop through each POST. |
| 132 | - foreach ( $_POST as $key => $value ) { |
|
| 132 | + foreach ($_POST as $key => $value) { |
|
| 133 | 133 | // Encode the value and append the data. |
| 134 | - $encoded_data .= $arg_separator . "$key=" . urlencode( $value ); |
|
| 134 | + $encoded_data .= $arg_separator."$key=".urlencode($value); |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // Convert collected post data to an array. |
| 140 | - parse_str( $encoded_data, $encoded_data_array ); |
|
| 140 | + parse_str($encoded_data, $encoded_data_array); |
|
| 141 | 141 | |
| 142 | - foreach ( $encoded_data_array as $key => $value ) { |
|
| 142 | + foreach ($encoded_data_array as $key => $value) { |
|
| 143 | 143 | |
| 144 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
| 145 | - $new_key = str_replace( '&', '&', $key ); |
|
| 146 | - $new_key = str_replace( 'amp;', '&', $new_key ); |
|
| 144 | + if (false !== strpos($key, 'amp;')) { |
|
| 145 | + $new_key = str_replace('&', '&', $key); |
|
| 146 | + $new_key = str_replace('amp;', '&', $new_key); |
|
| 147 | 147 | |
| 148 | - unset( $encoded_data_array[ $key ] ); |
|
| 149 | - $encoded_data_array[ $new_key ] = $value; |
|
| 148 | + unset($encoded_data_array[$key]); |
|
| 149 | + $encoded_data_array[$new_key] = $value; |
|
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | $api_response = false; |
| 154 | 154 | |
| 155 | 155 | // Validate IPN request w/ PayPal if user hasn't disabled this security measure. |
| 156 | - if ( give_is_setting_enabled( give_get_option( 'paypal_verification' ) ) ) { |
|
| 156 | + if (give_is_setting_enabled(give_get_option('paypal_verification'))) { |
|
| 157 | 157 | |
| 158 | 158 | $remote_post_vars = array( |
| 159 | 159 | 'method' => 'POST', |
@@ -173,25 +173,25 @@ discard block |
||
| 173 | 173 | ); |
| 174 | 174 | |
| 175 | 175 | // Validate the IPN. |
| 176 | - $api_response = wp_remote_post( give_get_paypal_redirect(), $remote_post_vars ); |
|
| 176 | + $api_response = wp_remote_post(give_get_paypal_redirect(), $remote_post_vars); |
|
| 177 | 177 | |
| 178 | - if ( is_wp_error( $api_response ) ) { |
|
| 179 | - give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( /* translators: %s: Paypal IPN response */ |
|
| 180 | - __( 'Invalid IPN verification response. IPN data: %s', 'give' ), json_encode( $api_response ) ) ); |
|
| 178 | + if (is_wp_error($api_response)) { |
|
| 179 | + give_record_gateway_error(__('IPN Error', 'give'), sprintf( /* translators: %s: Paypal IPN response */ |
|
| 180 | + __('Invalid IPN verification response. IPN data: %s', 'give'), json_encode($api_response) )); |
|
| 181 | 181 | |
| 182 | 182 | return; // Something went wrong. |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - if ( 'VERIFIED' !== $api_response['body'] ) { |
|
| 186 | - give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( /* translators: %s: Paypal IPN response */ |
|
| 187 | - __( 'Invalid IPN verification response. IPN data: %s', 'give' ), json_encode( $api_response ) ) ); |
|
| 185 | + if ('VERIFIED' !== $api_response['body']) { |
|
| 186 | + give_record_gateway_error(__('IPN Error', 'give'), sprintf( /* translators: %s: Paypal IPN response */ |
|
| 187 | + __('Invalid IPN verification response. IPN data: %s', 'give'), json_encode($api_response) )); |
|
| 188 | 188 | |
| 189 | 189 | return; // Response not okay. |
| 190 | 190 | } |
| 191 | 191 | }// End if(). |
| 192 | 192 | |
| 193 | 193 | // Check if $post_data_array has been populated. |
| 194 | - if ( ! is_array( $encoded_data_array ) && ! empty( $encoded_data_array ) ) { |
|
| 194 | + if ( ! is_array($encoded_data_array) && ! empty($encoded_data_array)) { |
|
| 195 | 195 | return; |
| 196 | 196 | } |
| 197 | 197 | |
@@ -200,28 +200,28 @@ discard block |
||
| 200 | 200 | 'payment_status' => '', |
| 201 | 201 | ); |
| 202 | 202 | |
| 203 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
| 203 | + $encoded_data_array = wp_parse_args($encoded_data_array, $defaults); |
|
| 204 | 204 | |
| 205 | - $payment_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
| 205 | + $payment_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0; |
|
| 206 | 206 | $txn_type = $encoded_data_array['txn_type']; |
| 207 | 207 | |
| 208 | 208 | // Check for PayPal IPN Notifications and update data based on it. |
| 209 | - $current_timestamp = current_time( 'timestamp' ); |
|
| 209 | + $current_timestamp = current_time('timestamp'); |
|
| 210 | 210 | $paypal_ipn_vars = array( |
| 211 | - 'auth_status' => isset( $api_response['body'] ) ? $api_response['body'] : 'N/A', |
|
| 212 | - 'transaction_id' => isset( $encoded_data_array['txn_id'] ) ? $encoded_data_array['txn_id'] : 'N/A', |
|
| 211 | + 'auth_status' => isset($api_response['body']) ? $api_response['body'] : 'N/A', |
|
| 212 | + 'transaction_id' => isset($encoded_data_array['txn_id']) ? $encoded_data_array['txn_id'] : 'N/A', |
|
| 213 | 213 | 'payment_id' => $payment_id, |
| 214 | 214 | ); |
| 215 | - update_option( 'give_last_paypal_ipn_received', $paypal_ipn_vars, false ); |
|
| 216 | - give_insert_payment_note( $payment_id, sprintf( |
|
| 217 | - __( 'IPN received on %s at %s', 'give' ), |
|
| 218 | - date_i18n( 'm/d/Y', $current_timestamp ), |
|
| 219 | - date_i18n( 'H:i', $current_timestamp ) |
|
| 215 | + update_option('give_last_paypal_ipn_received', $paypal_ipn_vars, false); |
|
| 216 | + give_insert_payment_note($payment_id, sprintf( |
|
| 217 | + __('IPN received on %s at %s', 'give'), |
|
| 218 | + date_i18n('m/d/Y', $current_timestamp), |
|
| 219 | + date_i18n('H:i', $current_timestamp) |
|
| 220 | 220 | ) |
| 221 | 221 | ); |
| 222 | - give_update_meta( $payment_id, 'give_last_paypal_ipn_received', $current_timestamp ); |
|
| 222 | + give_update_meta($payment_id, 'give_last_paypal_ipn_received', $current_timestamp); |
|
| 223 | 223 | |
| 224 | - if ( has_action( 'give_paypal_' . $txn_type ) ) { |
|
| 224 | + if (has_action('give_paypal_'.$txn_type)) { |
|
| 225 | 225 | /** |
| 226 | 226 | * Fires while processing PayPal IPN $txn_type. |
| 227 | 227 | * |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | * @param array $encoded_data_array Encoded data. |
| 233 | 233 | * @param int $payment_id Payment id. |
| 234 | 234 | */ |
| 235 | - do_action( "give_paypal_{$txn_type}", $encoded_data_array, $payment_id ); |
|
| 235 | + do_action("give_paypal_{$txn_type}", $encoded_data_array, $payment_id); |
|
| 236 | 236 | } else { |
| 237 | 237 | /** |
| 238 | 238 | * Fires while process PayPal IPN. |
@@ -244,12 +244,12 @@ discard block |
||
| 244 | 244 | * @param array $encoded_data_array Encoded data. |
| 245 | 245 | * @param int $payment_id Payment id. |
| 246 | 246 | */ |
| 247 | - do_action( 'give_paypal_web_accept', $encoded_data_array, $payment_id ); |
|
| 247 | + do_action('give_paypal_web_accept', $encoded_data_array, $payment_id); |
|
| 248 | 248 | } |
| 249 | 249 | exit; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | -add_action( 'give_verify_paypal_ipn', 'give_process_paypal_ipn' ); |
|
| 252 | +add_action('give_verify_paypal_ipn', 'give_process_paypal_ipn'); |
|
| 253 | 253 | |
| 254 | 254 | /** |
| 255 | 255 | * Process web accept (one time) payment IPNs. |
@@ -261,99 +261,99 @@ discard block |
||
| 261 | 261 | * |
| 262 | 262 | * @return void |
| 263 | 263 | */ |
| 264 | -function give_process_paypal_web_accept( $data, $payment_id ) { |
|
| 264 | +function give_process_paypal_web_accept($data, $payment_id) { |
|
| 265 | 265 | |
| 266 | 266 | // Only allow through these transaction types. |
| 267 | - if ( 'web_accept' !== $data['txn_type'] && 'cart' !== $data['txn_type'] && 'refunded' !== strtolower( $data['payment_status'] ) ) { |
|
| 267 | + if ('web_accept' !== $data['txn_type'] && 'cart' !== $data['txn_type'] && 'refunded' !== strtolower($data['payment_status'])) { |
|
| 268 | 268 | return; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | // Need $payment_id to continue. |
| 272 | - if ( empty( $payment_id ) ) { |
|
| 272 | + if (empty($payment_id)) { |
|
| 273 | 273 | return; |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | // Collect donation payment details. |
| 277 | 277 | $paypal_amount = $data['mc_gross']; |
| 278 | - $payment_status = strtolower( $data['payment_status'] ); |
|
| 279 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
| 280 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
| 281 | - $payment_meta = give_get_payment_meta( $payment_id ); |
|
| 278 | + $payment_status = strtolower($data['payment_status']); |
|
| 279 | + $currency_code = strtolower($data['mc_currency']); |
|
| 280 | + $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']); |
|
| 281 | + $payment_meta = give_get_payment_meta($payment_id); |
|
| 282 | 282 | |
| 283 | 283 | // Must be a PayPal standard IPN. |
| 284 | - if ( 'paypal' !== give_get_payment_gateway( $payment_id ) ) { |
|
| 284 | + if ('paypal' !== give_get_payment_gateway($payment_id)) { |
|
| 285 | 285 | return; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Verify payment recipient. |
| 289 | - if ( strcasecmp( $business_email, trim( give_get_option( 'paypal_email' ) ) ) !== 0 ) { |
|
| 289 | + if (strcasecmp($business_email, trim(give_get_option('paypal_email'))) !== 0) { |
|
| 290 | 290 | |
| 291 | - give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( /* translators: %s: Paypal IPN response */ |
|
| 292 | - __( 'Invalid business email in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id ); |
|
| 293 | - give_update_payment_status( $payment_id, 'failed' ); |
|
| 294 | - give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid PayPal business email.', 'give' ) ); |
|
| 291 | + give_record_gateway_error(__('IPN Error', 'give'), sprintf( /* translators: %s: Paypal IPN response */ |
|
| 292 | + __('Invalid business email in IPN response. IPN data: %s', 'give'), json_encode($data) ), $payment_id); |
|
| 293 | + give_update_payment_status($payment_id, 'failed'); |
|
| 294 | + give_insert_payment_note($payment_id, __('Payment failed due to invalid PayPal business email.', 'give')); |
|
| 295 | 295 | |
| 296 | 296 | return; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | // Verify payment currency. |
| 300 | - if ( $currency_code !== strtolower( $payment_meta['currency'] ) ) { |
|
| 300 | + if ($currency_code !== strtolower($payment_meta['currency'])) { |
|
| 301 | 301 | |
| 302 | - give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( /* translators: %s: Paypal IPN response */ |
|
| 303 | - __( 'Invalid currency in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id ); |
|
| 304 | - give_update_payment_status( $payment_id, 'failed' ); |
|
| 305 | - give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'give' ) ); |
|
| 302 | + give_record_gateway_error(__('IPN Error', 'give'), sprintf( /* translators: %s: Paypal IPN response */ |
|
| 303 | + __('Invalid currency in IPN response. IPN data: %s', 'give'), json_encode($data) ), $payment_id); |
|
| 304 | + give_update_payment_status($payment_id, 'failed'); |
|
| 305 | + give_insert_payment_note($payment_id, __('Payment failed due to invalid currency in PayPal IPN.', 'give')); |
|
| 306 | 306 | |
| 307 | 307 | return; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | // Process refunds & reversed. |
| 311 | - if ( 'refunded' === $payment_status || 'reversed' === $payment_status ) { |
|
| 312 | - give_process_paypal_refund( $data, $payment_id ); |
|
| 311 | + if ('refunded' === $payment_status || 'reversed' === $payment_status) { |
|
| 312 | + give_process_paypal_refund($data, $payment_id); |
|
| 313 | 313 | |
| 314 | 314 | return; |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | // Only complete payments once. |
| 318 | - if ( 'publish' === get_post_status( $payment_id ) ) { |
|
| 318 | + if ('publish' === get_post_status($payment_id)) { |
|
| 319 | 319 | return; |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | // Retrieve the total donation amount (before PayPal). |
| 323 | - $payment_amount = give_donation_amount( $payment_id ); |
|
| 323 | + $payment_amount = give_donation_amount($payment_id); |
|
| 324 | 324 | |
| 325 | 325 | // Check that the donation PP and local db amounts match. |
| 326 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 326 | + if (number_format((float) $paypal_amount, 2) < number_format((float) $payment_amount, 2)) { |
|
| 327 | 327 | // The prices don't match |
| 328 | - give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( /* translators: %s: Paypal IPN response */ |
|
| 329 | - __( 'Invalid payment amount in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id ); |
|
| 330 | - give_update_payment_status( $payment_id, 'failed' ); |
|
| 331 | - give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'give' ) ); |
|
| 328 | + give_record_gateway_error(__('IPN Error', 'give'), sprintf( /* translators: %s: Paypal IPN response */ |
|
| 329 | + __('Invalid payment amount in IPN response. IPN data: %s', 'give'), json_encode($data) ), $payment_id); |
|
| 330 | + give_update_payment_status($payment_id, 'failed'); |
|
| 331 | + give_insert_payment_note($payment_id, __('Payment failed due to invalid amount in PayPal IPN.', 'give')); |
|
| 332 | 332 | |
| 333 | 333 | return; |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | // Process completed donations. |
| 337 | - if ( 'completed' === $payment_status || give_is_test_mode() ) { |
|
| 337 | + if ('completed' === $payment_status || give_is_test_mode()) { |
|
| 338 | 338 | |
| 339 | - give_insert_payment_note( $payment_id, sprintf( /* translators: %s: Paypal transaction ID */ |
|
| 340 | - __( 'PayPal Transaction ID: %s', 'give' ), $data['txn_id'] ) ); |
|
| 341 | - give_set_payment_transaction_id( $payment_id, $data['txn_id'] ); |
|
| 342 | - give_update_payment_status( $payment_id, 'publish' ); |
|
| 339 | + give_insert_payment_note($payment_id, sprintf( /* translators: %s: Paypal transaction ID */ |
|
| 340 | + __('PayPal Transaction ID: %s', 'give'), $data['txn_id'] )); |
|
| 341 | + give_set_payment_transaction_id($payment_id, $data['txn_id']); |
|
| 342 | + give_update_payment_status($payment_id, 'publish'); |
|
| 343 | 343 | |
| 344 | - } elseif ( 'pending' === $payment_status && isset( $data['pending_reason'] ) ) { |
|
| 344 | + } elseif ('pending' === $payment_status && isset($data['pending_reason'])) { |
|
| 345 | 345 | |
| 346 | 346 | // Look for possible pending reasons, such as an echeck. |
| 347 | - $note = give_paypal_get_pending_donation_note( strtolower( $data['pending_reason'] ) ); |
|
| 347 | + $note = give_paypal_get_pending_donation_note(strtolower($data['pending_reason'])); |
|
| 348 | 348 | |
| 349 | - if ( ! empty( $note ) ) { |
|
| 350 | - give_insert_payment_note( $payment_id, $note ); |
|
| 349 | + if ( ! empty($note)) { |
|
| 350 | + give_insert_payment_note($payment_id, $note); |
|
| 351 | 351 | } |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | -add_action( 'give_paypal_web_accept', 'give_process_paypal_web_accept', 10, 2 ); |
|
| 356 | +add_action('give_paypal_web_accept', 'give_process_paypal_web_accept', 10, 2); |
|
| 357 | 357 | |
| 358 | 358 | /** |
| 359 | 359 | * Process PayPal IPN Refunds |
@@ -365,35 +365,35 @@ discard block |
||
| 365 | 365 | * |
| 366 | 366 | * @return void |
| 367 | 367 | */ |
| 368 | -function give_process_paypal_refund( $data, $payment_id = 0 ) { |
|
| 368 | +function give_process_paypal_refund($data, $payment_id = 0) { |
|
| 369 | 369 | |
| 370 | 370 | // Collect payment details. |
| 371 | - if ( empty( $payment_id ) ) { |
|
| 371 | + if (empty($payment_id)) { |
|
| 372 | 372 | return; |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | // Only refund payments once. |
| 376 | - if ( 'refunded' === get_post_status( $payment_id ) ) { |
|
| 376 | + if ('refunded' === get_post_status($payment_id)) { |
|
| 377 | 377 | return; |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | - $payment_amount = give_donation_amount( $payment_id ); |
|
| 380 | + $payment_amount = give_donation_amount($payment_id); |
|
| 381 | 381 | $refund_amount = $data['payment_gross'] * - 1; |
| 382 | 382 | |
| 383 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 383 | + if (number_format((float) $refund_amount, 2) < number_format((float) $payment_amount, 2)) { |
|
| 384 | 384 | |
| 385 | - give_insert_payment_note( $payment_id, sprintf( /* translators: %s: Paypal parent transaction ID */ |
|
| 386 | - __( 'Partial PayPal refund processed: %s', 'give' ), $data['parent_txn_id'] ) ); |
|
| 385 | + give_insert_payment_note($payment_id, sprintf( /* translators: %s: Paypal parent transaction ID */ |
|
| 386 | + __('Partial PayPal refund processed: %s', 'give'), $data['parent_txn_id'] )); |
|
| 387 | 387 | |
| 388 | 388 | return; // This is a partial refund |
| 389 | 389 | |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - give_insert_payment_note( $payment_id, sprintf( /* translators: 1: Paypal parent transaction ID 2. Paypal reason code */ |
|
| 393 | - __( 'PayPal Payment #%1$s Refunded for reason: %2$s', 'give' ), $data['parent_txn_id'], $data['reason_code'] ) ); |
|
| 394 | - give_insert_payment_note( $payment_id, sprintf( /* translators: %s: Paypal transaction ID */ |
|
| 395 | - __( 'PayPal Refund Transaction ID: %s', 'give' ), $data['txn_id'] ) ); |
|
| 396 | - give_update_payment_status( $payment_id, 'refunded' ); |
|
| 392 | + give_insert_payment_note($payment_id, sprintf( /* translators: 1: Paypal parent transaction ID 2. Paypal reason code */ |
|
| 393 | + __('PayPal Payment #%1$s Refunded for reason: %2$s', 'give'), $data['parent_txn_id'], $data['reason_code'] )); |
|
| 394 | + give_insert_payment_note($payment_id, sprintf( /* translators: %s: Paypal transaction ID */ |
|
| 395 | + __('PayPal Refund Transaction ID: %s', 'give'), $data['txn_id'] )); |
|
| 396 | + give_update_payment_status($payment_id, 'refunded'); |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | /** |
@@ -405,24 +405,24 @@ discard block |
||
| 405 | 405 | * |
| 406 | 406 | * @return string |
| 407 | 407 | */ |
| 408 | -function give_get_paypal_redirect( $ssl_check = false ) { |
|
| 408 | +function give_get_paypal_redirect($ssl_check = false) { |
|
| 409 | 409 | |
| 410 | - if ( is_ssl() || ! $ssl_check ) { |
|
| 410 | + if (is_ssl() || ! $ssl_check) { |
|
| 411 | 411 | $protocol = 'https://'; |
| 412 | 412 | } else { |
| 413 | 413 | $protocol = 'http://'; |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | // Check the current payment mode |
| 417 | - if ( give_is_test_mode() ) { |
|
| 417 | + if (give_is_test_mode()) { |
|
| 418 | 418 | // Test mode |
| 419 | - $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr'; |
|
| 419 | + $paypal_uri = $protocol.'www.sandbox.paypal.com/cgi-bin/webscr'; |
|
| 420 | 420 | } else { |
| 421 | 421 | // Live mode |
| 422 | - $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr'; |
|
| 422 | + $paypal_uri = $protocol.'www.paypal.com/cgi-bin/webscr'; |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | - return apply_filters( 'give_paypal_uri', $paypal_uri ); |
|
| 425 | + return apply_filters('give_paypal_uri', $paypal_uri); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | /** |
@@ -432,9 +432,9 @@ discard block |
||
| 432 | 432 | * @return string |
| 433 | 433 | */ |
| 434 | 434 | function give_get_paypal_page_style() { |
| 435 | - $page_style = trim( give_get_option( 'paypal_page_style', 'PayPal' ) ); |
|
| 435 | + $page_style = trim(give_get_option('paypal_page_style', 'PayPal')); |
|
| 436 | 436 | |
| 437 | - return apply_filters( 'give_paypal_page_style', $page_style ); |
|
| 437 | + return apply_filters('give_paypal_page_style', $page_style); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | /** |
@@ -448,26 +448,26 @@ discard block |
||
| 448 | 448 | * |
| 449 | 449 | * @return string |
| 450 | 450 | */ |
| 451 | -function give_paypal_success_page_content( $content ) { |
|
| 451 | +function give_paypal_success_page_content($content) { |
|
| 452 | 452 | |
| 453 | - if ( ! isset( $_GET['payment-id'] ) && ! give_get_purchase_session() ) { |
|
| 453 | + if ( ! isset($_GET['payment-id']) && ! give_get_purchase_session()) { |
|
| 454 | 454 | return $content; |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | - $payment_id = isset( $_GET['payment-id'] ) ? absint( $_GET['payment-id'] ) : false; |
|
| 457 | + $payment_id = isset($_GET['payment-id']) ? absint($_GET['payment-id']) : false; |
|
| 458 | 458 | |
| 459 | - if ( ! $payment_id ) { |
|
| 459 | + if ( ! $payment_id) { |
|
| 460 | 460 | $session = give_get_purchase_session(); |
| 461 | - $payment_id = give_get_donation_id_by_key( $session['purchase_key'] ); |
|
| 461 | + $payment_id = give_get_donation_id_by_key($session['purchase_key']); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | - $payment = get_post( $payment_id ); |
|
| 465 | - if ( $payment && 'pending' === $payment->post_status ) { |
|
| 464 | + $payment = get_post($payment_id); |
|
| 465 | + if ($payment && 'pending' === $payment->post_status) { |
|
| 466 | 466 | |
| 467 | 467 | // Payment is still pending so show processing indicator to fix the race condition. |
| 468 | 468 | ob_start(); |
| 469 | 469 | |
| 470 | - give_get_template_part( 'payment', 'processing' ); |
|
| 470 | + give_get_template_part('payment', 'processing'); |
|
| 471 | 471 | |
| 472 | 472 | $content = ob_get_clean(); |
| 473 | 473 | |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | -add_filter( 'give_payment_confirm_paypal', 'give_paypal_success_page_content' ); |
|
| 480 | +add_filter('give_payment_confirm_paypal', 'give_paypal_success_page_content'); |
|
| 481 | 481 | |
| 482 | 482 | /** |
| 483 | 483 | * Given a transaction ID, generate a link to the PayPal transaction ID details |
@@ -489,16 +489,16 @@ discard block |
||
| 489 | 489 | * |
| 490 | 490 | * @return string A link to the PayPal transaction details |
| 491 | 491 | */ |
| 492 | -function give_paypal_link_transaction_id( $transaction_id, $payment_id ) { |
|
| 492 | +function give_paypal_link_transaction_id($transaction_id, $payment_id) { |
|
| 493 | 493 | |
| 494 | 494 | $paypal_base_url = 'https://history.paypal.com/cgi-bin/webscr?cmd=_history-details-from-hub&id='; |
| 495 | - $transaction_url = '<a href="' . esc_url( $paypal_base_url . $transaction_id ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
| 495 | + $transaction_url = '<a href="'.esc_url($paypal_base_url.$transaction_id).'" target="_blank">'.$transaction_id.'</a>'; |
|
| 496 | 496 | |
| 497 | - return apply_filters( 'give_paypal_link_payment_details_transaction_id', $transaction_url ); |
|
| 497 | + return apply_filters('give_paypal_link_payment_details_transaction_id', $transaction_url); |
|
| 498 | 498 | |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | -add_filter( 'give_payment_details_transaction_id-paypal', 'give_paypal_link_transaction_id', 10, 2 ); |
|
| 501 | +add_filter('give_payment_details_transaction_id-paypal', 'give_paypal_link_transaction_id', 10, 2); |
|
| 502 | 502 | |
| 503 | 503 | |
| 504 | 504 | /** |
@@ -510,64 +510,64 @@ discard block |
||
| 510 | 510 | * |
| 511 | 511 | * @return string |
| 512 | 512 | */ |
| 513 | -function give_paypal_get_pending_donation_note( $pending_reason ) { |
|
| 513 | +function give_paypal_get_pending_donation_note($pending_reason) { |
|
| 514 | 514 | |
| 515 | 515 | $note = ''; |
| 516 | 516 | |
| 517 | - switch ( $pending_reason ) { |
|
| 517 | + switch ($pending_reason) { |
|
| 518 | 518 | |
| 519 | 519 | case 'echeck' : |
| 520 | 520 | |
| 521 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days.', 'give' ); |
|
| 521 | + $note = __('Payment made via eCheck and will clear automatically in 5-8 days.', 'give'); |
|
| 522 | 522 | |
| 523 | 523 | break; |
| 524 | 524 | |
| 525 | 525 | case 'address' : |
| 526 | 526 | |
| 527 | - $note = __( 'Payment requires a confirmed donor address and must be accepted manually through PayPal.', 'give' ); |
|
| 527 | + $note = __('Payment requires a confirmed donor address and must be accepted manually through PayPal.', 'give'); |
|
| 528 | 528 | |
| 529 | 529 | break; |
| 530 | 530 | |
| 531 | 531 | case 'intl' : |
| 532 | 532 | |
| 533 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations.', 'give' ); |
|
| 533 | + $note = __('Payment must be accepted manually through PayPal due to international account regulations.', 'give'); |
|
| 534 | 534 | |
| 535 | 535 | break; |
| 536 | 536 | |
| 537 | 537 | case 'multi-currency' : |
| 538 | 538 | |
| 539 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal.', 'give' ); |
|
| 539 | + $note = __('Payment received in non-shop currency and must be accepted manually through PayPal.', 'give'); |
|
| 540 | 540 | |
| 541 | 541 | break; |
| 542 | 542 | |
| 543 | 543 | case 'paymentreview' : |
| 544 | 544 | case 'regulatory_review' : |
| 545 | 545 | |
| 546 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations.', 'give' ); |
|
| 546 | + $note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations.', 'give'); |
|
| 547 | 547 | |
| 548 | 548 | break; |
| 549 | 549 | |
| 550 | 550 | case 'unilateral' : |
| 551 | 551 | |
| 552 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'give' ); |
|
| 552 | + $note = __('Payment was sent to non-confirmed or non-registered email address.', 'give'); |
|
| 553 | 553 | |
| 554 | 554 | break; |
| 555 | 555 | |
| 556 | 556 | case 'upgrade' : |
| 557 | 557 | |
| 558 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted.', 'give' ); |
|
| 558 | + $note = __('PayPal account must be upgraded before this payment can be accepted.', 'give'); |
|
| 559 | 559 | |
| 560 | 560 | break; |
| 561 | 561 | |
| 562 | 562 | case 'verify' : |
| 563 | 563 | |
| 564 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this donation.', 'give' ); |
|
| 564 | + $note = __('PayPal account is not verified. Verify account in order to accept this donation.', 'give'); |
|
| 565 | 565 | |
| 566 | 566 | break; |
| 567 | 567 | |
| 568 | 568 | case 'other' : |
| 569 | 569 | |
| 570 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance.', 'give' ); |
|
| 570 | + $note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance.', 'give'); |
|
| 571 | 571 | |
| 572 | 572 | break; |
| 573 | 573 | |
@@ -585,49 +585,49 @@ discard block |
||
| 585 | 585 | * |
| 586 | 586 | * @return mixed|string |
| 587 | 587 | */ |
| 588 | -function give_build_paypal_url( $payment_id, $payment_data ) { |
|
| 588 | +function give_build_paypal_url($payment_id, $payment_data) { |
|
| 589 | 589 | // Only send to PayPal if the pending payment is created successfully. |
| 590 | - $listener_url = add_query_arg( 'give-listener', 'IPN', home_url( 'index.php' ) ); |
|
| 590 | + $listener_url = add_query_arg('give-listener', 'IPN', home_url('index.php')); |
|
| 591 | 591 | |
| 592 | 592 | // Get the success url. |
| 593 | - $return_url = add_query_arg( array( |
|
| 593 | + $return_url = add_query_arg(array( |
|
| 594 | 594 | 'payment-confirmation' => 'paypal', |
| 595 | 595 | 'payment-id' => $payment_id, |
| 596 | 596 | |
| 597 | - ), get_permalink( give_get_option( 'success_page' ) ) ); |
|
| 597 | + ), get_permalink(give_get_option('success_page'))); |
|
| 598 | 598 | |
| 599 | 599 | // Get the PayPal redirect uri. |
| 600 | - $paypal_redirect = trailingslashit( give_get_paypal_redirect() ) . '?'; |
|
| 600 | + $paypal_redirect = trailingslashit(give_get_paypal_redirect()).'?'; |
|
| 601 | 601 | |
| 602 | 602 | // Item name. |
| 603 | - $item_name = give_payment_gateway_item_title( $payment_data ); |
|
| 603 | + $item_name = give_payment_gateway_item_title($payment_data); |
|
| 604 | 604 | |
| 605 | 605 | // Setup PayPal API params. |
| 606 | 606 | $paypal_args = array( |
| 607 | - 'business' => give_get_option( 'paypal_email', false ), |
|
| 607 | + 'business' => give_get_option('paypal_email', false), |
|
| 608 | 608 | 'first_name' => $payment_data['user_info']['first_name'], |
| 609 | 609 | 'last_name' => $payment_data['user_info']['last_name'], |
| 610 | 610 | 'email' => $payment_data['user_email'], |
| 611 | 611 | 'invoice' => $payment_data['purchase_key'], |
| 612 | 612 | 'amount' => $payment_data['price'], |
| 613 | - 'item_name' => stripslashes( $item_name ), |
|
| 613 | + 'item_name' => stripslashes($item_name), |
|
| 614 | 614 | 'no_shipping' => '1', |
| 615 | 615 | 'shipping' => '0', |
| 616 | 616 | 'no_note' => '1', |
| 617 | - 'currency_code' => give_get_currency( $payment_id, $payment_data ), |
|
| 618 | - 'charset' => get_bloginfo( 'charset' ), |
|
| 617 | + 'currency_code' => give_get_currency($payment_id, $payment_data), |
|
| 618 | + 'charset' => get_bloginfo('charset'), |
|
| 619 | 619 | 'custom' => $payment_id, |
| 620 | 620 | 'rm' => '2', |
| 621 | 621 | 'return' => $return_url, |
| 622 | - 'cancel_return' => give_get_failed_transaction_uri( '?payment-id=' . $payment_id ), |
|
| 622 | + 'cancel_return' => give_get_failed_transaction_uri('?payment-id='.$payment_id), |
|
| 623 | 623 | 'notify_url' => $listener_url, |
| 624 | 624 | 'page_style' => give_get_paypal_page_style(), |
| 625 | - 'cbt' => get_bloginfo( 'name' ), |
|
| 625 | + 'cbt' => get_bloginfo('name'), |
|
| 626 | 626 | 'bn' => 'givewp_SP', |
| 627 | 627 | ); |
| 628 | 628 | |
| 629 | 629 | // Add user address if present. |
| 630 | - if ( ! empty( $payment_data['user_info']['address'] ) ) { |
|
| 630 | + if ( ! empty($payment_data['user_info']['address'])) { |
|
| 631 | 631 | $default_address = array( |
| 632 | 632 | 'line1' => '', |
| 633 | 633 | 'line2' => '', |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | 'country' => '', |
| 638 | 638 | ); |
| 639 | 639 | |
| 640 | - $address = wp_parse_args( $payment_data['user_info']['address'], $default_address ); |
|
| 640 | + $address = wp_parse_args($payment_data['user_info']['address'], $default_address); |
|
| 641 | 641 | |
| 642 | 642 | $paypal_args['address1'] = $address['line1']; |
| 643 | 643 | $paypal_args['address2'] = $address['line2']; |
@@ -658,13 +658,13 @@ discard block |
||
| 658 | 658 | * |
| 659 | 659 | * @since 1.8 |
| 660 | 660 | */ |
| 661 | - $paypal_args = apply_filters( 'give_paypal_redirect_args', $paypal_args, $payment_data ); |
|
| 661 | + $paypal_args = apply_filters('give_paypal_redirect_args', $paypal_args, $payment_data); |
|
| 662 | 662 | |
| 663 | 663 | // Build query. |
| 664 | - $paypal_redirect .= http_build_query( $paypal_args ); |
|
| 664 | + $paypal_redirect .= http_build_query($paypal_args); |
|
| 665 | 665 | |
| 666 | 666 | // Fix for some sites that encode the entities. |
| 667 | - $paypal_redirect = str_replace( '&', '&', $paypal_redirect ); |
|
| 667 | + $paypal_redirect = str_replace('&', '&', $paypal_redirect); |
|
| 668 | 668 | |
| 669 | 669 | return $paypal_redirect; |
| 670 | 670 | } |
@@ -679,7 +679,7 @@ discard block |
||
| 679 | 679 | function give_get_paypal_button_type() { |
| 680 | 680 | // paypal_button_type can be donation or standard. |
| 681 | 681 | $paypal_button_type = '_donations'; |
| 682 | - if ( 'standard' === give_get_option( 'paypal_button_type' ) ) { |
|
| 682 | + if ('standard' === give_get_option('paypal_button_type')) { |
|
| 683 | 683 | $paypal_button_type = '_xclick'; |
| 684 | 684 | } |
| 685 | 685 | |
@@ -697,14 +697,14 @@ discard block |
||
| 697 | 697 | * |
| 698 | 698 | * @return string |
| 699 | 699 | */ |
| 700 | -function give_paypal_purchase_key( $custom_purchase_key, $gateway, $purchase_key ) { |
|
| 700 | +function give_paypal_purchase_key($custom_purchase_key, $gateway, $purchase_key) { |
|
| 701 | 701 | |
| 702 | - if ( 'paypal' === $gateway ) { |
|
| 703 | - $invoice_id_prefix = give_get_option( 'paypal_invoice_prefix', 'GIVEPAYPAL-' ); |
|
| 704 | - $custom_purchase_key = $invoice_id_prefix . $purchase_key; |
|
| 702 | + if ('paypal' === $gateway) { |
|
| 703 | + $invoice_id_prefix = give_get_option('paypal_invoice_prefix', 'GIVEPAYPAL-'); |
|
| 704 | + $custom_purchase_key = $invoice_id_prefix.$purchase_key; |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | return $custom_purchase_key; |
| 708 | 708 | } |
| 709 | 709 | |
| 710 | -add_filter( 'give_donation_purchase_key', 'give_paypal_purchase_key', 10, 3 ); |
|
| 710 | +add_filter('give_donation_purchase_key', 'give_paypal_purchase_key', 10, 3); |
|