Automattic\WooCommerce\Internal\PushNotifications\DataStores
PushTokensDataStore::has_tokens
Determines whether any push token exists, ignoring roles and preferences so callers can bail out before the cost of get_tokens_for_roles().
Method of the class: PushTokensDataStore{}
No Hooks.
Returns
bool. True if at least one push token exists.
Usage
$PushTokensDataStore = new PushTokensDataStore(); $PushTokensDataStore->has_tokens(): bool;
Changelog
| Since 11.2.0 | Introduced. |
PushTokensDataStore::has_tokens() PushTokensDataStore::has tokens code WC 11.3.0
public function has_tokens(): bool {
if ( null !== $this->has_tokens ) {
return $this->has_tokens;
}
global $wpdb;
// Exactly this SQL to leverage the wp_posts type_status_author index.
$this->has_tokens = (bool) $wpdb->get_var(
$wpdb->prepare(
"SELECT 1 FROM {$wpdb->posts} WHERE post_type = %s AND post_status = 'private' LIMIT 1",
PushToken::POST_TYPE
)
);
return $this->has_tokens;
}