Single

wordpress 注册用户可以使用中文昵称

WordPress应该是为了安全还是怎么滴,注册的时候只能用字母不支持中文昵称
只能动手在主题里改改咯!!~
找了下露兜宝宝的设置方法,做个笔记
functions.php 文件添加一段功能函数就好了

代码宝宝在下方

复制代码
  1. function ludou_sanitize_user ($username, $raw_username, $strict) {
  2. $username = wp_strip_all_tags( $raw_username );
  3. $username = remove_accents( $username );
  4. // Kill octets
  5. $username = preg_replace( ‘|%([a-fA-F0-9][a-fA-F0-9])|’, , $username );
  6. $username = preg_replace( ‘/&.+?;/’, , $username ); // Kill entities
  7. // 网上很多教程都是直接将$strict赋值false,
  8. // 这样会绕过字符串检查,留下隐患
  9. if ($strict) {
  10. $username = preg_replace (‘|[^a-z\p{Han}0-9 _.\-@]|iu’, , $username);
  11. }
  12. $username = trim( $username );
  13. // Consolidate contiguous whitespace
  14. $username = preg_replace( ‘|\s+|’, ‘ ‘, $username );
  15. return $username;
  16. }
  17. add_filter (‘sanitize_user’, ‘ludou_sanitize_user’, 10, 3);

暂无评论

发表评论