Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
coding-topic
Function or hook to auto-add user to forum based on a conditional
Avatar
Melanie Nelson
Member
Free Members
sp_UserOfflineSmall Offline
Feb 21, 2013 - 8:31 pm

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 :)

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Feb 21, 2013 - 8:45 pm

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... :(

Avatar
Melanie Nelson
Member
Free Members
sp_UserOfflineSmall Offline
Feb 21, 2013 - 8:53 pm

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)

 

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Feb 21, 2013 - 9:03 pm

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..

Avatar
Melanie Nelson
Member
Free Members
sp_UserOfflineSmall Offline
Feb 21, 2013 - 9:15 pm

Oh that makes things so much easier!  Thank you!

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Feb 21, 2013 - 9:26 pm

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)

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 619
Members: 17361
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10127
Posts: 79625