You have errors in the code
First, you are using current_user_can()
function the wrong way. It has two parameters — $capability
and $object_id
. You don’t need the latter one, so, in your case:
current_user_can('subscriber')
In my opinion, it’s better to use capability
instead of user role
in this function. For example, subscribers can’t edit posts, unlike other user roles, so I’d change 'subscriber'
to 'edit_posts'
:
Second, the if
condition. Your code says that user must be logged in OR his role must not be
a subscriber. It should sound like the user must be logged in AND must be not a
subscriber.
add_filter( 'wpmenucart_menu_item_wrapper', 'wpmenucart_hide_for_visitors', 10, 1 );
function wpmenucart_hide_for_visitors( $menu_item_li )
{
// user is logged in AND his role is higher than a subscriber
if ( is_user_logged_in() && current_user_can('edit_posts') ) {
return $menu_item_li;
} else {
return;
}
}
See current_user_can in the Codex.