2

我正在进行 WPMU 多站点安装,但遇到了一个小问题。

我在主域上的注册过程中创建了一个用户。类似以下内容。

$username = 'myname-'.time();
$user_id = wpmu_create_user($username,'anypassword','example@gmail.com');

add_user_to_blog(1, 5, 'subscriber');

$user = wp_signon(array(
"user_login" => $username,
"user_password" => 'anypassword',
"remember" => true
));

我所做的是创建用户,然后仅将其分配给主域,并使用 wp_signon 登录用户。但是,当访问子域上的网络子站点时,重要的是它的访问权限非常有限。我仍然登录,顶部的仪表板菜单仍然显示。

我使用 is_user_blog() 来尝试确定用户是否应该能够看到这个并可以将他们引导到子域的登录页面。但这意味着终止主域上的现有登录会话。理想情况下,如果您可以登录到主域并登录到子域但两者分开处理,那将是很酷的。

以前有人遇到过这个问题吗?

4

1 回答 1

1

是的,我有这个问题。而且,如果您需要特殊的用户管理,则必须设置一个新的自主(单站点)WordPress 安装。

这就是多站点的工作方式。所有用户都自动包含subscribers在网络中的所有站点中。

从文章不要使用 WordPress 多站点

如果您需要用户在不同的站点上,但不知道他们在网络上,请不要使用 MultiSite!现在,是的,有一些方法可以解决这个问题,但是对于任何大公司来说,这都是一场审计噩梦,并且在开始之前你应该意识到一个安全风险。

这个插件可能有帮助(但不确定):多站点用户管理

从我最近在 WordPress StackExchange 上给出的答案中,一些小技巧可能会有所帮助:(
我在我的开发环境中做了一些小测试,但请进行广泛的测试)

/*
 * Redirect users that are not members of the current blog to the home page, 
 * if they try to access the profile page or dashboard 
 * (which they could, as they have subscriber privileges)
 * http://not-my-blog.example.com/wp-admin/profile.php
 */
add_action( 'admin_init', 'wpse_57206_admin_init' );

function wpse_57206_admin_init()
{
    if( !is_user_member_of_blog() ) 
    {
        wp_redirect( home_url() );
        exit();
    }
}


/*
 * Redirect users that are not members of the current blog to the home page, 
 * if they try to access the admin
 * http://not-my-blog.example.com/wp-admin/
 */
add_action( 'admin_page_access_denied', 'wpse_57206_access_denied' );

function wpse_57206_access_denied()
{
    wp_redirect( home_url() );
    exit();
}


/*
 * Redirect users that are not members of the current blog to the home page, 
 * if they try to login
 * http://not-my-blog.example.com/wp-login.php
 */
add_filter( 'login_redirect', 'wpse_57206_login_redirect' );

function wpse_57206_login_redirect( $url )
{
    global $user;
    if ( !is_user_member_of_blog() ) 
    {
        $url = home_url();
    }
    return $url;
}


/*
 * Hide the admin bar for users which are not members of the blog
 */
add_filter( 'show_admin_bar', 'wpse51831_hide_admin_bar' );

function wpse51831_hide_admin_bar( $bool )
{
    if( !is_user_member_of_blog() )
    {
        $bool = false;
    }
    return $bool;
}
于 2012-11-19T11:36:36.277 回答