2012-03-20 73 views
2

我正在WPMU多站点安装上工作,但遇到了一些问题。Wordpress WPMU在多站点网络上登录一致性

我在主域上的注册过程中创建了一个用户。像下面这样的东西。

$username = 'myname-'.time(); 
$user_id = wpmu_create_user($username,'anypassword','[email protected]'); 

add_user_to_blog(1, 5, 'subscriber'); 

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

我要做的就是创建用户,然后将其仅分配给主域,并且记录用户与wp_signon。但是,当访问网络的子网站时,子网域的访问权限非常严格。我仍然登录,顶部的仪表板菜单仍然显示。

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

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

+1

有错误在你的示例代码中。它应该是'add_user_to_blog(1,$ user_id,'subscriber');'。 – brasofilo 2012-11-19 11:51:19

回答

1

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

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

从文章Don't Use WordPress Multisite

如果您需要用户在不同的网站,但不知道他们是在网络上,不使用多点会议!现在,是的,有办法解决这个问题,但是这对任何大型公司来说都是一场审计噩梦,并且在开始之前应该注意一个安全风险。

这个插件可能有帮助(但我不确定):Multisite User Management

this recent answer我给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; 
}