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.

I have added the code below to a plugin:

add_action( 'admin_init', 'remove_add_users_cap' );
function remove_add_users_cap() {
    $role = get_role( 'administrator' );
    $role->remove_cap( 'add_users' );
    $role->remove_cap( 'create_users' );
}

And I can see that the caps are no longer on my user:

if(!function_exists('wp_get_current_user')) {
    include(ABSPATH . "wp-includes/pluggable.php"); 
}
$current_user = wp_get_current_user();
echo '<pre>';
print_r($current_user);
echo '</pre>';

But I can still add new users O.o ...

Is there something else that needs to be done to achieve this? I would like to completely remove the ability for anyone to add a new user when this plugin is activated...

This is in a Wordpress Multisite context, and I have a feeling that may be complicating things.

Thanks,

share|improve this question
    
Incidentally, from the codex: "This setting is saved to the database (in table wp_options, field wp_user_roles), so it might be better to run this only once, probably on theme/plugin activation or deactivation" –  vancoder Apr 2 '13 at 22:07
add comment

1 Answer

Okay, so the code above does work, but not for super admins, you must explicitly remove permissions from super admins, like this:

// restrict super admin capabilites
add_filter('map_meta_cap', 'restrict_super_admins', 10, 4);
function restrict_super_admins($caps, $cap, $user_id, $args){
    $super = array(
        'add_users',
        'create_users',
    );
    if( in_array($cap, $super) ) {
        $caps[] = 'do_not_allow';
    }
    return $caps;
}
share|improve this answer
add comment

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.