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