Skip to content

Instantly share code, notes, and snippets.

@scarstens
Created September 23, 2013 02:39
Show Gist options
  • Select an option

  • Save scarstens/6665912 to your computer and use it in GitHub Desktop.

Select an option

Save scarstens/6665912 to your computer and use it in GitHub Desktop.
Force user to login before accessing the site (on WordPress)
//force user login, regardless of post type
//UNLESS public is in the URL
add_action('parse_request', 'rr_login_redirect');
function rr_login_redirect() {
global $wp;
if(stristr($wp->request,'public/') || stristr($wp->request,'/public')){}
elseif (!is_user_logged_in()) {
auth_redirect();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment