Change WordPress user roles and capabilities › Forums › Give user access to plugin – how to › Hide "Other Roles" control
Tagged: Additional capabilities, hide UI, wp backend
- This topic has 13 replies, 6 voices, and was last updated 3 months, 3 weeks ago by RVSCC.
-
AuthorPosts
-
13/03/2016 at 13:43 #2121dweb360Participant
Hello,
How to hide “Other Roles” selectbox in “Additional Capabilities section” depending on user role?
Thank you
13/03/2016 at 16:10 #2122VladimirKeymasterHi,
‘Other Roles’ section is shown, if this boolean filter ‘ure_show_additional_capabilities_section’ returns true (by default). It’s hidden in case this filter returns false.
23/05/2017 at 19:30 #3782RoxxiStudiosParticipantI have created a custom role based on administrator and am unable to hide the section in a user profile:
Other Roles Select additional roles for this user
I’d like to hide this from the custom role I’ve created, how can this be done?
Any help is appreciated.
Thank you!
24/05/2017 at 05:02 #3787VladimirKeymasterAdd this code to your active theme functions.php file or setup it as a Must Use plugin:
add_filter('ure_show_additional_capabilities_section', 'ure_show_additional_capabilities_section'); add_filter('ure_bulk_grant_roles', 'ure_show_additional_capabilities_section'); function ure_show_additional_capabilities_section($show) { if (current_user_can('user-manager')) { $show = false; } return $show; }
25/05/2017 at 00:50 #3788RoxxiStudiosParticipantThank you for the response, however, this had no effect.
I’ll just accept it the way it is.I will say this, I don’t really see the value in having the ability to assign additional roles to a user. From my perspective, it is an option that could be removed from the plugin altogether – your call.
Again, thanks for the response.
25/05/2017 at 03:05 #3789VladimirKeymasterThere are a lot of other users of User Role Editor which think different – they need multiple roles assignment to one user at WordPress. Historically, I developed this feature after I got multiple requests about it from plugins users.
I will add a user interface for this option (swith ON/OFF other roles section) later.
Currently it’s possible to manage this feature via filters, if your setup it correctly. This is a short demo video.
Check if you don’t have any accident typos in a code and it’s really executed. For example, code above works for the user with ‘user-manager’ role only. Did you change a role ID for your own or may be remove role checking code?
08/01/2021 at 03:58 #7244ToiBoxParticipantVladimir,
Good day to you. I recently came across this very same issue and attempted the PHP snippet that you provided but did not have any luck. Upon closer reading, however, I see that you also mention to try and set the plugin as a MU-Plugin, which isn’t an option for me due to maintenance and update agreements on my client end. Should the above snippet still work, or, might you suggest something better so that I can turn this UI off within the WP backend? I’d like to keep this option away from my clients so that they do not get confused at both New User Registration and Edit User scenarios.
Thank you.
08/01/2021 at 04:22 #7245VladimirKeymasterWhile code version above work for the user with ‘user-manager’ role only, this version works for all users including one with ‘administrator’ role:
add_filter('ure_show_additional_capabilities_section', 'ure_show_additional_capabilities_section'); function ure_show_additional_capabilities_section( $show ) { /* Remove comment if do not wish to apply this for administrators also $lib = URE_Lib::get_instance(); if ($lib->is_super_admin()) { return $show; } */ return false; }
08/01/2021 at 04:30 #7246ToiBoxParticipantVladimir,
Thank you, your solution worked out great.
Much appreciated!
07/10/2023 at 10:40 #8501TWarriorParticipantHello,
Congratulations on your plugin!
Have you thought about adding this “Hide Other Roles control” as an option in the plugin settings?
07/10/2023 at 17:20 #8502VladimirKeymasterHi @TWarrior,
Good suggestion. I will group similar recipes and add them as a separate settings section to the plugin options with one of the next update.
08/10/2023 at 14:43 #8503TWarriorParticipantHi Vladimir,
Great!
If we open in the wish list… there could also be the option to disable o hide “Grant Roles” button at Users list page:
I usually have it deactivated with code:
/*
* Hides “Grant Roles” button at Users list page
*/
add_filter(‘ure_bulk_grant_roles’, ‘ure_bulk_grant_roles’);
function ure_bulk_grant_roles( $show ) {
/* Remove comment if do not wish wish to apply this for administrators also
$lib = URE_Lib::get_instance();
if ($lib->is_super_admin()) {
return $show;
}
*/
return false;
}PD: The general idea behind all this is that I use your plugin to create a new role called “Manager”, with intermediate permissions between the Administrator and the Editor (something that surprises me a lot that does not come by default in WordPress).
This is the role for people who “manage” the contents of the site and create new users of the site, but can not access the settings, plugins, etc..
Thanks for your plugin!!!
08/10/2023 at 16:29 #8504VladimirKeymasterOK. Thanks for sharing this.
02/08/2024 at 12:59 #8703RVSCCParticipantHi Vladimir
Thank you for the code it removes the additional role option from the user profile page.
But how can we disable this other role option complete?
All our new user registrations are getting 2 roles by default
1. the role from wp core (this we prefer)
2. unmoderated role from user role pro plugin -
AuthorPosts
- You must be logged in to reply to this topic.