Purchased custom capabilities need to hide links to others

Hello all,

This is a bit long winded, but I hope somebody will be kind enough to help me work my problem out.

I have been working with S2Member to try to set up a site selling four courses for learning a language of different levels, eg beginners, intermediate etc…

After playing around with S2Member, and watching the custom capability video here: https://s2member.com/kb-article/video-custom-capabilities-for-wordpress/
I came to the conclusion that using custom capabilities via only Level 1 is the best way to achieve exclusive access to each level of the course without giving access to other levels of the course. ie if somebody purchases the highest level of the course I don’t want them to be able to see/use the lower level courses - if they want access to them they will need to make an additional purchase.

To make lesson management of each level of the course simpler, I decided to create a custom post type for each level. This also means I can use a different course menu for each course.

Anyway, I have finally worked out how to get the custom capabilities to work with custom post types so that if a user buys one course they won’t have access to other courses.

Now, on my welcome page, I have set up a “your courses” section with four links to an “overview” page for each course.

Ideally, I only want to show a link to the overview page of the course purchased.

However, and this is the problem I’m trying to solve, at the moment a user who has bought only one course can see all the other links to the other three courses.

Is there a way to hide the other links?
Do I need to add something to my functions.php file?
Or is there a better way I can achieve this?

Here’s the code I have added to my functions.php file:

function my_custom_capabilities ()
{

if (is_singular('beginners') && !current_user_can ("access_s2member_ccap_beginners"))
	
{
	header ("Location: ". S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
	exit();
}

else if (is_singular('pre-intermediate') && !current_user_can ("access_s2member_ccap_pre-intermediate"))
	
{
	header ("Location: ". S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
	exit();
}

else if (is_singular('intermediate') && !current_user_can ("access_s2member_ccap_intermediate"))
	
{
	header ("Location: ". S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
	exit();
}

else if (is_singular('upper-intermediate') && !current_user_can ("access_s2member_ccap_upper-intermediate"))
	
{
	header ("Location: ". S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
	exit();
}

}

Hi Duncan,

Now, on my welcome page, I have set up a “your courses” section with four links to an “overview” page for each course. Ideally, I only want to show a link to the overview page of the course purchased.

You can use conditionals that check the user’s capability before adding that link. https://s2member.com/kb-article/s2if-simple-shortcode-conditionals/

[s2If current_user_can(access_s2member_ccap_pre_beginners)]Link to Beginners[/s2If]
[s2If current_user_can(access_s2member_ccap_pre_intermediate)]Link to Pre-Intermediate[/s2If]
[s2If current_user_can(access_s2member_ccap_intermediate)]Link to Intermediate[/s2If]
[s2If current_user_can(access_s2member_ccap_upper_intermediate)]Link to Upper-Intermediate[/s2If]

:slight_smile:

Thanks Cristián,

Worked perfectly. I have another issue, but I’m going to open another topic as it’s not related to this one.

Duncan