Ticket #38741: 38741.8.diff
File 38741.8.diff, 12.2 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/class-wp-users-list-table.php
177 177 178 178 $wp_roles = wp_roles(); 179 179 180 $count_users = ! wp_is_large_user_count(); 181 180 182 if ( $this->is_site_users ) { 181 183 $url = 'site-users.php?id=' . $this->site_id; 182 switch_to_blog( $this->site_id );183 $users_of_blog = count_users( 'time', $this->site_id );184 restore_current_blog();185 184 } else { 186 $url = 'users.php'; 187 $users_of_blog = count_users(); 185 $url = 'users.php'; 188 186 } 189 187 190 $total_users = $users_of_blog['total_users']; 191 $avail_roles =& $users_of_blog['avail_roles']; 192 unset( $users_of_blog ); 188 $role_links = array(); 189 if ( $count_users ) { 190 if ( $this->is_site_users ) { 191 switch_to_blog( $this->site_id ); 192 $users_of_blog = count_users( 'time', $this->site_id ); 193 restore_current_blog(); 194 } else { 195 $users_of_blog = count_users(); 196 } 193 197 198 $total_users = $users_of_blog['total_users']; 199 $avail_roles =& $users_of_blog['avail_roles']; 200 unset( $users_of_blog ); 201 $role_links['all'] = "<a href='$url'$current_link_attributes>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>'; 202 } else { 203 $avail_roles = array(); 204 $role_links['all'] = "<a href='$url'$current_link_attributes>" . __( 'All' ) . '</a>'; 205 } 206 194 207 $current_link_attributes = empty( $role ) ? ' class="current" aria-current="page"' : ''; 195 196 $role_links = array();197 $role_links['all'] = "<a href='$url'$current_link_attributes>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>';198 208 foreach ( $wp_roles->get_names() as $this_role => $name ) { 199 if ( ! isset( $avail_roles[ $this_role ] ) ) {209 if ( $count_users && ! isset( $avail_roles[ $this_role ] ) ) { 200 210 continue; 201 211 } 202 212 … … 208 218 209 219 $name = translate_user_role( $name ); 210 220 /* translators: User role name with count */ 211 $name = sprintf( __( '%1$s <span class="count">(%2$s)</span>' ), $name, number_format_i18n( $avail_roles[ $this_role ] ) ); 221 if ( $count_users ) { 222 $name = sprintf( __( '%1$s <span class="count">(%2$s)</span>' ), $name, number_format_i18n( $avail_roles[ $this_role ] ) ); 223 } 212 224 $role_links[ $this_role ] = "<a href='" . esc_url( add_query_arg( 'role', $this_role, $url ) ) . "'$current_link_attributes>$name</a>"; 213 225 } 214 226 -
src/wp-admin/includes/schema.php
1133 1133 'subdomain_install' => intval( $subdomain_install ), 1134 1134 'global_terms_enabled' => global_terms_enabled() ? '1' : '0', 1135 1135 'ms_files_rewriting' => is_multisite() ? get_site_option( 'ms_files_rewriting' ) : '0', 1136 'user_count' => get_site_option( 'user_count' ), 1136 1137 'initial_db_version' => get_option( 'initial_db_version' ), 1137 1138 'active_sitewide_plugins' => array(), 1138 1139 'WPLANG' => get_locale(), -
src/wp-includes/default-filters.php
98 98 // Meta 99 99 add_filter( 'register_meta_args', '_wp_register_meta_args_whitelist', 10, 2 ); 100 100 101 // Counts 102 add_action( 'admin_init', 'wp_schedule_update_network_counts' ); 103 add_action( 'update_network_counts', 'wp_update_network_user_counts', 10, 0 ); 104 foreach ( array( 'user_register', 'deleted_user', 'wpmu_new_user', 'make_spam_user', 'make_ham_user' ) as $action ) { 105 add_action( $action, 'wp_maybe_update_network_user_counts', 10, 0 ); 106 } 107 101 108 // Places to balance tags on input 102 109 foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) { 103 110 add_filter( $filter, 'convert_invalid_entities' ); -
src/wp-includes/functions.php
6346 6346 } 6347 6347 } 6348 6348 } 6349 6350 /** 6351 * The number of active users in your installation. 6352 * 6353 * The count is cached and updated twice daily. This is not a live count. 6354 * 6355 * @since MU (3.0.0) 6356 * @since 4.8.0 The `$network_id` parameter has been added. 6357 * @since 5.0.0 Moved to functions.php 6358 * 6359 * @param int|null $network_id ID of the network. Default is the current network. 6360 * @return int Number of active users on the network. 6361 */ 6362 function get_user_count( $network_id = null ) { 6363 if ( ! is_multisite() && $network_id ) { 6364 _doing_it_wrong( __FUNCTION__, __( 'Unable to pass $nework_id if not using multisite.' ), '5.0.0' ); 6365 } 6366 6367 return get_network_option( $network_id, 'user_count' ); 6368 } 6369 6370 /** 6371 * Update the network-wide users count. 6372 * 6373 * If enabled through the {@see 'enable_live_network_counts'} filter, update the users count 6374 * on a network when a user is created or its status is updated. 6375 * 6376 * @since 3.7.0 6377 * @since 4.8.0 The `$network_id` parameter has been added. 6378 * @since 5.0.0 Moved to functions.php 6379 * 6380 * @param int|null $network_id ID of the network. Default is the current network. 6381 * 6382 * @return bool 6383 */ 6384 function wp_maybe_update_network_user_counts( $network_id = null ) { 6385 $is_small_network = ! wp_is_large_user_count(); 6386 6387 if ( ! is_multisite() && $network_id ) { 6388 _doing_it_wrong( __FUNCTION__, __( 'Unable to pass $nework_id if not using multisite.' ), '5.0.0' ); 6389 } 6390 6391 /** This filter is documented in wp-includes/ms-functions.php */ 6392 if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) { 6393 return; 6394 } 6395 6396 return wp_update_network_user_counts( $network_id ); 6397 } 6398 6399 /** 6400 * Update the network-wide user count. 6401 * 6402 * @since 3.7.0 6403 * @since 4.8.0 The `$network_id` parameter has been added. 6404 * @since 5.0.0 Moved to functions.php 6405 * 6406 * @global wpdb $wpdb WordPress database abstraction object. 6407 * 6408 * @param int|null $network_id ID of the network. Default is the current network. 6409 * 6410 * @return bool 6411 */ 6412 function wp_update_network_user_counts( $network_id = null ) { 6413 global $wpdb; 6414 6415 if ( ! is_multisite() && $network_id ) { 6416 _doing_it_wrong( __FUNCTION__, __( 'Unable to pass $nework_id if not using multisite.' ), '5.0.0' ); 6417 } 6418 6419 if ( is_multisite() ) { 6420 $query = "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'"; 6421 } else { 6422 $query = "SELECT COUNT(ID) as c FROM $wpdb->users"; 6423 } 6424 6425 $count = $wpdb->get_var( $query ); 6426 6427 return update_network_option( $network_id, 'user_count', $count ); 6428 } 6429 6430 /** 6431 * Schedule update of the network-wide counts for the current network. 6432 * 6433 * @since 3.1.0 6434 * @since 5.0.0 Moved to functions.php 6435 */ 6436 function wp_schedule_update_network_counts() { 6437 if ( ! is_main_site() ) { 6438 return; 6439 } 6440 6441 if ( ! wp_next_scheduled( 'update_network_counts' ) && ! wp_installing() ) { 6442 wp_schedule_event( time(), 'twicedaily', 'update_network_counts' ); 6443 } 6444 } 6445 6446 /** 6447 * @since 5.0.0 6448 * 6449 * @return boolean 6450 */ 6451 function wp_is_large_user_count() { 6452 $count = get_user_count(); 6453 6454 /** 6455 * Filters whether the site is considered large, based on its number of users. 6456 * 6457 * @since x.x.x 6458 * 6459 * @param bool $is_large_user_count Whether the site has more than 10000 users. 6460 * @param int $count The count of items for the component. 6461 */ 6462 return apply_filters( 'wp_is_large_user_count', $count > 10000, $count ); 6463 } 6464 No newline at end of file -
src/wp-includes/ms-default-filters.php
57 57 add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 ); 58 58 59 59 // Counts 60 add_action( 'admin_init', 'wp_schedule_update_network_counts' ); 61 add_action( 'update_network_counts', 'wp_update_network_counts', 10, 0 ); 62 foreach ( array( 'user_register', 'deleted_user', 'wpmu_new_user', 'make_spam_user', 'make_ham_user' ) as $action ) { 63 add_action( $action, 'wp_maybe_update_network_user_counts', 10, 0 ); 64 } 60 add_action( 'update_network_counts', 'wp_update_network_site_counts', 10, 0 ); 65 61 foreach ( array( 'make_spam_blog', 'make_ham_blog', 'archive_blog', 'unarchive_blog', 'make_delete_blog', 'make_undelete_blog' ) as $action ) { 66 62 add_action( $action, 'wp_maybe_update_network_site_counts', 10, 0 ); 67 63 } -
src/wp-includes/ms-functions.php
96 96 } 97 97 98 98 /** 99 * The number of active users in your installation.100 *101 * The count is cached and updated twice daily. This is not a live count.102 *103 * @since MU (3.0.0)104 * @since 4.8.0 The `$network_id` parameter has been added.105 *106 * @param int|null $network_id ID of the network. Default is the current network.107 * @return int Number of active users on the network.108 */109 function get_user_count( $network_id = null ) {110 return get_network_option( $network_id, 'user_count' );111 }112 113 /**114 99 * The number of active sites on your installation. 115 100 * 116 101 * The count is cached and updated twice daily. This is not a live count. … … 2446 2431 return $url; 2447 2432 } 2448 2433 2449 /**2450 * Schedule update of the network-wide counts for the current network.2451 *2452 * @since 3.1.02453 */2454 function wp_schedule_update_network_counts() {2455 if ( ! is_main_site() ) {2456 return;2457 }2458 2434 2459 if ( ! wp_next_scheduled( 'update_network_counts' ) && ! wp_installing() ) {2460 wp_schedule_event( time(), 'twicedaily', 'update_network_counts' );2461 }2462 }2463 2464 2435 /** 2465 2436 * Update the network-wide counts for the current network. 2466 2437 * … … 2506 2477 } 2507 2478 2508 2479 /** 2509 * Update the network-wide users count.2510 *2511 * If enabled through the {@see 'enable_live_network_counts'} filter, update the users count2512 * on a network when a user is created or its status is updated.2513 *2514 * @since 3.7.02515 * @since 4.8.0 The `$network_id` parameter has been added.2516 *2517 * @param int|null $network_id ID of the network. Default is the current network.2518 */2519 function wp_maybe_update_network_user_counts( $network_id = null ) {2520 $is_small_network = ! wp_is_large_network( 'users', $network_id );2521 2522 /** This filter is documented in wp-includes/ms-functions.php */2523 if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) {2524 return;2525 }2526 2527 wp_update_network_user_counts( $network_id );2528 }2529 2530 /**2531 2480 * Update the network-wide site count. 2532 2481 * 2533 2482 * @since 3.7.0 … … 2555 2504 } 2556 2505 2557 2506 /** 2558 * Update the network-wide user count.2559 *2560 * @since 3.7.02561 * @since 4.8.0 The `$network_id` parameter has been added.2562 *2563 * @global wpdb $wpdb WordPress database abstraction object.2564 *2565 * @param int|null $network_id ID of the network. Default is the current network.2566 */2567 function wp_update_network_user_counts( $network_id = null ) {2568 global $wpdb;2569 2570 $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );2571 update_network_option( $network_id, 'user_count', $count );2572 }2573 2574 /**2575 2507 * Returns the space used by the current blog. 2576 2508 * 2577 2509 * @since 3.5.0 … … 2701 2633 2702 2634 if ( 'users' == $using ) { 2703 2635 $count = get_user_count( $network_id ); 2636 2637 /** This filter is documented in wp-includes/functions.php */ 2638 $is_large_network = apply_filters( 'wp_is_large_user_count', $count > 10000, $count ); 2639 2704 2640 /** 2705 2641 * Filters whether the network is considered large. 2706 2642 * … … 2712 2648 * @param int $count The count of items for the component. 2713 2649 * @param int $network_id The ID of the network being checked. 2714 2650 */ 2715 return apply_filters( 'wp_is_large_network', $ count > 10000, 'users', $count, $network_id );2651 return apply_filters( 'wp_is_large_network', $is_large_network, 'users', $count, $network_id ); 2716 2652 } 2717 2653 2718 2654 $count = get_blog_count( $network_id );