admin管理员组文章数量:1422007
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
1 Answer
Reset to default 0To 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.
本文标签: profilesMake user’s first and last name as user slug
版权声明:本文标题:profiles - Make user’s first and last name as user slug 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745349555a2654682.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论