Categories
How To

Hide Your Site on Multisite

Hiding things is easy. Hiding them well is not. Especially on a Multisite.

Sometimes when you’re building a network, you don’t want all your sites to be available just yet. While you can install a ‘Coming Soon’ plugin, there are also built in ways to handle this.

First you’ll want to take advantage of two of the Network’s least loved features: Deactivate and Archive. When you go to the Sites page on the Network Admin and hover over the items, you have new options appear:

The edit options for your sites

Should you click on Deactivate, you’ll be asked to confirm and then you get this:

A deactivated site - it says 'Deleted'

Don’t panic!!

I know it says Deleted. It’s not. A deleted site is 100% deleted, the DB tables dropped and the images nuked. So while it ‘says’ deleted, it’s not. If you press Archive it’s a little more realistic:

A site that has been archived is in light pink and says 'archived'

What’s the difference? In both cases, this is what a non-logged in user sees:

What a visitor sees on a deactivated site is 'This site is no longer available.'
This site is no longer available.

And in both cases, you can’t log in, because this is what you see for wp-admin and wp-login.php.

Archived site WP Admin says the site is suspended

Deleted site WP Admin says the site isn't available

It’s weird, but it pretty much ‘archived’ the sites. You can, as a Super Admin, see it, but you can’t even change user roles from the network dashboard. (I spent about an hour trying to debug why I, as a Super Admin, couldn’t get to the dashboard at all, and it turned out I needed to flush my cache, so remember folks, caching is wonderful until you shoot your foot.) Still this presents a predicament.

Frankly, I don’t want people to know a site doesn’t exist. That can be easily done with a filter and a redirect:

// Archived sites only I can see
function helf_redirect_hidden_sites() {

	// Super Admins always get in
	if ( is_super_admin() || current_user_can( 'manage_options' ) ) {
		return true;
	} else {
		// Defines
		if ( defined( 'NOBLOGREDIRECT' ) ) {
			$goto = NOBLOGREDIRECT;
		} else {
			$goto = network_site_url();
		}

		$blog = get_blog_details();

		if( '1' == $blog->deleted || '2' == $blog->deleted || '1' == $blog->archived || '1' == $blog->spam ) {
			wp_redirect( $goto );
	        die();
		}
	}
}
add_filter('ms_site_check','helf_redirect_hidden_sites');

I wanted to allow my site admins and my super admin to view it, but if you don’t, edit if ( is_super_admin() || current_user_can( 'manage_options' ) ) to only allow what you want. And because I’m using a subdomain site, this makes it look like an archived/deleted site is just another non-existent site, by redirecting to NOBLOGREDIRECT.

But this doesn’t work around the problem that my whole wp-admin is blocked off to non logged in users. I mean, how can I log in? The only workaround is that if the site is a subdomain (test.halfelf.org) or a subfolder (halfelf.org/test), then I can log in at halfelf.org/wp-admin and then visit over. If this was a mapped domain, I’d be in trouble. So it’s clearly not a perfect solution for everyone.

By the way, you can customize the various messages for suspended or deleted sites by creating the following files in wp-content:

blog-suspended.php
blog-deleted.php
blog-inactive.php

So if you just want it to be pretty, that’s easy.

3 replies on “Hide Your Site on Multisite”

Comments are closed.