Change WordPress user roles and capabilities › Forums › How to or FAQ › Custom User Edit Page
- This topic has 22 replies, 3 voices, and was last updated 7 years, 6 months ago by [email protected].
-
AuthorPosts
-
26/04/2017 at 15:43 #3635[email protected]Participant
Hello,
We would like to give a custom role, the ability to assign and remove roles(limited by Other Roles access) for All users. However, we would not like to use the user-edit.php page the way it is right now, with the ability to edit many other things other than just the “Additional Capabilities” > other Roles.
1) Is it possible, using capabilities and Admin Menu restrictions, to limit the content of the user-edit.php (and users.php) pages, so that this new role only sees the users and ability to assign roles? No ability to edit capabilities/profile color/names etc.. that is available with “edit_users” capability.
2) Is it possible, to use a ure hook, to implement a page in a custom plugin, to list users and then a drop down, which on submission will update roles?
How would you solve this requirement?
Thanks,
Shweta26/04/2017 at 19:40 #3636[email protected]Participant3) Use a trimmed down “users.php” where, the only capability they have is to Grant Roles(URE) for users?
27/04/2017 at 15:28 #3637VladimirKeymasterHi,
It’s possible to hide ‘Edit’ link under every user row at users.php and block access to user profile editing adding this code to functions.php of active theme:add_filter('user_row_actions', 'custom_user_row_actions', 10, 2); function custom_user_row_actions($actions, $user) { if (current_user_can('user-manager')) { unset($actions['edit']); } return $actions; } add_action('admin_head', 'custom_block_user_profile', 101); function custom_block_user_profile() { $url = strtolower($_SERVER['REQUEST_URI']); if (strpos($url, 'user-edit.php')===false) { return; } if (!current_user_can('user-manager')) { return; } $url = admin_url() .'/users.php'; if (headers_sent()) { ?> <script> document.location.href = '<?php echo $url; ?>'; </script> <?php die; } else { wp_redirect($url); } }
So it seems that task was resolved as users.php has a “Grant Roles” button. But I discovered a problem here with your help. Thanks. User without ‘ure_manage_options’ capability can not use “Grant Roles” button. He will get “Not enough permissions” error message on a try to change user’s roles. It’s really wrong.
So I have to update base version of ‘User Role Editor’ to fix this issue. Let’s wait a next update – about a week.
27/04/2017 at 15:31 #3638VladimirKeymasterNon-admin user still can use WordPress’s “Change role to”. So if there is no urgent need to grant users multiple role you can use this recipe as it is. In order to grant multiple roles – wait a next update of URE and URE Pro.
27/04/2017 at 19:50 #3639[email protected]ParticipantVladimir,
Thank you so much for your quick response, and suggestion to update the code for this. I will try out this recipe and see how it works. We do require non-admin user, to be able to grant multiple roles.
Thanks,
Shweta28/04/2017 at 19:22 #3641[email protected]ParticipantVladimir,
another thing – With Grant Roles, it seems the list is not limited by the “Other Roles access”, and when user is granted those roles, it overwrites their primary role for the site too.
Is it possible, to Not allow this ‘user-manager’ to update the primary role, instead just update the “Other Roles” using Grant Roles button on All Users page?
29/04/2017 at 02:13 #3643VladimirKeymasterHi Shweta,
Yes, correct. ‘Grant Roles’ replaces all roles granted to user including a primary role.
I will look how to achieve this: using custom filter for example or something else.03/05/2017 at 15:04 #3667[email protected]ParticipantThats great. When do you think this could be released?
Thanks,
Shweta03/05/2017 at 16:38 #3669VladimirKeymasterHi Shweta,
I work on the update. “Grant Roles” window will have 2 parts: Primary role and Other roles.
Custom filter will allow to hide “Primary role” section.I suppose to publish the update next week.
08/05/2017 at 01:50 #3684[email protected]ParticipantThat’s great.. Let us know when you are ready!
-Shweta
16/05/2017 at 05:53 #3725[email protected]ParticipantVladimir,
Any ETA on the update? We have a critical implementation for a site, pending your update.
Thanks for working on this.
-Shweta
16/05/2017 at 06:22 #3726VladimirKeymasterHi Shweta,
It’s almost ready, but needs some additional testing before publishing. Can you test the updated version 1st at a stage environment?
16/05/2017 at 06:50 #3731VladimirKeymasterBeta 2 of version 4.34.2 is available after login from download page.
Related changes:
- Update: Core version: “Users->Grant Roles” button worked only for superadmin or user with ‘ure_manage_options’ capability. User with ‘edit_users’ can use this feature now.
- New: Core version: Boolean filter ‘ure_users_select_primary_role’ can hide ‘Primary role’ selection controls from the user profile edit page. Boolean filter ‘ure_users_show_wp_change_role’ can hide “Change Role” bulk action selection control from the Users page. So it’s possible to configure permissions for user who can change just other roles of a user without changing his primary role.
Custom filter samples:
add_filter('ure_users_select_primary_role', 'ure_users_select_primary_role'); function ure_users_select_primary_role($show) { $show = false; return $show; } add_filter('ure_users_show_wp_change_role', 'ure_show_wp_change_role'); function ure_show_wp_change_role($show) { $show = false; return $show; }
16/05/2017 at 16:30 #3732[email protected]ParticipantThanks! I will try it in our stage env and provide feedback.
17/05/2017 at 13:55 #3733OxfamParticipantHi,
Just a quick related question:
Update: Core version: “Users->Grant Roles” button worked only for superadmin or user with ‘ure_manage_options’ capability. User with ‘edit_users’ can use this feature now.
I noticed this issue, good to see it will be resolved! However, would it be possible to hide the “Grant Roles” button if the user has no rights to use it, to keep things clean and simple?
I have a custom role with none of the capabilities mentioned above, but still they see the button … As far as I can tell from the 4.34.1 code there is no limitation on show_grant_roles_html().
Greetings,
Frederik
-
AuthorPosts
- You must be logged in to reply to this topic.