// Require login for site
get_currentuserinfo();
global $user_ID;
if ($user_ID == '') {
header('Location: /wp-login.php'); exit();
}
The get_currentuserinfo() function provides a huge
object with information about the user. We then look at the user_ID
variable to see if the user's ID is defined -- if not, they aren't
logged in and we should send them to the login page!Do remember that your
header() calls must take place before any content is pushed to the page, so I recommend adding this content at the very top of your header.php file. There's also a WordPress plugin to accomplish this task.