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.

Restrict categories and menus by level

Home Forums Community Forum Restrict categories and menus by level

This topic contains 4 replies, has 2 voices. Last updated by  Eduan 4 years, 8 months ago.

Topic Author Topic
Posted: Friday Apr 20th, 2012 at 2:24 pm #11407
Sue Moss
Username: SueMoss

Hi, I have a question about membership levels and restricting access by category.

I have a member area with the following levels:

0: Willow = free schools
1: Hazel = paid groups
2: Oak = paid schools

I would like to restrict the menu shown to either schools only, or groups only depending on what level is logged in. I have the following code (modified from another post):

if (is_user_logged_in()) {

	if (current_user_can('access_s2member_level1')) {
		wp_nav_menu(array('theme_location' => 'groups-members'));
	}
		
	if (current_user_can('access_s2member_level0') || current_user_can('access_s2member_level2')) {
		wp_nav_menu(array('theme_location' => 'school-members'));
	}
	
}

The problem is I can see both menus regardless of which type of user I log in as (ie a group can see the schools stuff, and a school can see the groups stuff).

I am wondering if I’m confused about levels as in the category restriction options it states the categories are restricted to level X OR HIGHER. Does this mean level 2 can always see level 1 content, etc? Are member levels not self-contained?

I’m not using alternate views either as this makes some items in my non-restricted main menu disappear.

Any help is greatly appreciated. BTW I think s2member is a great product and everything else is working perfectly.

List Of Topic Replies

Viewing 4 replies - 1 through 4 (of 4 total)
Author Replies
Author Replies
Posted: Friday Apr 20th, 2012 at 2:35 pm #11409
Eduan
Username: Eduan
Moderator

Hello Sue,
I noticed you’re using current_user_can, this will allow anything with access to level 1 to view that, so a level 2 will also be able to see it.

So you might be interested in using current_user_is, this will make sure the user is the level you’re defining, otherwise, it won’t show it.

Hope this helps. :)

Posted: Friday Apr 20th, 2012 at 2:47 pm #11412
Sue Moss
Username: SueMoss

Hi Eduan

Thanks for the quick response. I just came across that info as well.

I notice if I do this:

if (current_user_is('access_s2member_level1')) {
	wp_nav_menu(array('theme_location' => 'groups-members'));
} else if (current_user_is('access_s2member_level2')) {
	wp_nav_menu(array('theme_location' => 'school-members'));
} else if (current_user_is('access_s2member_level0')) {
	wp_nav_menu(array('theme_location' => 'school-members'));
}

the menu for the free user doesn’t display. But if I do this:

if (current_user_is('access_s2member_level1')) {
	wp_nav_menu(array('theme_location' => 'groups-members'));
} else if (current_user_is('access_s2member_level2')) {
	wp_nav_menu(array('theme_location' => 'school-members'));
} else if (S2MEMBER_CURRENT_USER_ACCESS_LEVEL === 0) {
	wp_nav_menu(array('theme_location' => 'school-members'));
}

it does. It works but any ideas?

Thanks again.

Posted: Friday Apr 20th, 2012 at 3:05 pm #11415
Sue Moss
Username: SueMoss

Not sure why it works that way but it does. I’m happy. Thanks for your help!

Topic closed.

Posted: Friday Apr 20th, 2012 at 3:08 pm #11416
Eduan
Username: Eduan
Moderator

You’re welcome Sue!

Glad I was able to help. :)

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.