wp_maybe_update_user_counts()WP 6.0.0

Updates the total count of users on the site if live user counting is enabled.

Hooks from the function

Return

true|false. Whether the update was successful.

Usage

wp_maybe_update_user_counts( $network_id );
$network_id(int|null)
ID of the network.
Default: current network

Changelog

Since 6.0.0 Introduced.

wp_maybe_update_user_counts() code WP 6.5.2

function wp_maybe_update_user_counts( $network_id = null ) {
	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'
		);
	}

	$is_small_network = ! wp_is_large_user_count( $network_id );
	/** This filter is documented in wp-includes/ms-functions.php */
	if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) {
		return false;
	}

	return wp_update_user_counts( $network_id );
}