# Hooks

<!-- Generated by `pnpm docs:reference`. Do not edit this file; change the code it is read from. -->

SleekRank fires these hooks for site code. Each is documented by the `@api` docblock on the `apply_filters` or `do_action` call that fires it; a hook without one is internal and may change without notice.

## `sleekRank/activated`

Action, fired in `product/includes/classes/Lifecycle.php`.

Fires when SleekRank is activated on a site, after its tables exist and the rewrite rules were flushed.

## `sleekRank/cache/activeKeys`

Filter, fired in `product/includes/classes/ItemStore.php`.

Filters the cache keys the expiry and orphan sweeps keep. Add the keys of caches your own code fills so the sweeps leave them.

| Parameter | Type | Description |
| --- | --- | --- |
| `$keys` | `string[]` | Cache keys to keep; empty by default. |

**Returns** string[] The cache keys to keep.

## `sleekRank/data/item`

Filter, fired in `product/includes/classes/DataResolver.php`.

Filters the data row a generated page is built from, after the row was found in the page group's cached data and before any mapping reads it. It runs for public generated pages and for the workspace preview.

| Parameter | Type | Description |
| --- | --- | --- |
| `$item` | `array` | The row whose `slug` matched the requested URL. |
| `$pageGroup` | `\SleekRank\PageGroupInterface` | The page group serving the URL. |

**Returns** array The row the mappings read.

## `sleekRank/data/item/{slug}`

Filter, fired in `product/includes/classes/DataResolver.php`.

Filters the data row of one page group only, named by the group's slug, after `sleekRank/data/item` has run.

| Parameter | Type | Description |
| --- | --- | --- |
| `$item` | `array` | The row whose `slug` matched the requested URL. |
| `$pageGroup` | `\SleekRank\PageGroupInterface` | The page group serving the URL. |

**Returns** array The row the mappings read.

## `sleekRank/data/relatedItem`

Filter, fired in `product/includes/classes/DataResolver.php`.

Filters one related item `sleek_rank_related_items()` lists, so its title can come from any field of the row.

| Parameter | Type | Description |
| --- | --- | --- |
| `$related` | `array` | The item: `slug`, `title` and `url`. |
| `$item` | `array` | The related page's data row. |
| `$pageGroup` | `\SleekRank\PageGroupInterface` | The page group serving both pages. |

**Returns** array The item as listed.

## `sleekRank/data/resolved`

Action, fired in `product/includes/classes/OutputBuffer.php`, `product/includes/classes/PreviewRenderer.php`.

Fires when a request resolved to a row of a page group, on a public generated page or a workspace preview, before the base page loads.

| Parameter | Type | Description |
| --- | --- | --- |
| `$data` | `array` | The page's data row, after the item filters. |
| `$pageGroup` | `\SleekRank\PageGroupInterface` | The page group serving the page. |

## `sleekRank/dataSource/registered`

Action, fired in `product/includes/classes/DataSourceRegistry.php`.

Fires each time a data source type is registered, the built-in ones included.

| Parameter | Type | Description |
| --- | --- | --- |
| `$type` | `string` | The type name a data source configuration uses. |
| `$className` | `string` | The class that implements the type. |

## `sleekRank/deactivated`

Action, fired in `product/includes/classes/Lifecycle.php`.

Fires when SleekRank is deactivated on a site, after its scheduled events were cleared and the rewrite rules were flushed.

## `sleekRank/init`

Action, fired in `product/includes/classes/Plugin.php`.

Fires once SleekRank has booted and registered its data sources, mappings, sitemap integrations, commands and routes, on `after_setup_theme`, so a theme can hook it too.

| Parameter | Type | Description |
| --- | --- | --- |
| `$plugin` | `\SleekRank\Plugin` | The SleekRank instance, also returned by `sleekRank()`. |

## `sleekRank/output/after`

Filter, fired in `product/includes/classes/OutputBuffer.php`, `product/includes/classes/PreviewRenderer.php`.

Filters the complete HTML of a generated page, or of its workspace preview, after the mappings ran. On a public page the canonical link and `og:url` are pointed at the generated URL afterwards.

| Parameter | Type | Description |
| --- | --- | --- |
| `$html` | `string` | The HTML with the mappings applied. |
| `$pageGroup` | `\SleekRank\PageGroupInterface` | The page group serving the page. |
| `$data` | `array` | The page's data row. |

**Returns** string The HTML sent to the browser.

## `sleekRank/output/before`

Filter, fired in `product/includes/classes/OutputBuffer.php`, `product/includes/classes/PreviewRenderer.php`.

Filters the complete HTML of a generated page, or of its workspace preview, before the mappings run.

| Parameter | Type | Description |
| --- | --- | --- |
| `$html` | `string` | The buffered HTML of the base page. |
| `$pageGroup` | `\SleekRank\PageGroupInterface` | The page group serving the page. |
| `$data` | `array` | The page's data row. |

**Returns** string The HTML the mappings are applied to.

## `sleekRank/output/canonical`

Filter, fired in `product/includes/classes/OutputBuffer.php`.

Filters the canonical URL of a generated page, by default the page's own URL. It replaces the canonical link and `og:url` that WordPress and SEO plugins such as Yoast SEO, Rank Math, The SEO Framework and All in One SEO print for the base page; an empty string keeps the base page's.

| Parameter | Type | Description |
| --- | --- | --- |
| `$url` | `string` | The generated page's URL. |
| `$pageGroup` | `\SleekRank\PageGroupInterface` | The page group serving the page. |
| `$data` | `array` | The page's data row. |

**Returns** string The canonical URL, or an empty string to keep the base page's.

## `sleekRank/pageGroup/registered`

Action, fired in `product/includes/classes/PageGroupRegistry.php`.

Fires when custom code registers a page group object with the registry `sleekRank()->getPageGroupRegistry()` returns. Saved page groups do not pass through it.

| Parameter | Type | Description |
| --- | --- | --- |
| `$slug` | `string` | The slug it was registered under. |
| `$pageGroup` | `\SleekRank\PageGroupInterface` | The page group. |

## `sleekRank/register/dataSources`

Action, fired in `product/includes/classes/Providers/DataSources.php`.

Fires after the seven built-in data source types are registered, on `after_setup_theme`, so a plugin or a theme can register its own type or replace one by registering the same type name again.

| Parameter | Type | Description |
| --- | --- | --- |
| `$registry` | `\SleekRank\DataSourceRegistry` | Call `register( $type, $className )` with a class that implements `SleekRank\DataSourceInterface`. |

## `sleekRank/register/replacements`

Action, fired in `product/includes/classes/Providers/Replacements.php`.

Fires after the four built-in mapping types are registered, on `after_setup_theme`, so a plugin or a theme can add its own. The first registered replacement that supports a mapping applies it.

| Parameter | Type | Description |
| --- | --- | --- |
| `$engine` | `\SleekRank\ReplacementEngine` | Call `registerReplacement()` with a `SleekRank\ReplacementInterface`. |

## `sleekRank/register/sitemapIntegrations`

Action, fired in `product/includes/classes/Providers/Sitemaps.php`.

Fires after the integrations for The SEO Framework, Yoast SEO, Rank Math and All in One SEO are registered and before the WordPress core sitemap fallback, on `after_setup_theme`, so a plugin or a theme can add one for another sitemap. The first registered integration that reports itself active is used.

| Parameter | Type | Description |
| --- | --- | --- |
| `$registry` | `\SleekRank\SitemapRegistry` | Call `register()` with a `SleekRank\SitemapIntegrationInterface`. |

## `sleekRank/replacement/value`

Filter, fired in `product/includes/classes/Replacements/AbstractReplacement.php`.

Filters the value a tag, selector or meta mapping is about to write, after it was read from the row and escaped for where it goes.

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string` | The escaped value. |
| `$mapping` | `array` | The mapping: `type`, `target`, `field` and, where set, `mode` and `attribute`. |
| `$data` | `array` | The page's data row. |

**Returns** string The value written into the page.

## `sleekRank/replacement/value/{type}`

Filter, fired in `product/includes/classes/Replacements/AbstractReplacement.php`.

Filters the value of one mapping type only (`tag`, `selector` or `meta`), after `sleekRank/replacement/value` has run.

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string` | The escaped value. |
| `$mapping` | `array` | The mapping: `type`, `target`, `field` and, where set, `mode` and `attribute`. |
| `$data` | `array` | The page's data row. |

**Returns** string The value written into the page.

## `sleekRank/replacements/after`

Filter, fired in `product/includes/classes/ReplacementEngine.php`.

Filters a generated page's HTML after every mapping has been applied.

| Parameter | Type | Description |
| --- | --- | --- |
| `$html` | `string` | The HTML with the mappings applied. |
| `$data` | `array` | The page's data row. |
| `$mappings` | `array` | The page group's mappings. |

**Returns** string The HTML sent on.

## `sleekRank/replacements/before`

Filter, fired in `product/includes/classes/ReplacementEngine.php`.

Filters a generated page's HTML before its mappings are applied. It runs only when the page group has at least one mapping.

| Parameter | Type | Description |
| --- | --- | --- |
| `$html` | `string` | The rendered HTML of the base page. |
| `$data` | `array` | The page's data row. |
| `$mappings` | `array` | The page group's mappings. |

**Returns** string The HTML the mappings are applied to.

## `sleekRank/rewrites/registered`

Action, fired in `product/includes/classes/RewriteManager.php`.

Fires on `init` after the rewrite rules of every published page group have been added.

## `sleekRank/runtime/allowRouteInventory`

Filter, fired in `product/includes/classes/Plugin.php`.

Decides whether the generated route inventory may be built in this request. It is allowed under WP-CLI and from `wp sleek rank routes` only by default, because it reads every published page group's cached rows.

| Parameter | Type | Description |
| --- | --- | --- |
| `$allowed` | `bool` | Whether the request runs under WP-CLI or the routes command. |

**Returns** bool Whether `sleek_rank_generated_route_inventory()` answers the routes or an empty list.

## `sleekRank/sitemap/urlsPerSitemap`

Filter, fired in `product/includes/classes/SitemapProvider.php`.

Filters how many generated URLs one sitemap file holds before the next file starts, for the WordPress core, Yoast SEO and Rank Math sitemaps.

| Parameter | Type | Description |
| --- | --- | --- |
| `$perPage` | `int` | WordPress core's sitemap limit, 2000 by default. |

**Returns** int The number of URLs per sitemap file; a value below 1 counts as 1.
