Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter

In this Discussion

automatic assigning roles

This discussion is related to the Vanilla jsConnect addon.

Hi!

Is it possible when using jsconnect and php to assign users to a certain role? In the example the name, email etc. is passed. But there is no documentation about what else could be passed.

Thanks,

Jeroen

Tagged:

Best Answers

  • KezzBKezzB newb
    Answer ✓

    I just spent the whole day trying to figure this out and finally got it going.

    As mentioned above, you need 2.1 branch.

    After that it's actually super easy once you find it.

    You just add to your config.php this setting:

    $Configuration['Garden']['SSO']['SynchRoles'] = TRUE;
    

    Then your array of roles will carry through perfectly.

    I'm using WP Vanilla Connect plugin on WordPress, so I just changed it from this:

        $user = array(
                'uniqueid'  => $current_user->ID,
                'name'      => $current_user->display_name,
                'email'     => $current_user->user_email
            );
    

    To this:

         $user = array(
                'uniqueid'  => $current_user->ID,
                'name'      => $current_user->display_name,
                'email'     => $current_user->user_email,
                'roles'     => "Member,Moderator"
            );
    

    Now it's working great.

    I'm also going to have it check on my user's levels on WP first, as I'm using the s2Member plugin, so then I can create a tiered access system in the forum.

    Perfect!

    HalfCat
  • KezzBKezzB newb
    Answer ✓

    Thought I'd also share the code I used to synch my WP s2Member roles with my forum in case anyone else finds it useful:

    //get current user role
            if(current_user_can("access_s2member_level4")){
                $thisrole = "Level 4";
            } else if(current_user_can("access_s2member_level3")){
                $thisrole = "Level 3";
            } else if(current_user_can("access_s2member_level2")){
                $thisrole = "Level 2";
            } else if(current_user_can("access_s2member_level1")){
                $thisrole = "Level 1";
            } else if($current_user->role=="subscriber"){
                $thisrole = "Free Member";
            } else {
                $thisrole = "";
            }
    
            // Map the current user values for jsConnect
            $user = array(
                'uniqueid'  => $current_user->ID,
                'name'      => $current_user->display_name,
                'email'     => $current_user->user_email,
                'roles'     => $thisrole
            );
    
    HalfCat

Answers

Sign In or Register to comment.