在这篇文章中,老蒋整理两种让WordPress支持中文用户名注册的方法。如果我们有需要的可以使用,一般我们还是严格按照惯例使用英文比较好。
**第一、修改WordPress源码**
1、在wp-includes/formatting.php

> function sanitize_user( $username, $strict = false ) {
找到这一行,在这行下面添加:
> $strict = false;
不过这个问题就是下次升级之后我们还需要重新设置。
**第二、编辑当前主题**
> function huan_sanitize_user ($username, $raw_username, $strict) {
> $username = wp_strip_all_tags( $raw_username );
> $username = remove_accents( $username );
> // Kill octets
> $username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username );
> $username = preg_replace( '/&.+?;/', '', $username ); // Kill entities
> if ($strict) {
> $username = preg_replace ('|[^a-z\p{Han}0-9 _.\-@]|iu', '', $username);
> }
> $username = trim( $username );
> // Consolidate contiguous whitespace
> $username = preg_replace( '|\s+|', ' ', $username );
> return $username;
> }
> add_filter ('sanitize_user', 'ludou_sanitize_user', 10, 3);
在当前主题functions.php文件中添加上面代码,即可实现。比之前的方法好处就不用担心WP程序升级后被替换。