Advertisement
SergeyBiryukov

Private Site Plugin

May 8th, 2013
896
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Private Site
  4. Description: Site is only viewable by logged in users.
  5. Author: c.bavota
  6. Version: 1.0.0
  7. Author URI: http://www.bavotasan.com/
  8. */
  9. class Bavotasan_Private {
  10.     public function __construct() {
  11.         add_action( 'init', array( $this, 'init' ) );
  12.     }
  13.  
  14.     public function init() {
  15.         if ( ! is_user_logged_in() && ! $this->is_login() ) {
  16.             wp_redirect( wp_login_url() );
  17.             exit;
  18.         }
  19.     }
  20.  
  21.     public function is_login() {
  22.         return in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) );
  23.     }
  24. }
  25. $bavotasan_private = new Bavotasan_Private;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement