# Hide menu items for visitors and filter based on role

In my menu i've got some menu items that i don't want to show to people who aren't logged in. One of these i only want to show to logged in users of a certain roles the other to everyone logged in.

So one of them is called 'My Printer'. This should be visible to everyone that is logged in.

The other is called 'Partners'. This should only be visible to users with the partner role.

I've tried using Role Scoper but i find it very difficult to use and it doesn't make a lot of sense. It also interferes with a lot of other things as well which i don't need.

Is there anyway i can hide menu items based on their role?

Thanks

EDIT

Thanks for the 2 answers below, but neither achieve what i'm after.

-
Please move your "edit" to an answer to explain how you solved the problem and mark it as "the answer" so it will help future visitors to the site. –  EAMann Feb 12 '12 at 23:55

<?php
if ( is_user_logged_in() ) {
echo 'Welcome, registered user!';
} else {
echo 'Welcome, visitor!';
}
?>


Create a new role with the following code and put it in your functions.php

add_role('partners', 'Partners', array(
'read' => true, // True allows that capability, False specifically removes it.
'edit_posts' => true,
'delete_posts' => true,
'edit_published_posts' => true,
'publish_posts' => true,
'edit_files' => true,
'import' => true,
'upload_files' => true //last in array needs no comma!
));


Now lets say your partners has the capability "edit_published_posts". You can define the menu like this.

<?php
if ( is_user_logged_in() ) {
if(current_user_can('edit_published_posts')) {
echo 'Welcome, Partner!';
}
else {
echo 'Welcome, registered user!';
}
}
else {
echo 'Welcome, visitor!';
}
?>

-
Um, i don't understand how that's going hide menu items. I already have the roles so i don't need to add them. –  Corbula Dec 13 '11 at 15:14
Updated my answer –  Giri Dec 13 '11 at 15:15
I think you've misunderstood my original question. I'm trying to hide menu items based on a user's role, not display a message. –  Corbula Dec 13 '11 at 15:21
That message is just a dummy text. You should replace those dummy text with your href links like this. <a href="http://www.yourwebsite.com/partnet-link-page">Partners</a> –  Giri Dec 13 '11 at 15:29
I've updated the question. This is only good if i want to display something separate from the menu. Not if i want to hide an item of the menu. –  Corbula Dec 13 '11 at 16:02

You could do this by creating different menus in Appearance -> Menus, and then use something like this to show the menu for the current role:

     <?php
global $wp_roles; foreach ($wp_roles->role_names as $role =>$name ) :
if (current_user_can( $role ) &&$role == 'partner') {