Webatix has one simple goal: to turn your business ideas into a raging success.

Adding a Custom Navigation Menu per Wishlist Member Member Levels

November 18, 2011

For most membership sites it makes sense that visitors, free members and paid subscribers will have a navigational menu that helps them do the things they uniquely need to do. Guests need a sign up link, free members need a subscribe link, paid subscribers probably don’t want to see it. Additionally you might have different FAQ pages depending on membership level, etc.

Below is some code that will help you achieve this. We’ve implemented it on several of our projects that use Woo Themes, but it should work with any ‘Menu’ compatible WordPress theme.

First open the functions.php page in your theme folder and add this to the bottom:

add_action('init', 'register_header_menu');

function register_header_menu()
{
register_nav_menu('menu-loggedout', 'Logged Out');
register_nav_menu('menu-guests', 'Guests');
register_nav_menu('menu-members', 'Members');
}

You can add or subtract the number of custom nav menus you have by adding or substracting the following line:

register_nav_menu('menu-members', 'Members');

Just change ‘menu-members’ and ‘Members’ to whatever your new menu name will be.

Then open your header.php file in your theme folder if that is where you want your navigation. And add this:


global $current_user, $WishListMemberInstance;

$WLMCurrentUserLevels = WLMAPI::GetUserLevels($current_user->ID);

if ( function_exists('has_nav_menu') && (has_nav_menu('menu-members') || has_nav_menu('menu-guests') || has_nav_menu('menu-loggedout')) )
{
if ( has_nav_menu('primary-menu') )

//Replace 1205593475 with your membership level ID...do the same three lines down
if ($current_user->ID != 0 && array_key_exists('1305593475', $WLMCurrentUserLevels) && has_nav_menu('menu-member'))
{
wp_nav_menu( array( 'depth' => 5, 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'nav', 'menu_class' => 'fr', 'theme_location' => 'menu-members' ) );
}
elseif ($current_user->ID != 0 && array_key_exists('1305593477', $WLMCurrentUserLevels) && has_nav_menu('menu-guests'))
{
wp_nav_menu( array( 'depth' => 5, 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'nav', 'menu_class' => 'fr', 'theme_location' => 'menu-guests' ) );
}
else
{
if (has_nav_menu('menu-loggedout'))
{
wp_nav_menu( array( 'depth' => 5, 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'nav', 'menu_class' => 'fr', 'theme_location' => 'menu-loggedout' ) );
}
}
}
else
{
?>

We added this right before an If statement in the Woo theme that basically says ‘If there is a custom menu, use it’. Your theme will likely have a different structure, but if you add the above code and it breaks the PHP, just delete the last ‘else {‘.

Once you add these two code snippets,

1. go to ’Appearance–>Tools’

2. You should now see an option for ‘not logged in’, guests, members in the menu selector.

3. Create a menu for each.

4. Select the menu in the appropriate dropdown.

5. Save.

6. Test.

I hope this helps. We had to make a lot of usability compromises without this, but with it, we can deliver a cleaner, smoother experience for our users.

Be Sociable, Share!
Categories: Wordpress

Leave a Reply

You must be logged in to post a comment.