wp_signon() not working (2 posts)

  1. robahas
    Posted 3 years ago #

    Hi - I'm banging my head against wp_signon. I am attempting to set up a registration process where the last action is to sign the user in. It all happens on one page. I've tried all sorts of things and looked online too. Not a lot of info on this. Here is the code I am using. I get no error reported, but neither does it log the user in:

    //log new user in
    $creds = array();
    $creds['user_login'] = $_POST['userName'];
    $creds['user_password'] = $pass;
    $creds['remember'] = false;
    $user = wp_signon( $creds, false );
    if ( is_wp_error($user) ) { echo $user->get_error_message(); } else { ?>
    You are now signed in. Go to your shopping cart
    <?php } ?>
  2. robahas
    Posted 3 years ago #

    No one ever answers my questions here. If anyone knows why, I'd love to find out. In any case, I generally end up answering them myself! So, for future reference and to save time for the next person, here is the problem:

    wp_signon() has to be used before headers are sent (first thing in the php page).

    It makes sense if you think about it, since login in changes how the page renders. I guess I was assuming the function would refresh the page or take effect when the next page was loaded. Assumptions....

    I wish this insight would be added to the function description: http://codex.wordpress.org/Function_Reference/wp_signon

Topic Closed

This topic has been closed to new replies.

About this Topic