Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How to create new role with same capabilities of existing role. Eg: I would like to create a new role with same capabilities of administrator or editor and so on..

share|improve this question
    
What have you tried? What worked? What didn't? Have you tried Members Plugin? Or Capability Manager Plugin? Do they do the things you want? –  soulseekah Oct 19 '11 at 5:42
    
You can use User Role Editor if you want to do everything visually :) –  Tanmoy Sk Oct 19 '11 at 10:57

1 Answer 1

up vote 16 down vote accepted

Try this... This should work.

<?php
add_action('init', 'cloneRole');

function cloneRole()
{
    global $wp_roles;
    if ( ! isset( $wp_roles ) )
        $wp_roles = new WP_Roles();

    $adm = $wp_roles->get_role('administrator');
    //Adding a 'new_role' with all admin caps
    $wp_roles->add_role('new_role', 'My Custom Role', $adm->capabilities);
}
?>

Check it.

share|improve this answer
    
Watchout!! this seems to clone the role before the plugins add roles and capabilities. I'll try admin_init to see if this is better. –  spankmaster79 Jan 21 '14 at 17:21
    
@spankmaster79 Yes please, that will be great! –  Rutwick Gangurde Jan 22 '14 at 6:00
    
@RutwickGangurde didn't work any better. Role is still ignored by the plugin –  spankmaster79 Jan 24 '14 at 15:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.