我正在使用一个名为Ultimate Membership Pro的Wordpress插件,该插件正在使用Ajax调用来验证“注册”表单中的用户名。但是,当已注册的用户名试图再次注册时,我想检索用户的全名。
示例-我希望验证消息说:此用户名已由John Doe使用
我试图在插件目录中操作一个名为确实是membership-pro.php的文件名。
//I added this code under the function
//I called a global method
global $current_user;
$uid = get_user_by('login', $value);
case 'user_login':
if (!validate_username($value)){
$return = $register_msg['ihc_register_error_username_msg'];
}
if (username_exists($value)) {
//I concatenate the error message with the input username to get the user ID. But i need the user FirstName and Lastname
$return = $register_msg['ihc_register_username_taken_msg'] . $uid->ID;
}
break;
function ihc_check_value_field($type='', $value='', $val2='', $register_msg=array()){
//I called a global method
global $current_user;
$uid = get_user_by('login', $value);
if (isset($value) && $value!=''){
switch ($type){
case 'user_login':
if (!validate_username($value)){
$return = $register_msg['ihc_register_error_username_msg'];
}
if (username_exists($value)) {
//I am able to get the user ID But i need First Name and last Name
$return = $register_msg['ihc_register_username_taken_msg']. $uid->ID;
}
break;
case 'user_email':
if (!is_email($value)) {
$return = $register_msg['ihc_register_invalid_email_msg'];
}
if (email_exists($value)){
$return = $register_msg['ihc_register_email_is_taken_msg'];
}
$blacklist = get_option('ihc_email_blacklist');
if(isset($blacklist)){
$blacklist = explode(',',preg_replace('/\s+/', '', $blacklist));
if( count($blacklist) > 0 && in_array($value,$blacklist)){
$return = $register_msg['ihc_register_email_is_taken_msg'];
}
}
break;
case 'confirm_email':
if ($value==$val2){
$return = 1;
} else {
$return = $register_msg['ihc_register_emails_not_match_msg'];
}
break;
case 'pass1':
$register_metas = ihc_return_meta_arr('register');
if ($register_metas['ihc_register_pass_options']==2){
//characters and digits
if (!preg_match('/[a-z]/', $value)){
$return = $register_msg['ihc_register_pass_letter_digits_msg'];
}
if (!preg_match('/[0-9]/', $value)){
$return = $register_msg['ihc_register_pass_letter_digits_msg'];
}
} else if ($register_metas['ihc_register_pass_options']==3){
//characters, digits and one Uppercase letter
if (!preg_match('/[a-z]/', $value)){
$return = $register_msg['ihc_register_pass_let_dig_up_let_msg'];
}
if (!preg_match('/[0-9]/', $value)){
$return = $register_msg['ihc_register_pass_let_dig_up_let_msg'];
}
if (!preg_match('/[A-Z]/', $value)){
$return = $register_msg['ihc_register_pass_let_dig_up_let_msg'];
}
}
//check the length of password
if($register_metas['ihc_register_pass_min_length']!=0){
if (strlen($value)<$register_metas['ihc_register_pass_min_length']){
$return = str_replace( '{X}', $register_metas['ihc_register_pass_min_length'], $register_msg['ihc_register_pass_min_char_msg'] );
}
}
break;
case 'pass2':
if ($value==$val2){
$return = 1;
} else {
$return = $register_msg['ihc_register_pass_not_match_msg'];
}
break;
case 'tos':
if ($value==1){
$return = 1;
} else {
$return = $register_msg['ihc_register_err_tos'];
}
break;
default:
//required conditional field
$check = ihc_required_conditional_field_test($type, $value);
if ($check){
$return = $check;
} else {
$return = 1;
}
break;
}
if (empty($return)){
$return = 1;
}
return $return;
} else {
$check = ihc_required_conditional_field_test($type, $value);//Check for required conditional field
if ($check){
return $check;
} else {
return $register_msg['ihc_register_err_req_fields'];
}
}
}
add_action("wp_ajax_nopriv_ihc_ap_reset_custom_banner", "ihc_ap_reset_custom_banner");
add_action('wp_ajax_ihc_ap_reset_custom_banner', 'ihc_ap_reset_custom_banner');
答案 0 :(得分:0)
$user_object->display_name
是您要寻找的。 p>
鉴于此,在错误消息中显示诸如姓氏和名字之类的用户数据可能不是一个好主意。