I am using custom login form and here is the code. After successfull login it redirects to /portal page but again in portal page user logged in status is false.
$email = $_REQUEST['login_email'];
$password = $_REQUEST['login_password'];
$args = array(
'orderby' => 'login',
'order' => 'ASC',
'fields' => 'all'
);
$count=0;
$all_users = get_users( $args );
$login_data['user_password'] = $password;
$login_data['user_login'] = $email;
$login_data['remember'] = true;
$user_verify = wp_signon( $login_data, true );
$userID = $user_verify->ID;
do_action( 'wp_login', $email );
wp_set_current_user( $userID, $email );
wp_set_auth_cookie( $userID, true, false );
if ( is_wp_error($user_verify) ){
$loginerror = true;
$errors['login_error']=__("Error in login",'domain');
}
else{
$loginSuccess = true;
$_SESSION['login_email']=$email; // Initializing Session
if(empty($previous_location))
{
wp_safe_redirect( home_url('/portal/'));
}
else{
wp_safe_redirect($previous_location);
}
exit();
}
But in /portal page when i var_dump(is_user_logged_in()) it returns false. what is happening here? what have i done?
I had the same experience. It turned out that my custom registration mechanism was the fault. I was adding new users with custom sql queries using
$wpdbobject and insert method.Somehow this approach conflicts with latter
wp_signonusage. If you also have written custom registration mechanism try falling back towp_insert_usermethod and then update custom columns or whatever with$wpdb->update.