get_user_count() WordPress Function

The get_user_count() function is a simple function used to get the number of users on a WordPress site. This function is typically used to display the number of users on a site in the footer or sidebar.

get_user_count( int|null $network_id = null ) #

Returns the number of active users in your installation.


Description

Note that on a large site the count may be cached and only updated twice daily.


Top ↑

Parameters

$network_id

(int|null)(Optional)ID of the network. Defaults to the current network.

Default value: null


Top ↑

Return

(int) Number of active users on the network.


Top ↑

Source

File: wp-includes/user.php

function get_user_count( $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'
		);
	}

	return (int) get_network_option( $network_id, 'user_count', -1 );
}


Top ↑

Changelog

Changelog
VersionDescription
MU (3.0.0)MU (3.0.0)
6.0.0Moved to wp-includes/user.php.
4.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More