• I have a multisite set up and I’d like to be able to limit the registration of each one to a specific domain.

    So let’s say I have sites set up for two companies: CompanyA.mysite.com and CompanyB.mysite.com.

    What I’d like to be able to do is allow the employees to register themselves to the site, but require they use their company email address to sign up. So I’m basically looking to whitelist ONLY @companyA.com addresses to register for the first site, and ONLY @companyB.com addresses for the second.

    All of the plugins out there don’t seem to work on a multisite install and allows me — when sandboxing — to sign up from any domain. Any help?

    -Nick

Viewing 2 replies - 16 through 17 (of 17 total)
  • Thread Starter foxymcfox

    (@foxymcfox)

    I did that and it still wasn’t working…so I thought to myself: If I was me, what is the simplest mistake I could be making right now?

    …Turns out I didn’t have the plugin activated on the secondary subdomain I was testing. hahaha

    *Facepalm*

    Thanks again for your help.

    -Nick

    Thread Starter foxymcfox

    (@foxymcfox)

    And in the interest of sharing, here is where my additional code stands now in the pursuit of a locked down network site:

    add_action( 'wp', 'walled_garden' );
    
    function walled_garden() {
    	if ( is_user_logged_in() && !current_user_can('manage_options') && !is_user_member_of_blog() && !is_page('error')) {
    		wp_redirect(site_url('/error'));
    		exit;
    	}
    }
    
    function error_link() {
    	if(is_user_logged_in()&& !is_user_member_of_blog()) {
    		global $current_user;
      		$blogs = get_blogs_of_user( $current_user->id );
    
         		if($blogs) {
         	 		foreach ( $blogs as $blog ) {
             			echo '<strong>ERROR:</strong> You do not currently have permission to view this network. Please click<a href="https://' . $blog->domain . $blog->path .'">  here </a> to go to your network';
    			}
         		}
    }
    	else {
    		echo 'Hey!  How did you get here?';
    	}
    }
    
    add_shortcode('errortext', 'error_link');

    Again, I tagged this onto my private site plugin, based on jonradio’s “jonradio Private Site” plugin. (I listed my changes in a thread in that plugin’s support forum) Now, however, it allows you to redirect members of other blogs to an error page if they try to get into another site’s “walled garden.” This error page will tell them they don’t have access and give them a link to their network. (Since I’m only letting people sign up for one blog at a time, the way I did this shouldn’t be an issue, but you could modify the code to reset the array to only output the first result…OR just echo the array as a list if you have members who belong to other blogs)

    …and then as an Easter egg, there’s a customizable message if a member with access to a blog manually types in “error” after the link. For now, I just left mine as “Hey! How did you get here?”

    Hopefully someone out there can use this. If not, at least it’s useful to me. If anyone has any suggestions or additions, feel free to add them.

    -Nick

    EDIT: Since I realize I didn’t make it clear, this requires you to create a page on your sites called “error” and simply place the shortcode [errortext] on it. Through a hack or a plugin, then, just remove the link to the page from the navigation. Quick, dirty, and dead simple.

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘Restrict Domains on a Per-Multisite Basis?’ is closed to new replies.