Automattic\WooCommerce\Internal\PushNotifications\DataStores

PushTokensDataStore::count_tokens │ public │ WC 11.3.0

Counts every push token on the store, whatever the owner's role.

Registration requires one of the roles that receive push notifications, so no token starts out ineligible. A user can lose the role afterwards though, and their token stays, which is the difference between this count and what get_tokens_for_roles() returns.

Method of the class: PushTokensDataStore{}

No Hooks.

Returns

int.

Usage

$PushTokensDataStore = new PushTokensDataStore();
$PushTokensDataStore->count_tokens(): int;

Changelog

Since 11.3.0 Introduced.

PushTokensDataStore::count_tokens() code WC 11.3.0

public function count_tokens(): int {
	if ( null !== $this->token_count ) {
		return $this->token_count;
	}

	global $wpdb;

	$this->token_count = (int) $wpdb->get_var(
		$wpdb->prepare(
			"SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = %s AND post_status = 'private'",
			PushToken::POST_TYPE
		)
	);

	return $this->token_count;
}