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
Simple Press forum & category access from Wordpress Capabilities instead of User Roles
Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Feb 22, 2013 - 6:21 pm

we have built quite a powerful API into SP 5.x...  We just need to get it fully documented in the Codex and are working towards that end, with great help from BrandonC!

Avatar
tobbe
Member
Free Members
sp_UserOfflineSmall Offline
Mar 28, 2013 - 8:13 am

Melanie Nelson said
Okay, I got it. Probably not as "easy" and "automatic" as you'd like, but the hard part (FWIW) is done.  Keep in mind this is based on a site that's using a combination of WooCommerce, Simple:Press, and WishList Member - so you'll have to make adjustments.

In any case, for the forum, you have to set up user groups that are mapped to your membership levels.  The site I'm doing this on sells online classes, so each "product" is actually a bundle of other products that contain file downloads, access to private posts, and access to private forums.  (The idea of the forums is to provide a space for each course where the course instructor can go in and answer questions of her students.) So we have "User Groups" set up with names that relate to each course (so it's easy to know which membership level goes with which course)  In these forum permissions, we have no setting for pretty much everyone but Moderators and Administrators - so *everyone* is blocked.  Then we add a forum permission for each one, and add the proper user group with "Standard Access" for that forum.

i.e. we have several membership levels (set via WishList members).  For example, we'll say "Woodworking Members" and "Sewing Members". In our case, we are setting membership levels to match what courses are for sale, just so we can easily keep track of who goes with what, but you can name them whatever you want.  Wishlist Membership levels are mapped to Simple:Press groups (and these groups have the same name as the Membership Levels - again just to keep things straight) via the instructions I linked to in an earlier post in this thread.

We have forums for these courses - again, keeping the naming convention - "Woodworking" and "Sewing".

Both of these forums are set with "group permissions" that are pretty much blank - just allowing Administrator and Moderator access.  Everyone else is denied.  So you go to "Woodworking" and "Add Group Permission", and select "Woodworking Members", and give them "Standard Access".  Go to "Sewing > Add Group Permission", select "Sweing Members", and give them "Standard Access".

At this point, anyone who has a membership level of "Sewing Members" will be able to access the "Sewing" forum, but not the "Woodworking" one.

Hopefully I haven't lost you yet. :)

At this point, I wanted to trigger the addition of a user to a forum group permission set when the purchase of the forum access was complete.  I had to tap into the WooCommerce functions to do this.  The function looks like so:

<br />add_action( 'woocommerce_order_status_completed', 'add_user_to_forum' );<br />function add_user_to_forum( $order_id ) {<br /><br />    $order_user_id = get_post_meta( $order_id, '_customer_user', true ); // gets the user ID for the order that was passed<br /><br />    if ( $order_user_id ) {<br />      $user = new WP_User( $order_user_id );<br /><br />     // Get products by $order_id<br />     $product_meta = get_post_meta ($order_id, '_order_items', true); // gets everything in the order<br />     $ids = array(); //set up the array of product IDs for later use<br />     foreach ( $product_meta as $product ) {<br />        $search = get_post_meta($product['id'], 'usergroup_id', true);<br />        if(!$search) continue;<br />        $ids[] = $search; <br />     }<br /><br />     //now we have an array of forum IDs from the sale, if any<br />     if($ids) {<br />       foreach($ids as $id) {<br />          sp_add_membership($id, $order_user_id);<br />       }<br />     }<br />   }<br />}<br /><br />

So when the item is purchased (and the sale is successful and complete), the user is 1) set with the membership level, and 2) added to the list of users for the usergroup that's attached to the forum.  

Now again, our setup was a bit complex - what with three major components (forums, cart and memberships), but if you aren't SELLING forum access, then you could simply do everything I mentioned above (before the code) manually (give the user his membership level in his profile, and manually add the user to the group permission).  

At the most *basic* level, you could just take Simple:Press, create the groups and forum permissions as I mentioned above, and manually add users to each group (through User Groups > Manage User Groups, and click "Add Members".)  it's a manual process, but it would do the same thing without using WooCommerce and WishList Members.

I hope that helps - someone, at least :)  

(and thanks to Mr. Papa for making it *seriously* easy by telling me about that sp_add_membership tag...sweet!)

 

Hi Melenie it's great to hear that you solved your situation. My problem still persist and after having been around looking for alternative solution I have found that simple press is the best solution for me regardless if I manually need to add members to their right simple press group.

Speaking of which,

I wonder if you would be willing to have a look at my site and see if it would be possible to do what you did with your site on my site as well? I'll be happy to pay you for your work.

I really only need to have woocommerce and simple press work well together as my "free" user accounts needs to proceed through woocommerce checkout and I realise that they are "buying" a product although they don't have to pay for it.

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: 620
Members: 17365
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10128
Posts: 79626