0
function wpufe_auto_login_new_user( $user_id ) {   
    wp_set_current_user( $user_id );
    wp_set_auth_cookie( $user_id, false, is_ssl() );
}
add_action( 'user_register', 'wpufe_auto_login_new_user' );

I'm using the above function to automatically login a person after registration. It is for a specific use case and I would like to make it only work for a particular page or template where the form exists. Would this be possible?

Also, what might be the best way to add a page redirect to it? wp_redirect() possibly? I would like to redirect after the function fires.

Update:

I've tried the below conditional as a page id as well as a page name 'My Page' and it makes the action not fire at all over all forms on the site.

function wpufe_auto_login_new_user( $user_id ) {   
if ( is_page( 3943 )) {    
    wp_set_current_user( $user_id );
    wp_set_auth_cookie( $user_id, false, is_ssl() );
    }
}
add_action( 'user_register', 'wpufe_auto_login_new_user' );

Thanks.

0

You could do something like this:

function wpufe_auto_login_new_user( $user_id ) { 
     if ( is_page( 'Page Title' ){  
          wp_set_current_user( $user_id );
          wp_set_auth_cookie( $user_id, false, is_ssl() );
     }
}

Yes. I would use wp_redirect(). If your are redirecting from some other page to the login page. But I am unsure what you want to redirect to or where from.

| improve this answer | |
  • That actually made my function not fire at all. I have updated my question above. – Work-Together2013 Nov 25 '15 at 1:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.