|
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,
|
|
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?
|
|
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.
|
|
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
|
|
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?
|
|
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.
|
|
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
|
|
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?
|
|
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?
|
|
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?
|
|
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
|
|
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]
|
|
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
|
|
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
|
|
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/
|