Support Forum

Function or hook to auto-add user to forum based on a conditional

MN Melanie Nelson
Melanie Nelson
Member

I’m full of questions today :)

Okay, so I know you can set up a private forum, and you can bypass group permissions by manually adding a user to the private forum access list (via Forum > User Groups > Manage User Groups and adding a member to a user group’s “Selected” list) – but the key word is “manually”.  You have to go in and add each person to the list yourself.

I’m wanting to write a function that hooks into this, so when a particular action is taken (i.e. someone purchases access to the forum), I can update the database table for the user group and add the user to it.

Is there already a hook I can tie into (or code somewhere that someone’s already done this with, or something similar) that will allow me to update that table? (I *think* it’s _sfmembers.user_id = _sfmemberships.user_id AND _sfmemberships.usergroup_id = _sfpermissions.usergroup_id AND _sfpermissions.forum_id = _sfforums.forum_id that maps the user to the forum through a group).  I could use a WP custom select query to update the _sfmemberships table and add the member there (and I think that would be the only spot I’d need to add a row?) but if there’s already a hook or something in place for this, that would be great to know about :)

5 Answers

New Answer

MP Mr Papa
Mr Papa
Member

sorry, missing what you want to do…

add a new user?  add a new membership?  add user to usergroup?

sorry, been a long, long week… :(

MN Melanie Nelson
Melanie Nelson
Member

s’okay – it’s been a long week here ;)

I want to add a new row to the sfmemberships to add a user to that table. (basically add a user to the usergroup with a behind-the-scenes function instead of manually going to the Usergroups in the admin and doing it)

 

MP Mr Papa
Mr Papa
Member

so just call:

sp_add_membership($ug_id, $user_id);

of course, pass the proper ids…  ;)

keep in mind that this will obey the single membership option setting you have set for your forum…

we are concentrating on the api in the codex for the display template functions first… then will get to this portion of the API and get them documented too..

MN Melanie Nelson
Melanie Nelson
Member

Oh that makes things so much easier!  Thank you!

MP Mr Papa
Mr Papa
Member

np. glad to help. of course, there is a corresponding

sp_remove_membership($ug_id, $user_id)

sp_check_membership($ug_id, $user_id)

sp_reset_memberships($user_id)