wp_maybe_update_user_counts() WordPress Function

The wp_maybe_update_user_counts() function is used to check if a user's post count has changed and if so, update the user's count in the database. This function is called whenever a post is published or deleted.

wp_maybe_update_user_counts( int|null $network_id = null ) #

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


Parameters

$network_id

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

Default value: null


Top ↑

Return

(bool) Whether the update was successful.


Top ↑

Source

File: wp-includes/user.php

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
6.0.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