Try to add this code into your active theme functions.php file:
if (!current_user_can('administrator')) {
add_filter('editable_roles', 'exclude_role' );
public function exclude_role($roles)
{
if (isset($roles['administrator'])) {
unset($roles['administrator']);
}
return $roles;
}
}
If it work for you, add code for the rest of WP roles.
Thread Starter
Kyle H
(@cikez)
Vladimir,
I tried adding the following code to my themes functions.php file and got
if (!current_user_can('author')) {
add_filter('editable_roles', 'exclude_role' );
public function exclude_role($roles)
{
if (isset($roles['author'])) {
unset($roles['author']);
}
return $roles;
}
}
“HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.”
Any ideas?
Kyle,
Get rid of the “public” in front of function. I ran this and everything works great.
function exclude_role($roles) {
//Hide Defualt Roles
if (isset($roles['author'])) {
unset($roles['author']);
}
if (isset($roles['editor'])) {
unset($roles['editor']);
}
if (isset($roles['subscriber'])) {
unset($roles['subscriber']);
}
if (isset($roles['contributor'])) {
unset($roles['contributor']);
}
return $roles;
}
add_filter('editable_roles', 'exclude_role' );