I use form to send POST request to a page and to login user with wp_signon()
in order to authenticate user to my wordpress installation as described in WP documentation:
$creds = array();
$creds['user_login'] = $_POST["user-login"];
$creds['user_password'] = $_POST["user-password"];
$creds['remember'] = true;
$user = wp_signon( $creds, false );
After this little piece of code I'm checking if user was logged in:
if ( is_user_logged_in() ) { echo "SUCCESS"; } else { echo "FAIL!"; }
But I got FAIL!
all the time. Then after sniffing around I found this little trick:
wp_set_current_user( $user );
if ( is_user_logged_in() ) { echo "SUCCESS"; } else { echo "FAIL!"; }
I've got SUCCESS
on this one but when I leave this page I got FAIL
again and again.
Can anyone explain me how to login user with wp_signon()
without logging her out after page is changed or reloaded or whatever.
I've got desirable result when I go to /wp_admin
and login with WP's default login form. I can navigate through every page of my WP site remaining logged-in all the time. But when I try to do this outside the default form I FAIL
.
Guide me! PLEASE!
I don't know
))http://localhost/login-page/
orhttps://localhost/login-page/
?http://localhost:8888/registration/
but if you try to hint onwp_signon( $user, secure:true/false )
I've tried both and it didn't work. Anyway thanks.