Adding Custom User Roles in WordPress

Simon L. Dec 20, 2024 User Management
How can I make new types of users for my website with different permissions?
What is the method to create and assign custom user roles in WordPress, including capabilities and permissions for those roles?
Andy answered Dec 20, 2024

Adding Custom User Roles in WordPress

Custom Code Solution

The following code creates a custom user role and should be placed in your theme's functions.php file or in a site-specific plugin:

This code creates a new "Editor Plus" role with extended capabilities:

function create_editor_plus_role() {
    $editor_plus_capabilities = get_role('editor')->capabilities;
    $editor_plus_capabilities['edit_theme_options'] = true;
    $editor_plus_capabilities['manage_categories'] = true;
    
    add_role(
        'editor_plus',
        'Editor Plus',
        $editor_plus_capabilities
    );
}
add_action('init', 'create_editor_plus_role');

To remove the custom role when it's no longer needed:

function remove_editor_plus_role() {
    remove_role('editor_plus');
}
// Uncomment next line to remove the role
// add_action('init', 'remove_editor_plus_role');

To add specific capabilities to an existing role:

function modify_role_capabilities() {
    $role = get_role('author');
    $role->add_cap('upload_files', true);
    $role->add_cap('edit_published_posts', true);
}
add_action('init', 'modify_role_capabilities');

Common Capabilities Reference

  • edit_posts
  • publish_posts
  • edit_published_posts
  • delete_posts
  • upload_files
  • edit_pages
  • edit_theme_options
  • manage_categories
  • manage_options

Plugin Solutions

If you prefer using plugins, here are reliable options:

  1. User Role Editor - Most popular solution with a visual interface
  2. Members - Clean interface with role management features
  3. Capability Manager Enhanced - Advanced role management with multisite support

Best Practices

  1. Always test new roles in a development environment first
  2. Back up your database before making role changes
  3. Use the principle of least privilege - give users only the capabilities they need
  4. Consider using a plugin for complex role structures
  5. Document any custom roles and their purposes for future reference

Important Notes

  • Custom roles persist in the database even after deactivating themes/plugins
  • Use remove_role() when cleaning up custom roles
  • Changes to existing roles should be made with caution as they affect all users with that role
  • Consider using a must-use plugin instead of functions.php for role management in production