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 want my editors to have the possibility, to add other users. I added:

    $edit_editor->add_cap('create_users');
$edit_editor->add_cap('delete_users');
$edit_editor->add_cap('edit_users');

to the functions.php - but now, the editors are also able to create, change an Admin Role.

Is there any way, to exclude admin from the roles?

Thank you!

AD

share|improve this question

1 Answer 1

Giving the capability to delete and edit users would compromise your security, as then the editors would have the ability to modify your profile too. What you could do is just give the create_users capability to the editors. But the users thus created would be allotted "Subscribers" role by deafult.

EDIT: Try the following code ( Requires a bit of testing / sort of a hack for your requirement )

if ( isset( $_REQUEST['user_id'] ) ) {
    $userdata = get_user_by( 'id', $_REQUEST['user_id'] );
    if ( isset( $userdata->roles[0] ) && ( 'administrator' == $userdata->roles[0] ) ) {
        $edit_editor->remove_cap( 'create_users' );
        $edit_editor->remove_cap( 'delete_users' );
        $edit_editor->remove_cap( 'edit_users' );
    } else {
        $edit_editor->add_cap( 'create_users' );
        $edit_editor->add_cap( 'delete_users' );
        $edit_editor->add_cap( 'edit_users' );
    }
} else {
    $edit_editor->add_cap( 'create_users' );
    $edit_editor->add_cap( 'delete_users' );
    $edit_editor->add_cap( 'edit_users' );
}
share|improve this answer
    
Hi Joshua, thanks for the reply. Is there any way to make not "Subscribers" by default, but "Authors"? Maybe that would be just enough... –  ad2003 Jul 23 '12 at 14:03
    
Just try the above edited answer and see if it fulfills the requirement –  Joshua Abenazer Jul 23 '12 at 15:05
    
thank you for your effort! I tried it, but it didn't work. –  ad2003 Jul 24 '12 at 8:43
    
are you using $edit_editor = get_role('editor') to fetch the editor role? From the above code you should be able to assign any role to a new user but you can't edit existing users. –  Joshua Abenazer Jul 24 '12 at 9:51

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.