wordpress - WP multi 中的用户名只有小写字母和数字吗?

标签 wordpress multisite

我们在工作中的多个子域中使用 wordpress。 所以我们有每个域的管理员,他们可以创建用户来订阅编辑贡献。 问题是,我们公司修改了所有登录名/用户名必须像这样的规则:“first-name.family-name” ex “barack.obama”... :-) 但是管理员做不到,只有 super 管理员可以做! 在子域管理员模式下,有一条消息说:“只允许使用小写字母 a-z 和数字”。

所以我们想让管理员可以创建名字为.family-name 的用户,但是我们尝试搜索如何在代码中更改它,但没有找到。

如果有人能帮忙,谢谢!

最佳答案

在多站点中,用户名使用 wpmu_validate_user_signup 进行验证,您可以在 /wp-includes/ms-functions.php#L462 中找到.

您可以在 0-9 之后添加一个点,但不推荐这样做,因为这样您会讨厌更新 WordPress 核心。

if ( $user_name != $orig_username || preg_match( '/[^a-z0-9.]/', $user_name ) ) {

因此,更好的解决方案是为其创建一个插件。

您可以尝试在 php 文件中添加以下内容并将其添加到/wp-content/mu-plugins/

<?php
/*
Plugin Name: wpmu no username error
*/

function wpmu_no_username_error( $result ) {
    $error_name = $result[ 'errors' ]->get_error_messages( 'user_name' );
    if ( empty ( $error_name ) 
        or false===$key=array_search( __( 'Only lowercase letters (a-z) and numbers are allowed.' ), $error_name)
    ) {
    return $result;
    }
//  only remove the error we are disabling, leaving all others
    unset ( $result[ 'errors' ]->errors[ 'user_name' ][$key] );
/**
 *  re-sequence errors in case a non sequential array matters
 *  e.g. if a core change put this message in element 0 then get_error_message() would not behave as expected)
 */
    $result[ 'errors' ]->errors[ 'user_name' ] = array_values( $result[ 'errors' ]->errors[ 'user_name' ] );
    return $result;
}
add_filter( 'wpmu_validate_user_signup', 'wpmu_no_username_error' );

虽然我没有尝试过。这是基于“Changing the username character limit from four to less characters”。

希望对您有所帮助。至少它应该让你接近。 GL用它!

关于wordpress - WP multi 中的用户名只有小写字母和数字吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32047894/

相关文章:

css - Wordpress 如何处理/编译 SASS?

jquery - 如何在 wordpress 上创建具有更多浏览量的幻灯片图像

javascript - php脚本echo显示在控制台而不是文本输入中

javascript - 在多站点环境中使用 Service Worker API

css - Genesis 主导航和 Logo

php - 如何使用 $wpdb 类在 wordpress 中显示特色图片

wordpress - 如何使用子目录在 Azure 上设置 Wordpress 多站点

django - 同一个域上的鹡鸰多站点

mysql - 使用 1 个 MySQL 数据库安装 2 个 WordPress

Wordpress 多站点 SSL 问题