WordPress Create Custom Roles and Capabilities

  1. Home
  2. Knowledge Base
  3. WordPress Hacks
  4. WordPress Create Custom Roles and Capabilities

So you want to add a custom Role to your WordPress site to add more flexibility when assigning users their role, what do you do? Simply add a role, with a few lines of code in your themes functions.php file, using WordPress add_role() function, as defined below.

The example below adds a role of Video Manager with a custom cabability of manage videos.

NOTE: Once you add this code to your functions.php file and view any page on your site to make the role addition, you can and should comment it out so that it doesnt run on every page view.

Now, how do we use this new role with the new capability you ask? Simply use the WordPress current_user_can() function to check the users capability.

This technique can be combined with our WordPress Role Capability Restriction technique to add even more capabilities to your new custom role. Simply create your new role then use it in the get_role() function call detailed in our technique.

Was this article helpful?

Related Articles

Leave a Reply