Make WordPress Core

Changeset 22686


Ignore:
Timestamp:
11/19/2012 07:16:31 PM (12 years ago)
Author:
nacin
Message:

Less insane multiple role handling in the users list table.

If the user has more than one role, opt to show the first role that is
'editable', if present. Otherwise, fall back to the remaining roles.

In the future, we should show a comma-separated list of all roles,
editable or otherwise, and this list should be filterable, either by user,
or by the roles which can appear. Probably both.

In multisite, only hide users that have no capabilities (in case they
possess a leftover, empty wp_xx_capabilities key from the MU days),
not users that have no role, as they may have a cap but no role.

see #22361. fixes #17860.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-users-list-table.php

    r22423 r22686  
    194194            $post_counts = count_many_users_posts( array_keys( $this->items ) );
    195195
     196        $editable_roles = array_keys( get_editable_roles() );
     197
    196198        $style = '';
    197199        foreach ( $this->items as $userid => $user_object ) {
    198             $role = reset( $user_object->roles );
    199 
    200             if ( is_multisite() && empty( $role ) )
     200            if ( count( $user_object->roles ) <= 1 ) {
     201                $role = reset( $user_object->roles );
     202            } elseif ( $roles = array_intersect( array_values( $user_object->roles ), $editable_roles ) ) {
     203                $role = reset( $roles );
     204            } else {
     205                $role = reset( $user_object->roles );
     206            }
     207
     208            if ( is_multisite() && empty( $role->allcaps ) )
    201209                continue;
    202210
Note: See TracChangeset for help on using the changeset viewer.