跨多站点网络的Wordpress WPMU登录一致性 [英] Wordpress WPMU Login consistency across multisite network

查看:176
本文介绍了跨多站点网络的Wordpress WPMU登录一致性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在WPMU多站点安装中,但是遇到了一个小问题.

I'm working on a WPMU multisite install but have run into a wee problem.

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

I create a user during a signup process on my primary domain. With something like the following.

$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登录用户.但是,当访问子域上的网络子站点时,访问的限制非常重要,这一点非常重要.我仍然登录,顶部的仪表板菜单仍然显示.

What I do is create the user, and then assign it to the primary domain only, and the log the user in with wp_signon. However, when visiting a subsite of the network on a sub domain which is importantly very restrictive in it's access. I am still logged in and the dashboard menu at the top still shows.

我使用了is_user_blog()来尝试确定用户是否应该能够看到此消息并将其定向到子域的登录页面.但这意味着终止主域上的现有登录会话.理想情况下,如果您既可以登录到主域又可以登录到子域,但又将它们分开对待,那就太好了.

I used is_user_blog() to try and determine whether the user should be able to see this and could direct them to the login page of the sub domain. But this would mean terminating the existing login session on the primary domain. Ideally it would be cool if you could be logged in to the primary domain and also logged into the sub domain but both treated seperately.

有人遇到过这个问题吗?

Anyone run into this problem before?

推荐答案

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

Yes, I had this issue. And, if you need special user management, you'll have to set up a new autonomous (single site) WordPress installation.

这就是多站点的工作方式.所有用户将自动作为网络中所有站点的subscribers包括在内.

That's the way Multisite works. All users are automatically included as subscribers of all sites in the network.

摘自文章不要使用WordPress多站点:

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

If you need users to be on different sites, but not aware that they’re on a network, don’t use MultiSite! Now, yes, there are ways around this, however it’s an auditing nightmare for any large company, and a security risk that you should be aware of before you start.

此插件可能会有所帮助(但不确定):多站点用户管理.

This plugin may be of help (but am not sure): Multisite User Management.

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

From this recent answer I gave on WordPress StackExchange, some little hacks may be helpful:
(I did small tests in my development environment, but please, test extensively)

/*
 * 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;
}

这篇关于跨多站点网络的Wordpress WPMU登录一致性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆