解决wordpress错误:此用户名包含无效字符,请输入有效的用户名

今天在给我的WordPress网站博客添加管理员的时候,显示此用户名无效,因为它使用了非法字符。请输入有效的用户名。为什么给用WordPress做的博客添加管理员中文名字会失败呢,原来是WordPress CMS的建站程序不支持中文名注册,以前还真不知道。

但是想要注册一个特别的中文管理员名字,咋办呢?就只能度娘了,终于找到了方法,也测试成功了。晓得博客把两种解决方法整理分享一下:

方法:修改代码
1、打开:/wp-includes/formatting.php文件。

2、搜索或者在2096行左右找到此段代码:function sanitize_user在下面添加代码:

function sanitize_user( $username, $strict = false ) {
        $strict=false;//新增代码

3、修改后按照以前的编码格式保存后上传到对应的文件下即可,其余的代码保持不变,完整代码如下:

function sanitize_user( $username, $strict = false ) {
        $strict=false;//新增代码
	$raw_username = $username;
	$username     = wp_strip_all_tags( $username );
	$username     = remove_accents( $username );
	// Kill octets.
	$username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username );
	// Kill entities.
	$username = preg_replace( '/&.+?;/', '', $username );

	// If strict, reduce to ASCII for max portability.
	if ( $strict ) {
		$username = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $username );
	}

	$username = trim( $username );
	// Consolidate contiguous whitespace.
	$username = preg_replace( '|\s+|', ' ', $username );

	return apply_filters( 'sanitize_user', $username, $raw_username, $strict );
}

本站所有资源免费分享,仅供测试学习,如有帮助,欢迎打赏支持走的更远!

点击下面的广告帮助我收回服务器成本 ❤️


发表评论

(必填)

(必填)

(以便回访)