Sync User Roles Across WordPress Multisite Network



Need to synchronize users across WordPress Multisite domains, for instance to update roles & capabilities on a membership subscription website? Here's how.


Scenario: You share users across a WordPress Multisite network, and maybe for instance are using the Multisite User Management plugin to add new site subscribers to the network mapped master site or sub-sites. So far so good (and you can even share a single cookie using the Root Cookie plugin, by the way ;)).

But.

Setup Unmanaged VPS (4 Noobs!) ... with vpsBible
Secure WordPress. Properly. ... with wpCop, the platform's dedicated security website
Olly 'the_guv' Connelly's vpsBible.com site and 'WordPress 3 Ultimate Security' book.

Let's say a user role changes across those related sites, for example when a registered user becomes a subscriber? This will be an issue for master domains using sub-domains, for example, for the purposes of the ‘silo' SEO technique.

User “Bob” is logged into site “Foo” and then subscribes for your content. Hurrah!

So Bob becomes a special role, something like a Member or whatever level you set up with your membership plugin … on site “Foo”, that is.

The problem is, with capabilities being site-specific with WP Multisites, site “Bar” keeps Bob as a subscriber. Bummer.

The answer: to update user roles across a WordPress multisite network, pop this code in your functions file and Bob is now your uncle:-

Don't thank me. This (slightly abridged) code is from ‘brasofilo', some dude from Brazil (viva la revolution!):-

http://wordpress.stackexchange.com/questions/91745/how-to-sync-roles-across-multisite

3


About the Author:

Olly Connelly (yeah, that's me) blogs at guvnr.com, polices WordPress security at wpCop.com and helps noobs build web servers at vpsBible.com, so if you've got sleeping problems you know where to come.

Discussion

  1. Brian  February 11, 2014

    Hey Olly

    This might be a dumb question but, from what you’re saying here, I dump this in to my wp_config. Then if I have a member that is listed as a subscriber on one of my subdomains, that role will pass to all other subdomains in my network even if the member is not listed in another subdomain user list right?

    If it doesn’t do this then do you know how I can get that to work? basically push a role to all users to have access on every site.

    Thanks!

  2. Olly  February 3, 2014

    @IG, sorry for delay you got spam-canned!

    “when I upgrade a users details on one subsite it still remains unchanged on the other.”

    Are you changing user details at the Primary site? A change there should affect all cookie-sharing sites.

    “Iā€™m using the S2member plugin …”

    Me too. Nice init!

    ” … and the user-details that are changing are their custom capabilities”

    Aaaaaaaah. Hmmn. Ooooh! Buggered if I know, to be honest. Ask the big tomatoes at s2Member, if you’ve not already. I don’t see why ANY meta should not correctly update across your cookie-sharing sites.

  3. I G  January 10, 2014

    Thanks for posting this code – it’s exactly what I’ve been searching for! šŸ™‚
    However, I’m having trouble getting it to work. I’ve pasted the code as-is on all my functions files on my wp multisite and also used the Root Cookie plugin as you suggested.
    When I move from subsite to subsite my user-login-status carries over as expected, but when I upgrade a users details on one subsite it still remains unchanged on the other.
    I’m using the S2member plugin, and the user-details that are changing are their custom capabilities (their roles remain unchanged), I wonder if this might be an issue…
    Any ideas would be much-appreciated – I’ve been tearing my hair out over trying to sync wp users over the multisite! šŸ˜›
    Best wishes,
    I G

Add a Comment