Restrict the user access in multi site for non-assigned blogs

is_user_logged_in() is a pluggable function, which means you can override its functionality. That’s probably where I’d start.

Something like this may do what you’re looking for. This is untested code and comes with no warranties of any kind.

function is_user_logged_in() {
    $user = wp_get_current_user();
    $current_blog_id = get_current_blog_id();
    $allowed = false;
    $blogs_of_user = get_blogs_of_user( $user->ID );
    foreach( $blogs_of_user as $blog ) {
        if( $blog->userblog_id == $current_blog_id ) {
            $allowed = true;
        }
    }

    if( ! $allowed ) {
        return false;
    }

    return $user->exists();

}

References

Leave a Comment