We store user meta data on our website. I have a function hooked into the wp_login action to redirect the user to a form to update their meta if it's older than 1 year. If the user's information is up to date, I want to redirect to the page they were at when they first clicked "Log in". I haven't been able to figure this out though. For now, I just redirect to the home page (in the last "else" statement). Any ideas?
Thank you!
Edit: Essentially, I need some way to run a custom function that executes as the user is navigating to the login page through the link generated by the wp_loginout() function. This custom function should store the prior link, maybe via something like $redirect = $_SERVER["HTTP_REFERER"];
function check_user_info($username) {
$user = get_user_by('login', $username);
// Get current user ID
$wp_user_id=$user->ID;
// Unix display of times
$current_time_unix= time();
//add_user_meta($wp_user_id,'test4','test5',TRUE);
$last_update_unix=get_user_meta($wp_user_id, 'last_updated', TRUE);
$next_update_unix=get_user_meta($wp_user_id, 'next_update_request', TRUE);
// Nice display of times
$current_time = date('F j, Y H:i:s',$current_time_unix);
$last_update_time = date('F j, Y H:i:s',$last_update_unix);
$next_update_time = date('F j, Y H:i:s',$next_update_unix);
// Echo Last / Next update time
// echo "current time: ".$current_time."<br>";
// echo "last update: ".$last_update_time."<br>";
// echo "next update: ".$next_update_time."<br>";
// If meta doesn't exist, must be a new user through social login, redirect
if (!$last_update_unix) {
//echo 'redirect';
wp_redirect("https://eyeguru.org/register/?type=new_user_from_social_login");
exit;
}
// if meta exists, and the user information is 1+ years old, redirect
if ($last_update_unix && $current_time_unix>$next_update_unix) {
//echo 'redirect';
wp_redirect("https://eyeguru.org/register/?type=update_expired_info");
exit;
}
// if meta exists, and the user information is up to date, redirect to homepage
else {
wp_redirect("https://eyeguru.org/");
exit;
}
}
add_action('wp_login', 'check_user_info');