Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to create a clone role in WordPress
* Clone the subscriber role to create a tenant role
* Note: this only needs to be run once, so it can be removed after the role is created
function clone_subscriber_to_tenant() {
$new_role = 'tenant';
$new_role_name = 'Tenant';
$source_role = 'subscriber';
$wp_roles = wp_roles();
// skip if role exists
if ($wp_roles->get_role($new_role)) {
$source_capabilities = $wp_roles->get_role($source_role);
if (!$source_capabilities) {
$wp_roles->add_role($new_role, $new_role_name, $source_capabilities->capabilities);
add_action('init', 'clone_subscriber_to_tenant');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment