hook_user, OG, and post-approval

TM
TM's picture
Joined: 04/24/2009
User offline. Last seen 1 year 48 weeks ago.

Hello all,

I have two roles: "member" and "guest". All registrations must be approved by the admin, based upon some user-supplied info at registration. When the admin approves, he will assign the user to one of those two roles. What I'd like to do is auto-subscribe members (not guests) to certain Organic Groups. I don't need a fancy module with a UI to select which groups, which roles, etc. I can hard-code it. Basically I just need something that assigns somebody with "Role A" to "Organic Groups A, B, and C". I am thinking that hook_user() is the way to go. However, how do I "capture" the approval process? I don't want this to run every time the account is edited, obviously (mostly because I don't want to re-subscribe someone if they choose to unsubscribe). Only when it is approved by the admin.

Anybody ever do anything like this?

Blessings
Tom

Therefore, as you received Christ Jesus the Lord, so walk in Him, rooted and built up in Him and established in the faith, just as you were taught, abounding in thanksgiving. (Col 2:6-7)

TM
TM's picture
Joined: 04/24/2009
User offline. Last seen 1 year 48 weeks ago.
Got it

I figured it out. hook_user() was the way to go. Its arguments include both $edit and $account, which are (respectively) the items the user is changing and the user object prior to save. I triggered off the "update" operation in hook_user(), and then determined if the roles and status have changed based off the data in $edit and $account. Then I called og_delete_subscription() or og_save_subscription() as needed.

Tom

Therefore, as you received Christ Jesus the Lord, so walk in Him, rooted and built up in Him and established in the faith, just as you were taught, abounding in thanksgiving. (Col 2:6-7)

G&G Moderator
G&G Podcast Host
NonProfit's picture
Joined: 06/06/2007
User offline. Last seen 4 hours 49 min ago.
Thanks

Tom, thanks for the followup post! -NP

G&G Moderator
G&G Podcast Host
micah's picture
Joined: 06/21/2007
User offline. Last seen 2 weeks 3 days ago.
Multiple Mandatory Groups by Role

For future reference and anyone not wanting to write their own hook_user() code to solve this, you might want to try the Multiple Mandatory Groups by Role Module, which might also be the winner for longest module name ever. I've used it in the past and it works quite well for what you've described here.