diff --git a/wp-admin/includes/class-wp-ms-users-list-table.php b/wp-admin/includes/class-wp-ms-users-list-table.php
index e3d619ae8..53b924f67 100644
--- a/wp-admin/includes/class-wp-ms-users-list-table.php
+++ b/wp-admin/includes/class-wp-ms-users-list-table.php
@@ -131,7 +131,7 @@ class WP_MS_Users_List_Table extends WP_List_Table {
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 );
diff --git a/wp-admin/includes/class-wp-posts-list-table.php b/wp-admin/includes/class-wp-posts-list-table.php
index 717e84fb9..959e157b9 100644
--- a/wp-admin/includes/class-wp-posts-list-table.php
+++ b/wp-admin/includes/class-wp-posts-list-table.php
@@ -1557,7 +1557,7 @@ class WP_Posts_List_Table extends WP_List_Table {
post_type, 'author' ) ) :
+ if ( post_type_supports( $screen->post_type, 'author' ) && ! wp_is_large_user_count() ) :
$authors_dropdown = '';
if ( current_user_can( $post_type_object->cap->edit_others_posts ) ) :
diff --git a/wp-admin/includes/class-wp-users-list-table.php b/wp-admin/includes/class-wp-users-list-table.php
index 28e197872..16889e8f6 100644
--- a/wp-admin/includes/class-wp-users-list-table.php
+++ b/wp-admin/includes/class-wp-users-list-table.php
@@ -177,26 +177,37 @@ class WP_Users_List_Table extends WP_List_Table {
$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;
}
@@ -207,8 +218,10 @@ class WP_Users_List_Table extends WP_List_Table {
}
$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 ) {
+ /* translators: User role name with count */
+ $name = sprintf( __( '%1$s (%2$s)' ), $name, number_format_i18n( $avail_roles[ $this_role ] ) );
+ }
$role_links[ $this_role ] = "$name";
}
diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php
index e3160bb39..efefc34c9 100644
--- a/wp-admin/includes/dashboard.php
+++ b/wp-admin/includes/dashboard.php
@@ -406,7 +406,7 @@ function wp_network_dashboard_right_now() {
$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 */
diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php
index 20853da3e..fc55bc846 100644
--- a/wp-admin/includes/schema.php
+++ b/wp-admin/includes/schema.php
@@ -1248,6 +1248,7 @@ We hope you enjoy your new site. Thanks!
'subdomain_install' => $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(),
diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php
index ecdc87cb3..afd9a6954 100644
--- a/wp-includes/default-filters.php
+++ b/wp-includes/default-filters.php
@@ -98,6 +98,13 @@ add_filter( 'post_mime_type', 'sanitize_mime_type' );
// 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 );
+}
+
// Post meta
add_action( 'added_post_meta', 'wp_cache_set_posts_last_changed' );
add_action( 'updated_post_meta', 'wp_cache_set_posts_last_changed' );
diff --git a/wp-includes/functions.php b/wp-includes/functions.php
index c6542d62d..88331f1d6 100644
--- a/wp-includes/functions.php
+++ b/wp-includes/functions.php
@@ -7165,3 +7165,112 @@ function is_wp_version_compatible( $required ) {
function is_php_version_compatible( $required ) {
return empty( $required ) || version_compare( phpversion(), $required, '>=' );
}
+
+
+/**
+ * The number of active users in your installation.
+ *
+ * The count is cached and updated twice daily. This is not a live count.
+ *
+ * @since 5.3.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.3.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.3.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.3.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.3.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 );
+}
diff --git a/wp-includes/ms-default-filters.php b/wp-includes/ms-default-filters.php
index a9658398b..50d7524da 100644
--- a/wp-includes/ms-default-filters.php
+++ b/wp-includes/ms-default-filters.php
@@ -81,11 +81,7 @@ add_action( 'transition_post_status', '_update_blog_date_on_post_publish', 10, 3
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 );
}
diff --git a/wp-includes/ms-deprecated.php b/wp-includes/ms-deprecated.php
index 6763fcb38..e820cb009 100644
--- a/wp-includes/ms-deprecated.php
+++ b/wp-includes/ms-deprecated.php
@@ -552,6 +552,24 @@ function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) {
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 5.3.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.3.0', 'wp_get_user_count()' );
+
+ return get_network_option( $network_id, 'user_count' );
+}
+
/**
* Store basic site info in the blogs table.
*
diff --git a/wp-includes/ms-functions.php b/wp-includes/ms-functions.php
index dc774a399..ed212ef50 100644
--- a/wp-includes/ms-functions.php
+++ b/wp-includes/ms-functions.php
@@ -17,7 +17,7 @@
function get_sitestats() {
$stats = array(
'blogs' => get_blog_count(),
- 'users' => get_user_count(),
+ 'users' => wp_get_user_count(),
);
return $stats;
@@ -95,21 +95,6 @@ function get_active_blog_for_user( $user_id ) {
}
}
-/**
- * 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.
*
@@ -2264,21 +2249,6 @@ function filter_SSL( $url ) {
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.
*
@@ -2323,28 +2293,6 @@ function wp_maybe_update_network_site_counts( $network_id = null ) {
wp_update_network_site_counts( $network_id );
}
-/**
- * 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.
*
@@ -2373,23 +2321,6 @@ function wp_update_network_site_counts( $network_id = null ) {
update_network_option( $network_id, 'blog_count', $count );
}
-/**
- * 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.
*
@@ -2507,19 +2438,30 @@ function upload_size_limit_filter( $size ) {
*
* @since 3.3.0
* @since 4.8.0 The `$network_id` parameter has been added.
+ * @since 5.3.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.
+ * @param null $deprecated Deprecated; 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.3.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( $network_id );
+
+ /** 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.
*
@@ -2531,10 +2473,10 @@ function wp_is_large_network( $using = 'sites', $network_id = null ) {
* @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 );
}
diff --git a/wp-includes/update.php b/wp-includes/update.php
index 824575099..e9314b059 100644
--- a/wp-includes/update.php
+++ b/wp-includes/update.php
@@ -76,13 +76,10 @@ function wp_version_check( $extra_stats = array(), $force_check = false ) {
}
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( '/' );