PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Buddypress group as custom capability?

Common Questions/Problems/Tips. Posted by Administrators & Support Reps.

Buddypress group as custom capability?

Postby kipprsnak » December 30th, 2010, 4:39 pm

I am using groups in Buddypress as individual on-going classes. I want some people to have access to a specific course (group), but not other courses or groups, but I want all members to have access to two other groups. I don't want to base it on member levels, because I have more than 4 classes, so the URI protection based on level wouldn't seem to fit for this.

Any ideas on how I can achieve group specific access not based on level?

thanks for help!
User avatar
kipprsnak
Registered User
Registered User
 
Posts: 13
Joined: May 7, 2010

Re: Buddypress group as custom capability?

Postby roflmao » May 23rd, 2011, 2:36 pm

Hi there. Did you ever figure out if this can be done? I'm trying to do the exact same thing, using groups as classes.

Thanks!
Dan
User avatar
roflmao
Registered User
Registered User
 
Posts: 4
Joined: May 23, 2011

Re: Buddypress group as custom capability?

Postby peeld » August 24th, 2011, 10:19 pm

I'm curious as well.

Thanks!
Daisy
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Buddypress group as custom capability?

Postby roflmao » August 25th, 2011, 12:07 am

Hi! I was able to make this work using Custom Capabilities.

Here's a gret post that might help get you moving in the right direction:
viewtopic.php?t=684&p=3141

Here is the code I used in my functions.php to limit access to specific groups:

Code: Select all
add_action ("template_redirect""my_custom_capabilities"1);
function 
my_custom_capabilities ()
    {
        if ( 
bp_is_groups_component() && 'name-of-group' == bp_current_item() && !current_user_can ("access_s2member_ccap_customname"))
            {
                
header ("Location: " S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
                exit ();
            }
    } 


In the above example, "name-of-group" is the name of the group I want to restrict and "customname" is what I added to the Custom Capabilities field when creating a paypal button.

Hope that helps!
User avatar
roflmao
Registered User
Registered User
 
Posts: 4
Joined: May 23, 2011

Re: Buddypress group as custom capability?

Postby peeld » August 25th, 2011, 2:42 am

Super quick response! Thanks, I'll try it out and post back here to report on how it goes!

Thanks,
Daisy
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Buddypress group as custom capability?

Postby Cristián Lávaque » August 25th, 2011, 3:15 am

Thanks for sharing your solution, Dan! :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Buddypress group as custom capability?

Postby roflmao » August 25th, 2011, 7:05 am

Happy to help. I've been meaning on posting my solution ever since I figured it out so I'm glad it was brought back to my attention! :)

s2Member is amazing!
User avatar
roflmao
Registered User
Registered User
 
Posts: 4
Joined: May 23, 2011

Re: Buddypress group as custom capability?

Postby peeld » August 25th, 2011, 1:18 pm

Hmm, well, at first glance, the user *is* being set up in the system correctly, and with the correct custom capability...but if the user tries to access a group they don't have capability for, they don't get redirected to the options page...

That's just with the code you provided, no extra code yet (i.e. the else if line that is in the other code snippets), just the name-of-group has changed and of course the customname as well.

EDIT - I think I know the problem, possibly, but don't know the solution right off the bat. Now that I'm fussing with custom capabilities, I've removed all the restrictions from the s2member restrictions menu. I'm not sure where to set restrictions now. I'm just using Level 1 with Custom Capabilities, do I even *need* to fuss with the s2member restrictions options?

It WORKS!!! You guys rock.

Thanks,
Daisy

PS Agreed, this is a great membership system, really liking what I'm seeing in the testing so far. I'm implementing it in BuddyPress along with a plugin called courseware for online classes. SUPER excited about finding s2member. THANKS!
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Buddypress group as custom capability?

Postby Cristián Lávaque » August 25th, 2011, 10:20 pm

Thanks for the kudos, guys! :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Buddypress group as custom capability?

Postby peeld » August 29th, 2011, 1:02 am

Hi there,

I've run in to a question - I've got the code working properly but need to implement the following, if possible. Right now, I'm using some code like this:
Code: Select all
add_action ("template_redirect", "my_custom_capabilities", 1);
function my_custom_capabilities ()
    {
        if ( bp_is_groups_component() && 'groupA' == bp_current_item() && !current_user_can ("access_s2member_ccap_groupA"))
            {
                header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
                exit ();
            }
    }


It's working great. However, I have two levels of paying students in each group, working spots and auditing spots. When I try to put an additional line in:
Code: Select all
add_action ("template_redirect", "my_custom_capabilities", 1);
function my_custom_capabilities ()
    {
        if ( bp_is_groups_component() && 'groupA' == bp_current_item() && !current_user_can ("access_s2member_ccap_groupAauditing"))
            {
                header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
                exit ();
            }
    }

The code is broken, I'm assuming because there's already an if statement for groupA?

Here's the question:
Can I have this as a possibility (users with two different ccap codes with access to the same group)?

ALSO, I notice that there is a '1' in the code, I'm assuming to make it Level 1. Would it be better to put another statement in there like this:

Code: Select all
add_action ("template_redirect", "my_custom_capabilities", 2);
function my_custom_capabilities ()
    {
        if ( bp_is_groups_component() && 'groupA' == bp_current_item() && !current_user_can ("access_s2member_ccap_groupAauditing"))
            {
                header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
                exit ();
            }
    }


for those auditing students? That *sounds* enticing, because then I could set all users who are 'working' to level 1, and have the role be "Working", and all users who are auditing to level 2, and the role could be "Auditing". It would be an easy way for me to keep track of who has paid for auditing and who has paid for working.

At the end of the day, it's OK if I can't; I can still have two Paypal buttons, and if people pay for auditing they pay one price with the same ccap code as the working people who pay more. They both get access, but it'll be trickier for me to keep track of who has paid for what.

Please advise.

Thanks!
Daisy
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Buddypress group as custom capability?

Postby peeld » August 29th, 2011, 2:34 am

Tried this, doesn't work :(

Code: Select all
else if (bp_is_groups_component()  &&
    'goal-setting-and-mental-management' == bp_current_item() &&
    (!current_user_can ("access_s2member_ccap_goalsettingworking") || !current_user_can ("access_s2member_ccap_goalsettingauditing")))

   {header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
      exit ();
   
}


EDIT: I tried rewording the statement to the below but that didn't work either. I'll admit I'm a PHP newbie and don't even fully understand what the "1" is at the beginning of the code. Really, I'd be happy to have two statements, one where if the user had the ccap goalsettingworking they got access at level 1 (and a level 1 role), and if they had the ccap goalsettingauditing they got level 2 access, simply because then they'd automatically have a different role assigned, although they would still be limited to viewing only the groups they had ccap for.

Code: Select all
else if ((bp_is_groups_component()  &&
    'goal-setting-and-mental-management' == bp_current_item() &&
    (!current_user_can ("access_s2member_ccap_goalsettingworking")) ||(bp_is_groups_component()  &&
    'goal-setting-and-mental-management' == bp_current_item() &&
    (!current_user_can ("access_s2member_ccap_goalsettingauditing")))

   {header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
      exit ();
   
}
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Buddypress group as custom capability?

Postby peeld » August 30th, 2011, 3:56 pm

Just thought I'd post Christian's solution to this , which works great - it's an AND statement and not an OR statement :) Darned logic.

Daisy
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Buddypress group as custom capability?

Postby Cristián Lávaque » August 31st, 2011, 2:28 am

Here's it is for those interested: viewtopic.php?f=4&t=14719&p=33320#p33272 :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Buddypress group as custom capability?

Postby peeld » September 5th, 2011, 11:38 pm

I feel like this is a really dumb question...but...

OK, so the customer clicks the Paypal button. They make a payment. They get a custom capability which allows them to SEE a group. Then, they still have to JOIN that group. I've actually removed the 'join group' button for now and am manually adding members for the moment. I feel like it's just one more layer of complexity that most users will be turned off by.

Is there a way to have people with the correct custom capability ALSO be given membership to the group that they've purchased access to? And then when they get demoted at the EOT their membership is also revoked from that group?

I'm not sure I'm making myself clear, I hope so. It's not a huge deal to manually add people as members to the BP groups at the moment. And of course S2Member works just fine; even if I added a random member to a group, they still couldn't SEE that group if they didn't have the correct ccap for it. So that's working as it should. Just curious about the ability to auto add members to a group they've got ccap for.

Daisy
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Buddypress group as custom capability?

Postby Cristián Lávaque » September 7th, 2011, 4:03 am

You could use the Notifications API to run a custom script that adds/removes the user from the group. http://www.s2member.com/api-tracking-no ... ons-video/
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Buddypress group as custom capability?

Postby peeld » September 7th, 2011, 12:04 pm

Guess I'll have to watch the videos on that topic ;)

I'm by no stretch of the imagination a scripter, I'll hunt through the forums to see if there's something I can copy ;)

Thanks,
Daisy
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Buddypress group as custom capability?

Postby Cristián Lávaque » September 8th, 2011, 4:27 am

:)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Buddypress group as custom capability?

Postby peeld » October 22nd, 2011, 5:24 pm

I've upgraded to BP 1.5, and for some reason the code below no longer works - any thoughts?

Code: Select all
/** s2member code */
add_action ("template_redirect", "my_custom_capabilities", 1);
function my_custom_capabilities ()
   {
   if (bp_is_groups_component() && bp_current_item() == 'goal-setting-and-mental-management' && !current_user_can('access_s2member_ccap_goalsettingworkingfall2011') && !current_user_can('access_s2member_ccap_goalsettingauditingfall2011')) {
    header('Location: ' . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
    exit;
}
 
    else if (bp_is_groups_component() && bp_current_item() == 'runningcontacts-i' && !current_user_can("access_s2member_ccap_runningcontactsiworkingfall2011") && !current_user_can('access_s2member_ccap_runningcontactsiauditingfall2011'))
         {
                header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
                exit ();
            }

   else if ( bp_is_groups_component() && bp_current_item() == 'agility-foundation' && !current_user_can("access_s2member_ccap_foundationclassworkingfall2011") && !current_user_can('access_s2member_ccap_foundationclassauditingfall2011'))
     {
      header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
      exit ();
       }

   else if ( bp_is_groups_component() && bp_current_item() == 'hooligans' &&
!current_user_can("access_s2member_ccap_hooligan"))
    {
      header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
      exit ();
   }
   
   }
/** end s2member code */


Using latest version of WP, BP, and S2Member 111017

Thanks,
Daisy
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Buddypress group as custom capability?

Postby Cristián Lávaque » October 27th, 2011, 5:31 pm

Hi Daisy. Could you explain in more detail how it's not working?

Also, have you checked that bp_is_groups_component and bp_current_item functions still exist in the BP you upgraded to?
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Buddypress group as custom capability?

Postby peeld » October 27th, 2011, 9:13 pm

This page:
http://codex.buddypress.org/developer-docs/conditional-template-tags/
seems to suggest bp_is_groups_component is still available as a function, bp_current_item function as well.

If a user isn't logged in (random visitor), any class they click on takes them back to the url that I've specified in the s2member options.

Used to be, if a user was logged in and had purchased access to a group, if they clicked on a group they DIDN'T have access to, they'd also go back to the s2member specified URL. Now, if they click on a group they don't have access to, they get taken to that group's home page. They still can't view any of the class content, but they can view the homepage, and it used to be they'd go back to the s2member page.

Hope that helps?
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Buddypress group as custom capability?

Postby Cristián Lávaque » October 29th, 2011, 11:18 pm

They probably changed something, then.

Look at the example near the bottom, it may help you:

Code: Select all
Or if you wanted to show something on every single group page, regardless if it was the home page or not:

<?php if ( bp_is_groups_component() && bp_is_single_item() ) : ?> Show this on all single group pages <?php endif; ?>


Try adding && bp_is_single_item() to your conditions and see if it helps.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Buddypress group as custom capability?

Postby peeld » November 3rd, 2011, 11:44 am

Just to clarify, I should add that in in addition to bp_is_groups_component() and bp_current_item()?
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Buddypress group as custom capability?

Postby peeld » November 3rd, 2011, 11:50 am

Adding it in doesn't seem to change anything, still having the same issue :( My new session starts in a few weeks, hopefully I can suss this out by then...

Here's my updated code:
Code: Select all
/** s2member code */
add_action ("template_redirect", "my_custom_capabilities", 1);
function my_custom_capabilities ()
   {
   if (bp_is_groups_component() && bp_current_item()  && bp_is_single_item() == 'goal-setting-and-mental-management' && !current_user_can('access_s2member_ccap_goalsettingworkingfall2011') && !current_user_can('access_s2member_ccap_goalsettingauditingfall2011')) {
    header('Location: ' . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
    exit;
}
 
    else if (bp_is_groups_component() && bp_current_item() && bp_is_single_item() == 'runningcontacts-i' && !current_user_can("access_s2member_ccap_runningcontactsiworkingfall2011") && !current_user_can('access_s2member_ccap_runningcontactsiauditingfall2011'))
         {
                header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
                exit ();
            }

   else if ( bp_is_groups_component() && bp_current_item() && bp_is_single_item() == 'agility-foundation' && !current_user_can("access_s2member_ccap_foundationclassworkingfall2011") && !current_user_can('access_s2member_ccap_foundationclassauditingfall2011'))
     {
      header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
      exit ();
       }

   else if ( bp_is_groups_component() && bp_current_item() && bp_is_single_item() == 'hooligans' &&
!current_user_can("access_s2member_ccap_hooligan"))
    {
      header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
      exit ();
   }
   
   }
/** end s2member code */
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Buddypress group as custom capability?

Postby peeld » November 3rd, 2011, 12:01 pm

This doesn't seem to work either:

Code: Select all
/** s2member code */
add_action ("template_redirect", "my_custom_capabilities", 1);
function my_custom_capabilities ()
   {
   if (bp_is_groups_component() && bp_is_single_item() == 'goal-setting-and-mental-management' && !current_user_can('access_s2member_ccap_goalsettingworkingfall2011') && !current_user_can('access_s2member_ccap_goalsettingauditingfall2011')) {
    header('Location: ' . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
    exit;
}
 
    else if (bp_is_groups_component() && bp_is_single_item() == 'runningcontacts-i' && !current_user_can("access_s2member_ccap_runningcontactsiworkingfall2011") && !current_user_can('access_s2member_ccap_runningcontactsiauditingfall2011'))
         {
                header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
                exit ();
            }

   else if ( bp_is_groups_component() && bp_is_single_item() == 'agility-foundation' && !current_user_can("access_s2member_ccap_foundationclassworkingfall2011") && !current_user_can('access_s2member_ccap_foundationclassauditingfall2011'))
     {
      header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
      exit ();
       }

   else if ( bp_is_groups_component() && bp_is_single_item() == 'hooligans' &&
!current_user_can("access_s2member_ccap_hooligan"))
    {
      header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
      exit ();
   }
   
   }
/** end s2member code */
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Buddypress group as custom capability?

Postby peeld » November 3rd, 2011, 12:29 pm

Buddypress 1.5 *did* implement some changes, I'm no coder, but I do know that when I upgraded it added PAGES, for example, it added the page "Activity", which has nothing on it in edit mode, but which brings up the Activity feed when viewed properly, and it added the page "Classes" (which is what I've renamed groups to in my language file), which is empty but brings up classes when viewed properly. Maybe that helps?

EDIT: I also asked this question on the BP support groups:
Do the functions bp_is_groups_component and bp_current_item still work the same as they used to?

The answer was a simple Yes :)
Last edited by peeld on November 3rd, 2011, 1:12 pm, edited 1 time in total.
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Next

Return to Common Questions/Problems/Tips

Who is online

Users browsing this forum: No registered users and 2 guests

cron