WordPress.org

Make WordPress Core

Ticket #11726: 11726.patch

File 11726.patch, 1.5 KB (added by prettyboymp, 4 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{ 
     275        $role_search->role = $role_key; 
     276        $role_search->prepare_query(); 
     277        $role_search->query(); 
     278        if( $role_search->total_users_for_query > 0 ) 
     279                $avail_roles[$role_key] = $role_search->total_users_for_query; 
    277280} 
    278 unset($users_of_blog); 
    279281 
    280282$current_role = false; 
    281283$class = empty($role) ? ' class="current"' : ''; 
    282284$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 ) { 
     285foreach ( $registered_roles as $this_role => $name ) { 
    284286        if ( !isset($avail_roles[$this_role]) ) 
    285287                continue; 
    286288