Well I am newbie to WP and the question may sound duplicate but even after trying for few days I can not make this work.
I have integrated a custom login and registration form in my WP site which is different form usual WP login and register forms.
I need to perform the following actions
- Redirect user to login page if directly accessed any Page URL
- Redirect user to home page if directly accessed login/register URL.
For redirecting user to home page if tries to access login/register URL after being already logged in, I have used below code
function checkUser(){
$user = wp_get_current_user();
if ( empty( $user->ID ) )
return false;
return true;
}
function __construct(){
add_action('init', array($this, 'checkUser'));
}
Even if I use wp_redirect(site_url());exit;
; that do not seem to work and it goes into infinite loop.
Thanks.
is_user_logged_in()
instead.template_redirect
hook. Although it may not solve infinite redirect issue. Need to see more codes.