Ticket #38741: 38741.3.diff
File 38741.3.diff, 6.3 KB (added by , 8 years ago) |
---|
-
src/wp-admin/includes/class-wp-users-list-table.php
173 173 global $role; 174 174 175 175 $wp_roles = wp_roles(); 176 $count_users = true; 176 177 178 if ( wp_is_large_site() ) { 179 $count_users = false; 180 } elseif ( is_multisite() && wp_is_large_network( 'users' ) ) { 181 $count_users = false; 182 } 183 177 184 if ( $this->is_site_users ) { 178 185 $url = 'site-users.php?id=' . $this->site_id; 179 switch_to_blog( $this->site_id ); 180 $users_of_blog = count_users(); 181 restore_current_blog(); 186 if ( $count_users ) { 187 switch_to_blog( $this->site_id ); 188 $users_of_blog = count_users(); 189 restore_current_blog(); 190 } 182 191 } else { 183 192 $url = 'users.php'; 184 $users_of_blog = count_users(); 193 if ( $count_users ) { 194 $users_of_blog = count_users(); 195 } 185 196 } 186 197 187 $total_users = $users_of_blog['total_users']; 188 $avail_roles =& $users_of_blog['avail_roles']; 189 unset($users_of_blog); 198 if ( $count_users ) { 199 $total_users = $users_of_blog['total_users']; 200 $avail_roles =& $users_of_blog['avail_roles']; 201 unset( $users_of_blog ); 202 } else { 203 $avail_roles = array(); 204 } 190 205 191 206 $class = empty($role) ? ' class="current"' : ''; 192 207 $role_links = array(); 193 $role_links['all'] = "<a href='$url'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>'; 208 209 if ( $count_users ) { 210 $role_links['all'] = "<a href='$url'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>'; 211 } else { 212 $role_links['all'] = "<a href='$url'$class>" . _x( 'All', 'users' ) . '</a>'; 213 } 214 194 215 foreach ( $wp_roles->get_names() as $this_role => $name ) { 195 if ( !isset($avail_roles[$this_role]) )216 if ( $count_users && ! isset( $avail_roles[ $this_role ] ) ) { 196 217 continue; 218 } 197 219 198 220 $class = ''; 199 221 … … 202 224 } 203 225 204 226 $name = translate_user_role( $name ); 205 /* translators: User role name with count */ 206 $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, number_format_i18n( $avail_roles[$this_role] ) ); 227 if ( $count_users ) { 228 /* translators: User role name with count */ 229 $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, number_format_i18n( $avail_roles[$this_role] ) ); 230 } 207 231 $role_links[$this_role] = "<a href='" . esc_url( add_query_arg( 'role', $this_role, $url ) ) . "'$class>$name</a>"; 208 232 } 209 233 210 if ( ! empty( $avail_roles['none' ] ) ) {234 if ( ! $count_users || ! empty( $avail_roles['none' ] ) ) { 211 235 212 236 $class = ''; 213 237 … … 216 240 } 217 241 218 242 $name = __( 'No role' ); 219 /* translators: User role name with count */ 220 $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, number_format_i18n( $avail_roles['none' ] ) ); 243 if ( $count_users ) { 244 /* translators: User role name with count */ 245 $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, number_format_i18n( $avail_roles['none' ] ) ); 246 } 221 247 $role_links['none'] = "<a href='" . esc_url( add_query_arg( 'role', 'none', $url ) ) . "'$class>$name</a>"; 222 248 223 249 } -
src/wp-includes/functions.php
5642 5642 5643 5643 return $last_changed; 5644 5644 } 5645 5646 /** 5647 * Whether or not we have a large site. 5648 * 5649 * The default criteria for a large site is more than 10,000 users. 5650 * 5651 * @since x.x.x 5652 * 5653 * @return bool True if the site meets the criteria for large. False otherwise. 5654 */ 5655 function wp_is_large_site() { 5656 $count = wp_get_active_user_count(); 5657 /** 5658 * Filters whether the site is considered large. 5659 * 5660 * @since x.x.x 5661 * 5662 * @param bool $is_large_site Whether the site has more than 10000 users. 5663 * @param int $count The count of items for the component. 5664 */ 5665 return apply_filters( 'wp_is_large_site', $count > 10000, $count ); 5666 } 5667 5668 /** 5669 * Update the active user count. 5670 * 5671 * @since x.x.x 5672 * 5673 * @global wpdb $wpdb WordPress database abstraction object. 5674 */ 5675 function wp_active_user_count() { 5676 global $wpdb; 5677 5678 $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users" ); 5679 return $count; 5680 } 5681 5682 /** 5683 * The number of active users. 5684 * 5685 * The count is cached for a minimum of twelve hours. This is not a live count. 5686 * 5687 * @since x.x.x 5688 * 5689 * @return int 5690 */ 5691 function wp_get_active_user_count() { 5692 $count = get_transient( 'active_user_count' ); 5693 5694 if ( false === $count ) { 5695 $count = wp_active_user_count(); 5696 set_transient( 'active_user_count', $count, 12 * HOUR_IN_SECONDS ); 5697 } 5698 5699 return (int) $count; 5700 } -
src/wp-includes/update.php
78 78 $wp_install = network_site_url(); 79 79 $multisite_enabled = 1; 80 80 } else { 81 $user_count = count_users(); 82 $user_count = $user_count['total_users']; 81 $user_count = wp_get_active_user_count(); 83 82 $multisite_enabled = 0; 84 83 $num_blogs = 1; 85 84 $wp_install = home_url( '/' ); -
tests/phpunit/tests/functions.php
1114 1114 1115 1115 return $data; 1116 1116 } 1117 1118 /* 1119 * @ticket 38741 1120 */ 1121 1122 public function test_wp_get_active_user_count(){ 1123 1124 // make twenty additional users to make 21 users 1125 for( $i = 0; $i < 20; $i++ ){ 1126 self::factory()->user->create(); 1127 } 1128 1129 $user_count = wp_active_user_count(); 1130 1131 $this->assertEquals( $user_count, 21 ); 1132 } 1133 1134 /* 1135 * @ticket 38741 1136 */ 1137 public function test_wp_is_large_site(){ 1138 1139 if ( wp_using_ext_object_cache() ) { 1140 $this->markTestSkipped( 'Not testable with an external object cache.' ); 1141 } 1142 1143 // set the 'active_user_count' transient to over 10000 to emulate a large site 1144 set_transient( 'active_user_count', 10001 ); 1145 $this->assertTrue( wp_is_large_site() ); 1146 delete_transient( 'active_user_count' ); 1147 } 1117 1148 }