[ad_1]
Hi @samuelmarcinko,
The user registration plugin has a specific field for the user name and display name. You can see it in this screenshot
If you include this field, users can enter usernames or display names of their choice. We have added these fields to user registration because users always want to display the profile names based on their needs.
If you’re already familiar with these features but still want to generate a user name from the first and last names, try the code below.
add_action( 'user_registration_after_register_user_action', 'ur_insert_nickname', 1, 3 );
function ur_insert_nickname( $valid_form_data, $form_id, $user_id ) {
$username = isset( $valid_form_data['user_login'] ) ? $valid_form_data['user_login']->value : '';
wp_update_user([
'ID' => $user_id, // this is the ID of the user you want to update.
'first_name' => $username,
'last_name' => $username,
]);
}If you do not know where to custom code snippets on your site, please check this documentation .
Regards!
I used the following code and its working fine…
add_action( 'user_registration_after_register_user_action', 'ur_do_something_after_user_registered', 10, 3 );
function ur_do_something_after_user_registered( $valid_form_data, $form_id, $user_id ) {
$first_name = get_user_meta($user_id, 'first_name', true);
$last_name = get_user_meta($user_id, 'last_name', true);
$user_nickname = $first_name.' '.$last_name;
update_user_meta( $user_id, 'nickname', $user_nickname );
}
Hi @korynorthrop,
I’m glad you were able to meet the requirement with the custom code snippet,
If you have a moment to spare, we would appreciate your review of our plugin. Please click on this link and share your thoughts about our team and our plugin. We would love to hear from you.
Thanks!
