Fork me on GitHub
Current release is 2.1.6 (21 Nov 2014).

Users who have not yet upgraded to 2.1 should get security release 2.0.18.14 (1 Nov 2014). We will stop providing these security releases to 2.0 at the end of this year.

automatic assigning roles

jeroengjeroeng New
edited March 2012 in Vanilla 2.0 Help
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 New
    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!

    HalfCatUnderDogcassiofagundes
  • KezzBKezzB New
    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
«1

Answers

«1
Sign In or Register to comment.