去评论
距米网-精简版

如何让WordPress 支持中文用户名注册

JUMU
2018/11/27 07:57:03
将以下php代码复制到当前主题目录下的functions.php中,即可让WordPress支持使用中文用户名注册和登录
  1. function MBT_sanitize_user ($username, $raw_username, $strict) { $username = wp_strip_all_tags( $raw_username );
  2. $username = remove_accents( $username );
  3. $username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '',
  4. $username ); $username = preg_replace( '/&.+?;/', '', $username );  
  5. if ($strict) { $username = preg_replace ('|[^a-z\p{Han}0-9 _.\-@]|iu', '', $username);
  6. }
  7. $username = trim( $username );
  8. $username = preg_replace( '|\s+|', ' ', $username );
  9. return $username;
  10. }
  11. add_filter ('sanitize_user', 'MBT_sanitize_user', 10, 3);