How to add multiple user roles upon user creation

You can use the gform_user_registered filter to ADD an additional role to the role you have configured in the User Registration feed.

The code would look like this to add an additional role:

add_action( 'gform_user_registered', 'add_another_role', 10, 3 );
function add_another_role( $user_id, $feed, $entry ) {
    // edited code example July 19, 2021 to add the next line
    $user = new WP_User( $user_id );
	// add another role to the registered user
	$user->add_role( 'super-dude' );
}

That code can go into your theme functions.php file or a functionality plugin.

1 Like