On this page
wp_update_user_counts( int|null $network_id = null ): bool
Updates the total count of users on the site.
Parameters
$network_idint|null Optional-
ID of the network. Defaults to the current network.
Default:
null
Return
bool Whether the update was successful.
Source
File: wp-includes/user.php. View all references
function wp_update_user_counts( $network_id = null ) {
global $wpdb;
if ( ! is_multisite() && null !== $network_id ) {
_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: %s: $network_id */
__( 'Unable to pass %s if not using multisite.' ),
'<code>$network_id</code>'
),
'6.0.0'
);
}
$query = "SELECT COUNT(ID) as c FROM $wpdb->users";
if ( is_multisite() ) {
$query .= " WHERE spam = '0' AND deleted = '0'";
}
$count = $wpdb->get_var( $query );
return update_network_option( $network_id, 'user_count', $count );
}
Related
Uses
| Uses | Description |
|---|---|
| update_network_option() wp-includes/option.php | Updates the value of a network option that was already added. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| is_multisite() wp-includes/load.php | If Multisite is enabled. |
| _doing_it_wrong() wp-includes/functions.php | Marks something as being incorrectly called. |
| wpdb::get_var() wp-includes/class-wpdb.php | Retrieves one variable from the database. |
Used By
| Used By | Description |
|---|---|
| wp_maybe_update_user_counts() wp-includes/user.php | Updates the total count of users on the site if live user counting is enabled. |
| wp_update_network_user_counts() wp-includes/ms-functions.php | Updates the network-wide user count. |
Changelog
| Version | Description |
|---|---|
| 6.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_update_user_counts