Title: Code php for assign user to role
Last modified: September 3, 2020

---

# Code php for assign user to role

 *  Resolved [weblancerfr](https://wordpress.org/support/users/weblancerfr/)
 * (@weblancerfr)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/code-php-for-assign-user-to-role/)
 * Hello, can you give me a code for assign to user a role created with your plugin.
   
   Thank you

Viewing 1 replies (of 1 total)

 *  Plugin Author [Caseproof LLC](https://wordpress.org/support/users/caseproof/)
 * (@caseproof)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/code-php-for-assign-user-to-role/#post-13355409)
 * Hi [@weblancerfr](https://wordpress.org/support/users/weblancerfr/)
 * Here is simple example how to assign user to custom role:
 *     ```
       $user = new WP_User(123); // 123 is the user ID
       $user->add_role('sample_role'); // sample_role is the slug of your role
       ```
   
 * Cheers

Viewing 1 replies (of 1 total)

The topic ‘Code php for assign user to role’ 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/)

 * 1 reply
 * 2 participants
 * Last reply from: [Caseproof LLC](https://wordpress.org/support/users/caseproof/)
 * Last activity: [5 years, 9 months ago](https://wordpress.org/support/topic/code-php-for-assign-user-to-role/#post-13355409)
 * Status: resolved