我正在进行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()来尝试确定用户是否应该能够看到它并将它们引导到子域的登录页面。但这意味着终止主域上的现有登录会话。理想情况下,如果您可以登录到主域并登录到子域,但两者都单独处理,那将会很酷。
之前有人遇到过这个问题吗?
答案 0 :(得分:1)
是的,我有这个问题。而且,如果您需要特殊的用户管理,则必须设置一个新的自主(单站点)WordPress安装。
这就是Multisite的工作方式。所有用户都自动包含在网络中所有网站的subscribers
内。
来自文章Don't Use WordPress Multisite:
如果您需要用户在不同的网站上,但不知道他们在网络上,请不要使用MultiSite!现在,是的,有很多方法可以解决这个问题,但对于任何大型公司而言,这都是审计的噩梦,以及在开始之前应该注意的安全风险。
此插件可能有所帮助(但不确定):Multisite User Management。
从我在WordPress StackExchange上给出的this recent answer,一些小黑客可能会有所帮助:
(我在开发环境中做过小测试,但请进行广泛测试)
/*
* 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;
}