Forum Replies Created
- AuthorPosts
mary gallagherParticipantAs I understand it, the redirection is working. How are you sure that the user is not logged in? The Get Started button goes to the login page. The way I structured my app was to include a php if (is_user_logged_in()) test on each private page. If the user is not logged in, an else clause redirects to the login page. Once the user logs in, the Pie Register settings would automatically redirect the user to the video page – if that is where you want a logged in user to first land. It looks like your videos-page is currently automatically redirecting to the login page. But, these are just my observations without having created a registration.
To quickly test whether the user is actually getting logged in automatically, I suggest you create a “Hello world” page and set that to the destination for your hooked function. (Do not change any of your current Pie Register settings.)
mary gallagherParticipantHi, Syed.
The code you are using is still working for me. (My last post said redirection was to incorrect page. That is resolved although my notes don’t say how.) Can you tell me what is happening after a registration is submitted? Are cookies enabled? I am using version 2.0.14 of Pie Register and Tempera as my parent theme.Above, Moshin suggested using the pie_register_after_register hook. Perhaps using that hook and just doing a redirect in your function would work.
Cheers, Mary
mary gallagherParticipantRemoving 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);
mary gallagherParticipantHi. 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.
mary gallagherParticipantI 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.
mary gallagherParticipantI 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.- AuthorPosts
