Surprised I haven't found this Q.
I want to force users to login to the site before accessing any of the content.
I have this function:
function av_force_user_login() {
global $post;
global $pagenow;
if ( in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ) {
return;
}else{
auth_redirect();
}
}
add_action( 'get_header', 'av_force_user_login' );
This doesn't seem to work though and after I try and login I get redirected back to the login page.
One caveats to watch out for (in my case): I'm using BuddyPress' registration system which doesn't apply to the login page but it would apply to the wp-login.php?action=register
page which redirects to Buddypress' template for registration.
Nevertheless, is there anything wrong with the above code that would cause a redirect back to the login page?