1、如何用插件让注册用户名支持中文名?
我研究了下,函数如下:
function sanitize_chinese_user($username, $raw_username, $strict) { if ($username != $raw_username) $username = $raw_username; $username = strip_tags($username); $username = preg_replace('|[^a-z0-9 _.\-@一-龥]|ui', '', $username); // Consolidate contiguous whitespace $username = preg_replace('|\s+|', ' ', $username); return apply_filters('sanitize_chinese_user', $username, $raw_username, $strict); } add_filter('sanitize_user', 'sanitize_chinese_user', 1, 3);
使用方法:
- 方法一:直接把上面的函数放到主题的functions.php文件中,保存即可。
- 方法二:下载chinese-username.zip,解压后,上传到plugins文件夹中,最后到后台激活“中文用户名”即可。
有什么bug,请在这里留言告知,谢谢。
十分感谢你的帮助!(泪奔。。
不过我现在在移动设备上,测试不了,等我发现问题再问吧
另外关于第二个问题提到的函数,能不能直接替换掉某个原有函数而执行自定义函数?
用add_filter就可以了。
例如上面用到的:
其实就是用sanitize_chinese_user函数替换了sanitize_user函数的。
不过应该也不是绝对能替换的,可能有些函数就不能被替换。(我其实对filter这些也还不是太清晰。)
了解了,改天我试试
PS.我的域名你输错了…
哈哈,是你在你问我答那里输入错了。我改改。
[…] 如果有问题可以在这里留言 也可以去作者博客:http://wanwp.com/tips-tricks/wordpress-register-username-use-chinese-words/comment-page-1/?replytoco… […]
哈哈。我喜欢