WordPress子比主题优化:注册时禁止使用中文用户名,我们可以通过禁止非英文数字注册,达到我们想要的效果。
教程
在主题根目录下的func.php文件第一行写<?php换行插入下方的代码:
/*禁止非英文数字注册*/
function restrict_chinese_usernames($username) {
$error_msgs = array();
if (preg_match('/[^\x20-\x7F]/', $username)) {
if ( empty( $error_msgs ) ) {
$error_msgs[] = '仅允许字母数字作为用户名';
}
}
if ( ! empty( $error_msgs ) ) {
wp_send_json( array( 'error' => 1, 'msg' => $error_msgs ) );
}
return $username;
}
add_filter('sanitize_user', 'restrict_chinese_usernames', 10, 3);
代码也可以放在主题根目录下functions.php,效果是一样的。

重要提示
如有解压密码: 看下载页、看下载页、看下载页。
源码工具资源类具有可复制性: 建议具有一定思考和动手能力的用户购买。
请谨慎考虑: 小白用户和缺乏思考动手能力者不建议赞助。
虚拟商品购买须知: 虚拟类商品,一经购买打赏赞助,不支持退款。请谅解,谢谢合作!
© 版权声明
THE END





























暂无评论内容