So i came to three posible solutions to this question and can't decide which is better. What is your opinion?
First solution:
if ( ( in_array('administrator', userdata('role')) || in_array('editor', userdata('role')) ) == false) { add_filter('show_admin_bar', '__return_false'); } Second one:
if( ( current_user_can('editor') || current_user_can('administrator') ) == false ) { add_filter('show_admin_bar', '__return_false'); } Third one:
$allowed_roles = array('editor', 'administrator'); if( array_intersect($allowed_roles, userdata('role') ) == false ) { add_filter('show_admin_bar', '__return_false'); } User data function:
function userdata($userdata){ $userinfo = wp_get_current_user(); if ($userdata == 'nick') return $userinfo ->user_login; if ($userdata == 'mail') return $userinfo ->user_email; if ($userdata == 'id') return $userinfo ->ID; if ($userdata == 'role') return $userinfo ->roles; else return 'Eror'; } I am voting for the third solution.