Hi,
Inside Profile Builder Pro we have a module called Multiple Registration Forms that you could use to create custom forms with different fields for different user roles. Another option of this module is to Automatically Login the user after Registration.
You can test Profile Builder Pro on our demo install. If you have any other questions regarding the Pro version you can always submit a support ticket.
We can achieve the same functionality using custom code:
1. Create an empty plugin like this: https://gist.github.com/sareiodata/76f701e01db6685829db
2. Add the following code to the end of it:
/*
* Automatically Login the user after Registration and redirect him to a page
* Doesn't work if Admin Approval is set to Yes
*/
add_action( 'wppb_register_success', 'wppb_custom_autologin_redirect', 10, 3 );
function wppb_custom_autologin_redirect( $http_request, $form_name, $user_id ){
global $current_user;
$current_user = 0;
if(wp_get_object_terms($user_id, 'user_status')) {
die('Admin Approval is set to Yes. Automatically Login will not work.');
exit;
}
$token = wppb_create_onetime_token( 'pb_autologin_'.$user_id, $user_id );
$location = home_url() . "/?pb_autologin=true&pb_uid=$user_id&pb_token=$token";
echo "<script> window.location.replace('$location'); </script>";
}
add_action( 'init', 'wppb_custom_autologin' );
function wppb_custom_autologin(){
if( isset( $_GET['pb_autologin'] ) && isset( $_GET['pb_uid'] ) && isset( $_GET['pb_token'] ) ){
$uid = $_GET['pb_uid'];
$token = $_GET['pb_token'];
require_once( ABSPATH . 'wp-includes/class-phpass.php');
$wp_hasher = new PasswordHash(8, TRUE);
$time = time();
$hash_meta = get_user_meta( $uid, 'pb_autologin_' . $uid, true);
$hash_meta_expiration = get_user_meta( $uid, 'pb_autologin_' . $uid . '_expiration', true);
if ( ! $wp_hasher->CheckPassword($token . $hash_meta_expiration, $hash_meta) || $hash_meta_expiration < $time ){
die (' You are not allowed to do that. ');
exit;
} else {
wp_set_auth_cookie( $uid );
delete_user_meta($uid, 'pb_autologin' . $uid );
delete_user_meta($uid, 'pb_autologin' . $uid . '_expiration');
wp_redirect( home_url() . '/edit-profile/' );
exit;
}
}
}
function wppb_create_onetime_token( $action = -1, $user_id = 0 ) {
$time = time();
// random salt
$key = wp_generate_password( 20, false );
require_once( ABSPATH . 'wp-includes/class-phpass.php');
$wp_hasher = new PasswordHash(8, TRUE);
$string = $key . $action . $time;
// we're sending this to the user
$token = wp_hash( $string );
$expiration = $time + 60*10;
$expiration_action = $action . '_expiration';
// we're storing a combination of token and expiration
$stored_hash = $wp_hasher->HashPassword( $token . $expiration );
update_user_meta( $user_id, $action , $stored_hash ); // adjust the lifetime of the token. Currently 10 min.
update_user_meta( $user_id, $expiration_action , $expiration );
return $token;
}
2.1 Inside the wp_redirect() function we set to redirect the user to the Edit Profile page (adjust this as you want)
3. Install this plugin via FTP (copy it inside wp-content/plugins) or create a zip archive with it and install it via the WordPress plugin upload functionality
Let me know if it works for you.
Best regards,