Home › Toolset Professional Support › [Resolved] hide nickname and copy it from username
Problem:
The user would like to hide the nickname in a user form and automatically copy the email to the nickname.
Solution:
- Hide the nickname from the form options.
- Add the following code to copy the user email to the nickname:
/* update nickname field with the value of user_login. */ function my_copy_nickame_from_username( $user_id ) { $user = get_user_by( 'id', $user_id); update_user_meta( $user_id, 'nickname', $user->user_login ); } add_action( 'user_register', 'my_copy_nickame_from_username' );
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
This topic is split from https://toolset.com/forums/topic/user-register-form-missing-confirm-password-label/
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - | - | 9:00 – 13:00 |
14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - | - | 14:00 – 18:00 |
Supporter timezone: Africa/Casablanca (GMT+01:00)
Tagged: Toolset Forms, User-registration forms
Related documentation:
This topic contains 2 replies, has 2 voices.
Last updated by WeiS2074 4 years, 7 months ago.
Assisted by: Jamal.
Great, I have followed the pattern and make a label. Another question, can I hide "nickname" on the front end, but when user enter "username" it automatically copies "username" into "nickname". How do I make this approach?
To hide the nickname, I would suggest removing the field from the form. Switch to expert mode and remove the field.
There is an option to auto-generate the nickname, check this screenshot.
If you need to copy the username to the nickname, you will have to use custom code on your theme's functions.php, a new plugin, or in Toolset->Settings->Custom code(tab).
/* update nickname field with the value of user_login. */ function my_copy_nickame_from_username( $user_id ) { $user = get_user_by( 'id', $user_id); update_user_meta( $user_id, 'nickname', $user->user_login ); } add_action( 'user_register', 'my_copy_nickame_from_username' );
My issue is resolved now. Thank you!
Notifications