Hi,
I have a function in functions.php that redirects users to the login page if they’re trying to access any other page without being logged in which works fine.
COPY CODE
if (!function_exists('restrict_access_if_logged_out')){
function restrict_access_if_logged_out(){
$current_url=$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
if (!is_user_logged_in() && !($current_url === $loginpage)){
wp_redirect($loginpage);
exit;
}
}
}
add_action( 'wp', 'restrict_access_if_logged_out', 3 );
The problem is that I need to redirect them to the url they were trying to go to after they successfully log in.
Is there a way to do this?
PS : I tried passing $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]
to the ‘kleo_modal_login_redirect’
filter in the login form action. But since the requested url is already changed to the $loginpage url by this time, it just redirects to the home page after log in.