• Resolved VERYA Inc.

    (@veryaca)


    Hi!

    First off, I love this plugin.

    Question: is there a hook, a function, a filter I can use to add a user to a specific group? I’m using your plugin as the forum feature of our site, and would like to be able to add a user to a group programmatically.

    For example: when I user sends an email via a form, I want to add that user to a specific group.

    I know you can’t help with the form part. That, I will take care of. I want to know if I can call something similar to:

    add_user_to_asgaros_group($user_id, $group_id);

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter VERYA Inc.

    (@veryaca)

    Looking at your core code, I think I may have found what I’m looking for:

    AsgarosForumUserGroups::insertUserGroupsOfUsers

    Would that work?

    Plugin Author Asgaros

    (@asgaros)

    Hello @veryaca

    Yes, you are basically correct. This implementation is unfortunately very old and a bit tricky, so you have to be aware of something:

    • In the first parameter you pass the ID of the user
    • In the second parameter you have to pass an array of usergroup IDs of which the user should be a member of

    Take into account, that this has to be the full list. So for example if the user currently belongs to group 1,2,3 and you now pass 4 to it, the user will not belong to 1,2,3 anymore. Instead, you have to pass 1,2,3,4 to it.

    Confusing, I know, and I should rewrite that one day.

    Thread Starter VERYA Inc.

    (@veryaca)

    Fair enough, I’ll try an work things out. Is there a way I can get a list of groups a user belong too? That way, I’ll merge the new ID to the existing one before saving it again.

    That being said, where is the data saved in the DB? In the wp_usermeta table? I couldn’t find it.

    Thread Starter VERYA Inc.

    (@veryaca)

    Again, I got my answer by looking at your code. I can use AsgarosForumUserGroups::getUserGroupsOfUser($user_id, 'ids'); to fetch the user groups, and than add to it (merge).

    Thanks!

    Plugin Author Asgaros

    (@asgaros)

    Correct, that function should do the trick! ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add user to group’ is closed to new replies.