Skip to content

Definitive guide to WordPress roles and capabilities

Alejandro Frades
Guía definitiva sobre roles y capacidades en WordPress Modular
  • Creating Custom Roles in WordPress

    WordPress, by default, comes with a set of predefined roles: Administrator, Editor, Author, Contributor, Subscriber, and Super Admin (for multisites). However, depending on your project, you may need more specific roles with custom capabilities. Let’s see how you can achieve this both manually and with plugins:

    1. Using a Plugin:

    The “User Role Editor” plugin is one of the most popular tools for this task:
    Steps:

    1. Plugin Installation:
      • Go to your WordPress admin panel.
      • Navigate to ‘Plugins’ > ‘Add New’.
      • Search for “User Role Editor” and proceed to install and activate it.
    2. Creating a Custom Role:
      • In the WordPress menu, go to ‘Users’ > ‘User Role Editor’.
      • Click on ‘Add Role’.
      • Enter the role name (no spaces) and a display name.
      • Select the capabilities you want to assign to this role.
      • Click on ‘Update’.

    Advantages: The interface is intuitive and makes it easy to assign specific capabilities to each role. Plus, it allows you to clone existing roles and modify them according to your needs.

    2. Manually (through code):

    If you prefer not to use a plugin, you can add custom roles using functions in the functions.php file of your theme.
    Steps:

    1. Go to the WordPress admin area.
    2. Navigate to ‘Appearance’ > ‘Theme Editor’.
    3. Select the functions.php file.
    4. Add one of the following codes for roles (examples, you can take their permissions and create one to your liking).:

    1. Role for Developers:

    function role_developers() {
        add_role(
            'developer',
            __('Developer'),
            array(
                'read' => true,
                'activate_plugins' => true,         // Activate plugins
                'edit_plugins' => true,             // Edit plugins
                'install_plugins' => true,          // Install plugins
                'update_plugins' => true,           // Update plugins
                'edit_files' => true,               // Edit files
                'edit_themes' => true,              // Edit themes
                'install_themes' => true,           // Install themes
                'update_themes' => true,            // Update themes
                'edit_theme_options' => true,       // Edit theme options
                'unfiltered_html' => true           // Insert unfiltered HTML
            )
        );
    }
    add_action('init', 'role_developers');
    

     
    2. Role for Editors:

    
    function role_editors() {
        add_role(
            'editor',
            __('Editor'),
            array(
                'read' => true,
                'edit_posts' => true,               // Edit posts
                'publish_posts' => true,            // Publish posts
                'delete_posts' => true,             // Delete posts
                'edit_published_posts' => true,     // Edit published posts
                'delete_published_posts' => true,   // Delete published posts
                'edit_others_posts' => true,        // Edit others' posts
                'delete_others_posts' => true,      // Delete others' posts
                'manage_categories' => true         // Manage categories
            )
        );
    }
    add_action('init', 'role_editors');
    

    Advantages: Greater control over the roles and capabilities assigned. No need to rely on plugins.

    Conclusion

    Creating custom user roles in WordPress is a powerful way to manage user permissions and access to different parts of your site. Whether you choose to use a plugin or add the roles manually, make sure to carefully plan which capabilities each role should have to ensure a secure and efficient user management system.
    Hope this helps! Let me know if you have further questions or need additional assistance!

    Alejandro Frades marketing specialist Modular
    Autor
    Alejandro Frades
    Marketing Specialist
    La mente detrás de los contenidos sociales de Modular. Siempre al tanto de las últimas tendencias para aprovecharlas y hacer que el mundo digital sea más ameno y entretenido.

    Subscribe to our Newsletter about the web world