I have a custom plugin that handles the login and verification of customers. It creates default WordPress users with custom usermeta. But as an admin whenever I try to access the wp-admin dashboard on my live site I get an error page with too many redirects. This however works on my local dev site. Below is the function that fires after logging in and gives the error.
function redirect_to_lvkg_login() {
if ( $_SERVER['REQUEST_METHOD'] == 'GET' ) {
if ( is_user_logged_in() ) {
lvkg_redirect_logged_in_user();
exit;
}
$login_url = home_url( 'login' );
if (!empty($_REQUEST['redirect_to'])) {
$login_url = add_query_arg('redirect_to', $_REQUEST['redirect_to'], $login_url);
}
if (!empty($_REQUEST['checkemail'])) {
$login_url = add_query_arg('checkemail', $_REQUEST['checkemail'], $login_url);
}
if (!empty($_REQUEST['verify']) && lvkg_check_code($_REQUEST['verify'], 'verif_id')) {
$user_id = lvkg_check_code($_REQUEST['verify'], 'verif_id');
$user_stat = get_user_meta($user_id, 'status', true);
$user_info = get_userdata($user_id);
$args = array('login' => $user_info->user_login);
$args['verify'] = ($user_stat == "unverified") ? 'verified' : 'already_verified';
if($user_stat == "unverified")
update_user_meta($user_id, 'status', 'verified');
$login_url = add_query_arg($args, $login_url);
}
wp_redirect($login_url);
exit;
}
}
function lvkg_redirect_logged_in_user($redirect_to = null ) {
$user = wp_get_current_user();
if (user_can($user,'manage_options')) {
if ($redirect_to) {
wp_safe_redirect($redirect_to);
exit;
} else {
wp_redirect(admin_url());
exit;
}
} else {
wp_redirect(home_url());
exit;
}
}
Am I missing something, or could this be a problem with my hosting?