In my multi-site network, I am using "User Role Editor" plugin to assign capabilities to roles. I want the site-admins (administrators) of sub-sites to have capability to change role of any user to any other role except the super-admin role. The only way to achieve that, as per my limited understanding, is to hide the super-admin role from the options of "change role to" menu on the user listing page.
I can hide the administrator and the editor roles for the aforementioned menu, using the following code available here:
function wdm_user_role_dropdown($all_roles) {
global $pagenow;
if( current_user_can('editor') && $pagenow == 'user-edit.php' ) {
// if current user is editor AND current page is edit user page
unset($all_roles['administrator']);
unset($all_roles['editor']);
}
return $all_roles;
}
add_action ('editable_roles','wdm_user_role_dropdown');
Based on this, I tried following code to hide the super-admin role as desired:
function schoolers_user_role_dropdown($all_roles) {
global $pagenow;
if( current_user_can('remove_users') && $pagenow == 'user-edit.php' ) {
// if current user can "remove_users" AND current page is edit user page
unset($all_roles['administrator']);
unset($all_roles['superadmin']);
}
return $all_roles;
}
add_action('editable_roles','schoolers_user_role_dropdown');
This modified code, however, is not hiding super-admin.
While editing the reference code, I had assumed that slug for Super-admin role is either superadmin or super_admin. But when both didn't work, I searched for the required slug and stumbled upon the fact that Super-admin role does not have a slug. So, possibly, we can not hide super-admins like that.
Can any one suggest a correction in the above code and/or help with another method to achieve what I need?
Thanks!
print_r( $all_roles );
? Not sure why you have superadmin as an option in the select box.