conditionals in_category can't get working
Posted: August 28th, 2010, 8:10 am
I have a blog with structure as follow
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
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