I am trying to add a function to bp_core_activated_user, where I want it to do the following:
- Activate the user
- Login the user
- Redirect the user to their profile edit screen
I don't have any issues with 1. and nor with 3, but since the second step is not working, it will not do #3 properly.
Here is my code example
function auto_login_activation($user_id, $key, $user) {
$bp = buddypress();
$bp->activation_complete = true;
//now login and redirect
$user = get_user_by( 'id', $user_id );
if( $user ) {
wp_set_current_user( $user_id, $user->user_login );
wp_set_auth_cookie( $user_id );
}
bp_core_redirect( bp_core_get_user_domain( $user_id ) .$bp->profile->slug .'/edit/' );
}
add_action( 'bp_core_activated_user', 'auto_login_activation', 0, 3 );
If I disable the redirect, it shows on my screen as logged in (will show Log Out, and hide Log In and Sign Up) but when I go to a page that is only for logged in users, it states I am logged out.
I know step 1 is working, as the user receives an automated welcome email on activation. Step 2 is where it falls down, and step 3, I use the bp_core_redirect elsewhere within my code without issues I had been using a plugin for this purpose, but it also stopped working, and is basically the same code.