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]
- WordPress Multisite Profile Picture Sync Error with Nextend Social Login Plugin
- Hide fields in woocommerce settings
- implement custom roles in custom plugin
- Allow a particular user to access a particular plugin?
- Multisite – Cloning CPT pages + content (including ACF Flexible Content) from site to site
- Javascript embedded disappears for editors
- See which user role / capability is needed to use a plugin
- WP Forms not displaying,becomming an fatal error
- Can we hide a certain user in WP?
- Easily adding multiple existing users to a multisite site
- Can I edit multiple sites with an online WordPress account?
- disable plugin activation on no multisite
- Fatal error: require_once(): Failed opening required
- Need help with Task assigning and rewarding as currency which withdrawable
- How to Fix WordPress multisite woocommerce 403 file error
- How to display total user count by specific role in WordPress as statistics?
- How to capture hidden values with Gravity Forms
- the content of the uploads folder gets deleted periodically, how to figure out what causes it?
- Clean old users
- After reading 3 story by user ask for subscription popup
- Allow editor user to full permission to access plugin settings
- Creating one user access account for all the multiple sites
- User updating their profile wipes my custom fields
- Allow a page to be edited by a specific custom role
- Comment restrictions Wodpress
- How to use get_blogs_of_user?
- How to make this custom capability work? [duplicate]
- How to create different views for different user roles?
- How To Export User’s Custom Fields in CSV or XLSX
- Reverse count page view and show on other page
- Public WP website with one area just for members
- Get all user meta_keys and then group users by matching values
- On button click, redirect users to registration page instead of another page
- Multisite converted to Single Site can’t add new plugins or new themes
- How can I disable access to plugin settings in wp admin for other roles
- Searchable Semi Random Number Generator on User Profiles
- How do I run my custom function in my plugin when a wordpress user is deleted?
- Remove dashboard links from wordpress
- Copying content from my other websites
- How to show private pages based on a user’s role?
- How can I store user preferences in WordPress and retreive them later?
- Simulate Update User button click
- Disable plugin for administrator
- Install/Enable/Activate plugin on multisite without access to master site
- how to add navigation icons in specific template?
- How do I restrict a second admin certain access?
- Why my multisite is this slow? (stats inside)
- Update User Meta Via Ajax
- Category as Subdomain for One WP Install
- User Following System
- How to get the total count of Favorite/Favorited authors
- How to set plugin across network in multisite and modify it in one place?
- Restrict role to use a plugin
- Update javascript URL in header – Domain Mapping Plugin [closed]
- Implementation to count page visits of unique visitors based on a cookie
- How to see in Edit Comments if comment is from User and her Roles
- Renamed plugin folder and when I changed back nothing was activated
- How To Add Code To WP Without Plugin or Functions
- Custom User Notice Upon Login
- Any way to force a specific plugin to use single site tables in multisite installation?
- Why user profile update creates Additional Capabilities
- A different role for each site in a multisite
- How can I save cookies to members
- How to make wp multisite subdomain exist search
- How to Call Function From Separate WordPress Install on Same Server?
- Paid Memberships Pro, Display User Limit
- How to prevent authors from editing their post count?
- Overwrite user role
- Confusing problem with displaying message recipient metadata
- Specific plugin script not working on subdomain
- Coming soon pages with rest of site in maintenance mode
- Query Shortcode from a multisite to appear on a different site?
- Every time I use wp_get_current_user() my plugin breaks
- How to enable Admins to see Plugins