I have a snippet in my functions.php that removes the admin role from the "change role to" drop down menu in the users listing screen, so that editors who can list users and manage roles won't be able to turn another user into an admin. The code below works perfectly.
function isa_pre_user_query($user_search) {
$user = wp_get_current_user();
if (!current_user_can('administrator')) { // Is Not Administrator - Remove Administrator
global $wpdb;
$user_search->query_where =
str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.ID IN (
SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
WHERE {$wpdb->usermeta}.meta_key = '{$wpdb->prefix}capabilities'
AND {$wpdb->usermeta}.meta_value NOT LIKE '%administrator%')",
$user_search->query_where
);
}
}
add_action('pre_user_query','isa_pre_user_query');
Now, my question is, how can I also have the Editor role removed from that drop down, so that Editors cannot create other editors? I want to remove both the Admin and the Editor role from that drop-down menu, and restrict the role choices only to Author, Contributor and Subscriber.
Any ideas?
NOT LIKE '$administrator%' OR '%editor%'