/** * Gets the login fields for the login form on the checkout. This function hooks * on the give_purchase_form_login_fields to display the login form if a user already * had an account. * * @since 1.0 * * @param int $form_id * * @return string */ function give_get_login_fields($form_id) { global $give_options; $color = isset($give_options['checkout_color']) ? $give_options['checkout_color'] : 'gray'; $color = $color == 'inherit' ? '' : $color; $show_register_form = give_get_option('show_register_form', 'none'); ob_start(); ?> <fieldset id="give_login_fields"> <legend><?php _e('Login to Your Account', 'give'); if (!give_no_guest_checkout($form_id)) { echo ' <span class="sub-text">' . __('(optional)', 'give') . '</span>'; } ?> </legend> <?php if ($show_register_form == 'both') { ?> <p id="give-new-account-wrap"> <?php _e('Need to create an account?', 'give'); ?> <a href="<?php echo remove_query_arg('login'); ?> " class="give_checkout_register_login" data-action="checkout_register"> <?php _e('Register', 'give'); if (!give_no_guest_checkout($form_id)) { echo ' ' . __('or checkout as a guest.', 'give'); } ?> </a> </p> <?php } ?> <?php do_action('give_checkout_login_fields_before', $form_id); ?> <p id="give-user-login-wrap" class="form-row form-row-first"> <label class="give-label" for="give-username"><?php _e('Username', 'give'); ?> </label> <input class="<?php if (give_no_guest_checkout($form_id)) { echo 'required '; } ?> give-input" type="text" name="give_user_login" id="give_user_login" value="" placeholder="<?php _e('Your username', 'give'); ?> " /> </p> <p id="give-user-pass-wrap" class="give_login_password form-row form-row-last"> <label class="give-label" for="give-password"><?php _e('Password', 'give'); ?> </label> <input class="<?php if (give_no_guest_checkout($form_id)) { echo 'required '; } ?> give-input" type="password" name="give_user_pass" id="give_user_pass" placeholder="<?php _e('Your password', 'give'); ?> " /> <input type="hidden" name="give-purchase-var" value="needs-to-login" /> </p> <p id="give-user-login-submit" class="give-clearfix"> <input type="submit" class="give-submit give-btn button <?php echo $color; ?> " name="give_login_submit" value="<?php _e('Login', 'give'); ?> " /> <span class="give-loading-animation"></span> </p> <?php do_action('give_checkout_login_fields_after'); ?> </fieldset><!--end #give_login_fields--> <?php echo ob_get_clean(); }
/** * Get Purchase Form User * * @param array $valid_data * * @access private * @since 1.0 * @return array */ function give_get_purchase_form_user($valid_data = array()) { // Initialize user $user = false; $is_ajax = defined('DOING_AJAX') && DOING_AJAX; if ($is_ajax) { // Do not create or login the user during the ajax submission (check for errors only) return true; } else { if (is_user_logged_in()) { // Set the valid user as the logged in collected data $user = $valid_data['logged_in_user']; } else { if ($valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true) { // New user registration if ($valid_data['need_new_user'] === true) { // Set user $user = $valid_data['new_user_data']; // Register and login new user $user['user_id'] = give_register_and_login_new_user($user); // User login } else { if ($valid_data['need_user_login'] === true && !$is_ajax) { /* * The login form is now processed in the give_process_purchase_login() function. * This is still here for backwards compatibility. * This also allows the old login process to still work if a user removes the * checkout login submit button. * * This also ensures that the donor is logged in correctly if they click "Purchase" * instead of submitting the login form, meaning the donor is logged in during the purchase process. */ // Set user $user = $valid_data['login_user_data']; // Login user give_log_user_in($user['user_id'], $user['user_login'], $user['user_pass']); } } } } } // Check guest checkout if (false === $user && false === give_no_guest_checkout($_POST['give-form-id'])) { // Set user $user = $valid_data['guest_user_data']; } // Verify we have an user if (false === $user || empty($user)) { // Return false return false; } // Get user first name if (!isset($user['user_first']) || strlen(trim($user['user_first'])) < 1) { $user['user_first'] = isset($_POST["give_first"]) ? strip_tags(trim($_POST["give_first"])) : ''; } // Get user last name if (!isset($user['user_last']) || strlen(trim($user['user_last'])) < 1) { $user['user_last'] = isset($_POST["give_last"]) ? strip_tags(trim($_POST["give_last"])) : ''; } // Get the user's billing address details $user['address'] = array(); $user['address']['line1'] = !empty($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : false; $user['address']['line2'] = !empty($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : false; $user['address']['city'] = !empty($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : false; $user['address']['state'] = !empty($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : false; $user['address']['country'] = !empty($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : false; $user['address']['zip'] = !empty($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : false; if (empty($user['address']['country'])) { $user['address'] = false; } // Country will always be set if address fields are present if (!empty($user['user_id']) && $user['user_id'] > 0 && !empty($user['address'])) { // Store the address in the user's meta so the cart can be pre-populated with it on return purchases update_user_meta($user['user_id'], '_give_user_address', $user['address']); } // Return valid user return $user; }