Adding multiple user roles dynamically

We are using this plugin Members to give users multiple roles on our site, in this case we have "Vendor" and "Instructor".

After submitting a Gravity form to become a 'Vendor' I have added this code to functions.php to dynamically add a secondary user role of 'Instructor'.

function add_instructor_role( $entry, $form ) {
  $user_id = get_current_user_id();
  $user = new WP_User($user_id);
  $user-add_role('Instructor');
}
add_action( 'gform_after_submission', 'add_instructor_role', 10, 2 );

This code does not work like we had hoped it would.

So, with the Members plugin working it adds a checklist instead of a dropdown menu in the backend users page.(example.com/wp-admin/user-edit.php?user_id=71) This UI allows you to check off multiple roles for an individual user and hit save, now the user has the capabilities of multiple roles.

We are trying to achieve the same thing with the code above but after running and viewing the user backend page the Instructor role checkbox is not checked and it should be.

It seems to be adding the Instructor Capabilities but not the ROLE, see image below.

Topic plugin-gravity-forms plugin-members user-roles Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.