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
tobbe
Member
Free Members
sp_UserOfflineSmall Offline
Feb 20, 2013 - 4:04 pm

Melanie Nelson said

These are the instructions we used to map the membership levels to Simple:Press groups.

How to configure Simple:Press with a membership plugin?

 

You can assign logged-in users specific forum access by going into Forums > User Groups > Manage User Groups, find the forum you want to add members to and click "Add Members"

 

Hi Melenie, 

Thanks for the tip. However I already know about this and although a technical valid solution it is rather impractical as I will be selling quite a few products and WP is limited to only having 1 active or primary WP user role at a time.

This means that I would need to create a WP user role for every possible product combination that I want to attach a product forum to which is doable with very low number of products. When you go over 3 or 4 the number of WP roles needed just goes nightmarish unless you know of a way to make WP recognise multiple WP Roles at the same time (allow to stack and get recognised)...

 

Or perhaps you meant that I can add the manually? (It's getting late here and I really should goto bed...)

To manually add them does seem like the simplest solution right now however it is prone to me having to be there doing that as well as being human error related. A code solution for me is of course the best possible solution to this...

Avatar
Melanie Nelson
Member
Free Members
sp_UserOfflineSmall Offline
Feb 20, 2013 - 4:12 pm

But that's what I was saying before...you DON'T attach the groups to user ROLES.  You use a custom user meta field to create membership levels.  Forget the roles - act like they aren't even there.  WordPress *does not* support multiple roles for a single user.  Use the membership levels you create to map to the forum groups.  Then all you have to do is create membership levels that have access to whatever, and map those levels to the group permissions in the forum.

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Feb 20, 2013 - 7:00 pm

watching interestingly! ;)

Avatar
tobbe
Member
Free Members
sp_UserOfflineSmall Offline
Feb 21, 2013 - 1:03 am

Melanie Nelson said
But that's what I was saying before...you DON'T attach the groups to user ROLES.  You use a custom user meta field to create membership levels.  Forget the roles - act like they aren't even there.  WordPress *does not* support multiple roles for a single user.  Use the membership levels you create to map to the forum groups.  Then all you have to do is create membership levels that have access to whatever, and map those levels to the group permissions in the forum.

I tried setting this up doing as you said and ignoring WP USER roles, didn't work but that could possibly be because the groups plugin that I use to create and controll access does so by using WP user capabilities and doesn't inject custom user meta fields?

Avatar
Melanie Nelson
Member
Free Members
sp_UserOfflineSmall Offline
Feb 21, 2013 - 9:08 am

It could be.  Like I said, we're using WishList Member, and it creates custom tables for this extra user info (instead of just adding to the usermeta table).  but WishList isn't a free plugin.  If you wanted to accomplish this for free, then you'd have to use a free plugin (and look at your database tables to see where this info is being stored), or write some code to look at the custom user meta field and map it to the group permissions in Simple:Press.

I don't know what plugin you're using, but you can add your own user meta fields to the user profiles like this:

Add Extra Profile Information

And then you'd have to write some code to make Simple:Press recognize that these meta fields can be mapped to user groups. (Something I can't think of off the top of my head right now, but it can be done)

You might look at the docs for the groups plugin you're using to see how they handle it.

 

ETA: an alternative method would just be to edit the Simple:Press template file.  You could leave your "private" forums with "public" access, and then add a conditional in the SimplePress theme to check the usermeta for the positiv presence of the membership level that can access that forum.  if it's not there, then skip even showing it. (That might actually be easier)

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Feb 21, 2013 - 9:56 am

An interesting appendix you added to that post....

andy-signature.png
YELLOW
SWORDFISH
Avatar
Melanie Nelson
Member
Free Members
sp_UserOfflineSmall Offline
Feb 21, 2013 - 12:03 pm

You know what's funny is that I was having an issue with the same thing (which is why I was reading this thread) and I solved my own problem with that "appendix".  Off to give it a shot now :)

Avatar
tobbe
Member
Free Members
sp_UserOfflineSmall Offline
Feb 21, 2013 - 12:34 pm

Melanie Nelson said
It could be.  Like I said, we're using WishList Member, and it creates custom tables for this extra user info (instead of just adding to the usermeta table).  but WishList isn't a free plugin.  If you wanted to accomplish this for free, then you'd have to use a free plugin (and look at your database tables to see where this info is being stored), or write some code to look at the custom user meta field and map it to the group permissions in Simple:Press.

I don't know what plugin you're using, but you can add your own user meta fields to the user profiles like this:

Add Extra Profile Information

And then you'd have to write some code to make Simple:Press recognize that these meta fields can be mapped to user groups. (Something I can't think of off the top of my head right now, but it can be done)

You might look at the docs for the groups plugin you're using to see how they handle it.

 

ETA: an alternative method would just be to edit the Simple:Press template file.  You could leave your "private" forums with "public" access, and then add a conditional in the SimplePress theme to check the usermeta for the positiv presence of the membership level that can access that forum.  if it's not there, then skip even showing it. (That might actually be easier)

Im not a programmer so unfortunately this is a bit above my head so I don't quite get this :/

Avatar
Melanie Nelson
Member
Free Members
sp_UserOfflineSmall Offline
Feb 21, 2013 - 4:18 pm

Well, the link I posted tells you how to add extra fields to the user's profile.  That example uses address fields, but you can rename them to membership levels.  As an admin, you can check the boxes for te membership levels, and then each member has a user_meta in the database saying which membership level they belong to.

The idea is then that you can run a check against the user_meta to see if the Forum ID (that you've set for a level) matches the forums on the site.  If they match, user has access, and there you go.  If they don't, then the forum isn't even pulled in.

If you're not a programmer, then you might need to hire someone who can do that for you.  I'd tell you, but I haven't figured out the "make it hide forums" part yet XD

Avatar
Melanie Nelson
Member
Free Members
sp_UserOfflineSmall Offline
Feb 22, 2013 - 11:55 am

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:

add_action( 'woocommerce_order_status_completed', 'add_user_to_forum' );
function add_user_to_forum( $order_id ) {

    $order_user_id = get_post_meta( $order_id, '_customer_user', true ); // gets the user ID for the order that was passed

    if ( $order_user_id ) {
      $user = new WP_User( $order_user_id );

     // Get products by $order_id
     $product_meta = get_post_meta ($order_id, '_order_items', true); // gets everything in the order
     $ids = array(); //set up the array of product IDs for later use
     foreach ( $product_meta as $product ) {
        $search = get_post_meta($product['id'], 'usergroup_id', true);
        if(!$search) continue;
        $ids[] = $search; 
     }

     //now we have an array of forum IDs from the sale, if any
     if($ids) {
       foreach($ids as $id) {
          sp_add_membership($id, $order_user_id);
       }
     }
   }
}

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

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