# PHP functions

SleekTrack defines global PHP functions for its tracked sites and groups, so a
theme or plugin reads them without knowing how SleekTrack stores them. They
exist only while SleekTrack is active, so guard calls with `function_exists()`
in code that can run without it. Its hooks, WP-CLI commands and REST operations
are listed in the generated references: [hooks](/docs/track/reference/hooks.md),
[CLI](/docs/track/reference/cli.md) and [REST](/docs/track/reference/rest.md).

Tracked sites and their groups are kept in SleekTrack's own tables. A site is
answered as `id`, `domain`, `name`, `token` (the token its tracker sends, or
`null`), `is_active`, `auto_inject`, `subdomains`, `group`, `heatmaps`,
`webhook_url`, `webhook_secret`, `created_at` and `updated_at`; a group as `id`,
`name`, `color`, `order` and `siteCount`.

## Functions

- `sleek_track_get_site( int $id ): ?array`: The tracked site with this id, or
  `null`.
- `sleek_track_get_site_by_domain( string $domain ): ?array`: The active or
  inactive site that tracks exactly this domain, or `null`.
- `sleek_track_get_sites(): array`: Every active and inactive tracked site,
  newest first.
- `sleek_track_get_group( int $id ): ?array`: The site group with this id, or
  `null`.
- `sleek_track_get_groups(): array`: Every site group, by its order and then its
  name.

## Example

```php
if (function_exists('sleek_track_get_site')) {
    $site = sleek_track_get_site_by_domain('shop.example.com');
    if ($site !== null && $site['is_active']) {
        $token = $site['token'];
    }
}
```
