-
-
Save rtpHarry/6e1d73d026fca369569f11798736dc7a to your computer and use it in GitHub Desktop.
How to create a clone role in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 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)) { | |
return; | |
} | |
$source_capabilities = $wp_roles->get_role($source_role); | |
if (!$source_capabilities) { | |
return; | |
} | |
$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