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.

Doing things with menus based on member level

Home Forums Community Forum Doing things with menus based on member level

This topic contains 15 replies, has 3 voices. Last updated by  Cristián Lávaque 4 years, 10 months ago.

Topic Author Topic
Posted: Thursday Mar 8th, 2012 at 12:29 pm #7626
Andy White
Username: 58twelve

Hi

Newbie here in need of some guidance, please.

I have a resources section which will offer free resources to everyone, a level of resources to non-paying subscribers, and a level of resources that will be available to paid subscribers.

I have 3 menus set up: Free Resources, Level 1 Resources and Level 2 resources.

What I want to be able to do is display menus in the left hand sidebar according to membership level. ie everyone sees free Resources, non paying subscribers see that one plus Level 1 Resources, and paying members see all three. I kind of got it working using what I found here: http://www.primothemes.com/forums/viewtopic.php?t=707&p=54152 but only if each menu included the others – ie menu 2 was menu 1 plus menu 2 and menu 3 was menu 1 items plus menu 2 items plus menu 3 items.

But I need to be able to style each menu differently and have it self enclosed (ie not one long list) hence wanting to bring in additional menus separately based on member level.

I tried using conditionals but it kept throwing errors. I was trying something along the lines of:

<?php 
if(!is_user_logged_in()){
    wp_nav_menu (array ("theme_location" => "primary-public"));
elseif(!is_user_logged_in()) {
    S2MEMBER_CURRENT_USER_ACCESS_LEVEL=1;
    wp_nav_menu (array ("theme_location" => "resources-level-1"));
} elseif(!is_user_logged_in()) {
    S2MEMBER_CURRENT_USER_ACCESS_LEVEL=2;
    wp_nav_menu (array ("theme_location" => "resources-level-2"));
} else {!is_user_logged_in()){
    wp_nav_menu (array ("theme_location" => "resources-level-0"));
    }
     ?>

I couldnt find anywhere if S2MEMBER_CURRENT_USER_ACCESS_LEVEL even worked in the way I am trying to make it work, but I just tried to be logical. Unfortunately the very steep learning curve I am on has not taken me to the levels necessary where I understand enough about php to have even half a clue what I am doing wrong.

Can anyone help me out, please?

Many thanks

Andy

List Of Topic Replies

Viewing 15 replies - 1 through 15 (of 15 total)
Author Replies
Author Replies
Posted: Thursday Mar 8th, 2012 at 12:46 pm #7627
cassel
Username: cassel

Do you really need to have separate menus or could you simply have ONE menu, but divide the content according to conditionals? So in the single resource page, you could have

if level 0 or above
show these resources
if level 1 and above
also show these resources
if level 2 and above
also show these resources

I am no tech, just another s2M user but i wanted to achieve that a while back but ended up using the menu always visible to all, but incorporate conditionals instead, and if the visitor is not reaching the lowest level i set, i can have a little sale pitch, encouraging the visitor to register or purchase the access.

Someone more knowledgeable in the coding and s2M will surely come and add info on the technical side,

Posted: Thursday Mar 8th, 2012 at 1:49 pm #7632
Andy White
Username: 58twelve

Hi Cassell

Thanks for stepping in!

That is something I wondered about doing – I thought maybe I was trying to be too clever using the wp_navs, but I still couldn’t find anywhere how to set the conditional based on member level.

I’m guessing if I could get the conditional to work for teh way you suggested it ought to work for the alternative, but I am utterly stumped.

How did you make the conditional work?

Posted: Thursday Mar 8th, 2012 at 2:14 pm #7635
cassel
Username: cassel

Conditionals are very easy once you understand them (i LOVE them). You have several examples in the API /Scripting > Simple/Shortcode Conditionals in your s2M. Check the example #3 and you will see exactly what you can do for those different levels.

Good luck.

Posted: Thursday Mar 8th, 2012 at 2:30 pm #7636
Andy White
Username: 58twelve

Thanks Cassell. I thought I’d cracked it when I followed your link, but I must be doing something very wrong.

My S@ Member level is 4, but I get the ‘else’ result when I try this:

<?php if (current_user_is("s2member_level4")){
    wp_nav_menu (array ("theme_location" => "resources-level-2"));
 } 
	
	else if (current_user_is("s2member_level3")){
    wp_nav_menu (array ("theme_location" => "resources-level-2"));
} 

	else if (current_user_is("s2member_level2")){
    wp_nav_menu (array ("theme_location" => "resources-level-2"));
 } 

	else if (current_user_is("s2member_level1")){
    wp_nav_menu (array ("theme_location" => "resources-level-2"));
} 
	
	else if (current_user_is("s2member_level0")){
    wp_nav_menu (array ("theme_location" => "resources-level-1"));
	}
	
	else { ?>
   You can't access this
	<?php } 
?>

I know you said you aren’t a tech, but you are doing a great job of helping me out, so if you have anything you can throw on why this isn’t working, it’d be much appreciated :-)

Thanks for your help!

Andy

Posted: Thursday Mar 8th, 2012 at 2:49 pm #7638
Andy White
Username: 58twelve

Now here’s a twist. Created a new user with L4 and that user sees what they should see. It seems to be with existing members that I am having the issue. Weird. Any thoughts?

Posted: Thursday Mar 8th, 2012 at 2:57 pm #7639
cassel
Username: cassel

I am really not familiar with the wp_nav_menu command (or variable) and definitely not knowledgeable with the pnp coding, so this is above my abilities.

But if you want to use the shortcode to include all the content on the same page, then you can use something like this:

[s2If current_user_is(s2member_level0)]
    put the resources accessible to all the registered members.
    
    [s2If current_user_is(s2member_level1)]
        add the resources accessible to those with level 1 membership.
    
        [s2If current_user_is(s2member_level2)]
            add the resources accessible to those with level 2 membership.
 
             [s2If current_user_is(s2member_leve3)]
                add the resources accessible to those with level 3membership.
                
                [s2If current_user_is(s2member_level4)]
                    add the resources accessible to those with level 4 membership.

                [/s2If]
            [/s2If]
        [/s2If]                                    
    [/s2If]   
[/s2If]

This will display all the resources you want but only according to what you allow each level to see. And you can also add this:

[s2If !is_user_logged_in()]
    something to encourage the visitor to either log in, or to register or purchase whatever package you offer along with a little sale pitch!
[/s2If] 

But again,if you want to just display the menus according to their level, hopefully Christian or Raam will chime in.

Posted: Thursday Mar 8th, 2012 at 3:03 pm #7641
Andy White
Username: 58twelve

Thanks Cassell. I really appreciate your help. I have the conditional working perfectly now, but only for new users. Despite my user list showing me as a level 4 member, with this conditional I get the ‘you can’t access this’ message. Yet, for a new user I set up at L4 they see what they should see, as does a user I set up at L1. If Christian or Raam can help ith highlighting what I am doing wrong there, that’d be fantastic.

Cassell, once again, thanks for steering me in the right direction and taking the time to respond. For anyone who may be interested, here is te conditional that now works:

<?php if (current_user_is("s2member_level4")){
     wp_nav_menu (array ("theme_location" => "resources-level-1"));
     wp_nav_menu (array ("theme_location" => "resources-level-2"));
	 } 
 	
 	else if (current_user_is("s2member_level3")){
     wp_nav_menu (array ("theme_location" => "resources-level-1"));
     wp_nav_menu (array ("theme_location" => "resources-level-2"));
	} 
 
 	else if (current_user_is("s2member_level2")){
     wp_nav_menu (array ("theme_location" => "resources-level-1"));
     wp_nav_menu (array ("theme_location" => "resources-level-2"));
	 } 
 
 	else if (current_user_is("s2member_level1")){
     wp_nav_menu (array ("theme_location" => "resources-level-1"));
     wp_nav_menu (array ("theme_location" => "resources-level-2"));
	} 
 	
 	else if (current_user_is("s2member_level0")){
     wp_nav_menu (array ("theme_location" => "resources-level-1"));
 	}
 	
 	else { ?>
    You can't access this
 	<?php } 
 ?>

This was executed after first following the instructions here: http://www.primothemes.com/forums/viewtopic.php?t=707&p=54152 to register the menus.

I can’t figure out why I am having issues with existing users, though. So, any help from anyone with that would be much appreciated.

Cheers

Andy

Posted: Thursday Mar 8th, 2012 at 3:11 pm #7644
cassel
Username: cassel

Are you having the problem with all the existing users? Since you are an admin, sometimes it affects what you can and cannot see, so you have to be careful in not counting on what the admin sees. Maybe check with another existing member?

Another detail, (and i re-state that my coding knowledge is very very limited): i wonder if you didn`t add extra spaces before your “else ” lines?

Posted: Thursday Mar 8th, 2012 at 3:56 pm #7648
Andy White
Username: 58twelve

Yeah – I have tried it with another user. Same result.

They are spaces, but they don’t seem to affect it running. I usually put them in to help me follow what’s going on, but that may well be the wrong thing to do?

Posted: Thursday Mar 8th, 2012 at 5:55 pm #7661
cassel
Username: cassel

Again, just trying, i checked the examples for the Advanced Conditionals (using php), and here is the example they have:

<?php if (current_user_is("s2member_level4")){ ?>
    Some premium content for Level 4 Members.
<?php } else if (current_user_is("s2member_level3")){ ?>
    Some premium content for Level 3 Members.
<?php } else if (current_user_is("s2member_level2")){ ?>
    Some premium content for Level 2 Members.
<?php } else if (current_user_is("s2member_level1")){ ?>
    Some premium content for Level 1 Members.
<?php } else if (current_user_is("s2member_level0")){ ?>
    Some content for Free Subscribers.
<?php } else { ?>
    Some public content.
<?php } ?> 

So it seems that there is a

<?php }

in their example that is not in yours. Could that cause it?

Posted: Friday Mar 9th, 2012 at 1:53 am #7692
Andy White
Username: 58twelve

Like you, I have limited knowledge in all of this, but as far as I know the reason the } is followed by a closing of the php statement is that non-php code follows, so you have to close it, put in your html then open a new <?php until you get to the next lot of html.

I think that because I am using all php functions I am OK without doing that.

The conditional itself is working great, it's just not functioning for existing users – it's as if it is not recognizing the S2 Member levels.

I have a meeting this morning but after that I am going to see if assigning a different level to an existing user has any effect to try and isolate if it is just a database thing with membership assignments that needs nudging to change or if it is connected to the user itself. I am hoping not to need to delete and recreate users!

If any of the devs can throw some light on this before I have to do anything drastic, that'd be much appreciated, an in the meantime, once again, thanks for all your input, Cassell

Andy

Posted: Friday Mar 9th, 2012 at 4:43 am #7703

Hi Andy.

Funny that your existing members aren’t getting the same menu the new ones get. I wonder if it’s related to caching? Do you have a caching plugin installed?

By the way, most of your conditions are repeating the same thing. You could try a shorter code like this:

[hilite pre_code]
'resources-level-1'));
if (current_user_can('access_s2member_level1'))
wp_nav_menu(array('theme_location' => 'resources-level-2'));
}
else
{
echo "You can't access this";
}

!>
[/hilite]

Posted: Friday Mar 9th, 2012 at 7:20 am #7718
Andy White
Username: 58twelve

Thanks for the code Cristian – much neater! I am learning so much in such a short space of time on this project. Properly awesome!

I have nailed the issue. It’s to do with Super-Admin. I created a new user and gave them super-admin on all the sites in the network. Then took super admin off me. Once I did that it all worked for me, but the new super admin gets the ‘you can’t access this’ message.

I am guessing this is to do with my lack of knowledge re network setups, but have I done something wrong?

Thanks for your help!

Andy

Posted: Friday Mar 9th, 2012 at 7:24 am #7719
Andy White
Username: 58twelve

Ok, I am answering my own question here:

Just used your code in the template and the super-admin sees the right stuff now. I guess I was restricting it by being level specific in my conditional where yours is more open – with the whole can_access thing going on instead of s2member_level thing that I had going on. Good piece of learning for me there – thanks!

Out of interest, what level is a super-admin?

Thanks for getting me out of this dead end Cristian and Cassell – very much appreciated.

Andy

Posted: Friday Mar 9th, 2012 at 5:02 pm #7782

You’re welcome, Andy. Glad you solved it. :)

The super admin has access to everything. s2Member won’t restrict it, like with the Admin, if I’m not mistaken.

You can use a plugin like the User Role Editor to view all the capabilities he has.
http://wordpress.org/extend/plugins/user-role-editor/

Viewing 15 replies - 1 through 15 (of 15 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.