Support Forum

Password Protect forum?

LI lisalew
lisalew
Member

I am using s2member, which integrates great with simple press.  However, I want people to be able to purchase access to one or more forums.  I can’t use roles to determine usergroup, because a person can only have one role at a time.  I could manually add each member to a usergroup, but this could be extremely tedious (several will sign up each day, and it will be hard to match a username with a paypal purchase, etc).  Is there a way I could just password-protect a board so that I could give a password out to everyone who is supposed to access it, instead of basing access on wp role?

 

If it can’t be password protected, is there a function that I could use that would add a username to a usergroup? s2member allows me to redirect to a url after successful purchase, so maybe I could pass a username and it could be added to the correct usergroup?

17 Answers

New Answer

MP Mr Papa
Mr Papa
Member

you can password protect any wp page… that is built into wp…  just edit the wp page the forum appears on and choose to password protect it…

if you want to password protect each individual forum, you will need to use usergroups and permissions to accomplish this…

yes, absolutely there is an api for adding members to a usergroup…  just use:

sfc_add_membership($usergroup_id, $user_id);

in 5.0, with full plugin api, you could probably write a short plugin to help you out…

LI lisalew
lisalew
Member

I want to use this: sfc_add_membership($usergroup_id, $user_id);

to add a user id to a usergroup after a successful paypal purchase.  I will be able to get the user id from the query string in my success page url (myreturn url is =”my-thank-you-page/?userid=%%user_id%%”).  So would I simply use the following syntax in my success page (after installing a plugin that allows php in posts). 

 

<?php

      $usergroup_id=xyz;

      $user_id=$_REQUEST[‘userid’];

     

      sfc_add_membership($usergroup_id, $user_id);

     

      ?>

 

This seems too easy, but it would be great if it worked!

MP Mr Papa
Mr Papa
Member

couple things… 

usergroup id will be an integer number…

if your are going to get the user id from $_REQUEST, make sure you sanitize it before calling the add membership routine so someone doesnt try some sql injection on you…

LI lisalew
lisalew
Member

I really appreaciate your help because I know this level of support isn’t part of the bargain.  I’m not able to find where this function sfc_add_membership() is defined (I ran a search on the simple press files, and it isn’t coming up for some reason).  I’m not familiar with php, but once I find the function, can I just copy and paste it above the code (in the post above) in my php file, and then save my file anywhere?  Or do I need to incorporate it into the simple press plugin by using the “hooks” you’ve mentioned before? 

 

Maybe there is a php programmer out there who I could pay to do this since I’m so clueless….

MP Mr Papa
Mr Papa
Member

its in simple-forum/library/sf-common-functions.php

you will want to include that file and then call the function with your arguments for the usergroup id you want to insert into and the user id of the user…

LI lisalew
lisalew
Member

THANK YOU!  I can’t even believe how awesome your support is!

MP Mr Papa
Mr Papa
Member

np. glad to help. Thanks for the kind words!  good to hear now and then!

LI lisalew
lisalew
Member

I am using this function, sfc_add_membership(), to automatically add users to a specific forum when they register for a class.

The function is adding the user to the proper user group (like when I go and look at the usergroup after the code runs, the username is in the proper group).  However, the user is not actually able to access what they should be able to access unless I delete them out of the usergroup and re-add them via the admin Usergroup area.  Is this function missing an important step?

YS Yellow Swordfish
Yellow Swordfish
Member

Not ignoring you. Want to get Steve involved in this one and he should be around later.

LI lisalew
lisalew
Member

Thanks, I’ve had a terrible time with usergroups today.  Even when I delete the users and re-add them manually through the Usergroup area, some still don’t have access (but some do).  If I do it a few times (delete member and add again), it seems to fix the problem most of the time. 

LI lisalew
lisalew
Member

Yellow Swordfish said

Not ignoring you. Want to get Steve involved in this one and he should be around later.

Just bumping this in case Steve missed it…any idea why this sfc_add_membership() function isn’t working properly? (Users all show up in the usergroups, but some can’t access the forum) 

MP Mr Papa
Mr Papa
Member

yeah, missed it… sorry…

I just tested it again within normal forum operation (ie from the manage usergroups panel) and cant find anything not working…  havent tried from a non standard place but should behave the same…

what do you mean by it adds them to the usergroup but they dont get the permissions? by that, I mean how are telling this?

are you limiting usergroup membership to a single usergroup?  are you using forum ranks for auto promotion to usergroup?

does the user have multiple usergroup permissions? because there was a bug in this area fixed this past weekend so need to make sure you are on latest version in trunk.

LI lisalew
lisalew
Member

Basically, after a user pays for access to a specific forum, a file runs that calls this function and adds the user to the usergroup he or she paid for.  Several people were automatically added this way.  Some were able to get into their forums, some were not.  For instance, user Jennifer signed up and was added to the “Photographer” usergroup (which gives permission to view the “Photograher 1 Forum”.  I could see her name listed in the “Photographer” usergroup, but when I logged in as her, I confirmed that I could not access the “Photographer 1 Forum.”  I had to remove her from the usergroup and manually add her again for her to actually have access.  In some cases, I had to create a whole new usergroup in order for them to be able to get access (simply removing and adding again didn’t help in every case). 

 

Sorry if this sounds confusing.  I will test the fix and see what happens.