Set user after wp_create_user?

Here is a function I wrote that hooks into the gravity forms create user form but it can be added to whatever action hook your wp_create_user function is attached to.

function my_auto_login( $user_id ) {
    wp_set_auth_cookie( $user_id, false, is_ssl() );
    wp_redirect( admin_url( 'profile.php' ) );
    exit;
}

The important part is wp_set_auth_cookie. This has to fire after the user is the best (only?) way to auto login a user without filling out the login form.

Leave a Comment