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]
- How to do I get a list of active plugins on my wordpress blog programmatically?
- Why are my roles not visible in a Multi-site/Network?
- How to add field for new site-wide option on Network Settings screen?
- How to tell if a plugin is multisite compatible?
- How to run Two WordPress blogs with different themes and with single database and same content
- Disable text tab on WordPress text-editor
- Allowing Custom Capability to Manage Plugin Options
- Prevent multisite sites from using a plugin
- Prevent user creating new users with specific roles
- How do I add a widget programmatically to a newly created site (WPMU) within a plugin?
- Duplicate settings of master blog to slave blogs in WP multi-site installation
- Woocommerce: change user role after completing order
- WordPress network: set themes and plugins for new blog
- What is the function to get plugin base url in multisite?
- How can I get a list of plugins and which blogs are using them?
- Multiple Domains with Single WordPress Install
- Removing WordPress Plugin Menu Item for a specific user
- Multisite mu-plugins site-specific directory
- Allow Facebook to preview posts before published
- Multisite Backup Plugin [closed]
- Keep user’s privileges on accessing contents in JSON response
- Multisite Widget/Content
- update_user_meta add value on the top on existing value
- Set user ID at time of wp_create_user
- Multisite installation but do plugins always have to be multisite compatible?
- Assign role to user on first login, if they are first (after admin)
- Auto delete WordPress users according to time
- Make a user administrator to a sub directory site and a contributor to main site in multisite network
- How to associate more than one user to a post?
- Portfolio + Blog: multisite or plugin?
- Error shown for Trying to get property ‘roles’ of non-object in WordPress After Content for User Roles
- Multiple sites, multiple countries
- Disable plugin per user role
- How to create user groups and allow custom posts and plugin modify/access to specific group?
- How can I disable the multisite feature of WordPress 3.0?
- wp_set_auth_cookie causes 403 error in the wooCommerce checkout
- External Domain on WordPress Multisite
- Multiple domains issue
- Is there a way to get plugins and themes not built for multisite to work on a network subsite?
- Why shortcode always displayed after footer not in body
- WordPress Multisite: Programmatically Activate / Deactivate a Plugin of a Specific Blog
- Specific way to allow WordPress users to view their current password? And edit it?
- How to see which sites use my installed plugins (wordpress multisite)
- Redirect Plugins.php to New Plugin Page
- Do WordPress plugins suport multisite site?
- WordPress plugin for Limited days user
- can’t create user without email for an author after converting single site to multisite
- Hide fields in woocommerce settings
- implement custom roles in custom plugin
- Javascript embedded disappears for editors
- See which user role / capability is needed to use a plugin
- Need help with Task assigning and rewarding as currency which withdrawable
- the content of the uploads folder gets deleted periodically, how to figure out what causes it?
- Clean old users
- How to make this custom capability work? [duplicate]
- Simulate Update User button click
- Disable plugin for administrator
- How do I restrict a second admin certain access?
- Why my multisite is this slow? (stats inside)
- Update User Meta Via Ajax
- User Following System
- How to set plugin across network in multisite and modify it in one place?
- Any way to force a specific plugin to use single site tables in multisite installation?
- Every time I use wp_get_current_user() my plugin breaks
- Custom User Role
- WordPress MU LDAP connection failures
- Plugin menu replaced by another plugin?
- WordPress internationalization + domains
- Plugin De/Activation Not Firing On MultiSite install
- Zigconnect Plugin: Allowing editors to remove connections
- how to embed a crop feature for cropping images uploaded by the user
- 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