PHP_SLIVER_FUNCTIONS:WordPress允许中文名

因为WP是英文程序,所以用在注册的时候不能输入中文名,此函数就是为了解决这个需求的。

php_sliver_functions:站长多年来积累的一套代码片段库,码云地址:

https://gitee.com/sliver-ring/php_sliver_functions

描述

因为WP是英文程序,所以用在注册的时候不能输入中文名,此函数就是为了解决这个需求的。

代码

function allowed_chinese_name ($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 ); 
	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', 'allowed_chinese_name', 10, 3);

说明

将此函数放于主题的 functions.php 文件中,WP运行是会自动加载此函数,无须调用!

给TA打赏
共{{data.count}}人
人已打赏
WordPress开发

wordpress函数之get_adjacent_post()

2019-8-31 12:52:49

WordPress开发

uni-app+WordPress 实现注册功能

2020-2-26 10:31:24

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索