WordPress.org

Make WordPress Core

Ticket #15636: 15636.1.patch

File 15636.1.patch, 1.1 KB (added by mario-siteground, 17 months ago)
  • wp-admin/includes/user.php

     
    184184        global $wp_roles; 
    185185 
    186186        $all_roles = $wp_roles->roles; 
     187         
     188        uasort( $editable_roles, '_sort_editable_roles' ); 
     189         
    187190        $editable_roles = apply_filters('editable_roles', $all_roles); 
    188191 
    189192        return $editable_roles; 
    190193} 
    191194 
    192195/** 
     196 * Helper function used in the one above - get_editable_roles, as sorting 
     197 * callback, in order to achieve sorted roles by capabilities. 
     198 *   
     199 * @param array $role_a 
     200 * @param array $role_b 
     201 * @return int 
     202 */ 
     203function _sort_editable_roles($role_a, $role_b) { 
     204        $first_cap_count = count( $role_a['capabilities'] ); 
     205        $second_cap_count = count( $role_b['capabilities'] ); 
     206 
     207        // The capability count is equal, sorting by name then. 
     208        if ( $first_cap_count == $second_cap_count ) 
     209                return strcmp ( $role_a['name'], $role_b['name'] ); 
     210 
     211        // Less capabilities goes up 
     212        return ( $first_cap_count > $second_cap_count ) ? 1 : -1; 
     213} 
     214 
     215/** 
    193216 * Retrieve user data and filter it. 
    194217 * 
    195218 * @since 2.0.5