What is the better way to restrict a user of any role being logging into a blog of wordpress multisite network if he/she is not assigned to that particular blog as a user even though he is an administrator of another blog in that network. I hope it can be done using get_blogs_of_user( $user );
function where $user
is the username of person who trying to login.
EDIT: My code as follows.
$info = array();
$info['user_login'] = $_POST['username'];
$info['user_password'] = $_POST['password'];
$info['remember'] = true;
$user_signon = wp_signon($info, false);
if (is_wp_error($user_signon)) {
echo json_encode(array('loggedin' => false, 'message' => __('Invalid Credentials.')));
} else {
$get_blogs = get_blogs_of_user(get_user_by('login',$info['user_login'])->ID);
$is_has_access = array_search(get_current_blog_id(), array_column($get_blogs, 'userblog_id'));
if (!$is_has_access) {
wp_logout();
echo json_encode(array('loggedin' => false, 'message' => __('You have no permission to access.')));
} else {
echo json_encode(array('loggedin' => true, 'message' => __('Login successful')));
}
}
Is there any better ways?