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 Custom Capabilities for Groups not working - HELP

s2Member Plugin. A Membership plugin for WordPress®.

Buddypress Custom Capabilities for Groups not working - HELP

Postby peeld » November 9th, 2011, 8:29 pm

Hi there. Back in September I got S2Member to protect groups on my WP/BP Online Classroom. It's great! Worked great, everything.

I upgraded to BP 1.5+, and now, my custom capability code, placed in my theme's functions.php file, is no longer working. I am currently using URI protection to at least keep general users who aren't logged in from seeing groups they haven't paid for access to, but those who have paid access can still see any group that's Private. The way it USED to work was just as it should; if the user had the correct ccap, they could view the group by clicking on it in the menu, but if they didn't they got bumped back to the S2Member Options Page.

The code I used that was working til the BP 1.5+ upgrade is shown below:

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

**The Above Code does NOT currently work**

The code Christian recommended is below but also doesn't work:

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() && 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_is_single_item() && 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_is_single_item() && 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_is_single_item() && bp_current_item() == 'hooligans' &&
    !current_user_can("access_s2member_ccap_hooligan"))
        {
          header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
          exit ();
       }

       }
    /** end s2member code */


Christian also rewrote the code to clean it up, and THAT didn't work either:

Code: Select all
add_action('template_redirect', 'my_custom_capabilities', 1);
function my_custom_capabilities()
{
    if ((bp_is_groups_component() && bp_is_single_item()) && (
        (bp_current_item() == 'goal-setting-and-mental-management' && !current_user_can('access_s2member_ccap_goalsettingworkingfall2011') && !current_user_can('access_s2member_ccap_goalsettingauditingfall2011')) ||
        (bp_current_item() == 'runningcontacts-i' && !current_user_can('access_s2member_ccap_runningcontactsiworkingfall2011') && !current_user_can('access_s2member_ccap_runningcontactsiauditingfall2011')) ||
        (bp_current_item() == 'agility-foundation' && !current_user_can('access_s2member_ccap_foundationclassworkingfall2011') && !current_user_can('access_s2member_ccap_foundationclassauditingfall2011')) ||
        (bp_current_item() == 'hooligans' && !current_user_can('access_s2member_ccap_hooligan'))
    ))
    {
        header('Location: ' . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
        exit;
    }
}


I would LOVE any help anybody can provide. To recap, I HAD Buddypress groups protected as custom capabilities, and it was AWESOME, perfect for my needs. As of the BP 1.5+, it no longer works, although URI protection DOES. I have confirmed with the Buddypress people that the functions used in the code are still valid functions and that their use hasn't changed. I've also posted in the Buddypress forums but nobody has answered :(

**Thanks**

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

Re: Buddypress Custom Capabilities for Groups not working -

Postby peeld » November 10th, 2011, 3:19 pm

Can I **pay** somebody for help?! This is really getting urgent....

I *am* a Pro purchaser, not a freebie user, and I'm still willing to pay MORE. Hopefully that gives an idea of the urgency here...
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Buddypress Custom Capabilities for Groups not working -

Postby Cristián Lávaque » November 12th, 2011, 12:24 am

Hi Daisy.

I'm not very familiar with BuddyPress, and custom capability protection of groups is not something that s2Member does by default, free or Pro, that's why you needed that hack in functions.php, even if it wasn't very complicated. I really don't know why it won't work now although it used to before. It's not that I help you less because I thought you weren't a Pro user.

I suggest that you post a job for a freelance developer to make this work for you again. You can try here: viewforum.php?f=37

I really hope that 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 Custom Capabilities for Groups not working -

Postby peeld » November 12th, 2011, 1:08 am

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

Re: Buddypress Custom Capabilities for Groups not working -

Postby Cristián Lávaque » November 12th, 2011, 3:44 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 Custom Capabilities for Groups not working -

Postby peeld » November 14th, 2011, 1:42 am

Cristian,

I got several responses to my request, are most of these legit, how much do I need to worry about filtering out people who might potentially take advantage of access to my back end?
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Buddypress Custom Capabilities for Groups not working -

Postby Cristián Lávaque » November 15th, 2011, 1:58 am

I don't know, that's really up to you.

If I were hiring someone, I'd look at the feedback they've received for past jobs (elance.com has this integrated, jobs.wordpress.net doesn't). I'd also make a full backup of the site before giving him access. I'd change the login info after he finishes the job. I'd compare the files with the ones in the backup to see what he did.

Another solution would be to have him install the stuff in his own server (WordPress, BuddyPress and s2Member, same versions you have), code the customization you need and then just deliver to you the file with the hack so you just upload it. Make sure you review the code to check that it doesn't do anything weird. I'd probably prefer this approach.

I hope that 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 Custom Capabilities for Groups not working -

Postby peeld » November 15th, 2011, 1:35 pm

OK thanks for the tips :)

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

Re: Buddypress Custom Capabilities for Groups not working -

Postby peeld » November 15th, 2011, 2:12 pm

I couldn't get comfortable with posting a job out there, so I guess I'll just limp along and manually enter people til S2Member implements an official fix :)
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Buddypress Custom Capabilities for Groups not working -

Postby Jason Caldwell » November 15th, 2011, 5:22 pm

Thanks for the heads up on this thread.

In more recent versions of BuddyPress and s2Member, the template_redirect Hook is too late in the processing routines to work as expected. Try changing all of your add_action calls to "wp" instead.

Create this directory and file:
/wp-content/mu-plugins/s2-hacks.php
( these are MUST USE plugins, see: http://codex.wordpress.org/Must_Use_Plugins )
Code: Select all
<?php
add_action 
("wp", "my_custom_capabilities");
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 ();
            }
    }
?>
Attachments
s2-hacks.zip
(513 Bytes) Downloaded 25 times
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Buddypress Custom Capabilities for Groups not working -

Postby peeld » November 15th, 2011, 9:49 pm

YOU ROCK. YOU ROCK. YOU ROCK. Not only have you got it to work again, now I can update my theme without worrying about losing all the code, didn't know about the mu-plugin thing.

I'm using that 'donate' button right now to donate as a thanks - much rather give that $$ to the software developer, glad I didn't go with the custom coding thing after all ;)
User avatar
peeld
Registered User
Registered User
 
Posts: 97
Joined: August 24, 2011

Re: Buddypress Custom Capabilities for Groups not working -

Postby Jason Caldwell » November 15th, 2011, 10:43 pm

@peeld
Donation received. Thank you VERY much.
~ You are very welcome :-)

Please let us know if you need anything.
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA


Return to s2Member Plugin

Who is online

Users browsing this forum: No registered users and 3 guests

cron