Ok here is how I did it:
add_action( 'editable_roles' , 'hide_editable_roles' );
function hide_editable_roles( $roles ){
$blog_id = get_current_blog_id(); // Get current subsite id
switch($blog_id) { // Define different max agents numbers depending on subsite id
case 6:
$max_agents = 10; //for subsite id#6 we can have maximum 10 agents
break;
case 7: //for subsite id#7 we can have maximum 3 agents
$max_agents = 3;
break;
default:
$max_agents = 3000; //default is 3000 agents
break;
}
$agents = get_users( array( 'role' => 'agent' ) ); // here you define the role
$agents = count( $agents );
if ($max_agents <= $agents){
unset( $roles['agent'] ); // here you define the role
}
return $roles;
}
Related Posts:
- Understanding State in WordPress Multisites
- Creating teams of users in WordPress
- How to assign user a role if none is present when logging in
- How can I let users to access plugin functions based on roles?
- Multisite functions to communicate with individual site functions
- Reset WordPress website
- Getting user roles in plugin files
- How to write a plugin to add users to a mail list
- How can I copy all users to newly created site on a multisite network in WordPress?
- How to create restrict content to users (by user, not by role)
- How to create user that has permission to create new sites on WordPress with multisite option enabled?
- Add User Role: Pre-saved in User-Meta [SOLVED]
- Custom Login page with custom redirects for each user?
- Mutliple users editing single document in wordspress
- Remove specific administrator’s capability
- Plugin permissions for Editor role
- Completely remove ability to create users?
- Role based permission edit for plugins
- Plugin privelages for “editors”
- How to implement data residency in my WordPress site
- how to create user profile pages and display them based on users roles
- User / membership Plugin [closed]
- Defined user role to access plugin’s pages
- Want to add post to user dashboard
- How to give different user access to different people?
- How to give access to the particular page in wordpress for specific username/email NOT roles [closed]
- ‘Global’ settings page for multisite plugin
- Override WordPress user with Oauth2 account
- How to prevent a post from being deleted?
- Loading posts associated only to the logged in user on recent posts page
- How can i force Display names to be the same as Usernames?
- WordPress Capabilities: edit_user vs edit_users
- Can I enable/disable/hide plugins on a per-site basis in multisite?
- How can a plugin run a script after being updated in MultiSite?
- Network-Wide Plugin Settings Management
- How to create custom LOGIN and REGISTRATION forms?
- Is there a way to share content amongst wordpress sites
- delete_user_meta Delete one value out of array
- Restricting users to a specific front end page [closed]
- WordPress Plugin for One-Time Event Registration? [closed]
- Will WordPress username displayed somewhere in the site?
- Upload files programmatically to users
- Current user in plugin returns NULL
- Advanced Custom Fields/User Role Editor – how to hide ACF for certain users?
- How to hide plugin from WordPress Multisite admin plugin list
- Is the wordpress user-model changed in wpmu?
- Unable to install theme recommended plugins on Multisite
- How to achieve certain page (url) accessible to certain users
- How to make a customize role and view a specific plugins base on that role?
- Solutions to repost categories into multisite blogs?
- Any recommendation on how to manage ads?
- Plugins not showing in Multisite dashboard
- How can I force users to a particular subdomain to log in for MU (Multisite)?
- Does any one have Idea to get these functionalities with the plugin wp-multi-network
- WordPress multi domain – redirect
- How can I change the meta_key for a particular piece of information?
- Subdomains with almost the same content
- Uninstalling plugins across all sites
- Custom table naming/access convention for multisite: $table_prefix vs base_prefix or other?
- Add user role to generated plugin
- Is there any way to make myself an admin?
- How to show the number of website visitors in my theme
- One sub site is slow while all others load fine, same theme & plugins [closed]
- Add Content to Content()
- How to check wp_options’s rewrite_rules if current and existing are the same before flush the rules?
- Is there a plugin for WordPress for creating ‘Accounts’ where all users who belong to that Account can only see Account data? [closed]
- How to integrate together a website currently hosted WordPress.com and a custom web application currently hosted on Azure?
- How limit user connection?
- WordPress /users/me endpoint request forbidden
- Show media-uploads to all users
- Cannot add edit themes and add plugins after multisite update
- How To Create A File Archive in WordPress?
- how to make a wplang for network fill automatically
- Plugin to create unlimited custom shortcodes?
- Plugin access and Roles
- Plugin Hook When New Author Added
- Shortcode not displaying HTML within the function
- Janrain/Simple Modal under Redirected Domain
- Show an admin menu item in Editor role
- In a WPMU that uses several different domains, how to enable users to register subdomains of any domain from the main site?
- WP Forms not displaying,becomming an fatal error
- Can we hide a certain user in WP?
- disable plugin activation on no multisite
- After reading 3 story by user ask for subscription popup
- Multisite converted to Single Site can’t add new plugins or new themes
- How do I run my custom function in my plugin when a wordpress user is deleted?
- Category as Subdomain for One WP Install
- Implementation to count page visits of unique visitors based on a cookie
- Custom User Notice Upon Login
- How to Call Function From Separate WordPress Install on Same Server?
- How to enable Admins to see Plugins
- How to order users alphabetically by name? in plugin UPME
- How create a multisite setup with “phantom” accounts and passwords?
- Multiple Accounts on 1 email – Multisite
- How change menu for each user in plugin?
- Check if user is in a group of another site within multisite network [closed]
- WordPress multisite haml templates
- edit slider plugin capability for custom_role
- Change email notification language based on the site language in WPForms
- Issues with creating user profile for a subscriber, but with different profile page and functionalities