I create a template page as seen below to check if user is logged in or not. If user is not logged in, I want to redirect user to first login page and after login I want him to redirect previous page.
With the code below, Login redirection function redirects to login page again after user login. How can I fix that code?
In my template page :
<?php
if(!is_user_logged_in())
{
wp_redirect( 'http://....../wp-login.php', 302 );
}
else
{
wp_redirect('----------otherpage---',302 );
exit;
}
?>
in functions.php :
function directtorequest( $redirect_to, $request, $user )
{
// instead of using $redirect_to we're redirecting back to $request
return $request;
}
add_filter('login_redirect', 'directtorequest', 10, 3);