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, 5 months ago by [email protected].
-
AuthorPosts
-
17/05/2017 at 14:57 #3737VladimirKeymaster
Hi Frederik,
Good point! Fixed. Try the updated beta version 4.34.2.b3
17/05/2017 at 15:16 #3738OxfamParticipantWorks great!
(Changed the required capability to ‘promote_users’ for my needs.)
25/05/2017 at 17:53 #3791[email protected]ParticipantVladimir,
Clicking on Grant Roles, pops up the window with Primary Role and Secondary roles- but the user’s roles are not pre-selected. I think the previously set roles should be selected before the user starts to make changes. Can you check on that please?
26/05/2017 at 00:58 #3792VladimirKeymasterI did not select current role(s) at “Grant Roles” dialog as I positioned this feature for the bulk action. There is no sense to pre-select current roles when action is applied to multiple users at once.
But I agree with you such pre-selection will enhance usability if action is applied to a single user. I will update a code to work this way. Thanks.
06/06/2017 at 18:51 #3833[email protected]ParticipantVladimir,
I finally got to setting this up. I’ve applied the filter to return true using the code for user with role ‘ga_site_administrator’. I tried to debug, and added some debug statements in classes/grant-roles.php
FILTER TO ALLOW GRANT ROLES FOR EDIT_USERS
add_filter('ure_bulk_grant_roles', 'ga_show_ure_bulk_grant_roles'); function ga_show_ure_bulk_grant_roles($show) { if(current_user_can_for_blog(null, 'ga_site_administrator') && !ga_is_super_admin()) { $show = TRUE; echo " Show GRANT ROLES "; } return $show; }
GRANT ROLES CODE:
public function show_grant_roles_html() { if (!$this->lib->is_right_admin_path('users.php')) { return; } if (!current_user_can('edit_users')) { echo " IN show_grant_roles_html ".current_user_can('edit_users'); if(current_user_can('ga_site_administrator')) echo " use has ga_site_administrator"; print_r(get_role('ga_site_administrator' )->capabilities); return; } ?>
06/06/2017 at 18:54 #3834[email protected]ParticipantFYI: To test, I removed edit_users in this function, and replaced with the custom role-‘ga_site_administrator’ — and Grant Roles showed up. However, since it’s in the plugin code, it should be fixed there.. eventually. What could be going wrong?
public function show_grant_roles_html() { if (!$this->lib->is_right_admin_path('users.php')) { return; } if (!current_user_can('ga_site_administrator')) {
Image didn’t get included earlier.. trying again.
The bug it seems is that it’s not passing !current_user_can(‘edit_users’), even even the capabilities listed for the user show that edit_users => 1
07/06/2017 at 07:53 #3836VladimirKeymasterif (!$this->lib->is_right_admin_path()
$this->lib object is not defined inside your function. So you get a PHP fatal error here and code is not executed further.
You have to use it this way:
$lib = URE_Lib_Pro::get_instance(); if (!$lib->is_right_admin_path('user.php') {
07/06/2017 at 17:05 #3838[email protected]ParticipantVladimir,
This is the grant-roles.php file in the plugin code. I was just modifying it to debug.
The contructor instantiates $lib, and within show_grant_roles_html, its used as $this->lib, which passes through and works.public function __construct() { $this->lib = URE_Lib::get_instance();
public function show_grant_roles_html() { if (!$this->lib->is_right_admin_path('users.php')) { return; } // if ( !current_user_can('edit_users')) { if ( !current_user_can('edit_users')) { /*echo " IN show_grant_roles_html ".current_user_can('edit_users'); if(current_user_can('ga_site_administrator')) echo " use has ga_site_administrator"; print_r(get_role('ga_site_administrator' )->capabilities); */ return; }
The moment i change ga_site_administrator (which is a custom role, with edit_users capability), the to ‘edit_users’, the grant roles button disappears.
Also, another interesting thing – with my change applied – if I select 1 user and click on Grant Roles, I get URE: Insufficient Privileges. If I select 2 or more, It brings up the html for Granting Roles.
Thanks,
Shweta
-
AuthorPosts
- You must be logged in to reply to this topic.