WordPress.org

Make WordPress Core

Ticket #11726: 11726.2.patch

File 11726.2.patch, 1.5 KB (added by prettyboymp, 8 years ago)
  • wp-admin/users.php

     
    265265<?php
    266266$role_links = array();
    267267$avail_roles = array();
    268 $users_of_blog = get_users_of_blog();
    269 $total_users = count( $users_of_blog );
    270 foreach ( (array) $users_of_blog as $b_user ) {
    271         $b_roles = unserialize($b_user->meta_value);
    272         foreach ( (array) $b_roles as $b_role => $val ) {
    273                 if ( !isset($avail_roles[$b_role]) )
    274                         $avail_roles[$b_role] = 0;
    275                 $avail_roles[$b_role]++;
    276         }
     268$role_search = new WP_User_Search();
     269$total_users = $role_search->total_users_for_query;
     270$role_search->users_per_page = 1; //no need to get more than 1 result since we only need the count
     271$registered_roles = $wp_roles->get_names();
     272
     273foreach( $registered_roles as $role_key => $role_name ) {
     274        $role_search->role = $role_key;
     275        $role_search->prepare_query();
     276        $role_search->query();
     277        if( $role_search->total_users_for_query > 0 )
     278                $avail_roles[$role_key] = $role_search->total_users_for_query;
    277279}
    278 unset($users_of_blog);
    279280
    280281$current_role = false;
    281282$class = empty($role) ? ' class="current"' : '';
    282283$role_links[] = "<li><a href='users.php'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>';
    283 foreach ( $wp_roles->get_names() as $this_role => $name ) {
     284foreach ( $registered_roles as $this_role => $name ) {
    284285        if ( !isset($avail_roles[$this_role]) )
    285286                continue;
    286287