Private Site Plugin for WordPress
by Bandicoot Marketing on | Posted in Downloads | 9 comments
Sometimes, you may have a site that you want to be viewed by only logged in users. Especially if it’s some type of internal tool used by a private company or group. I recently needed to this on a site I was using to test out some themes, so I thought I would share it in case someone out there needed something similar.
It’s not a very complicated plugin but it gets the job done.
Here’s the code:
<?php
/*
Plugin Name: Private Site
Description: Site is only viewable by logged in users.
Author: c.bavota
Version: 1.0.0
Author URI: http://www.bavotasan.com/
*/
class Bavotasan_Private {
public function __construct() {
add_action( 'init', array( $this, 'init' ) );
}
public function init() {
if ( ! is_user_logged_in() && ! $this->is_login() ) {
wp_redirect( admin_url() );
exit;
}
}
public function is_login() {
return in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) );
}
}
$bavotasan_private = new Bavotasan_Private;
You can download it through the link below.

9 comments for “Private Site Plugin for WordPress”