Community Support Forums — WordPress® ( Users Helping Users ) — 2010-08-31T18:57:31-05:00 http://www.primothemes.com/forums/feed.php?f=4&t=625 2010-08-31T18:57:31-05:00 http://www.primothemes.com/forums/viewtopic.php?t=625&p=2800#p2800 <![CDATA[Re: conditionals in_category can't get working]]>
micb11 wrote:
Do you also know if there are any conditionals with buddypress. I would have liked to restrict viewing members profiles as well

There are a couple of ways to accomplish this:

1. The Super Easy way:
Go to s2Member -> General Options -> URI Level Restrictions
enter the following word fragment:
Code:
/members/

2. Advanced Conditionals integrated into your theme:
Code:
if(preg_match("/\/members\//", $_SERVER["REQUEST_URI"])){
    header("Location: http://example.com/you-cannot-view-this-content");
    exit();
}

If you're running BuddyPress, be sure to use s2Member v3.2.4+
s2Member v3.2.3 had a bug related specifically to BuddyPress, which was corrected in 3.2.4+.
http://www.primothemes.com/post/s2membe ... th-paypal/

Also, be sure to use the full URL in the header redirection call.
Some browsers choke when you put in a relative URL.
So use the full URL, starting with http.

Code:
header("Location: http://example.com/you-cannot-view-this-content");

Statistics: Posted by Jason Caldwell — August 31st, 2010, 6:57 pm


]]>
2010-08-31T04:42:08-05:00 http://www.primothemes.com/forums/viewtopic.php?t=625&p=2767#p2767 <![CDATA[Re: conditionals in_category can't get working]]>
Thanks for that , works a treat!!

Do you also know if there are any conditionals with buddypress. I would have liked to restrict viewing members profiles as well

for example

if member is in ccap_cobham and memberprofile is in ccap_cobham
then let them view page
else
redirect to no access page

Any Ideas

Statistics: Posted by micb11 — August 31st, 2010, 4:42 am


]]>
2010-08-30T09:37:37-05:00 http://www.primothemes.com/forums/viewtopic.php?t=625&p=2689#p2689 <![CDATA[Re: conditionals in_category can't get working]]> Thanks for the great question.
I'm updating your rank to "Experienced User".
~ It's great to see developers integrating s2Member in more advanced ways.

OK. So let me clarify how these two functions work:

1. is_category()
This checks to see if the current WP query is an Archive view of a specific Category, and if so, is it the specific Category that you ask it about? i.e. is_category("green-grapes").

2. in_category()
This function is different. Instead of looking at the current WP query, it looks at the current Post, ( or the first Post in an archive view ). So using this function works great, but ONLY if you know that you're on a Singular Post or Page, and NOT in an Archive view of your Blog.

In other words, this is how you should use in_category()
Code:
if(is_singular() && in_category("green-grapes))

Now, how to apply this to your current set of Conditionals ( as seen above ).
Here is a brief example of how you might accomplish what you need:

Code:
if((is_category("cobham") || (is_singular() && in_category("cobham"))) && !current_user_can("access_s2member_ccap_cobham"))
{
header("Location: /you-cannot-view-this-content");
exit();
}

In other words, if the User is attempting to access the Archive for "cobham", OR (||) if they're on a Singular Post that is nested into the "cobham" Category.

Statistics: Posted by Jason Caldwell — August 30th, 2010, 9:37 am


]]>
2010-08-28T08:10:28-05:00 http://www.primothemes.com/forums/viewtopic.php?t=625&p=2634#p2634 <![CDATA[conditionals in_category can't get working]]>
Meetings Blog (Partent Category)
- cobham
- walton on thames
- woking
- guildford
- weybridge

when the user signs up he can become part of only when of the child categories. I have written conditionals in the php functions as follows and it all works a treat

add_action('template_redirect',"my_custom_capabilities");

function my_custom_capabilities()
{
if(is_category("cobham")&& !current_user_can("access_s2member_ccap_cobham"))
{
header("Location: /you-cannot-view-this-content");
exit();
}
else if(is_category("dorking") && !current_user_can("access_s2member_ccap_dorking"))
{
header("Location: /you-cannot-view-this-content");
exit();
}
else if(is_category("guildford") && !current_user_can("access_s2member_ccap_guildford"))
{
header("Location: /you-cannot-view-this-content");
exit();
}
else if(is_category("richmond") && !current_user_can("access_s2member_ccap_richmond"))
{
header("Location: /you-cannot-view-this-content");
exit();
}
else if(is_category("tunbridge-wells") && !current_user_can("access_s2member_ccap_tunbridgewells"))
{
header("Location: /you-cannot-view-this-content");
exit();
}
else if(is_category("virginia-water") && !current_user_can("access_s2member_ccap_virginiawater"))
{
header("Location: /you-cannot-view-this-content");
exit();
}
else if(is_category("walton-on-thames") && !current_user_can("access_s2member_ccap_waltononthames"))
{
header("Location: /you-cannot-view-this-content");
exit();
}
else if(is_category("weybridge") && !current_user_can("access_s2member_ccap_weybridge"))
{
header("Location: /you-cannot-view-this-content");
exit();
}
else if(is_category("wimbledon") && !current_user_can("access_s2member_ccap_wimbledon"))
{
header("Location: /you-cannot-view-this-content");
exit();
}
else if(is_category("woking") && !current_user_can("access_s2member_ccap_woking"))
{
header("Location: /you-cannot-view-this-content");
exit();
}

}

However when the user clicks on the parent category he can see all the latest from all blogs (which is fine) but if he clicks on a post from a blog he should not be able to access, he can. So I thought that if I wrote some more conditional using in_category that should stop it and boot him out. But instead when I write an in_category conditional the user can no longer access any of the child categories.

Any help would be apreciated

Thanks

Statistics: Posted by micb11 — August 28th, 2010, 8:10 am


]]>