Support Forum

Simple Press forum & category access from WordPress Capabilities instead of User Roles

31 Answers

New Answer

TO tobbe
tobbe
Member

Before proceeding I just want to check that you guys understand my suggestion on how I see this working from an “admin” point of view?

Secondly perhaps this can shed some light upon the “coding/programming” point of view?

http://codex.wordpress.org/Function_Reference/current_user_can

So in the Simple Press user groups setting another option is added as described above where the function you have in place is something similar to the link above.

ex.

if ( current_user_can('moderate_comments') ) {
echo 'The current user can moderate comments';
}

In my suggest case I would define a user capability. Inside of the Simple Press Groups Permission, there is a setting where I can define the parameter for what the if code looks for so the logic would look something like this

if ( current_user_can('mycustom_capability') ) {
echo 'Grant Permission to the simple press group ';
}

ex. Multiple capability check

if ( current_user_can('mycustom_capability1', 'mycustom_capability2', 'mycustom_capability3') ) {
echo 'Grant permission to the simple press group or the user is automatically added to the user group. Not fully sure how the coding backand works with simple press for this function'.
}
 

I understand this is a bit more ellaborate then in the example, I just hope it better illustratres from a programming perspective what I am trying to achieve. I also realise that this deviates from how simple press currently works for checking permissions which is, of course, why were having this discussion as WP user roles integration simply isn’t practical in my case.

I really don’t have an alternative to Simple Press (belive me I’ve done my research) and from a business perspective I don’t have any other options then to A) find a customization / programmed solution as described above or B) Manually give every customer & user their respective relevant forum access which increases admin work load for me but more importantly increases waiting time for the customer and also increases the chances of humar error.

Please let me know if I need to better describe what I am need Simple Press to do or if I in any other way shape or form can be an active part in moving this forward. I don’t have your guys programming or hands on knowledge of either WordPress or Simple Press from a programming perspective which makes it harder for me to grasp the full scope of the difficulties and challenges that lies ahead.

 

 

YS Yellow Swordfish
Yellow Swordfish
Member

I think you are still really missing the point of how SP currently handles access control. As I have said before – it has absolutely nothing to do with WP roles. It is the ‘marriage’ of a set of permissions against a user group assigned at forum level.

What you are suggesting negates all of that infrastructure and all of the current permission checking throughout the entire forum. That touches much, much more then whether a user can ‘view’ a forum or create posts.

MN Melanie Nelson
Melanie Nelson
Member

I’ve been watching this thread with some interest, because I currently have a client wanting to do the same thing.  however, unlike the OP, our setup is different, and I’m wondering if the OP is missing a step.

We’re using a combination of WooCommerce, WishList Member, and Simple:Press.  My client is selling online courses, basically, and we needed WooCommerce to sell these courses as product bundles: you’ll be getting PDF worksheets and other file downloads, as well as access to the classes in video format, and access to a private forum for just that particular class.

We used WishList Member to create “Membership Levels”, which we’ve mapped to groups in Simple:Press. So there’s no need to actually mess with the Roles – it’s just a checkbox/setting in the database that sets a membership level that’s mapped to a group in the forums.  So when someone purchases a course, they are returned to the site to access the downloads and the video classes.  Right now, I’m currently trying to figure out how to get the forums to recognize the newly added membership level.  The idea is that I can hook into WooCommerce to see if the purchase was successful, and upon the variabel that states is *was* successful, then I can update the WishList Membership level for that user, and tab into the database and update the forum access (by adding the user’s name to the Forums > Manage User Groups > Add Members)  I haven’t completely gotten to that point, though – WooCommerce’s hooks are proving to fight me a bit on this, and won’t tell me if a purchase was successful so it will trigger the updates. :)

This process WILL require the admin to create membership levels and forum group permission sets for every course. But there’s no need to create a new role for every single item – which is good because if you *based* it on the user role, then they would purchase 3 different courses, but could only access one because of their role.  Using the membership levels instead allows them to belong to multiple levels and not have that problem.

TO tobbe
tobbe
Member

I see, is there any way to make it so that the plugin groups can controll simple press forum access or somehow assign customers a specific forum access on a per product basis? 

This is the API info the programmer has available

http://www.itthinx.com/documentation/groups/api/

MN Melanie Nelson
Melanie Nelson
Member

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”

 

TO tobbe
tobbe
Member

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…

MN Melanie Nelson
Melanie Nelson
Member

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.

TO tobbe
tobbe
Member

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?

MN Melanie Nelson
Melanie Nelson
Member

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)

YS Yellow Swordfish
Yellow Swordfish
Member

An interesting appendix you added to that post….

MN Melanie Nelson
Melanie Nelson
Member

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

TO tobbe
tobbe
Member

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

MN Melanie Nelson
Melanie Nelson
Member

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

MN Melanie Nelson
Melanie Nelson
Member

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