Community Support Forums — WordPress® ( Users Helping Users ) — 2011-08-25T17:20:03-05:00 http://www.primothemes.com/forums/feed.php?f=4&t=684 2011-08-25T17:20:03-05:00 http://www.primothemes.com/forums/viewtopic.php?t=684&p=32899#p32899 <![CDATA[Re: Restricting URI access based on ccap in functions.php ?]]>
Here's the solution: viewtopic.php?f=36&t=1405

EDIT 11/6/2011: As of BP 1.5 for some reason my code doesn't work anymore, FYI. Trying to troubleshoot.

Statistics: Posted by peeld — August 25th, 2011, 5:20 pm


]]>
2011-08-25T02:31:19-05:00 http://www.primothemes.com/forums/viewtopic.php?t=684&p=32842#p32842 <![CDATA[Re: Restricting URI access based on ccap in functions.php ?]]>

Any new suggestions on what I could be doing wrong? I'm happy to submit my functions.php file...

Daisy

Statistics: Posted by peeld — August 25th, 2011, 2:31 am


]]>
2010-12-01T08:18:16-05:00 http://www.primothemes.com/forums/viewtopic.php?t=684&p=4923#p4923 <![CDATA[Re: Restricting URI access based on ccap in functions.php ?]]>
function my_custom_capabilities ()
{
if(current_user_can('level_10'))
{
return false;
}
...

Statistics: Posted by svenl77 — December 1st, 2010, 8:18 am


]]>
2010-11-27T12:48:12-05:00 http://www.primothemes.com/forums/viewtopic.php?t=684&p=4894#p4894 <![CDATA[Re: Restricting URI access based on ccap in functions.php ?]]>
That is, Restrict access by URI, but also use the buddypress conditionals for fine-tuning (like only letting some people create new groups)?

Statistics: Posted by startasocialnetwork — November 27th, 2010, 12:48 pm


]]>
2010-11-26T21:01:36-05:00 http://www.primothemes.com/forums/viewtopic.php?t=684&p=4891#p4891 <![CDATA[Re: Restricting URI access based on ccap in functions.php ?]]>
I know since this post (and the video) you've added custom capabilities fields to pages/posts to make using ccaps easier. Is the above stratgey still the only way to work with ccaps and URIs, or has this also been improved?

Thanks
Ric

Statistics: Posted by startasocialnetwork — November 26th, 2010, 9:01 pm


]]>
2010-09-09T22:59:15-05:00 http://www.primothemes.com/forums/viewtopic.php?t=684&p=3141#p3141 <![CDATA[Re: Restricting URI access based on ccap in functions.php ?]]> Thanks for the kudos!

Statistics: Posted by Jason Caldwell — September 9th, 2010, 10:59 pm


]]>
2010-09-09T12:14:33-05:00 http://www.primothemes.com/forums/viewtopic.php?t=684&p=3114#p3114 <![CDATA[Re: Restricting URI access based on ccap in functions.php ?]]>

This work perfectly! I'm working on a Premium BuddyPress Theme with S2Member integration and some blog posts on how to achieve BuddyPress specific things with it.. Seriously this plugin is so powerful it blows my mind.

When the theme is released I'll send you a copy so you can take a look :)

Thanks again!

Statistics: Posted by BoweFrankema — September 9th, 2010, 12:14 pm


]]>
2010-09-07T22:14:35-05:00 http://www.primothemes.com/forums/viewtopic.php?t=684&p=3017#p3017 <![CDATA[Re: Restricting URI access based on ccap in functions.php ?]]> Hi Bowe. Thanks for the great question.

Here is how you would integrate BuddyPress Conditional Tags:
Code:
<?php
add_action 
("template_redirect", "my_custom_capabilities", 1);
function my_custom_capabilities ()
    {
        if (bp_is_group_forum () && !current_user_can ("access_s2member_ccap_forums"))
            {
                header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
                exit ();
            }
    }
?>

So you're just swapping out a native WordPress® Conditional tag like has_tag(), and instead using a specialized BuddyPress Conditional Tag, like: bp_is_group_forum(). Other BuddyPress Conditional Tags are documented here: http://codex.buddypress.org/developer-d ... late-tags/

--------------------------------

Now, if instead; you wanted to bypass all Conditional Tags, and go straight to the URI itself, you would test word fragments against the $_SERVER["REQUEST_URI"]. So something like this:
Code:
<?php
add_action 
("template_redirect", "my_custom_capabilities", 1);
function my_custom_capabilities ()
    {
        if (fnmatch ("/activity*", $_SERVER["REQUEST_URI"]) && !current_user_can ("access_s2member_ccap_activity"))
            {
                header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
                exit ();
            }
        else if (fnmatch ("/forums*", $_SERVER["REQUEST_URI"]) && !current_user_can ("access_s2member_ccap_forums"))
            {
                header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
                exit ();
            }
    }
?>

So here we are testing word fragments against $_SERVER["REQUEST_URI"].

Important to note:
- A URL looks like this: http://domain/path/to/file.php
- A URI is just the path: /path/to/file.php ( and this is what $_SERVER["REQUEST_URI"] represents ).

The function fnmatch() is documented here, and it's very simple.
The asterisk (*) represents a wildcard.
http://php.net/manual/en/function.fnmatch.php

Statistics: Posted by Jason Caldwell — September 7th, 2010, 10:14 pm


]]>
2010-09-06T07:09:44-05:00 http://www.primothemes.com/forums/viewtopic.php?t=684&p=2934#p2934 <![CDATA[Restricting URI access based on ccap in functions.php ?]]>
I'm really digging into S2Member now, and I want to use it for another project of mine. I've decided that Custom Capabilities are the best solution for my needs, and now I want to use it to protect specific BuddyPress Groups (where support and downloads can be found). So my idea was to do this:

Make a new Custom Capability for every new Premium Group which add that tag that I would like to use to define that membership.

Then go into my themes functions.php file and restrict the access to that group to the member with that custom capability added, like you showed in the video. But since I can't write any PHP I have no idea how to write the code that allows me to block someone from a hard coded URL. In the video example you use Image
for restricting access based on tags or categories.

So what I would like to do is create levels that allows access to a certain group URL only.
but I have no idea to modify it to replace tags/categories with an hardcoded url or a BuddyPress conditonal tag. Any ideas how to achieve this?

Thanks in advance,
Bowe

Statistics: Posted by BoweFrankema — September 6th, 2010, 7:09 am


]]>