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.



git-svn-id: http://core.svn.wordpress.org/trunk@22686 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2012-11-19 19:16:31 +00:00
parent 22579938ae
commit d88922565e

View File

@ -193,11 +193,19 @@ class WP_Users_List_Table extends WP_List_Table {
if ( ! $this->is_site_users )
$post_counts = count_many_users_posts( array_keys( $this->items ) );
$editable_roles = array_keys( get_editable_roles() );
$style = '';
foreach ( $this->items as $userid => $user_object ) {
$role = reset( $user_object->roles );
if ( count( $user_object->roles ) <= 1 ) {
$role = reset( $user_object->roles );
} elseif ( $roles = array_intersect( array_values( $user_object->roles ), $editable_roles ) ) {
$role = reset( $roles );
} else {
$role = reset( $user_object->roles );
}
if ( is_multisite() && empty( $role ) )
if ( is_multisite() && empty( $role->allcaps ) )
continue;
$style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';