latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

URI and Custom Capabilties

Home Forums Community Forum URI and Custom Capabilties

Tagged: 

This topic contains 4 replies, has 3 voices. Last updated by  Raam Dev 4 years, 5 months ago.

Topic Author Topic
Posted: Tuesday Jul 31st, 2012 at 9:31 pm #20842

I am a new s2 Member user and am trying to wrap my brain around all this….

My WordPress site is using the BuddyPress plugin. One of my main challenges is to control access to BuddyPress groups (marketed as “Learning Communities”). I have tested the the URI restriction procedure and it works like a champ.

My challenge is I will be offering several learning communities which do not have a hierarchical relationship. Quite frankly, I find the hierarchical requirement of 0,1,2,3,4,5 to be limiting. So it looks like my only choice is to use custom capabilities. I have watched most of the videos and I see examples of using ccaps with posts and pages. However, can they be used for URI restriction? I assume it is going to require some custom conditional script to be placed in functions.php. And can a user subcruibe to multiple learning groups if using the ccap solution?

Thanks in advance for any help on this!

List Of Topic Replies

Viewing 4 replies - 1 through 4 (of 4 total)
Author Replies
Author Replies
Posted: Wednesday Aug 1st, 2012 at 2:11 am #20877
Raam Dev
Username: Raam
Staff Member

Hi Grant,

You can add the following code to wp-content/mu-plugins/s2-hacks.php to restrict access to a specific URI by Custom Capability:

<?php
// Only allows access to a specific URI if user has the corresponding Custom Capability
add_action ("wp", "my_custom_capabilities", 1);
function my_custom_capabilities() {
	$allowed = TRUE;
	
	if (fnmatch ("/members/", $_SERVER&#91;"REQUEST_URI"&#93;) && !current_user_can("access_s2member_ccap_members")) {
		$allowed = FALSE;
	}
	
	if (fnmatch ("/secret-area/", $_SERVER&#91;"REQUEST_URI"&#93;) && !current_user_can("access_s2member_ccap_james_bond")) {
		$allowed = FALSE;
	}
	
	// If any of the URIs above matched, but the user did not have the necessary ccap, redirect to Membership Options
	if (FALSE === $allowed) {
		header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
		exit ();
	}
}
?>

You can add as many if-blocks as necessary to check various URIs against various Custom Capabilities.

Members can have multiple Custom Capabilities, and you can sell existing members additional Custom Capabilities using Dashboard -› s2Member® -› PayPal® Pro Forms -› Capability (Buy Now) Forms.

If you want new members to automatically have certain Custom Capabilities when they sign up, you can simply add those capabilities to the Pro-Form when you generate it in Dashboard -› s2Member® -› PayPal® Pro Forms -› Membership Level # Forms.

Posted: Wednesday Aug 1st, 2012 at 7:35 am #20904

Thanks. I’ll test it out.

Posted: Thursday Aug 2nd, 2012 at 4:03 am #20976

Hi Raam

Can you also use this against against membership levels? Do something like?

<?php // Only allows access to a specific URI if user has the corresponding Custom Capability.
		add_action ("wp", "my_custom_capabilities", 1);
		function my_custom_capabilities() {	
		$allowed = TRUE;		
	
	if (fnmatch ("/members/", $_SERVER["REQUEST_URI"]) && !current_user_can("access_s2member_level0")) {		
		$allowed = FALSE;	
	}		
	
	if (fnmatch ("/members/?pid=2", $_SERVER["REQUEST_URI"]) && !current_user_can ("access_s2member_level0"))
                {
        $allowed = FALSE;
                }
    if (fnmatch ("/members/?pid=1&pagetitle=mypage", $_SERVER["REQUEST_URI"]) && !current_user_can ("access_s2member_level1"))
                {
                  $allowed = FALSE;
                }
// If any of the URIs above matched, but the user did not have the necessary ccap, redirect to Membership Options.	
	
	if (FALSE === $allowed) {		
		header ("Location: " . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);		
		exit ();	}
	}
?>

Thanks

Posted: Friday Aug 3rd, 2012 at 6:41 am #21075
Raam Dev
Username: Raam
Staff Member

Suhaib,

Yes, that should work.

Viewing 4 replies - 1 through 4 (of 4 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.