How synchronize a user change of role (on the master site) to a subsites that already exists ?

Hello guys !
Well, that is my scenario :
i have a multisite.
Mastersite with PROSITES & MEMBERSHIP installed.
- (Say that the roles lists are identical on mastersite and subsites, and exist.)

- [Moreover, my aim is that I want filter menu's elements, functionnalities etc with the ROLES. So, for example, on his subsite, user with "LEVEL1" doesn't see the menu/functionnality "create a poll" but a user role "LEVEL2" can see it.]

So, in short :
When a user (visitor) goes to the mastersite, he subscribes to "create a new site" via PROSITES.
Automaticly, this new (creator) user has a "LEVEL1" on the mainsite and a "LEVEL1" role on his new subsite.
OK that works.

Next, via Membership subscriptions page, the user chooses a subscription (I have associatedg each subscription with a specific role).
So, when he chooses a subscription, his role changes to "LEVEL3" for exemple.

--> But here is my problem, this role changes only on mastersite and not on his subsite.

So I only need a little code hack (or other solution?) in order to synchronize/copy (?) the role of a user on mastersite and his subsite at moment of subsciption change in MEMBERSHIP.

I try to be more clear, for example :
1) subsite creation on mastersite with PROSITES form.
2) "role1" by default is set for this user on mastersite and his new subiste.
3) the user change his subscription plan in MEMBERSHIP's form (on mastersite) where subscription level2 is associated with "role2" .
4) then in Mastersite, role for this user has been correctly changed to "role2".
5) BUT this user on his subsite always has "role1" set...
6) So, here i need that a hack or code or plugin do that : "automaticly take actual user role (for this user) on mainsite and copy to his userrole in the subsite of the concerned user".
7) In fact, I need that roles on subsites are ALWAYS identical to roles in the mainsite for a user.

Thus, as admin on mainsite, i can change rules and functionalities for roles and it will change the rights of users (by roles) on the subsites.

Sorry, it's a little bit complicated to explain.
All works, I just need this little hack.

Can someone can has an idea/example to correctly do it ?

If you need more details, don't hesitate to ask me.
In advance, 1000 thanks you !

For developpers, what code i need:
- In membership, when a user choose/click on one of subscriptions :
(At this moment, when user clicks a subscription ("Sign up"), the associated role/subscription Membership (in rules) is already automaticly set in mainsite)
- get his role in Mastersite
- copy it in the subsite that this user own.


  • boll

    thanks to @aristath, I understand my mistake... (if my user has multiples subsites, whit this script, userrole will be changed (and will be the same) on all of them even if the user had diiferent subscriptions on each of them).

    In reality, I think I don't need to copy roles between mainsite and subsites for a user, no synchronization.

    Rather my need is : When a user clicks on a "sign up" offer (that is associated with a specific role in rules), simply "copy this 'new' role to the actual userrole on this subsite and that's all.

    Thus, between mainsite and subsites there is no synchro, but a same user could have specific role on each of his subsites, and I (admin) could manage rights via mainsite for this roles.

    Another script @aristath ?



  • aristath

    Hello again @boll,

    Users in WordPress cannot have more than 1 roles.
    So if they get this new "role, they will no longer be admins on their site.

    What is it that you want to achieve exactly? Why are you using Pro-Sites AND Membership? Won't pro-sites simply do what you need? In most cases all it takes is a couple lines of custom code to extend it to do what you're looking for... Or simply a different way of business structure.
    What do you need membership for?
    Can you please provide some more details about your use-case?

    Please advise,

  • boll

    hello @aristath

    Sorry for this late response. I have tried some things with some plugins...

    Today my need is really :
    - automaticly change the user's userole on his subsite when he changes of submision with Membership.

    - a user create his account + subsite (with prosites). -> userrole on mainsite = SUBSCRIBER, userrole on subsite = i choose EDITOR).

    => so his subsite and account are ok.

    - I want he subscribes via membership ir order to manage his access.
    Then I "force" him to subscribe via membership.
    In membership options, level access, we can use the associate role options in order to change the role when the user change for this level access.
    My problem is that it changes the user role on Mainsite, but what i need is that it could change on SUBsite.

    I need the subscription with access level change userrole on subsite.
    In this project, each user that has created a subsite, can have a userrole on his subsite depending subscription he chooses and pay.

    Have you an idea how achieved it ?

    Thanks you in advance and have a good day !

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.