WordPress子比主题优化 禁止中文用户名注册

广告位招租1743133323

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,效果是一样的。

20231028

 

广告位招租1743133323
© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享
评论 抢沙发
头像
请遵守相关法律法规,文明评论➠🎉
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容