Creating a custom user experience often requires more than the five default roles WordPress provides out of the box. Whether you need an "Editor Plus" with extra settings or a "Junior Admin" with restricted access, the most efficient way to start is by duplicating an existing role. In this guide, you will learn how to clone a WordPress user role using both programmatic methods and user-friendly plugins.
By cloning a role, you inherit a proven set of capabilities, ensuring that your new role functions correctly from the moment it is created. This approach saves you the tedious task of manually selecting dozens of individual permissions like edit_posts, upload_files, or manage_options.
Why You Might Need to Clone a WordPress Role
WordPress comes with a robust permission system, but the default roles (Administrator, Editor, Author, Contributor, and Subscriber) are often too rigid for complex sites. You might encounter a scenario where you want a user to have all the powers of an Editor, plus the ability to manage specific plugin settings.
Directly modifying the default roles is generally discouraged because it can lead to confusion or security gaps if you ever need to revert them. Instead, creating a cloned role allows you to experiment and customize permissions without affecting the core WordPress hierarchy. This is especially useful for membership sites, client handovers, or multi-author blogs where specific workflows are required.
Method 1: Programmatically Cloning a Role (The Developer Way)
If you are comfortable with PHP or are building a custom theme or plugin, cloning a role programmatically is the cleanest method. It ensures the role is registered directly in the WordPress database and doesn't require the overhead of an additional plugin.
To do this, we hook into the init action. We access the global $wp_roles object, retrieve the capabilities of the "source" role, and then use the add_role function to create the new one.
The Code Snippet
Add the following code to your theme's functions.php file or a custom functionality plugin:
<?php
add_action('init', 'cloneRole');
function cloneRole()
{
global $wp_roles;
if ( ! isset( $wp_roles ) )
$wp_roles = new WP_Roles();
// Get the capabilities of the administrator role
$adm = $wp_roles->get_role('administrator');
// Adding a 'new_role' with all administrator capabilities
// Parameters: Role Slug, Display Name, Capabilities Array
$wp_roles->add_role('new_role', 'My Custom Role', $adm->capabilities);
}
?>
How the Code Works
- The Hook: We use
add_action('init', ...)because user roles need to be registered when WordPress initializes. - The Global Object:
global $wp_rolesgives us access to the WordPress Role Management API. - The Source:
$wp_roles->get_role('administrator')fetches the entire object for the Administrator role, including itscapabilitiesarray. - The Creation:
$wp_roles->add_role()takes three arguments: the internal slug (e.g.,new_role), the display name (e.g.,My Custom Role), and the array of capabilities we just copied from the admin.
Note: Once this code runs once, the role is saved to the database. You don't necessarily need to keep this code active forever, though leaving it in your functions.php is harmless as add_role will simply return null if the role already exists.
Method 2: Using the User Role Editor Plugin (The No-Code Way)
For those who prefer a graphical user interface or need to manage roles across multiple sites without touching code, the User Role Editor plugin is the industry standard. It provides a simple "duplicate" feature that handles the heavy lifting for you.
Steps to Clone a Role with a Plugin
- Install the Plugin: Search for "User Role Editor" in the WordPress Plugin Repository, install, and activate it.
- Navigate to Settings: Go to Users > User Role Editor in your WordPress dashboard.
- Add a New Role: Look for the "Add Role" button on the right-hand side of the interface.
- Select the Source: In the dialogue box that appears, you will see a field labeled "Make copy of." Select the role you wish to duplicate (e.g., Editor) from this dropdown.
- Name the Role: Enter a unique Role ID (slug) and a Display Name.
- Finalize: Click "Add Role."
The plugin will immediately create the new role with an identical set of checkboxes selected. You can then immediately begin checking or unchecking specific capabilities to fine-tune the permissions.
Managing and Refining Your Cloned Role
Cloning is just the first step. Once you have successfully duplicated a role, you likely want to modify it.
If you are using the code method, you can use add_cap() or remove_cap() to tweak the role. For example, if you cloned the Editor role but want to prevent the user from deleting pages, you could add this to your function:
$role = get_role('new_role');
$role->remove_cap('delete_pages');
If you are using the User Role Editor plugin, simply select your new role from the dropdown at the top of the page, toggle the checkboxes for the permissions you want to change, and click "Update."
Frequently Asked Questions
Will my cloned role receive updates if the original role changes?
No. When you clone a role, you are taking a "snapshot" of the capabilities at that specific moment. If a plugin adds a new capability to the Administrator role later on, your cloned role will not automatically receive that new permission. You will need to add it manually.
Can I delete a cloned role safely?
Yes, you can delete custom roles. However, ensure no users are currently assigned to that role before deleting it. WordPress usually defaults users with no valid role to "Subscriber" or "None," which might lock them out of necessary dashboard areas.
Does cloning a role affect the original role?
Not at all. The cloning process creates a completely independent entry in the wp_options table (under the wp_user_roles key). Any changes made to the clone will not reflect on the original role, and vice versa.
Wrapping Up
Cloning a WordPress user role is a fundamental skill for developers and site administrators who need granular control over user permissions. Whether you choose the programmatic approach using WP_Roles or the intuitive interface of the User Role Editor plugin, duplicating roles ensures a consistent and secure starting point for your custom permission sets.
Always remember to test your new roles thoroughly. Log in as a user with the new role to ensure they have access to everything they need—and more importantly, that they are restricted from the things they don't.