Page 2 of 2

Re: Buddypress group as custom capability?

PostPosted: November 3rd, 2011, 12:54 pm
by peeld
I really don't know anything about coding but figured I could at least do some legwork for you guys to see if you could more quickly solve this. Here are a couple of links that might be of use?

http://plugins.trac.wordpress.org/brows ... action.php

http://buddypress.trac.wordpress.org/br ... e.php#L946

Re: Buddypress group as custom capability?

PostPosted: November 3rd, 2011, 12:58 pm
by peeld
Here's another one that addresses plugins and how BP 1.5 has changed how concatenation of links needs to be handled:

http://bpdevel.wordpress.com/2011/07/31 ... ity-slugs/

Re: Buddypress group as custom capability?

PostPosted: November 4th, 2011, 12:52 am
by Cristián Lávaque
You seem to have changed the conditionals when you added that new check. Just add it without changing the others:

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


I hope that works.

Here's your code rewritten, just for fun, but I haven't tested it. :P

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;
    }
}
 

Re: Buddypress group as custom capability?

PostPosted: November 4th, 2011, 6:17 pm
by peeld
I'm going to test it now. I'm still happy as a clam with S2Member, the support is great, and I'll take any opportunity to get cleaned up code ;) Will report back!

Re: Buddypress group as custom capability?

PostPosted: November 4th, 2011, 6:38 pm
by peeld
Well, neither of the codes you submitted throw an error, so I suppose that's good news, but the same incorrect behavior persists - if I'm not logged in at all, then trying to click on classes takes me to the s2member options page, but if I'm logged in as a user who has a custom capability for only one of the classes, I can still view ALL of them, even though I don't have access to them based on the above code. Grrr. I do notice that when I'm not logged in, the end of the URL when I get bumped to the s2member options page says something that indicates I'm being redirected because I'm not level1, rather than that I don't have the ccapability.

So, I went to my restriction options in the s2member panel, and I had a URI restriction on /classes/. When I remove THAT, the above code is clearly not working at ALL - even a not logged in user can see everything. The only thing keeping the world from seeing the classes was that I had a URI restriction set; the code above isn't working at all anymore. Seems so weird. I've got the URI restriction back in place for now.

Thanks for your continued support,

Daisy

EDIT: Do you think changing from bp group conditionals to just uri conditionals would work? Not sure how to format that but I can see where it might work?

Re: Buddypress group as custom capability?

PostPosted: November 5th, 2011, 9:59 pm
by Cristián Lávaque
Sorry my suggestion didn't work.

If I were you, I'd go back to the code you had working before, post it in the BP forums telling them it used to work and now doesn't, and if they could help.

Re: Buddypress group as custom capability?

PostPosted: November 6th, 2011, 10:07 am
by peeld
Will do. Do you have an example of the code using uri snippets instead of buddypress group components? I only have four classes that need to be protected, so I was thinking if I could just change from bp group components to uri's, it might work?

Thanks,
Daisy

Re: Buddypress group as custom capability?

PostPosted: November 6th, 2011, 9:02 pm
by peeld
I haven't heard back yet from the BP group. Kind of disappointed as not being able to use this functionality kind of leaves me back at ground zero :( I hunted around and tried the code below, as it seemed it might be a workaround, but it doesn't work either:

Code: Select all
/**s2member code */

add_action ("template_redirect", "my_custom_capabilities", 1);
function my_custom_capabilities ()
    {
        if (fnmatch ("/classes/goal-setting-and-mental-management*", $_SERVER["REQUEST_URI"]) && !current_user_can("access_s2member_ccap_goalsettingworkingfall2011") && !current_user_can("access_s2member_ccap_goalsettingauditingfall2011"))
            {
                header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
                exit ();
            }
        else if (fnmatch ("/classes/runningcontacts-i*", $_SERVER["REQUEST_URI"]) && !current_user_can("access_s2member_ccap_runningcontactsiworkingfall2011") && !current_user_can("access_s2member_ccap_runningcontactsiauditingfall2011"))
            {
                header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
                exit ();
            }
   else if (fnmatch ("/classes/agility-foundation*", $_SERVER["REQUEST_URI"]) && !current_user_can("access_s2member_ccap_foundationclassworkingfall2011") && !current_user_can("access_s2member_ccap_foundationclassauditingfall2011"))
       {
      header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
      exit ();
       }
   else if (fnmatch ("/classes/hooligans*", $_SERVER["REQUEST_URI"]) && !current_user_can("access_s2member_ccap_hooligan"))
       {
      header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
      exit ();
       }
    }

/**end s2member code */

Re: Buddypress group as custom capability?

PostPosted: November 8th, 2011, 12:02 pm
by peeld
I hate to be a pest but my Online Classroom opens this Friday for registration and I'd love to have this issue solved. Is there anything I can do to spur a solution along? Should I ask for individual assistance/paid assistance? I'm happy to do so. I haven't heard anything back from the buddypress.org support community.

:cry:

Re: Buddypress group as custom capability?

PostPosted: November 12th, 2011, 2:13 am
by Cristián Lávaque
I just replied in your other thread about this. I suggest you get hlep from a freelance developer familiar with BuddyPress, maybe you'll find someone over at http://jobs.wordpress.net

I hope that helps. :)