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 8 replies, 4 voices, and was last updated 2 years, 4 months ago by
ToiBox.
-
AuthorPosts
-
13/03/2016 at 13:43 #2121
dweb360
ParticipantHello,
How to hide “Other Roles” selectbox in “Additional Capabilities section” depending on user role?
Thank you
13/03/2016 at 16:10 #2122Vladimir
KeymasterHi,
‘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 #3782RoxxiStudios
ParticipantI 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 #3787Vladimir
KeymasterAdd 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 #3788RoxxiStudios
ParticipantThank 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 #3789Vladimir
KeymasterThere 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 #7244ToiBox
ParticipantVladimir,
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 #7245Vladimir
KeymasterWhile 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 #7246ToiBox
ParticipantVladimir,
Thank you, your solution worked out great.
Much appreciated!
-
AuthorPosts
- You must be logged in to reply to this topic.