Title: Add additional role to user programmatically
Last modified: January 4, 2022

---

# Add additional role to user programmatically

 *  Resolved [Cory](https://wordpress.org/support/users/corypina/)
 * (@corypina)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/add-additional-role-to-user-programmatically/)
 * I apologize if this isn’t specific to this plugin, but I have some roles added
   via Members that I would like to programmatically add to certain users.
 * For example, I’ve got a custom role `faculty`, that I would like to add to certain
   user upon registration if certain conditions are met. I can’t seem to nail down
   the right method to run on the user that will give the additional role to the
   user.
 * Is there a function from the plugin I can run to accomplish this?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Caseproof LLC](https://wordpress.org/support/users/caseproof/)
 * (@caseproof)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/add-additional-role-to-user-programmatically/#post-15217340)
 * Hi Cory,
 * To add role on registration you can use this code snippet, modify it, and add
   at the end of your theme’s functions.php file:
 *     ```
       add_action( 'user_register', function( $user_id ) {
         $user = get_user_by( 'ID', $user_id );
         if ( /* Your condition here */ ) {
           $user->add_role( 'faculty' );
         }
       });
       ```
   
 * Hopefully, that helps.
 *  Thread Starter [Cory](https://wordpress.org/support/users/corypina/)
 * (@corypina)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/add-additional-role-to-user-programmatically/#post-15218781)
 * Thank you, [@caseproof](https://wordpress.org/support/users/caseproof/)! I’ve
   actually tried this and it wasn’t working for me, but that just tells me I’ve
   got some errors somewhere. Thanks for confirming I was on the right track.
 *  Thread Starter [Cory](https://wordpress.org/support/users/corypina/)
 * (@corypina)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/add-additional-role-to-user-programmatically/#post-15219342)
 * **Update:** I definitely just had a few code typos, and this works perfectly.
   I’m going to forgive myself because it was the first day back after the holiday.
   🙂
 * Thanks again, [@caseproof](https://wordpress.org/support/users/caseproof/).

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Add additional role to user programmatically’ is closed to new replies.

 * ![](https://ps.w.org/members/assets/icon-256x256.png?rev=3508404)
 * [Members - Membership & User Role Editor Plugin](https://wordpress.org/plugins/members/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/members/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/members/)
 * [Active Topics](https://wordpress.org/support/plugin/members/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/members/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/members/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Cory](https://wordpress.org/support/users/corypina/)
 * Last activity: [4 years, 5 months ago](https://wordpress.org/support/topic/add-additional-role-to-user-programmatically/#post-15219342)
 * Status: resolved