Ticket #38741: 38741.5.diff
File 38741.5.diff, 8.9 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..90711e2f1b 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_site() ) { 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..4db2b37339 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_maybe_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..7629fea0e1 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. 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_site() { 5748 $count = wp_get_active_user_count(); 5749 /** 5750 * Filters whether the site is considered large. 5751 * 5752 * @since x.x.x 5753 * 5754 * @param bool $is_large_user_count Whether the site has more than 10000 users. 5755 * @param int $count The count of items for the component. 5756 */ 5757 return apply_filters( 'wp_is_large_user_count', $count > 10000, $count ); 5758 } 5759 5760 /** 5761 * Update the active user count. 5762 * 5763 * @since x.x.x 5764 * 5765 * @global wpdb $wpdb WordPress database abstraction object. 5766 */ 5767 function wp_update_active_user_count() { 5768 global $wpdb; 5769 5770 $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users" ); 5771 update_option( 'active_user_count', $count ); 5772 5773 return $count; 5774 } 5775 5776 /** 5777 * The number of active users. 5778 * 5779 * The count is cached for a minimum of twelve hours. This is not a live count. 5780 * 5781 * @since x.x.x 5782 * 5783 * @return int 5784 */ 5785 function wp_get_active_user_count() { 5786 5787 $count = get_option( 'active_user_count' ); 5788 5789 if ( empty ( $count ) ){ 5790 $count = wp_update_active_user_count(); 5791 } 5792 return (int) $count; 5793 } 5794 5795 /** 5796 * Update the user count. 5797 * 5798 * If enabled through the {@see 'enable_live_network_counts'} filter, update the sites count 5799 * on a network when a site is created or its status is updated. 5800 * 5801 * @since x.x.x 5802 */ 5803 function wp_maybe_update_active_user_count() { 5804 $is_small_site = ! wp_is_large_site(); 5805 5806 /** 5807 * Filters whether to update network site or user counts when a new site is created. 5808 * 5809 * @since x.x.x 5810 * 5811 * @see wp_is_large_site() 5812 * 5813 * @param bool $small_site Whether the site is considered small. 5814 */ 5815 if ( ! apply_filters( 'enable_live_site_counts', $is_small_site ) ){ 5816 return; 5817 } 5818 5819 wp_update_active_user_count(); 5820 } -
src/wp-includes/ms-functions.php
diff --git src/wp-includes/ms-functions.php src/wp-includes/ms-functions.php index 7c28844e0c..472a239a1a 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 /** This filter is documented in wp-includes/functions.php */ 2555 $is_large = apply_filters( 'wp_is_large_user_count', $is_large, $count ); 2553 2556 /** 2554 2557 * Filters whether the network is considered large. 2555 2558 * … … function wp_is_large_network( $using = 'sites', $network_id = null ) { 2561 2564 * @param int $count The count of items for the component. 2562 2565 * @param int $network_id The ID of the network being checked. 2563 2566 */ 2564 return apply_filters( 'wp_is_large_network', $ count > 10000, 'users', $count, $network_id );2567 return apply_filters( 'wp_is_large_network', $is_large, 'users', $count, $network_id ); 2565 2568 } 2566 2569 2567 2570 $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..6816d1923e 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_site(){ 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_site() ); 1142 delete_option( 'active_user_count' ); 1143 } 1113 1144 }