Index: src/wp-admin/includes/class-wp-ms-users-list-table.php
===================================================================
--- src/wp-admin/includes/class-wp-ms-users-list-table.php (revision 43336)
+++ src/wp-admin/includes/class-wp-ms-users-list-table.php (working copy)
@@ -133,7 +133,7 @@
protected function get_views() {
global $role;
- $total_users = get_user_count();
+ $total_users = wp_get_user_count();
$super_admins = get_super_admins();
$total_admins = count( $super_admins );
Index: src/wp-admin/includes/class-wp-users-list-table.php
===================================================================
--- src/wp-admin/includes/class-wp-users-list-table.php (revision 43336)
+++ src/wp-admin/includes/class-wp-users-list-table.php (working copy)
@@ -177,26 +177,36 @@
$wp_roles = wp_roles();
+ $count_users = ! wp_is_large_user_count();
+
if ( $this->is_site_users ) {
$url = 'site-users.php?id=' . $this->site_id;
- switch_to_blog( $this->site_id );
- $users_of_blog = count_users( 'time', $this->site_id );
- restore_current_blog();
} else {
- $url = 'users.php';
- $users_of_blog = count_users();
+ $url = 'users.php';
}
- $total_users = $users_of_blog['total_users'];
- $avail_roles =& $users_of_blog['avail_roles'];
- unset( $users_of_blog );
+ $role_links = array();
+ if ( $count_users ) {
+ if ( $this->is_site_users ) {
+ switch_to_blog( $this->site_id );
+ $users_of_blog = count_users( 'time', $this->site_id );
+ restore_current_blog();
+ } else {
+ $users_of_blog = count_users();
+ }
+ $total_users = $users_of_blog['total_users'];
+ $avail_roles =& $users_of_blog['avail_roles'];
+ unset( $users_of_blog );
+ $role_links['all'] = "" . sprintf( _nx( 'All (%s)', 'All (%s)', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '';
+ } else {
+ $avail_roles = array();
+ $role_links['all'] = "" . __( 'All' ) . '';
+ }
+
$current_link_attributes = empty( $role ) ? ' class="current" aria-current="page"' : '';
-
- $role_links = array();
- $role_links['all'] = "" . sprintf( _nx( 'All (%s)', 'All (%s)', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '';
foreach ( $wp_roles->get_names() as $this_role => $name ) {
- if ( ! isset( $avail_roles[ $this_role ] ) ) {
+ if ( $count_users && ! isset( $avail_roles[ $this_role ] ) ) {
continue;
}
@@ -208,7 +218,9 @@
$name = translate_user_role( $name );
/* translators: User role name with count */
- $name = sprintf( __( '%1$s (%2$s)' ), $name, number_format_i18n( $avail_roles[ $this_role ] ) );
+ if ( $count_users ) {
+ $name = sprintf( __( '%1$s (%2$s)' ), $name, number_format_i18n( $avail_roles[ $this_role ] ) );
+ }
$role_links[ $this_role ] = "$name";
}
Index: src/wp-admin/includes/dashboard.php
===================================================================
--- src/wp-admin/includes/dashboard.php (revision 43336)
+++ src/wp-admin/includes/dashboard.php (working copy)
@@ -408,7 +408,7 @@
$actions['create-user'] = '' . __( 'Create a New User' ) . '';
}
- $c_users = get_user_count();
+ $c_users = wp_get_user_count();
$c_blogs = get_blog_count();
/* translators: %s: number of users on the network */
Index: src/wp-admin/includes/schema.php
===================================================================
--- src/wp-admin/includes/schema.php (revision 43336)
+++ src/wp-admin/includes/schema.php (working copy)
@@ -1133,6 +1133,7 @@
'subdomain_install' => intval( $subdomain_install ),
'global_terms_enabled' => global_terms_enabled() ? '1' : '0',
'ms_files_rewriting' => is_multisite() ? get_site_option( 'ms_files_rewriting' ) : '0',
+ 'user_count' => get_site_option( 'user_count' ),
'initial_db_version' => get_option( 'initial_db_version' ),
'active_sitewide_plugins' => array(),
'WPLANG' => get_locale(),
Index: src/wp-includes/default-filters.php
===================================================================
--- src/wp-includes/default-filters.php (revision 43336)
+++ src/wp-includes/default-filters.php (working copy)
@@ -98,6 +98,13 @@
// Meta
add_filter( 'register_meta_args', '_wp_register_meta_args_whitelist', 10, 2 );
+// Counts
+add_action( 'admin_init', 'wp_schedule_update_network_counts' );
+add_action( 'update_network_counts', 'wp_update_network_user_counts', 10, 0 );
+foreach ( array( 'user_register', 'deleted_user', 'wpmu_new_user', 'make_spam_user', 'make_ham_user' ) as $action ) {
+ add_action( $action, 'wp_maybe_update_network_user_counts', 10, 0 );
+}
+
// Places to balance tags on input
foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
add_filter( $filter, 'convert_invalid_entities' );
Index: src/wp-includes/functions.php
===================================================================
--- src/wp-includes/functions.php (revision 43336)
+++ src/wp-includes/functions.php (working copy)
@@ -6346,3 +6346,111 @@
}
}
}
+
+/**
+ * The number of active users in your installation.
+ *
+ * The count is cached and updated twice daily. This is not a live count.
+ *
+ * @since 5.0.0
+ *
+ * @return int Number of active users on the network.
+ */
+function wp_get_user_count() {
+ return get_site_option( 'user_count', -1 );
+}
+
+/**
+ * Update the network-wide users count.
+ *
+ * If enabled through the {@see 'enable_live_network_counts'} filter, update the users count
+ * on a network when a user is created or its status is updated.
+ *
+ * @since 3.7.0
+ * @since 4.8.0 The `$network_id` parameter has been added.
+ * @since 5.0.0 Moved to functions.php
+ *
+ * @param int|null $network_id ID of the network. Default is the current network.
+ *
+ * @return bool
+ */
+function wp_maybe_update_network_user_counts( $network_id = null ) {
+ $is_small_network = ! wp_is_large_user_count();
+
+ if ( ! is_multisite() && $network_id ) {
+ _doing_it_wrong( __FUNCTION__, __( 'Unable to pass $nework_id if not using multisite.' ), '5.0.0' );
+ }
+
+ /** This filter is documented in wp-includes/ms-functions.php */
+ if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) {
+ return;
+ }
+
+ return wp_update_network_user_counts( $network_id );
+}
+
+/**
+ * Update the network-wide user count.
+ *
+ * @since 3.7.0
+ * @since 4.8.0 The `$network_id` parameter has been added.
+ * @since 5.0.0 Moved to functions.php
+ *
+ * @global wpdb $wpdb WordPress database abstraction object.
+ *
+ * @param int|null $network_id ID of the network. Default is the current network.
+ *
+ * @return bool
+ */
+function wp_update_network_user_counts( $network_id = null ) {
+ global $wpdb;
+
+ if ( ! is_multisite() && $network_id ) {
+ _doing_it_wrong( __FUNCTION__, __( 'Unable to pass $nework_id if not using multisite.' ), '5.0.0' );
+ }
+
+ if ( is_multisite() ) {
+ $query = "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'";
+ } else {
+ $query = "SELECT COUNT(ID) as c FROM $wpdb->users";
+ }
+
+ $count = $wpdb->get_var( $query );
+
+ return update_network_option( $network_id, 'user_count', $count );
+}
+
+/**
+ * Schedule update of the network-wide counts for the current network.
+ *
+ * @since 3.1.0
+ * @since 5.0.0 Moved to functions.php
+ */
+function wp_schedule_update_network_counts() {
+ if ( ! is_main_site() ) {
+ return;
+ }
+
+ if ( ! wp_next_scheduled( 'update_network_counts' ) && ! wp_installing() ) {
+ wp_schedule_event( time(), 'twicedaily', 'update_network_counts' );
+ }
+}
+
+/**
+ * @since 5.0.0
+ *
+ * @return boolean
+ */
+function wp_is_large_user_count() {
+ $count = wp_get_user_count();
+
+ /**
+ * Filters whether the site is considered large, based on its number of users.
+ *
+ * @since x.x.x
+ *
+ * @param bool $is_large_user_count Whether the site has more than 10000 users.
+ * @param int $count The count of items for the component.
+ */
+ return apply_filters( 'wp_is_large_user_count', $count > 10000, $count );
+}
\ No newline at end of file
Index: src/wp-includes/ms-default-filters.php
===================================================================
--- src/wp-includes/ms-default-filters.php (revision 43336)
+++ src/wp-includes/ms-default-filters.php (working copy)
@@ -57,11 +57,7 @@
add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 );
// Counts
-add_action( 'admin_init', 'wp_schedule_update_network_counts' );
-add_action( 'update_network_counts', 'wp_update_network_counts', 10, 0 );
-foreach ( array( 'user_register', 'deleted_user', 'wpmu_new_user', 'make_spam_user', 'make_ham_user' ) as $action ) {
- add_action( $action, 'wp_maybe_update_network_user_counts', 10, 0 );
-}
+add_action( 'update_network_counts', 'wp_update_network_site_counts', 10, 0 );
foreach ( array( 'make_spam_blog', 'make_ham_blog', 'archive_blog', 'unarchive_blog', 'make_delete_blog', 'make_undelete_blog' ) as $action ) {
add_action( $action, 'wp_maybe_update_network_site_counts', 10, 0 );
}
Index: src/wp-includes/ms-deprecated.php
===================================================================
--- src/wp-includes/ms-deprecated.php (revision 43336)
+++ src/wp-includes/ms-deprecated.php (working copy)
@@ -546,3 +546,22 @@
return isset( $current_user->$local_key );
}
+
+
+/**
+ * The number of active users in your installation.
+ *
+ * The count is cached and updated twice daily. This is not a live count.
+ *
+ * @since MU (3.0.0)
+ * @since 4.8.0 The `$network_id` parameter has been added.
+ * @deprecated 4.9.0
+ *
+ * @param int|null $network_id ID of the network. Default is the current network.
+ * @return int Number of active users on the network.
+ */
+function get_user_count( $network_id = null ) {
+ _deprecated_function( __FUNCTION__, '5.0.0', 'wp_get_user_count()' );
+
+ return get_network_option( $network_id, 'user_count' );
+}
\ No newline at end of file
Index: src/wp-includes/ms-functions.php
===================================================================
--- src/wp-includes/ms-functions.php (revision 43336)
+++ src/wp-includes/ms-functions.php (working copy)
@@ -17,7 +17,7 @@
function get_sitestats() {
$stats = array(
'blogs' => get_blog_count(),
- 'users' => get_user_count(),
+ 'users' => wp_get_user_count(),
);
return $stats;
@@ -96,21 +96,6 @@
}
/**
- * The number of active users in your installation.
- *
- * The count is cached and updated twice daily. This is not a live count.
- *
- * @since MU (3.0.0)
- * @since 4.8.0 The `$network_id` parameter has been added.
- *
- * @param int|null $network_id ID of the network. Default is the current network.
- * @return int Number of active users on the network.
- */
-function get_user_count( $network_id = null ) {
- return get_network_option( $network_id, 'user_count' );
-}
-
-/**
* The number of active sites on your installation.
*
* The count is cached and updated twice daily. This is not a live count.
@@ -2446,21 +2431,7 @@
return $url;
}
-/**
- * Schedule update of the network-wide counts for the current network.
- *
- * @since 3.1.0
- */
-function wp_schedule_update_network_counts() {
- if ( ! is_main_site() ) {
- return;
- }
- if ( ! wp_next_scheduled( 'update_network_counts' ) && ! wp_installing() ) {
- wp_schedule_event( time(), 'twicedaily', 'update_network_counts' );
- }
-}
-
/**
* Update the network-wide counts for the current network.
*
@@ -2506,28 +2477,6 @@
}
/**
- * Update the network-wide users count.
- *
- * If enabled through the {@see 'enable_live_network_counts'} filter, update the users count
- * on a network when a user is created or its status is updated.
- *
- * @since 3.7.0
- * @since 4.8.0 The `$network_id` parameter has been added.
- *
- * @param int|null $network_id ID of the network. Default is the current network.
- */
-function wp_maybe_update_network_user_counts( $network_id = null ) {
- $is_small_network = ! wp_is_large_network( 'users', $network_id );
-
- /** This filter is documented in wp-includes/ms-functions.php */
- if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) {
- return;
- }
-
- wp_update_network_user_counts( $network_id );
-}
-
-/**
* Update the network-wide site count.
*
* @since 3.7.0
@@ -2555,23 +2504,6 @@
}
/**
- * Update the network-wide user count.
- *
- * @since 3.7.0
- * @since 4.8.0 The `$network_id` parameter has been added.
- *
- * @global wpdb $wpdb WordPress database abstraction object.
- *
- * @param int|null $network_id ID of the network. Default is the current network.
- */
-function wp_update_network_user_counts( $network_id = null ) {
- global $wpdb;
-
- $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );
- update_network_option( $network_id, 'user_count', $count );
-}
-
-/**
* Returns the space used by the current blog.
*
* @since 3.5.0
@@ -2688,19 +2620,30 @@
*
* @since 3.3.0
* @since 4.8.0 The `$network_id` parameter has been added.
+ * @since 5.0.0 Deprecated $network_id
*
* @param string $using 'sites or 'users'. Default is 'sites'.
* @param int|null $network_id ID of the network. Default is the current network.
* @return bool True if the network meets the criteria for large. False otherwise.
*/
-function wp_is_large_network( $using = 'sites', $network_id = null ) {
- $network_id = (int) $network_id;
+function wp_is_large_network( $using = 'sites', $deprecated = null ) {
+
+ if ( null !== $deprecated ) {
+ _deprecated_argument( __FUNCTION__, __( 'Unable to pass $network_id. ' ), '5.0.0' );
+ }
+
+ $network_id = (int) $deprecated;
if ( ! $network_id ) {
$network_id = get_current_network_id();
}
if ( 'users' == $using ) {
- $count = get_user_count( $network_id );
+
+ $count = wp_get_user_count();
+
+ /** This filter is documented in wp-includes/functions.php */
+ $is_large_network = apply_filters( 'wp_is_large_user_count', $count > 10000, $count );
+
/**
* Filters whether the network is considered large.
*
@@ -2712,10 +2655,10 @@
* @param int $count The count of items for the component.
* @param int $network_id The ID of the network being checked.
*/
- return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count, $network_id );
+ return apply_filters( 'wp_is_large_network', $is_large_network, 'users', $count, $network_id );
}
- $count = get_blog_count( $network_id );
+ $count = get_blog_count();
/** This filter is documented in wp-includes/ms-functions.php */
return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count, $network_id );
}
Index: src/wp-includes/update.php
===================================================================
--- src/wp-includes/update.php (revision 43336)
+++ src/wp-includes/update.php (working copy)
@@ -75,14 +75,12 @@
$mysql_version = 'N/A';
}
+ $user_count = wp_get_user_count();
if ( is_multisite() ) {
- $user_count = get_user_count();
$num_blogs = get_blog_count();
$wp_install = network_site_url();
$multisite_enabled = 1;
} else {
- $user_count = count_users();
- $user_count = $user_count['total_users'];
$multisite_enabled = 0;
$num_blogs = 1;
$wp_install = home_url( '/' );