profiles - Make user’s first and last name as user slug

I allow users to sign up with their first name, last name and e-mail addresses. I want to make their first and last name

I allow users to sign up with their first name, last name and e-mail addresses. I want to make their first and last name as slug. For example user first name is “John” and last name is “James”. The slug should be example/users/john-james/ I do not want to use any plugin to make changes.

There are already 300 registered members on the website and i want to change their slug too.

I allow users to sign up with their first name, last name and e-mail addresses. I want to make their first and last name as slug. For example user first name is “John” and last name is “James”. The slug should be example/users/john-james/ I do not want to use any plugin to make changes.

There are already 300 registered members on the website and i want to change their slug too.

Share Improve this question asked Jul 3, 2019 at 8:36 JackJack 133 bronze badges 3
  • Hey, you have to change their user_login meta to achieve that. PS : By default the user_login is composed by the first and last name of a user ! – Rachid Chihabi Commented Jul 3, 2019 at 8:54
  • @RachidChihabi Could you please let me know how can i do this? – Jack Commented Jul 3, 2019 at 9:06
  • i just put an answer cuz comments are limited...see bellow – Rachid Chihabi Commented Jul 3, 2019 at 9:31
Add a comment  | 

1 Answer 1

Reset to default 0

To update existing users, try to make a script file and put that code on it (you have to require necessary file wp-load.php if you put that file in the root of your wp instance) or by listning on a hook like init hook :

$blogusers = get_users( 'role=subscriber' ); //get users by role
// Array of WP_User objects.
foreach ( $blogusers as $user ) { //loop throught users
    update_user_meta($user->ID, 'user_login', sanitize_title($user->first_name.' '.$user->last_name)); //update user login

    //if $user->first_name / $user->last_name didn't work, try to get the first and last names by using get_user_meta($user->ID, 'first_name', true)...
}

if you wanna use that behaviour just after user has registred, you have to use the user_register hook, and then put the same code above in your function...

PS : Code not tested.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745349555a4623747.html

相关推荐

  • profiles - Make user’s first and last name as user slug

    I allow users to sign up with their first name, last name and e-mail addresses. I want to make their first and last name

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信