Created
May 23, 2022 18:50
-
-
Save DumahX/365ea1fabeb2365cc482bd1b694ac716 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function check_duplicate_address_fields($errors) { | |
$mepr_options = MeprOptions::fetch(); | |
$address_fields = array( | |
$_POST['mepr-address-one'], | |
$_POST['mepr-address-two'], | |
$_POST['mepr-address-city'], | |
$_POST['mepr-address-zip'], | |
$_POST['mepr-address-state'] | |
); | |
$uniq_address_fields = array_unique($address_fields); //removes duplicate elements | |
$number_of_duplicates = count($address_fields) - count($uniq_address_fields); | |
if ($number_of_duplicates > 1) { | |
// Create user if they don't already exist. | |
$user = new MeprUser(); | |
$user->user_login = ($mepr_options->username_is_email)?sanitize_email($_POST['user_email']):sanitize_user($_POST['user_login']); | |
$user->user_email = sanitize_email($_POST['user_email']); | |
$user->first_name = isset($_POST['user_first_name']) && !empty($_POST['user_first_name']) ? sanitize_text_field(wp_unslash($_POST['user_first_name'])) : ''; | |
$user->last_name = isset($_POST['user_last_name']) && !empty($_POST['user_last_name']) ? sanitize_text_field(wp_unslash($_POST['user_last_name'])) : ''; | |
$password = ($mepr_options->disable_checkout_password_fields === true) ? wp_generate_password() : $_POST['mepr_user_password']; | |
// Have to use rec here because we unset user_pass on __construct | |
$user->set_password($password); | |
try { | |
$user->store(); | |
// Need to refresh the user object. | |
$user = new MeprUser($user->ID); | |
} catch(Exception $e) { | |
// Fail silenty... | |
return $errors; | |
} | |
// Store some information about the potential spammer. | |
update_user_meta($user->ID, 'mepr_ip_address', $_SERVER['REMOTE_ADDR']); | |
update_user_meta($user->ID, 'mepr_registration_url', $_SERVER['REQUEST_URI']); | |
// Redirect to the Thank You page. | |
MeprUtils::wp_redirect('/thank-you'); | |
} | |
return $errors; | |
} | |
add_filter('mepr-validate-signup', 'check_duplicate_address_fields'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment