wp_update_user_counts()WP 6.0.0

Updates the total count of users on the site.

Хуков нет.

Возвращает

true|false. Whether the update was successful.

Использование

wp_update_user_counts( $network_id );
$network_id(int|null)
ID of the network.
По умолчанию: current network

Заметки

  • Global. wpdb. $wpdb WordPress database abstraction object.

Список изменений

С версии 6.0.0 Введена.

Код wp_update_user_counts() WP 6.6.2

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