I have a multisite plugin that operates at the network level. It's job is to assign additional roles to different sites across the network. For example, I have three sites.
- Course (LMS)
Users can sign up for either the Library or the Course. When a new user account is created, I have created a plugin that distributes additional roles for the other sites accross the network.
For example: A new user signs up on the library, a new role is setup for the CRM site. - or - When a new user signs up on the course, new roles are setup for both the CRM and the Library.
This later case is where I"m having the challenge. My plugin functions at the network level (
Network:True in the plugin meta).
Now here's where it gets funny. On the Library site, access is controlled by a membership plugin that adds a user meta value. The access to the library is not controlled by a user role or capability, it is exclusively defined in the user meta for that site.
The membership plugin and its user meta info are exclusive to that one site. (Of course it's all accessible via the database, but I'll discuss the cons to this approach below.) Now there is an API and also RESTful API calls associated with this membership plugin as well. I've tried to call them from my network plugin, but have not had any success using wordpress wp_remote_get function. The plugin specific API functions come back as being non-existent at the network level, and a REST API calls creates an infinity loop. I even tried the
switch_to_blog() functions to see if that would make it act as if it was on that site. Nothing.
So my next attempt was to try and setup a secondary plugin on the Library website to listen for when a new user was created by the network plugin. I've tried access all three available action hooks
profile_update, and even
add_user_to_blog, but the site specific plugin doesn't even flinch when the network level plugin is doing it's thing. It's as if they are in two separate domains. So even though I should in theory have access to all the Membership API functionality that I need by having a plugin on the specific library site, I cannot get it to acknowledge when a new user is being added for that specific site from the network level plugin.
My next plan of action is to attempt either to create a Cron Job to check periodically for new user added to the site, or to hack the database directly, my reason for not wanting to do the direct database route is that I'm then bypassing all the built-in functionality of the plugin API. I'd much rather use the plugin's functions and features.