I have a series of sites that I maintain as part of a WordPress multisite install. I’d like to be able to create users accounts that are restricted to viewing only a single one of these sites. Is this possible?

Once this is accomplished, is there a way to determine this permission status programmatically? I’d like to be able to get a list of all the sites the current user has access to, or at the very least, test if the user has permission to access a specific site.

1 Answer
1

Use is_user_member_of_blog() to check if the current user has been assigned to the blog in wp-admin/network/site-users.php. Then hook into template_redirect and run the test:

add_action( 'template_redirect', function() {

    if ( ! is_user_member_of_blog() )   
        die( 'Please ask the network administrator to get access to this blog.' );
});

Leave a Reply

Your email address will not be published. Required fields are marked *