Anyone?
Something bad/wrong in My post?
Thanks
I have a function set up in my register.php that copies the user-supplied username (in the registration form,) copies it over to the “Display Name” field, and hides the display name field on the registration form. This way, whatever the user entered for username will automatically be used for his/her display name. (To avoid asking the user for a name 2 times!)
Would you like to do this? If so, I’d be glad to share my register.php file with you. Let me know. If this is not what you need, then please disregard this message.
Hi aaronthomas1979
Thanks for yuor answer
Absolutely yes! please share your code!
I would like to do something a bit different, but I think that I should start from your code adapting it to my scope.
What I exactly want to achieve: something like facebook do, that is to copy the full name (that is the only name the user will digit in the registration form) in the username (that must be automatically generated). The problem with this solution is that the username must be unique so I could insert a code like the following to insert a number at the end of the name making it unique:
function username( $username){
$username = $username[0];
$j = 1;
while ( username_exists( $username ) ){
$username = $username . '_' . $j;
$j++;
}
return $username;
}
I think this is the cleanest solution: the users will insert the real name in the registration form, (without asking to change the full name inserted if another user with the same name is already registered) but a unique username is created silently anyway.
Please share, hope to find a solution with yours o any other contribute
Thanks
Ositive
So just to be clear, my registration form does not ask for real name. It asks for username, email address, password, and then it proceeds to the extended profile questions. But it does NOT ask for “Display Name,” it just copies whatever the user typed for username into the “Display Name” field. A friend of mine created the function, and I am not extremely PHP literate, but this is working on my site.
I’m a little embarrassed, because I don’t know exactly where in the code is this function that my buddy created for me, so I will have to give you the URL to my register.php file, and then you can view it in it’s entirety. (Code view with your browser.)
Click here to see my register.php
@ositive I’m trying to do basically the exact same thing you’re describing here, and I was wondering if you ever figured out a solution that you could share?
This is the function i’ve used, with a random function to create unique username. I hope can help.
Ositive
add_action( 'bp_core_validate_user_signup', 'custom_validate_user_signup' );
function custom_validate_user_signup($result){
unset($result['errors']->errors['user_name']);
if(!empty($_POST['field_1']))
{
$result['user_name'] = $_POST['field_1'] . '_' . rand(1, 9999);
$_POST['signup_username'] = $result['user_name'];
$result['user'] = $_POST['field_1'];
$_POST['signup_password_confirm']=$_POST['signup_password'];
}
return $result;
}
Did you put this in functions.php or did you modify the plugin code directly?
Thanks ositive for the code. Gonna try it out now.
WordPress Email Opt-in Plugin
@aaronthomas1979 Hello buddy, you have exactly what I need, but I have no idea how to find this code or where to insert it, is there any way you could help me?