auto login

This topic contains 16 replies, has 7 voices, and was last updated by Avatar mary gallagher 4 years, 1 month ago.

Viewing 10 posts - 1 through 10 (of 17 total)
  • Author
    Posts
  • #10002981
    Avatar
    daniel 2030
    Participant

    Hello, Is it possible to auto login after registration?

    #10002990
    Avatar
    Pie Register
    Participant

    Hello,

    I am afraid at the moment it’s not possible perhaps we will add this
    feature in our future releases.

    Thanks

    #10003091
    Avatar
    mary gallagher
    Participant

    I agree that this is a needed feature. Many of my users – most not very used to on-line registrations – are completely flummoxed by having to login after registering. Auto login would be the expected UX behavior.

    On the other hand, is there a hook that might be useful to accomplish this???
    Thanks.

    #10003094
    Avatar
    mary gallagher
    Participant

    I was just able to get automatic login by using the user_registration hook.
    /* ——————————————————————-
    Automatically login a user who has just registered. Pie-Register
    does not currently support automatic login.
    ——————————————————————*/
    function auto_login_new_user( $user_id ) {
    $_SESSION[‘auto’] = $_POST;
    wp_set_current_user($user_id);
    wp_set_auth_cookie($user_id);
    // wp_safe_redirect( home_url() ); OR…
    wp_safe_redirect( home_url(‘/your-page/’) );
    exit;
    }
    add_action( ‘user_register’, ‘auto_login_new_user’ );

    Hope this helpful to anyone looking for a solution. Cheers.

    #10003096
    Avatar
    Fernando Morales
    Participant

    Hi Mary, where do you put that hook? in index? or in all pages?

    Thanks in advance

    #10003123
    Avatar
    mary gallagher
    Participant

    Hi. I’m sorry to have to report that the hook does not work in one important respect. The registration function no longer add the first and last name of the registrant to the usermeta table. So, my form that should initialize the first name to [first_name} and last_name to [last_name] are blank. These are the only usermeta fields in my registration, but I also note that description, which I do not use, is not initialized. All the other standard usermeta fields are set.

    I’ve tried setting lower and higher priorities, to no avail. I would certainly appreciate it if someone could suggest why this data is not being stored.

    Fernando, the hook is placed in functions.php. However, I would not suggest using it until this is cleared up.

    #10003124
    Avatar
    mary gallagher
    Participant

    Removing the exit statement appears to fix things although now I am not getting redirected to the correct page. I’m still investigating this. So, use with caution and test well!

    function auto_login_new_user( $user_id ) {
    wp_set_current_user($user_id);
    wp_set_auth_cookie($user_id);
    // wp_safe_redirect( home_url() ); OR…
    wp_safe_redirect( home_url(‘/your-page/’) );
    }
    add_action( ‘user_register’, ‘auto_login_new_user’ , 10, 1);

    #10003130
    Avatar
    Pie Register
    Participant

    Hello,

    I’d suggest you to use Pie-Register Hook pie_register_after_register this hook return User Object as defined in line # 1482 of pie_save_registration function.

    I hope it helps.

    Thanks

    #10003465
    Avatar
    gerard kilbirde
    Participant

    Would anybody expand on where to put this code to get it to work?

    thanks again

    #10003467
    Avatar
    Pie Register
    Participant

    This is coming along with many other excited features in pro version soon!

Viewing 10 posts - 1 through 10 (of 17 total)

The forum ‘Installation’ is closed to new topics and replies.

Checkout
0
PURCHASE NOW