plugin development - How do I add a prefix when a user registers

I am looking for any built in function that when I add a user or a user wants to register, the username will be automati

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.

Share Improve this question edited May 9, 2019 at 8:36 Fayaz 9,0172 gold badges33 silver badges51 bronze badges asked May 9, 2019 at 7:01 Akhtarujjaman ShuvoAkhtarujjaman Shuvo 2081 silver badge6 bronze badges 2
  • 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
Add a comment  | 

2 Answers 2

Reset to default 1

You 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

相关推荐

  • plugin development - How do I add a prefix when a user registers

    I am looking for any built in function that when I add a user or a user wants to register, the username will be automati

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信