I realize auto login after user registration is not native behavior to CRED user forms (yet) , however there is an excellent post (along with a video) by Simon Toulson on CRED User forms that does just that with a function.
hidden link
He has implemented it successfully with the following:
function auto_login_new_user( $user_id ) {
wp_set_current_user($user_id);
wp_set_auth_cookie($user_id);
// If we logged in from our CRED registration form (id = 389), then redirect to our owner area,
// otherwise, send user to the home page
if isset( $_POST['_cred_cred_prefix_form_id'] && $_POST['_cred_cred_prefix_form_id'] === 389 ) {
$url='/owner-area/';
} else {
$url= home_url();
}
wp_redirect( $url );
exit;
}
add_action( 'user_register', 'auto_login_new_user' );
I have entered nearly the identical snippet into my functions file - just replacing my CRED User Form ID from what he had. And my user account page slug with what he had as well:
function auto_login_new_user( $user_id ) {
wp_set_current_user($user_id);
wp_set_auth_cookie($user_id);
// If we logged in from our CRED registration form (id = 542), then redirect
// to our post author account page, otherwise, send user to the home page
if isset( $_POST['_cred_cred_prefix_form_id'] && $_POST['_cred_cred_prefix_form_id'] === 542 ) {
$url='/account/';
} else {
$url= home_url();
}
wp_redirect( $url );
exit;
}
add_action( 'user_register', 'auto_login_new_user' );
But I receive the following error:
Parse error: syntax error, unexpected 'isset' (T_ISSET), expecting '(' in ......
I'm assuming it's because I'm on a multisite install? Or is there a problem with that function?
Any suggestions how to get this to work on a multisite setup? It sure would be a great feature to add to CRED User Forms.
Any insight would be greatly appreciated!
Cheers