Instead of relying on switch_to_blog or reaching into the site from the root blog/elsewhere, consider instead using a queue/job system. This way you don’t limit the max number of sites you can have based on how many sites PHP can get through before the time execution limit.
In order to do this, you’re going to need a way to store the details of the job to be done ( assign role X to user Y ), as well as a cron job that runs regularly that can pick it up.
This way, the cron job runs in the context of the site, not the root blog, allowing you to use filters that plugins can hook into, specific to that site.
I would recommend using a custom post type to store the job entries, deleting the posts as the work is done by the cron job. This also gives you a free pending job list if you give declare the post type as 'public' => false but give it a UI anyway
Related Posts:
- Multisite – maximum number of users with specific role
- 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]
- 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 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
- 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 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]
- 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
- 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
- How to order users alphabetically by name? in plugin UPME
- Run only on plug-in activation instead of wp_head
- Users Ultra: Hide asterisk for required registration fields?
- How do plugin updates work?
- Allow non-admin users to access plug-in
- Automatization for automatization
- How know the “admin” blog from wordpress multisite?
- Different email notifications (about pending posts) to different users