Skip to content

Instantly share code, notes, and snippets.

@juanmafla
Created July 25, 2017 17:01
Show Gist options
  • Save juanmafla/286e0d9b09255e87751bc33afa2bf964 to your computer and use it in GitHub Desktop.
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)
// 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