WordPress Nav menu roles based on capability

WordPress Nav menu roles based on capability

where to buy cheap Dilantin follow link This code adds a nav menu role ‘visitsreports’. The second function checks weather the menu item should be visible for users if they have the capability ‘view_visit_reports’.


[cc lang=”php” escaped=”true” width=”90%” theme=”default” line_numbers=”on”]
function kia_new_roles( $roles ){
$roles[‘visitreports-role’] = ‘visitsreports’;
return $roles;
}
add_filter( ‘nav_menu_roles’, ‘kia_new_roles’ );

function kia_item_visibility( $visible, $item ){
if( isset( $item->roles ) && is_array( $item->roles ) && in_array( ‘visitreports-role’, $item->roles ) ){

if ( current_user_can(‘view_visit_reports’) ) {
$visible = true;
} else {
$visible = false;
}
return $visible;
}
add_filter( ‘nav_menu_roles_item_visibility’, ‘kia_item_visibility’, 10, 2 );