Last active
August 29, 2015 14:11
-
-
Save w3b-beweb/9afcbaf70a45773b548e to your computer and use it in GitHub Desktop.
modded userpro_side_validate() from ajax.php of wordpress Userpro plugin
This file contains hidden or 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
function userpro_side_validate(){ | |
global $userpro; | |
if ( $_POST['action'] != 'userpro_side_validate') | |
die(); | |
extract($_POST); | |
$output['error'] = ''; | |
switch($ajaxcheck) { | |
case 'envato_purchase_code': | |
if ( !$userpro->verify_purchase($input_value) ) { | |
$output['error'] = __('Invalid purchase code or Envato API is down.','userpro'); | |
} else { | |
$output['error'] = ''; | |
} | |
break; | |
case 'display_name_exists': | |
if ($userpro->display_name_exists($input_value)) { | |
$output['error'] = __('The display name is already in use.','userpro'); | |
} | |
break; | |
case 'username_exists': | |
if (username_exists($input_value)){ | |
$output['error'] = __('Username already taken.','userpro'); | |
} else if ( !preg_match("/^[A-Za-z0-9_]+$/", $input_value) ) { | |
$output['error'] = __('Illegal characters are not allowed in username.','userpro'); | |
} | |
break; | |
case 'email_exists': | |
if (!is_email($input_value)) { | |
$output['error'] = __('Please enter a valid email.','userpro'); | |
} else if (email_exists($input_value)) { | |
$output['error'] = __('Email is taken. Is that you? Try to <a href="#" data-template="login">login</a>','userpro'); | |
} | |
break; | |
case 'validatesecretkey': | |
if (strlen($input_value) != 20) { | |
$output['error'] = __('The secret key you entered is invalid.','userpro'); | |
} else { | |
$users = get_users(array( | |
'meta_key' => 'userpro_secret_key', | |
'meta_value' => $input_value, | |
'meta_compare' => '=', | |
)); | |
if (!$users[0]) { | |
$output['error'] = __('The secret key is invalid or expired.','userpro'); | |
} | |
} | |
break; | |
} | |
//if no check was triggered before | |
if ( $output['error'] == '' ){ | |
$output = apply_filters('custom_ajax_check_callback',$output,$ajaxcheck,$input_value); | |
} | |
$output=json_encode($output); | |
if(is_array($output)){ print_r($output); }else{ echo $output; } die; | |
} | |
This is exactly what I was looking for, only slightly different.
Can you help with the code if I just want to modify the code to do a ajax validation with the phone_number field and prevent registration if phone number already exist?
sorry, i'm reading your comment just now! The code above does exactly these 2 things: validate a phone number via regex and, if it is valid, checks if passed phone number is already in use as username. In that case it outputs an error
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add a custom validation via filter: