Change WordPress user roles and capabilities › Forums › Restrict or Permit access inside WordPress – how to › How can i hide Other Roles dropdown menu from user editor, Grant Role button…
- This topic has 10 replies, 3 voices, and was last updated 5 years, 11 months ago by whitenoise.
-
AuthorPosts
-
16/03/2018 at 12:01 #4681Fotini KokkinosParticipant
Hello!
I searched this forum and I found the following function but it doesn’t work for me:
————————
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;
}
——————————
I want to hide the Other Roles dropdown menu from user editor for specific Roles.Additionally I want to hide the “Grant Role” button for specific roles, but I didn’t find any relative thread in this forum that is applicable to my case.
Finally, I want to hide the “View” action from the Users list because I have completely ristricted any Frontend view for all the users of all the roles.
Your help is really appreciated!
17/03/2018 at 01:31 #4682VladimirKeymasterHi Fotini,
Code above works for the user with ‘user-manager’ role only. Replace ‘user-manager’ with your own role ID or check if your user really has ‘user-manager’ role.
17/03/2018 at 02:02 #4683VladimirKeymasterThis code hides ‘View’ actions at Users list from all user except user with ‘administrator’ role:
add_filter('user_row_actions', 'hide_users_view_action', 10, 1); function hide_users_view_action($actions) { if (current_user_can('administrator')) { return $actions; } if (isset($actions['view'])) { unset($actions['view']); } return $actions; }
17/03/2018 at 12:31 #4686Fotini KokkinosParticipantThank you so much for your code snippets.They worked just fine!
What about the “Grant Roles” button? How can I hide it too from certain roles?
Thank again!
18/03/2018 at 02:34 #4687VladimirKeymasterCode, which you showed above, should work for the users with right role. Let me know if you still have difficulties with it after checking a role ID.
It’s possible to use ‘ure_bulk_grant_roles’ filter. Return false with it to hide “Grant Roles” button. This is a quote from the URE source code:
$bulk_grant_roles = apply_filters('ure_bulk_grant_roles', true); if ($bulk_grant_roles) { new URE_Grant_Roles(); }
18/03/2018 at 13:59 #4688Fotini KokkinosParticipantHello!
I have the followng code that works fine for hiding the “Other Roles” dropdown field fro the User’s Editor screen. This snippet, doesn’t affect the “Grant Roles” Button.
//Hide “other roles” from user editor//
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(‘comapny_editor’)) {
$show = false;
}return $show;
}I tried the new snippet you gave me, with “False” but the button is till there….
Pls see the screenshot
http://nimb.ws/oKGmaE19/03/2018 at 13:09 #4689Fotini KokkinosParticipantHello!
Is there any solution finally for hiding the “Grant Roles” button or the whole “Grant Role” feauter for specific user roles?or else,
How can I completely disable this plugin’s feature?
Pls advice.
19/03/2018 at 13:27 #4690VladimirKeymasterHi,
1) Quick workaround. Open user-role-editor-pro/includes/classes/user-role-editor.php and comment line #193
Code will look like:$bulk_grant_roles = apply_filters('ure_bulk_grant_roles', true); if ($bulk_grant_roles) { // new URE_Grant_Roles(); }
This change will be lost after every update to a new version.
2) Needs some time and PHP developer experience – find why you can not set false via ‘ure_bulk_grant_roles’ filter.
19/03/2018 at 13:36 #4691Fotini KokkinosParticipantT H A N K Y O U!!!
This one worked!27/11/2018 at 11:07 #5310whitenoiseParticipantPerfect! I’ve added this code and it works great 🙂
27/11/2018 at 11:09 #5311whitenoiseParticipantAlso I wanted to remove some (but not all) of the roles from the ‘Role’ box on the new user screen. I came across this code:
// Remove Administrator role from roles list add_action( 'editable_roles' , 'hide_adminstrator_editable_roles' ); function hide_adminstrator_editable_roles( $roles ){ if ( isset( $roles['administrator'] ) && !current_user_can('level_10') ){ unset( $roles['administrator'] ); // add more unset rules here for your user roles } return $roles; }
Which does the job perfectly if it helps anyone else.
-
AuthorPosts
- You must be logged in to reply to this topic.