Support » Plugin: User Role Editor » Primary Role empty while grant role

  • Hey,

    In Users page, Grant role functionality has issue.

    If I am Super admin in multisite and I am trying to assign additional role to more than one user without selecting primary role, it set all selected user with empty primary role. This is unexpected behaviour.
    Instead of this is should display error.

    
    $lib = URE_Lib::get_instance();
    $select_primary_role = apply_filters('ure_users_select_primary_role', true);
    if ($select_primary_role  || $lib->is_super_admin()) {
        foreach ($users as $user_id) {
            self::grant_primary_role_to_user($user_id, $primary_role);
        }
        if (empty($primary_role)) { //  users don't have primary role, so they should not have any other roles - stop processing
            $answer = array('result'=>'success', 'message'=>esc_html__('Users does not have role for this site', 'user-role-editor'));
            return;
        }
    }
    

    Bug: In above code primary role value check after assign user primary role, and instead of error (.$answer ) it simply return empty
    We should check primary role variable is empty or not before set user primary role

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Vladimir Garagulia

    (@shinephp)

    Hi,

    Thanks for your help. I wrote the code this way in order to provide ability to revoke roles from users in bulk, similar as you can do for a single user via his profile page – select ‘No role for this site’ at a ‘Role:’ drop-down list. WordPress built in “Change Role to:” does not include such option.

    There is no sense to assign additional role(s) to user without selecting a primary one. WordPress stores all roles assigned to a user as an array. It defines a primary role as the 1st element of a roles array. That’s why I revoke all roles if user sends empty primary role and stop user request processing in spite of there were additional roles there or were not.

    May be a prompt to a user will be useful for this case: “You did not select a primary role. All roles will be revoked from selected user(s). Continue?”. What do you think?

    Plugin Author Vladimir Garagulia

    (@shinephp)

    And thanks for pointing me a real bug, when code did not return the $answer variable, while defines it.

    Hi,

    Prompt to a user will be useful for this case: “You did not select a primary role. All roles will be revoked from selected user(s).

    It’s good option

    But, I think It will not work in case of user only want to change additional role for multiple user with different primary role.
    So as per my opinion, we should not overwrite primary role if primary role is empty. and we can add option in dropdown for revoke all roles.

    This way it will be work for all.

    Plugin Author Vladimir Garagulia

    (@shinephp)

    I agree, a separate option for roles revoke with ability to change ‘other’ roles separately from the primary role will be a universal solution. I will re-write ‘Grant Roles’ this way. Thanks a lot.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Primary Role empty while grant role’ is closed to new replies.