Ticket #38741: 38741.6.diff
File 38741.6.diff, 8.4 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/class-wp-users-list-table.php
diff --git src/wp-admin/includes/class-wp-users-list-table.php src/wp-admin/includes/class-wp-users-list-table.php index 61ea897c5a..6825bca5f0 100644
class WP_Users_List_Table extends WP_List_Table { 166 166 global $role; 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(); 186 if ( $count_users ) { 187 $users_of_blog = count_users(); 188 } 178 189 } 179 190 180 $total_users = $users_of_blog['total_users']; 181 $avail_roles =& $users_of_blog['avail_roles']; 182 unset($users_of_blog); 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 = ''; 192 213 … … class WP_Users_List_Table extends WP_List_Table { 195 216 } 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 = ''; 206 229 … … class WP_Users_List_Table extends WP_List_Table { 209 232 } 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 216 241 } -
src/wp-includes/default-filters.php
diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php index a196f4ff19..23355d0759 100644
add_filter( 'nav_menu_item_id', '_nav_menu_item_id_use_once', 10, 2 ); 464 464 // Widgets 465 465 add_action( 'init', 'wp_widgets_init', 1 ); 466 466 467 // User counts 468 foreach ( array( 'user_register', 'deleted_user' ) as $action ){ 469 add_action( $action, 'wp_update_active_user_count' ); 470 } 471 467 472 // Admin Bar 468 473 // Don't remove. Wrong way to disable. 469 474 add_action( 'template_redirect', '_wp_admin_bar_init', 0 ); -
src/wp-includes/functions.php
diff --git src/wp-includes/functions.php src/wp-includes/functions.php index 03c6126d5b..22314b2910 100644
All at ###SITENAME### 5734 5734 $site_name 5735 5735 ), $email_change_email['message'], $email_change_email['headers'] ); 5736 5736 } 5737 5738 /** 5739 * Whether or not we have a large site, based on its number of users. 5740 * 5741 * The default criteria for a large site is more than 10,000 users. 5742 * 5743 * @since x.x.x 5744 * 5745 * @return bool True if the site meets the criteria for large. False otherwise. 5746 */ 5747 function wp_is_large_user_count() { 5748 $count = wp_get_active_user_count(); 5749 return true; 5750 /** 5751 * Filters whether the site is considered large, based on its number of users. 5752 * 5753 * @since x.x.x 5754 * 5755 * @param bool $is_large_user_count Whether the site has more than 10000 users. 5756 * @param int $count The count of items for the component. 5757 */ 5758 return apply_filters( 'wp_is_large_user_count', $count > 10000, $count ); 5759 } 5760 5761 /** 5762 * Update the active user count. 5763 * 5764 * @since x.x.x 5765 * 5766 * @global wpdb $wpdb WordPress database abstraction object. 5767 * 5768 * @return int The active user count. 5769 */ 5770 function wp_update_active_user_count() { 5771 global $wpdb; 5772 5773 $count = $wpdb->get_var( " 5774 SELECT COUNT(ID) as c 5775 FROM $wpdb->users 5776 " ); 5777 update_option( 'active_user_count', $count ); 5778 5779 return (int) $count; 5780 } 5781 5782 /** 5783 * The number of active users. 5784 * 5785 * @since x.x.x 5786 * 5787 * @return int The active user count. 5788 */ 5789 function wp_get_active_user_count() { 5790 $count = get_option( 'active_user_count', false ); 5791 5792 if ( false === $count ) { 5793 $count = wp_update_active_user_count(); 5794 } 5795 return (int) $count; 5796 } -
src/wp-includes/ms-functions.php
diff --git src/wp-includes/ms-functions.php src/wp-includes/ms-functions.php index 7c28844e0c..2dd90d0432 100644
function wp_is_large_network( $using = 'sites', $network_id = null ) { 2550 2550 2551 2551 if ( 'users' == $using ) { 2552 2552 $count = get_user_count( $network_id ); 2553 $is_large = ( $count > 10000 ); 2554 2555 /** This filter is documented in wp-includes/functions.php */ 2556 $is_large = apply_filters( 'wp_is_large_user_count', $is_large, $count ); 2557 2553 2558 /** 2554 2559 * Filters whether the network is considered large. 2555 2560 * … … function wp_is_large_network( $using = 'sites', $network_id = null ) { 2561 2566 * @param int $count The count of items for the component. 2562 2567 * @param int $network_id The ID of the network being checked. 2563 2568 */ 2564 return apply_filters( 'wp_is_large_network', $ count > 10000, 'users', $count, $network_id );2569 return apply_filters( 'wp_is_large_network', $is_large, 'users', $count, $network_id ); 2565 2570 } 2566 2571 2567 2572 $count = get_blog_count( $network_id ); -
src/wp-includes/update.php
diff --git src/wp-includes/update.php src/wp-includes/update.php index f25e644d62..a14e050bd3 100644
function wp_version_check( $extra_stats = array(), $force_check = false ) { 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
diff --git tests/phpunit/tests/functions.php tests/phpunit/tests/functions.php index 252d890bbb..4f231cc286 100644
class Tests_Functions extends WP_UnitTestCase { 1110 1110 1111 1111 return $data; 1112 1112 } 1113 1114 /* 1115 * @ticket 38741 1116 */ 1117 1118 public function test_wp_get_active_user_count(){ 1119 1120 // make twenty additional users to make 21 users 1121 for( $i = 0; $i < 20; $i++ ){ 1122 self::factory()->user->create(); 1123 } 1124 1125 $user_count = wp_get_active_user_count(); 1126 1127 $this->assertEquals( $user_count, 21 ); 1128 } 1129 1130 /* 1131 * @ticket 38741 1132 */ 1133 public function test_wp_is_large_user_count(){ 1134 1135 if ( wp_using_ext_object_cache() ) { 1136 $this->markTestSkipped( 'Not testable with an external object cache.' ); 1137 } 1138 1139 // set the 'active_user_count' transient to over 10000 to emulate a large site 1140 update_option( 'active_user_count', 10001 ); 1141 $this->assertTrue( wp_is_large_user_count() ); 1142 delete_option( 'active_user_count' ); 1143 } 1113 1144 }