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 don't want to accidentally select Administrator role.

So is there a way to remove it from Settings -> General -> New User Default Role ?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Okay, this looks tricky, but I think it's possible.

  1. The user-new.php file calls wp_dropdown_roles() to output the list of roles.
  2. The wp_dropdown_roles() function calls get_editable_roles() to get the list of roles to output.
  3. The get_editable_roles() function has a filter, editable_roles.

So, you should be able to add a filter for editable_roles, such that, if the current page is user-new.php, you unset administrator from $editable_roles.

Edit

It would be awesome if you can give me the code for my functions.php file.

This is completely untested, but should get you in the right direction. I'm assuming that $editable_roles is an array of user roles, e.g. array( 'subscriber', 'author', 'editor', 'administrator' ), but I've not verified.

<?php
function wpse_40897_filter_get_editable_roles_for_new_user( $editable_roles ) {
    global $pagenow;
    if ( 'user-new.php' == $pagenow ) {
        unset( $editable_roles['administrator'] );
    }
    return $editable_roles;

}
add_filter( 'editable_roles', 'wpse_40897_filter_get_editable_roles_for_new_user' );
?>

Caveat: This isn't turn-key code, but rather is merely example code. If you're not comfortable grokking it to get where you need, then I wouldn't recommend using it for copy-pasta.

share|improve this answer
    
Hello Mr.Bennett, Thanks for the answer. It would be awesome if you can give me the code for my functions.php file. I hope it will definitely useful for others too. Thanks –  Giri Feb 2 '12 at 10:44
    
See updated answer. Also: please note the caveat. –  Chip Bennett Feb 2 '12 at 14:25

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.