One step is to use the
editable_rolesfilter to remove roles from the dropdown but this doesn’t prevent the user from modifying the select value and create a user with “not allowed” role.
Yes it does. This filter is not just for the dropdown. Modifying editable_roles does in fact prevent users from assigning a role they’re not allowed to.
This is because edit_user() (the function used for adding new users) calls get_editable_roles() as well and bails when one is not allowed to give users that role.
Here’s a simple example of what you can do:
/**
* Removes Administrator from roles list if user isn't an admin themselves.
*
* This way, only admins can make new admins.
*
* @param array $all_roles List of roles.
* @return array Modified list of roles.
*/
function wpse_293133_filter_editable_roles( $all_roles ) {
if ( ! is_super_admin( get_current_user_id() ) ) {
unset( $all_roles['administrator'] );
}
return $all_roles;
}
add_filter( 'editable_roles', 'wpse_293133_filter_editable_roles' );
Related Posts:
- A different role for each site in a multisite
- WPMU – new users are automatically subscribed to the main blog – how to prevent that?
- How to change a user role after registering in multisite?
- Easily adding multiple existing users to a multisite site
- Why are my roles not visible in a Multi-site/Network?
- wordpress multisite, how to keep user on subdomain throughout registration process?
- How to enable a site administrator to edit users in a WordPress network/ multisite setup?
- Possible to make custom role in multisite that can add sites?
- How to add multiple existing users to a multisite site?
- In MultiSite, can some users automatically have Site Admin rights on all sites, without granting them Network Admin access?
- create_users capabilities on a role on multisite
- Update User Role Across Network when Main Site User is Updated
- Assign role to user on first login, if they are first (after admin)
- Get the User ID Who Owns a Given Blog ID in Multisite
- Make a user administrator to a sub directory site and a contributor to main site in multisite network
- Displaying a message upon user registration
- How to change user starting role in WordPress MultiSite?
- Allow Author on Site A capability to upload files on Site B in Multi Site
- Add a user to a specific blog when they register?
- Add menu items/actions for multisite users who are registered on the network but do not have a role or capability in any sites
- Four columns in the wp_users table
- Subsite access without being a member of the subsite in wp multisite network
- Create Custom Multisite User Role to Reduce Capabilities
- Restrict Capability of Administrator to Create, Edit and Delete Pages in Multisite
- Copy user role on multisite so the user can access subsites with same role
- How to fix that new users show up again in subsite of a Multisite?
- WordPress Multisite Add User
- can’t create user without email for an author after converting single site to multisite
- Possible to have duplicate usernames on different two multisites
- Modify new user email notification in network admin screen wp multisite
- Users getting linked unwanted to main mu in WordPress multisite (WPMU)
- Can’t activate a user on multisite install
- Multisite “Skip Confirmation Email” Log Out Problem
- How to create child/sub user under parent user
- How create a multisite setup with “phantom” accounts and passwords?
- Is there any way to give all users access to one blog in a multisite network without using a plugin?
- How to give “author” user role appropriate capabilities to add PollDaddy polls? WordPress multisite
- Using a number for limiting registering or banning on multisite
- Non-super-admin users cannot access CPT even though I have explicitly added the capabilities to the user role
- Where are available Roles Defined in the wp_ database?
- User-edit role setting distinct from wp_capabilities? [closed]
- WordPress Multisite allow site admin to add user without email confirmation
- Network not displaying all sites and users
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- What the user_status column?
- Add Custom User Capabilities Before or After the Custom User Role has Been Added?
- Give to site admin the option to “skip confirmation email” when adding new user
- Do not allow users to create new posts and pages
- Adding capabilities to super admins
- Get first_name and last_name on user_register hook
- How do I fix problems with users not being able to publish and only submit for review after upgrade of Multisites installation?
- Allowing logged in users to comment without moderation across a multisite installation
- Can you have multi-site WP and keep users separate?
- How to customize wp_signon()
- Can I use multisite functions in a single-site installation?
- User registration on sub site
- Restrict Admin Capabilities in MultiSite
- How can I delete a user from entire multisite nework
- delete_user_meta : how to delete all the metadata of a given user (witout SQL)
- How to search users globally on a multisite install?
- Within the database, where is the flag which says that a user has Super Admin rights?
- current_user_can() always returns true if user is super admin
- Getting users by specific capability, not role
- Query users by capability – uninstall/deactivate callback
- access the plugins for each role in WordPress multisite
- What sites are you registered to when joining a multisite?
- Auto creation of multisite blog on user registration
- Remove Capabilities from WP admin for specific user role
- Displaying different in-page content to cliente/admin
- Is the Multi site functionality a viable option for Country and Language targeting?
- Good way to block users within a multisite setup without deleting them?
- Multisite user roles – capabilities not working
- How can you override the is_multisite check in wp-login.php for individual login/registration?
- Limit number of users a role can create
- How can I prevent certain custom roles from seeing other custom roles on the user list page?
- Understanding State in WordPress Multisites
- User registration on two sites in same multisite
- How to sync roles across Multisite?
- What’s the correct way to add capabilites to user roles?
- Delete user from multisite when removed from subsite
- Combining user database tables while keeping all other data in seperate for multiple sites?
- User registration is currently not allowed
- Give users acces to admin a single post or set up WP network?
- How to make WordPress ‘editor’ role to list/view/add/edit users only with the role ‘author’?
- Language per user role, how can I achieve this?
- Automatic registration on main site upon user registration on Multisite
- Disabling user capability to edit_posts or delete_posts in the front-end
- How to allow mixed case characters in multisite site name?
- Multisite – each site with it’s own set of users
- Multisite – site user limited only for this site
- User / membership Plugin [closed]
- Importing Posts into New Website with Same User ID’s
- Groups roles & capabilities
- Activation of new Registered site fails on multisite
- Is Multisite the RIGHT option for my case?
- How to Create WPMu New User?
- How can I display all Multisite blogs where this user is administrator?
- Multisite and users being listed on network administration dashboard and not main site dashboard
- Want to add post to user dashboard
- Change a subsite Admin role of a WordPress Multisite after 24 hours registering