Ticket #38741: 38741.4.diff
File 38741.4.diff, 8.5 KB (added by , 7 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/default-filters.php
456 456 // Widgets 457 457 add_action( 'init', 'wp_widgets_init', 1 ); 458 458 459 // User counts 460 foreach ( array( 'user_register', 'deleted_user' ) as $action ){ 461 add_action( $action, 'wp_maybe_update_active_user_count' ); 462 } 463 459 464 // Admin Bar 460 465 // Don't remove. Wrong way to disable. 461 466 add_action( 'template_redirect', '_wp_admin_bar_init', 0 ); -
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_user_count 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_user_count', $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_update_active_user_count() { 5676 global $wpdb; 5677 5678 $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users" ); 5679 update_option( 'active_user_count', $count ); 5680 5681 return $count; 5682 } 5683 5684 /** 5685 * The number of active users. 5686 * 5687 * The count is cached for a minimum of twelve hours. This is not a live count. 5688 * 5689 * @since x.x.x 5690 * 5691 * @return int 5692 */ 5693 function wp_get_active_user_count() { 5694 5695 $count = get_option( 'active_user_count' ); 5696 5697 if ( empty ( $count ) ){ 5698 $count = wp_update_active_user_count(); 5699 } 5700 return (int) $count; 5701 } 5702 5703 /** 5704 * Update the user count. 5705 * 5706 * If enabled through the {@see 'enable_live_network_counts'} filter, update the sites count 5707 * on a network when a site is created or its status is updated. 5708 * 5709 * @since x.x.x 5710 */ 5711 function wp_maybe_update_active_user_count() { 5712 $is_small_site = ! wp_is_large_site(); 5713 5714 /** 5715 * Filters whether to update network site or user counts when a new site is created. 5716 * 5717 * @since x.x.x 5718 * 5719 * @see wp_is_large_site() 5720 * 5721 * @param bool $small_site Whether the site is considered small. 5722 */ 5723 if ( ! apply_filters( 'enable_live_site_counts', $is_small_site ) ){ 5724 return; 5725 } 5726 5727 wp_update_active_user_count(); 5728 } -
src/wp-includes/ms-functions.php
2486 2486 function wp_is_large_network( $using = 'sites' ) { 2487 2487 if ( 'users' == $using ) { 2488 2488 $count = get_user_count(); 2489 $is_large = ( $count > 10000 ); 2490 /** This filter is documented in wp-includes/functions.php */ 2491 $is_large = apply_filters( 'wp_is_large_user_count', $is_large, $count ); 2489 2492 /** 2490 2493 * Filters whether the network is considered large. 2491 2494 * … … 2495 2498 * @param string $component The component to count. Accepts 'users', or 'sites'. 2496 2499 * @param int $count The count of items for the component. 2497 2500 */ 2498 return apply_filters( 'wp_is_large_network', $ count > 10000, 'users', $count );2501 return apply_filters( 'wp_is_large_network', $is_large, 'users', $count ); 2499 2502 } 2500 2503 2501 2504 $count = get_blog_count(); -
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_get_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 update_option( 'active_user_count', 10001 ); 1145 $this->assertTrue( wp_is_large_site() ); 1146 delete_option( 'active_user_count' ); 1147 } 1117 1148 }