WordPress怎么支持中文注册,其实追格小编之前也没去尝试过去解决这个问题,今天趁有空研究了一下,不用WordPress插件即可轻松实现,方法很简单,将下面代码插入到当前主题functions.php中即可!
//WordPress支持中文名注册 追格 zhuige.com
function zhuige_sanitize_user ($username, $raw_username, $strict) {
$username = wp_strip_all_tags( $raw_username );
$username = remove_accents( $username );
$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 );
$username = preg_replace( '|\s+|', ' ', $username );
return $username;
}
add_filter ('sanitize_user', 'zhuige_sanitize_user', 10, 3);
或者使用下面的代码也可以:
function zhuige_sanitize_user($username, $raw_username, $strict)
{
if (!$strict)
return $username;
return sanitize_user(stripslashes($raw_username), false);
}
add_filter('sanitize_user', 'zhuige_sanitize_user', 10, 3);
其实,上面两段代码几乎无差别。只要看看 sanitize_user 函数的源码就知道了。
function sanitize_user( $username, $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 );
/**
* Filters a sanitized username string.
*
* @since 2.0.1
*
* @param string $username Sanitized username.
* @param string $raw_username The username prior to sanitization.
* @param bool $strict Whether to limit the sanitization to specific characters.
*/
return apply_filters( 'sanitize_user', $username, $raw_username, $strict );
}
当 $strict = false 执行的代码就是第一段代码。$strict 为 true 时,将禁止非 ASCII 字符,去掉这个限制就可以支持中文了。
-
WordPress小程序开发教程WordPress和小程序开发教程网上挺多的,追格小编简单分享几个。
-
追格网址导航主题源码下载追格小站点评主题是一个互联网创新产品分享与点评导航主题。若不太理解,你也可以理解为是一个网址导航就好,哈哈哈。
-
微信小程序开源框架市面上有很多优秀的微信小程序开源框架,常见的多半是前端框架,比如:vant-weapp、wux-weapp、Taro等等。
-
WordPress主题插件制作教程之三分钟热度教程:WordPress插件制作教程WordPress主题插件制作教程之三分钟热度教程-WordPress插件制作教程
-
5款国产WordPress主题模版分享(含3款开源版)国产WordPress主题模版开发者很多,但开源的并不多见,优秀的付费主题模版也有不少,今天追格小编分享追格开发的几款主题,有兴趣的朋友可以看看。
-
追格主题(开源版)追格主题(基于WordPress开发),免费开源并支持二开。专为资源下载、资讯媒体、图文博客网站而设计,响应式布局且自带用户中心、点赞收藏评论、SEO、个人主页、文章目录等功能。
暂无评论,抢个沙发...