• Is there a hook/filter I can call to prevent admins from being able to create new users?

    I’ve disabled user creation, and I’ve been using a small custom plugin to hide the new-user link on the users page (a little bit of CSS), but users keep finding ways around it. We use an external authentication system (Shibboleth), which will create WordPress users when needed, and which enforces certain rules (making sure the WP user name matches that of the external system, etc.).

Viewing 2 replies - 1 through 2 (of 2 total)
  • Add a custom admin user role, perhaps: subadmin, using this: How to Create Custom User Roles in WordPress.

    Use the exact role capabilities as an Admin, but eliminate the ability to create users. There should be at least one Admin capable of creating users, though, and that would be you.

    Thread Starter David E. Smith

    (@desmith)

    When I can, I try not to get into custom roles, because (IMO) they’re not very well-supported.

    One of my colleagues came up with this, which I haven’t yet tested but which looks promising:

    add_filter( 'map_meta_cap', 'disallow_create_users', 10, 2 );
    function disallow_create_users( $caps, $cap ) {
       if ( $cap === 'create_users' ) {
        $caps[] = 'do_not_allow';
       }
    ​
       return $caps;
     }
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Hook to prevent admins from creating users?’ is closed to new replies.