Created
July 25, 2017 17:01
-
-
Save juanmafla/286e0d9b09255e87751bc33afa2bf964 to your computer and use it in GitHub Desktop.
Wordpress. Login user after registration. (After a user has successfully registered, login automatically)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // add this to functions.php file | |
| function reg_new_user( $user_id ) { | |
| $userdata= get_userdata($user_id); // get new user data by ID | |
| wp_set_current_user( $user_id, $userdata->user_email ); //set user with ID and E-mail | |
| wp_set_auth_cookie( $user_id ); // set cookie by user ID | |
| do_action( 'wp_login', $userdata->user_email ); // wp_login action hook with user E-mail | |
| } | |
| add_action('register_new_user', 'reg_new_user'); | |
| // Tested in Wordpress 4.8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment