admin管理员组文章数量:1130349
user_nicename has the same value with user_login. I want to change user_nicename value only by using code snippet into functions.php or wp-config.php. Is it possible without using phpmyadmin or any plugin?
user_nicename has the same value with user_login. I want to change user_nicename value only by using code snippet into functions.php or wp-config.php. Is it possible without using phpmyadmin or any plugin?
Share Improve this question edited Dec 13, 2018 at 2:53 Tom J Nowell♦ 61.2k7 gold badges79 silver badges150 bronze badges asked Dec 13, 2018 at 1:22 Serdar KoçakSerdar Koçak 522 silver badges7 bronze badges 7 | Show 2 more comments1 Answer
Reset to default 6Yes, you can use wp_update_user():
wp_update_user( array(
'ID' => 123,
'user_nicename' => 'value'
) );
Just replace 123 with the proper user ID, and value with the preferred user_nicename value.
The function also enables you to change the value of other fields in the WordPress users table (wp_users).
user_nicename has the same value with user_login. I want to change user_nicename value only by using code snippet into functions.php or wp-config.php. Is it possible without using phpmyadmin or any plugin?
user_nicename has the same value with user_login. I want to change user_nicename value only by using code snippet into functions.php or wp-config.php. Is it possible without using phpmyadmin or any plugin?
Share Improve this question edited Dec 13, 2018 at 2:53 Tom J Nowell♦ 61.2k7 gold badges79 silver badges150 bronze badges asked Dec 13, 2018 at 1:22 Serdar KoçakSerdar Koçak 522 silver badges7 bronze badges 7-
1
Note that
user_nicenameanduser_loginare separate for a reason, and they aren't the same.user_nicenameis the URL sanitized version ofuser_login, changing it to something else might break things in unexpected ways. Perhaps you actually wanted to changedisplay_name? – Tom J Nowell ♦ Commented Dec 13, 2018 at 2:53 - Hi @TomJNowell , I wanted to change user_nicename only because if I didn't change it, hackers can detect it easy via url and attack to my blog. (brute force). The blog is more secure now. – Serdar Koçak Commented Dec 13, 2018 at 13:09
- usernames and IDs aren't secret, they can be fetched via the REST API, XML RPC, even the CSS classes and URLs in a webpage. Doing this does nothing to improve your security, and if your sites security depends on these things being secret then you have major problems – Tom J Nowell ♦ Commented Dec 13, 2018 at 16:32
- @TomJNowell Could you please clarify what kind of problems do you mean? I didn't change user_login table. I changed user_nicename only. Also I blocked XML-RPC and REST API requests. There is no css class about user_login. My blog is minimal. user_nicename is used to create author permalink only. Hackers can discover username by author query. So I changed it only. – Serdar Koçak Commented Dec 14, 2018 at 0:05
-
e.g. on the author pages, when you comment on things. Also by blocking the REST API you're crippling a number of plugins and core features, e.g. the 5.0 block editor, Yoast SEO, Jetpack, etc User IDs and logins aren't a secret, they were never meant to be a secret, and exposing them shouldn't be a security risk. What we have here is security theatre. The only reason
user_nicenameexists is because if you have an umlaut or other non-URL friendly character in your username, it wouldn't match when you did the query, so it sanitises it ahead of time for performance – Tom J Nowell ♦ Commented Dec 14, 2018 at 14:35
1 Answer
Reset to default 6Yes, you can use wp_update_user():
wp_update_user( array(
'ID' => 123,
'user_nicename' => 'value'
) );
Just replace 123 with the proper user ID, and value with the preferred user_nicename value.
The function also enables you to change the value of other fields in the WordPress users table (wp_users).
本文标签: phpChanging usernicename
版权声明:本文标题:php - Changing user_nicename 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749104056a2316458.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


user_nicenameanduser_loginare separate for a reason, and they aren't the same.user_nicenameis the URL sanitized version ofuser_login, changing it to something else might break things in unexpected ways. Perhaps you actually wanted to changedisplay_name? – Tom J Nowell ♦ Commented Dec 13, 2018 at 2:53user_nicenameexists is because if you have an umlaut or other non-URL friendly character in your username, it wouldn't match when you did the query, so it sanitises it ahead of time for performance – Tom J Nowell ♦ Commented Dec 14, 2018 at 14:35