Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use wp_signon() and it returns a user, not an error. However when I do is_user_logged_in() it returns false.

Help would be very much appreciated :)

share|improve this question

3 Answers

After using wp_signon(), the user info is not set, which is how WP checks for a user in is_user_logged_in(). It should be just a matter of calling get_currentuserinfo() after wp_signon().

share|improve this answer
Is it possible to replicate the user having signed in through the login form. I would like the user to stay logged in, as with regular log in. – Benedicte Nov 4 '10 at 14:13
Thanks you so much btw. – Benedicte Nov 4 '10 at 14:14
1  
try $creds = array(); $creds['user_login'] = $user_login; $creds['user_password'] = $user_pass; $creds['remember'] = true; $user = wp_signon( $creds, false ); to remember the user – Philip Seyfi Nov 17 '11 at 19:49

get_currentuserinfo() didn't work for me. I've written about this problem and solution at my blog:

http://blog.rhysgoodwin.com/programming/wordpress-wp_signon-current_user-is-not-populated/

Cheers, Rhys

share|improve this answer

I've had same problem. Here the full working snippet that fixed that problem:

    if( isset($_POST['log']) && isset($_POST['pwd']) ):
      $creds = array( 'user_login' =>  $_POST['log'], 'user_password' => $_POST['pwd'], 'remember' => $_POST['rememberme'] );
      $user = wp_signon( $creds, false );
      if ( is_wp_error($user) ): echo $user->get_error_message(); endif;
      wp_set_current_user($user->ID);
      return $user;
    endif;

Also wp_logout() has same problem. Here how to make it work too:

wp_logout();  
wp_set_current_user(0);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.