在我的安装中,我有3个站点。我想有一个用户在每个页面上,只能登录这个网站。
但是,默认的多站点行为是不同的。分配给site1的用户也可以登录到site2和site3,但没有分配角色。
总结。我希望实现这样一种情况,即user1只能在site1上登录,user2只能在site2上登录,等等。
请帮帮我。
在我的安装中,我有3个站点。我想有一个用户在每个页面上,只能登录这个网站。
但是,默认的多站点行为是不同的。分配给site1的用户也可以登录到site2和site3,但没有分配角色。
总结。我希望实现这样一种情况,即user1只能在site1上登录,user2只能在site2上登录,等等。
请帮帮我。
把这个放在一个盒子里。php文件,将其作为插件上传,然后通过网络激活它。有关详细信息,请阅读代码中的注释。
如果您有任何疑问或它对您不起作用,请告诉我。我这样做是为了让超级管理员可以使用所有网站,无论发生什么。
<?php
/*
Plugin Name: No Role No Login
Description: If the user in a multisite has no role for a site, he will not be able to access it while logged in. Does not affect super administrators.
Author: Nikolay Nikolov
Version: 1.0.0
*/
add_action( \'init\', \'no_role_no_login\' );
function no_role_no_login() {
// If the user is logged-in and not a super administrator we continue
if ( is_user_logged_in() && ! current_user_can( \'manage_network\' ) ) {
// If this is a logout attempt, we do nothing, so we allow it
if ( ( ( isset( $GLOBALS[\'pagenow\'] ) && \'wp-login.php\' === $GLOBALS[\'pagenow\'] )
|| ( isset( $_SERVER[\'PHP_SELF\'] ) && \'/wp-login.php\' === $_SERVER[\'PHP_SELF\'] ) )
&& isset( $_GET[\'action\'] ) && \'logout\' === $_GET[\'action\'] ) {
// If this is not a logout attempt, we will check if the user has a role for the site and deny access if he does not (and show a message)
} else {
$get_users = get_users(
array(
\'blog_id\' => get_current_blog_id(),
\'include\' => array( get_current_user_id() )
)
);
if ( empty( $get_users ) ) {
wp_die( \'You cannot access this site while logged in. To view it, you have to <a href="\' . wp_logout_url() . \'">logout</a>.\' );
}
}
}
}
我可以访问以下网站:www.foo.com and www.bar.com 但我无法访问登录-网站为空。foo.com/wp-login.php bar.com/wp-login.php 我有以下日志。[Mon Jan 01 16:26:03.229924 2018] [core:notice] [pid 17589] AH00052: child pid 24869 exit signal Segmentation fault (11) [Mon Jan 0