WordPress for registered users only

WordPress for registered users only. Is it possible? How to make blog content accessible for your visitors only after login? First way is to use some of existing plugins. Try to search for keyword “members” at WordPress plugins repository.
If you think that plugins you found are too heavy, or noisy with advertisement, or you wish some simple decision e.g. “install and forget”, try this one – in the form of the “must-use” plugin. It does not require the activation and has no any menu or settings page. Just place PHP file with the code below to the wp-content/mu-plugins/ folder.

add_action('wp_head', 'force_login');
function force_login() {    
  if (is_user_logged_in()) {
      return;
  }
  $site_root = site_url();  
  $protocol = is_ssl() ? 'https' : 'http';
  $current_url = $protocol .'://'. $_SERVER['HTTP_HOST'];
  $request_uri = filter_var($_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL);
  if (!empty($request_uri)) {
      $current_url .= $request_uri;
  }  

  wp_redirect($site_root .'/wp-login.php?redirect_to='. urlencode($current_url));
  
}

You may download ZIP package with force-login.php file inside from this link.

Share