1

I'm using a slightly modified copy of the Multi Site User Management plugin to keeps users synced across a multisite network, but have one problem with it. When a user's role is updated on the main site, the role is NOT updated on the sub site. In order for everything to work correctly, user roles must stay in sync.

I've been looking without success, so is there an action that runs when a user is updated? I know about the profile_update and wp_update_user functions / hooks, but neither of these work because the user role is updated via an external function. So I need a new way of always syncing user roles.

Any ideas?

16
  • What exactly does "external" function mean? You can include every file from every where, so including and triggering it during runtime on hooked functions will work.
    – kaiser
    Commented Aug 18, 2011 at 21:05
  • Sorry, that wasn't very clear. I just mean that the user role is updated manually via a function, and not from the user's admin page in WP.
    – Pippin
    Commented Aug 18, 2011 at 21:52
  • n/p. Why don't you then include the file and execute the function in the update hook?
    – kaiser
    Commented Aug 18, 2011 at 22:49
  • The update role function is done through the amember wordpress plugin, so I cannot modify it. So I really need a way of detecting when a user role is updated, or just a general way to always keep roles in sync. Perhaps a check that runs on a cron job.
    – Pippin
    Commented Aug 18, 2011 at 22:53
  • 1
    You could check for the hooks where the plugin(s?) add their actions and simply run some custom code afterwards.
    – kaiser
    Commented Aug 18, 2011 at 23:07

3 Answers 3

2

I've found a way around the problem. It's not a "fix", but rather a way to get around the problem of needing synchronized user roles. Instead of trying to make all user roles match up, I decided to only check the user roles for the main site. see my function below for how I did it:

/*
* Function to check a specified user from a subsite against
* the role of that same user on the main site
*
* @param int $site_to_check the id of the site to check the user's role from
* @param int $user_id the user's id to check
*/
function cgc_check_for_citizen($site_to_check = 1, $user_id = null) {
    if(!isset($user_id)) {
        return false;
    }
    $citizen = false;

    global $blog_id;

    if($blog_id == 1) { // we're on the main site
        if(user_can($user_id, 'read_citizen')) {
            $citizen = true;
        }
    } else {
        switch_to_blog($site_to_check);
            if(user_can($user_id, 'read_citizen')) {
                $citizen = true;
            }
        restore_current_blog();
    }
    return $citizen;
}
1

I'm thinking if you can't figure it out, no one can. ;(

Anyway, this plugin automatically updates user roles for sub-sites based on the main site. So maybe you can extract the code:

http://wordpress.org/extend/plugins/user-role-editor/

1
  • Ha right . . . Thanks for the plugin. That one is new to me. Maybe it work
    – Pippin
    Commented Aug 15, 2011 at 18:58
0

Hi i'm not sure whether this plugin will help you or not. But give it a try. Try scribu's proper-network-activation plugin

1
  • Nope, sorry. I need a way to trigger a function (from which I can update user roles) anytime the role of a user on the main site is changed.
    – Pippin
    Commented Aug 15, 2011 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.