I am looking for any built in function that when I add a user or a user wants to register, the username will be automatically prepended with a predefined text.
For example, if the user registers with abul
, the username will be saved as tk_abul
.
I am looking for any built in function that when I add a user or a user wants to register, the username will be automatically prepended with a predefined text.
For example, if the user registers with abul
, the username will be saved as tk_abul
.
- how do you save the user? – Vishwa Commented May 9, 2019 at 7:06
- I want to add user from WordPress dashboard – Akhtarujjaman Shuvo Commented May 9, 2019 at 7:09
2 Answers
Reset to default 1You can use pre_user_login
filter to customize username when registered. Example.
add_filter( 'pre_user_login', 'wpse_customize_user' );
function wpse_customize_user( $username ) {
return 'tk_' . $username;
}
Try user_register
hook. The following code wasn't tested.
<?php
add_action( 'user_register', 'my_nickname_prepend_function' );
function my_nickname_prepend_function( $user_id )
{
if ( isset( $_POST['user_login'] ) )
update_user_meta( $user_id, 'nickname', 'tk_' . $_POST['user_login'] );
}
}
Remember about user input validation.
Action Reference is at your service.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745510653a4630755.html
评论列表(0条)