I am using Wordpress as an application that requires all users to be logged in to access. The function that I have been using to do this is
function logoutApp_redirect() {
global $post;
if( ! is_user_logged_in() ){
wp_redirect( home_url() . '/dashboard' );
}
}
add_action( 'template_redirect', 'logoutApp_redirect' );
if
a user is logged out then I want to return them to the page that they were previously on. For example, if a user is on home_url() . '/page1' );
and they are logged out for inactivity return them to this page upon login.
A few ideas I had was first to use AJAX and overlay the login (so they never leave the page they are on) and upon login the overlay is removed. This is my ultimate solution, yet for security, anyone with the knowledge of inspect could hide the overlay to see the private information.
Thus the reasoning for adding a redirect to the wp-login
and bringing my second idea of when a user is logged out they are redirected and upon login they are returned to the previous page. This is the better method for security but it means that any information that was not stored to the DB will be lost.
How can I address a solution that will fix these issues?
PLEASE NOTE I do not want a plugin as the solution and would prefer to keep things operating from within my functions.php