Changeset 41613
- Timestamp:
- 09/27/2017 01:03:03 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-users-list-table.php
r41180 r41613 167 167 168 168 $wp_roles = wp_roles(); 169 $count_users = true; 170 171 if ( wp_is_large_user_count() ) { 172 $count_users = false; 173 } elseif ( is_multisite() && wp_is_large_network( 'users' ) ) { 174 $count_users = false; 175 } 169 176 170 177 if ( $this->is_site_users ) { 171 178 $url = 'site-users.php?id=' . $this->site_id; 172 switch_to_blog( $this->site_id ); 173 $users_of_blog = count_users( 'time', $this->site_id ); 174 restore_current_blog(); 179 if ( $count_users ) { 180 switch_to_blog( $this->site_id ); 181 $users_of_blog = count_users( 'time', $this->site_id ); 182 restore_current_blog(); 183 } 175 184 } else { 176 185 $url = 'users.php'; 177 $users_of_blog = count_users(); 178 } 179 180 $total_users = $users_of_blog['total_users']; 181 $avail_roles =& $users_of_blog['avail_roles']; 182 unset($users_of_blog); 186 if ( $count_users ) { 187 $users_of_blog = count_users(); 188 } 189 } 190 191 if ( $count_users ) { 192 $total_users = $users_of_blog['total_users']; 193 $avail_roles =& $users_of_blog['avail_roles']; 194 unset($users_of_blog); 195 } else { 196 $avail_roles = array(); 197 } 183 198 184 199 $class = empty($role) ? ' class="current"' : ''; 185 200 $role_links = array(); 186 $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>'; 201 202 if ( $count_users ) { 203 $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>'; 204 } else { 205 $role_links['all'] = "<a href='$url'$class>" . _x( 'All', 'users' ) . '</a>'; 206 } 187 207 foreach ( $wp_roles->get_names() as $this_role => $name ) { 188 if ( !isset($avail_roles[$this_role]) )208 if ( $count_users && !isset($avail_roles[$this_role]) ) { 189 209 continue; 210 } 190 211 191 212 $class = ''; … … 196 217 197 218 $name = translate_user_role( $name ); 198 /* translators: User role name with count */ 199 $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, number_format_i18n( $avail_roles[$this_role] ) ); 219 if ( $count_users ) { 220 /* translators: User role name with count */ 221 $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, number_format_i18n( $avail_roles[$this_role] ) ); 222 } 200 223 $role_links[$this_role] = "<a href='" . esc_url( add_query_arg( 'role', $this_role, $url ) ) . "'$class>$name</a>"; 201 224 } 202 225 203 if ( ! empty( $avail_roles['none' ] ) ) {226 if ( ! $count_users || ! empty( $avail_roles['none' ] ) ) { 204 227 205 228 $class = ''; … … 210 233 211 234 $name = __( 'No role' ); 212 /* translators: User role name with count */ 213 $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, number_format_i18n( $avail_roles['none' ] ) ); 235 if ( $count_users ) { 236 /* translators: User role name with count */ 237 $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, number_format_i18n( $avail_roles['none' ] ) ); 238 } 214 239 $role_links['none'] = "<a href='" . esc_url( add_query_arg( 'role', 'none', $url ) ) . "'$class>$name</a>"; 215 240 -
trunk/src/wp-includes/default-filters.php
r41361 r41613 467 467 add_action( 'init', 'wp_widgets_init', 1 ); 468 468 469 // User counts 470 foreach ( array( 'user_register', 'deleted_user' ) as $action ){ 471 add_action( $action, 'wp_update_active_user_count' ); 472 } 473 469 474 // Admin Bar 470 475 // Don't remove. Wrong way to disable. -
trunk/src/wp-includes/functions.php
r41388 r41613 5834 5834 ), $email_change_email['message'], $email_change_email['headers'] ); 5835 5835 } 5836 5837 /** 5838 * Whether or not we have a large site, based on its number of users. 5839 * 5840 * The default criteria for a large site is more than 10,000 users. 5841 * 5842 * @since 4.9.0 5843 * 5844 * @return bool True if the site meets the criteria for large. False otherwise. 5845 */ 5846 function wp_is_large_user_count() { 5847 $count = wp_get_active_user_count(); 5848 5849 /** 5850 * Filters whether the site is considered large, based on its number of users. 5851 * 5852 * The default criteria for a large site is more than 10,000 users. 5853 * 5854 * @since 4.9.0 5855 * 5856 * @param bool $is_large_user_count Whether the site is considered large. 5857 * @param int $count The number of users on the site. 5858 */ 5859 return apply_filters( 'wp_is_large_user_count', $count > 10000, $count ); 5860 } 5861 5862 /** 5863 * Update the active user count. 5864 * 5865 * @since 4.9.0 5866 * @global wpdb $wpdb WordPress database abstraction object. 5867 * 5868 * @return int The active user count. 5869 */ 5870 function wp_update_active_user_count() { 5871 global $wpdb; 5872 5873 $count = $wpdb->get_var( " 5874 SELECT COUNT(ID) as c 5875 FROM {$wpdb->users} 5876 " ); 5877 $count=12345; 5878 update_option( 'active_user_count', $count ); 5879 5880 return (int) $count; 5881 } 5882 5883 /** 5884 * The number of active users. 5885 * 5886 * @since 4.9.0 5887 * 5888 * @return int The active user count. 5889 */ 5890 function wp_get_active_user_count() { 5891 $count = get_option( 'active_user_count', false ); 5892 5893 if ( false === $count ) { 5894 $count = wp_update_active_user_count(); 5895 } 5896 return (int) $count; 5897 } -
trunk/src/wp-includes/ms-functions.php
r41596 r41613 2554 2554 if ( 'users' == $using ) { 2555 2555 $count = get_user_count( $network_id ); 2556 $is_large = ( $count > 10000 ); 2557 2558 /** This filter is documented in wp-includes/functions.php */ 2559 $is_large = apply_filters( 'wp_is_large_user_count', $is_large, $count ); 2560 2556 2561 /** 2557 2562 * Filters whether the network is considered large. … … 2565 2570 * @param int $network_id The ID of the network being checked. 2566 2571 */ 2567 return apply_filters( 'wp_is_large_network', $ count > 10000, 'users', $count, $network_id );2572 return apply_filters( 'wp_is_large_network', $is_large, 'users', $count, $network_id ); 2568 2573 } 2569 2574 -
trunk/src/wp-includes/update.php
r41605 r41613 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; -
trunk/tests/phpunit/tests/functions.php
r41388 r41613 1161 1161 return $data; 1162 1162 } 1163 1164 /** 1165 * @ticket 38741 1166 */ 1167 public function test_wp_get_active_user_count() { 1168 $user_count = wp_get_active_user_count(); 1169 $this->assertSame( $user_count, 1 ); 1170 1171 // make twenty additional users to make 21 users 1172 self::factory()->user->create_many( 20 ); 1173 1174 $user_count = wp_get_active_user_count(); 1175 $this->assertSame( $user_count, 21 ); 1176 } 1177 1178 /** 1179 * @ticket 38741 1180 */ 1181 public function test_wp_get_active_user_count_caching() { 1182 global $wpdb; 1183 1184 // Ensure we start with 1 user 1185 $user_count = wp_get_active_user_count(); 1186 $this->assertSame( $user_count, 1 ); 1187 1188 self::factory()->user->create(); 1189 1190 delete_option( 'active_user_count' ); 1191 1192 // Ensure we now have 2 users 1193 $user_count = wp_get_active_user_count(); 1194 $this->assertSame( $user_count, 2 ); 1195 1196 $queries = $wpdb->num_queries; 1197 1198 // Ensure that caching inside wp_get_active_user_count() works as expected 1199 $user_count = wp_get_active_user_count(); 1200 $this->assertSame( $user_count, 2 ); 1201 $this->assertSame( $queries, $wpdb->num_queries ); 1202 } 1203 1204 /** 1205 * @ticket 38741 1206 */ 1207 public function test_wp_is_large_user_count() { 1208 // set the 'active_user_count' value to over 10000 to emulate a large site 1209 update_option( 'active_user_count', 10001 ); 1210 $user_count = wp_get_active_user_count(); 1211 $this->assertSame( $user_count, 10001 ); 1212 $this->assertTrue( wp_is_large_user_count() ); 1213 1214 delete_option( 'active_user_count' ); 1215 $this->assertFalse( wp_is_large_user_count() ); 1216 } 1163 1217 }
Note: See TracChangeset
for help on using the changeset viewer.