WP多用户名只有小写和数字吗?

时间:2015-08-17 10:17:41

标签: wordpress multisite

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

因此,我们希望管理员可以使用first-name.family-name创建用户,但我们会尝试搜索如何在代码中更改它,而不会找到它。

如果有人可以提供帮助,谢谢!

1 个答案:

答案 0 :(得分:1)

在多站点用户名中使用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' );

我没有尝试过。这基于&#34; Changing the username character limit from four to less characters&#34;。

我希望这会有所帮助。至少它应该让你接近。 GL吧!