WordPress.org

Make WordPress Core

Ticket #22361: 22361.2.patch

File 22361.2.patch, 2.2 KB (added by johnjamesjacoby, 18 months ago)

Revised patch includes all of the first version, plus prevents a user's capabilities from being completely deleted in multisite setups when setting 'role' to none

  • wp-admin/includes/class-wp-users-list-table.php

     
    257257                } else { 
    258258                        $edit = '<strong>' . $user_object->user_login . '</strong>'; 
    259259                } 
    260                 $role_name = isset( $wp_roles->role_names[$role] ) ? translate_user_role( $wp_roles->role_names[$role] ) : __( 'None' ); 
     260 
     261                // Compare user role against currently editable roles 
     262                if ( in_array( $role, array_keys( get_editable_roles() ) ) ) { 
     263                        $role_name = translate_user_role( $wp_roles->role_names[$role] ); 
     264                } else { 
     265                        $role_name = __( 'None' ); 
     266                } 
     267 
    261268                $avatar = get_avatar( $user_object->ID, 32 ); 
    262269 
    263270                $r = "<tr id='user-$user_object->ID'$style>"; 
  • wp-admin/user-edit.php

     
    130130                        $delete_role = true; 
    131131                } 
    132132        } 
    133         if ( !isset( $errors ) || ( isset( $errors ) && is_object( $errors ) && false == $errors->get_error_codes() ) ) 
     133        if ( !isset( $errors ) || ( isset( $errors ) && is_object( $errors ) && false == $errors->get_error_codes() ) ) { 
    134134                $errors = edit_user($user_id); 
     135                $user   = get_userdata( $user_id ); 
     136        } 
     137 
    135138        if ( $delete_role ) // stops users being added to current blog when they are edited 
    136                 delete_user_meta( $user_id, $blog_prefix . 'capabilities' ); 
     139                $user->remove_role( $_POST[ 'role' ] ); 
    137140 
    138141        if ( is_multisite() && is_network_admin() && !IS_PROFILE_PAGE && current_user_can( 'manage_network_options' ) && !isset($super_admins) && empty( $_POST['super_admin'] ) == is_super_admin( $user_id ) ) 
    139142                empty( $_POST['super_admin'] ) ? revoke_super_admin( $user_id ) : grant_super_admin( $user_id ); 
     
    249252<tr><th><label for="role"><?php _e('Role') ?></label></th> 
    250253<td><select name="role" id="role"> 
    251254<?php 
    252 // Get the highest/primary role for this user 
     255// Compare user role against currently editable roles 
    253256// TODO: create a function that does this: wp_get_user_role() 
    254 $user_roles = $profileuser->roles; 
    255 $user_role = array_shift($user_roles); 
     257$user_roles = array_intersect( array_values( $profileuser->roles ), array_keys( get_editable_roles() ) ); 
     258$user_role  = array_shift( $user_roles ); 
    256259 
    257260// print the full list of roles with the primary one selected. 
    258261wp_dropdown_roles($user_role);