---
title: "Modal Kit for Developers: Hooks, Filters and REST Routes"
description: "Modal Kit for developers: one block of core blocks, the browser’s dialog and the Interactivity API, with hooks, filters, browser events and REST routes."
language: "en-US"
canonical_url: "https://modalkitwp.com/developers/"
source_url: "https://modalkitwp.com/developers/"
content_type: "text/markdown"
---

Developers

# Built from *WordPress*, not around it.

A modal is one block holding core blocks, shown with the browser’s own dialog and run by the Interactivity API that ships with WordPress. Everything else is hooks, events and post meta you already know how to work with.

[Download free](https://packages.cocartheadless.com/download/latest/modal-kit.zip)

[Jump to the hooks](#hooks)

1

**Custom block in free**

modal-kit/modal. Everything inside it is a core block.

37

**PHP hooks**

Filters and actions in Free and Pro, listed below.

10

**Editor filters**

For the editor and settings screens, through wp.hooks.

0

**jQuery or UI libraries**

The browser’s dialog, the Interactivity API and script modules.

Architecture

## One block, the platform for the rest

**One block, core blocks inside**

The free plugin registers a single block, modal-kit/modal. Headings, images, buttons, columns and video are the core blocks you already use, so themes style them as usual.

**The browser’s own dialog**

Each modal renders as a <dialog>. The browser puts it above the page and makes the page behind inert. Focus moves to the heading on open and back to the trigger on close.

**Interactivity API and script modules**

The front end is a viewScriptModule on the Interactivity API that ships with WordPress. Triggers and the video player are separate modules, imported only when a modal on the page uses them.

**Editor matches the front end**

One shared style.scss styles both the editor canvas and your site. editor.scss is editor chrome only.

**Your theme’s values**

Native, Soft and Editorial read theme.json presets for colour, spacing, radius and type, never hard-coded colours. Fixed styles are token sets you can add with modal_kit_styles.

**Validated settings**

Triggers, rules, overrides and plugin settings are checked against JSON schemas on save, in the REST API as in the editor.

**Pro’s blocks**

Each one goes inside a modal and loads its script only where it’s used.

`modal-kit/step`

`modal-kit/form`

`modal-kit/field`

`modal-kit/prize-wheel`

`modal-kit/scratch-card`

`modal-kit/pick-a-gift`

`modal-kit/slot-reel`

`modal-kit/age-check`

`modal-kit/countdown`

`modal-kit/carousel`

`modal-kit/slide`

`modal-kit/reviews`

`modal-kit/cart-summary`

PHP hooks

## Every filter and action

This list comes from the plugins’ source, with the arguments each hook passes. Pro uses the same hooks to extend the free plugin. Each hook has its own page with working code: open its name.


					Free · 20
					Pro · 14
					Pro updates · 3



Hook

What it’s for

`[modal_kit_layouts](https://modalkitwp.com/docs/hooks/modal_kit_layouts/)`

filter

Add or change layouts. A layout can extend a built-in one (base) and turn off closing (closable: false). Pro adds the age gate this way.

$layouts

`[modal_kit_styles](https://modalkitwp.com/docs/hooks/modal_kit_styles/)`

filter

Add fixed styles: a token set of colours, fonts, radius and shadow, like the bundled Fieldnote. Fonts beyond the bundled ones are yours to load.

$styles

`[modal_kit_theme_tokens](https://modalkitwp.com/docs/hooks/modal_kit_theme_tokens/)`

filter

Change the values Native, Soft and Editorial take from theme.json: surface, ink, radius, space, shadow, primary and on-primary, and z, the stacking order from Settings → Display.

$tokens

`[modal_kit_meta_schema](https://modalkitwp.com/docs/hooks/modal_kit_meta_schema/)`

filter

Extend the JSON schema for a modal’s triggers, rules, overrides or enabled meta, for example to allow a new trigger type.

$schema, $key

`[modal_kit_targets_request](https://modalkitwp.com/docs/hooks/modal_kit_targets_request/)`

filter

Decide whether a modal’s page targeting matches the page being built.

$targeted, $post

`[modal_kit_dialog_context](https://modalkitwp.com/docs/hooks/modal_kit_dialog_context/)`

filter

Change the triggers, rules, closing and focus settings the browser receives for a modal.

$context, $post, $resolved

`[modal_kit_dialog_panel](https://modalkitwp.com/docs/hooks/modal_kit_dialog_panel/)`

filter

Add markup to a modal’s panel before the dialog is built. Pro adds step progress here.

$panel, $post, $resolved, $attrs

`[modal_kit_button_actions](https://modalkitwp.com/docs/hooks/modal_kit_button_actions/)`

filter

Register button actions the front end understands. Pro adds its step, form, game and cart actions.

$actions

`[modal_kit_render_button_action](https://modalkitwp.com/docs/hooks/modal_kit_render_button_action/)`

action

Add attributes to a button that uses your action. The WP_HTML_Tag_Processor is positioned on the button.

$processor, $action, $block

`[modal_kit_link_prefix](https://modalkitwp.com/docs/hooks/modal_kit_link_prefix/)`

filter

Change the prefix of modal links and dialog ids. The default, modal-, is set in Settings → General.

$prefix

`[modal_kit_close_label](https://modalkitwp.com/docs/hooks/modal_kit_close_label/)`

filter

Change the close button’s accessible label for a modal.

$label, $post_id

`[modal_kit_post_type_capabilities](https://modalkitwp.com/docs/hooks/modal_kit_post_type_capabilities/)`

filter

Change the capabilities needed to create, edit and publish modals.

$caps

`[modal_kit_pattern_categories](https://modalkitwp.com/docs/hooks/modal_kit_pattern_categories/)`

filter

Change the categories in the template picker.

$categories

`[modal_kit_pattern_collections](https://modalkitwp.com/docs/hooks/modal_kit_pattern_collections/)`

filter

Add template collections to the picker.

$collections

`[modal_kit_pattern_collection_types](https://modalkitwp.com/docs/hooks/modal_kit_pattern_collection_types/)`

filter

Set the types listed inside each collection.

$types

`[modal_kit_starter_settings](https://modalkitwp.com/docs/hooks/modal_kit_starter_settings/)`

filter

Change the triggers, rules and overrides a starter template applies when it’s picked.

$settings

`[modal_kit_backdrop_capability](https://modalkitwp.com/docs/hooks/modal_kit_backdrop_capability/)`

filter

Change who gets the editor’s homepage backdrop. Default: edit_others_posts.

$capability

`[modal_kit_backdrop_request](https://modalkitwp.com/docs/hooks/modal_kit_backdrop_request/)`

action

Fires when the editor loads your homepage as its backdrop, so server-side analytics can skip that visit.

`[modal_kit_optimizer_paths](https://modalkitwp.com/docs/hooks/modal_kit_optimizer_paths/)`

filter

Folders that speed and cache plugins must not combine, delay or move to a CDN. Add yours if your add-on has its own script modules. Pro adds its folder.

$paths

`[modal_kit_pro_listings](https://modalkitwp.com/docs/hooks/modal_kit_pro_listings/)`

filter

The Pro features listed in the free plugin’s screens. Pro removes the ones it provides.

$listings



Hook

What it’s for

`[modal_kit_pro_providers](https://modalkitwp.com/docs/hooks/modal_kit_pro_providers/)`

filter

Add form destinations to Send to. See Your own form destination below.

$list

`[modal_kit_pro_captcha_providers](https://modalkitwp.com/docs/hooks/modal_kit_pro_captcha_providers/)`

filter

Add or remove bot check providers.

$list

`[modal_kit_pro_captcha_hostnames](https://modalkitwp.com/docs/hooks/modal_kit_pro_captcha_hostnames/)`

filter

Hostnames a bot check token may be solved on, such as a static copy of the site that still posts to this one.

$hosts

`[modal_kit_pro_country](https://modalkitwp.com/docs/hooks/modal_kit_pro_country/)`

filter

Supply the visitor’s two-letter country from your own lookup, or an empty string when unknown. Never store the visitor’s address.

$code, $lookup

`[modal_kit_pro_country_sources](https://modalkitwp.com/docs/hooks/modal_kit_pro_country_sources/)`

filter

Add country lookups: a label, the server keys to read and the header they come from.

$sources

`[modal_kit_pro_results_goal](https://modalkitwp.com/docs/hooks/modal_kit_pro_results_goal/)`

filter

Set a modal’s main goal on Results: played, signed_up, coupon, watched, clicked or added_to_cart.

$goal, $post

`[modal_kit_pro_results_count](https://modalkitwp.com/docs/hooks/modal_kit_pro_results_count/)`

filter

Whether a page sends counts to your site. Simply Static exports are handled; turn it off for other static exporters.

$counts

`[modal_kit_pro_coupon_issued](https://modalkitwp.com/docs/hooks/modal_kit_pro_coupon_issued/)`

action

Fires after a game creates a WooCommerce coupon, for example to log it or send it to a CRM.

$code, $prize, $modal_id

`[modal_kit_pro_visitor_address](https://modalkitwp.com/docs/hooks/modal_kit_pro_visitor_address/)`

filter

The address used for rate limits and one play per visitor, for proxy setups. The constant MODAL_KIT_PRO_CLIENT_IP_HEADER covers the usual case.

$address

`[modal_kit_pro_play_rate_limit](https://modalkitwp.com/docs/hooks/modal_kit_pro_play_rate_limit/)`

filter

Plays one address gets per hour. 20 by default.

$limit

`[modal_kit_pro_form_daily_limit](https://modalkitwp.com/docs/hooks/modal_kit_pro_form_daily_limit/)`

filter

Entries a form takes per day through your site. 1,000 by default.

$limit, $modal_id, $form_id

`[modal_kit_pro_address_daily_limit](https://modalkitwp.com/docs/hooks/modal_kit_pro_address_daily_limit/)`

filter

Times one email address can be sent per day, across forms. 3 by default.

$limit

`[modal_kit_pro_events_rate_limit](https://modalkitwp.com/docs/hooks/modal_kit_pro_events_rate_limit/)`

filter

Results requests one address can send in ten minutes. 120 by default.

$limit

`[modal_kit_pro_modal_events_per_hour](https://modalkitwp.com/docs/hooks/modal_kit_pro_modal_events_per_hour/)`

filter

Events one modal can count per hour. 20,000 by default.

$limit, $modal_id



Hook

What it’s for

`[modal_kit_pro_is_staging](https://modalkitwp.com/docs/hooks/modal_kit_pro_is_staging/)`

filter

Whether the site is staging or local, where the license key is checked without using one of its sites.

$staging

`[modal_kit_pro_pre_rollback](https://modalkitwp.com/docs/hooks/modal_kit_pro_pre_rollback/)`

filter

Short-circuit a rollback, for hosts that manage plugin files themselves. Return true or a WP_Error to skip it.

$result, $package, $version

`[modal_kit_pro_tested_up_to](https://modalkitwp.com/docs/hooks/modal_kit_pro_tested_up_to/)`

filter

The free plugin version Pro was tested up to, used to warn about a newer free plugin.

$tested



### Editor filters (JavaScript)

Through `wp.hooks`, for adding to the editor and settings screens.

`[modalKit.layouts](https://modalkitwp.com/docs/hooks/modalkit-layouts/)`

The editor side of modal_kit_layouts, with labels, position labels, mobile help and a note for the Triggers panel.

layouts

`[modalKit.triggerTypes](https://modalkitwp.com/docs/hooks/modalkit-triggertypes/)`

Trigger types in the Triggers panel: label, description, defaults, and optionally a Settings component and a menu group.

types

`[modalKit.triggerMenuGroups](https://modalkitwp.com/docs/hooks/modalkit-triggermenugroups/)`

Extra groups in the add-trigger menu.

[]

`[modalKit.buttonActions](https://modalkitwp.com/docs/hooks/modalkit-buttonactions/)`

Actions in a button’s Modal Kit action menu: { value, label, Settings? }.

actions

`[modalKit.canvasChrome](https://modalkitwp.com/docs/hooks/modalkit-canvaschrome/)`

Editor chrome around the modal on the canvas. Pro adds step tabs.

null, { clientId, attributes, setAttributes }

`[modalKit.settingsTabs](https://modalkitwp.com/docs/hooks/modalkit-settingstabs/)`

Tabs on Modal Kit → Settings: { name, title, Component, saves }.

tabs

`[modalKit.toolsRows](https://modalkitwp.com/docs/hooks/modalkit-toolsrows/)`

Extra rows on the Tools tab.

[]

`[modalKit.pickerPreview](https://modalkitwp.com/docs/hooks/modalkit-pickerpreview/)`

Whether the template picker shows live previews.

false

`[modalKit.styleTarget](https://modalkitwp.com/docs/hooks/modalkit-styletarget/)`

What the block’s Style panel edits. Pro points it at the A/B variant on the canvas.

useOwnStyle

`[modalKit.styleEditor](https://modalkitwp.com/docs/hooks/modalkit-styleeditor/)`

The editor that opens from Edit on Settings → Styles. Pro adds its style editor.

null

[Every hook, with examples](https://modalkitwp.com/docs/hooks/)

In the browser

## Links, events and your own scripts

Each modal is a `<dialog>` with the id `modal-{slug}`. Any link to `#modal-{slug}` or `?modal={slug}` opens it, even without JavaScript for the hash link. Both formats and the prefix are in Settings → General.

Event

Fires on

When, and its detail

`modal-kit:ready`

Free

dialog

The modal is set up and listens for modal-kit:request-open. Its dialog also gets data-modal-kit-ready.

{ slug }

`modal-kit:configure`

Free

dialog

Just before a modal starts its automatic triggers; change detail.config to adjust them (Pro swaps in an A/B variant’s trigger). To set a modal up first, put data-modal-kit-wait on the dialog or an element inside it and remove it when done: the triggers wait for it, at most 4 seconds.

{ slug, config }

`modal-kit:open`

Free

dialog

A modal opened. source is link, a trigger type such as scroll, or what an add-on passed.

{ slug, source }

`modal-kit:close`

Free

dialog

A modal closed. reason is button, esc, outside, action, auto (the auto-close timer), ended (its video ended) or closed.

{ slug, reason }

`modal-kit:action`

Free

button

A button with an add-on’s action was pressed (registered with modal_kit_button_actions).

{ action, button }

`modal-kit:video-ended`

Free

dialog

The video in a modal finished.

`modal-kit:form-submitted`

Pro

form

A Form block’s entry was sent.

`modal-kit:game-played`

Pro

game

A wheel was spun, a card scratched, a gift picked or a reel pulled.

{ modal, game, prize, prizeId }

`modal-kit:prize-won`

Pro

game

The play won a prize. The detail has the prize’s label, never its code.

{ modal, game, prize, prizeId }

`modal-kit:added-to-cart`

Pro

dialog

A product was added to the cart from the modal (counted as the Added to cart goal).

`modal-kit:age-passed`

Pro

dialog

A visitor passed the age gate.

`modal-kit:event`

Pro

window

Every analytics event, when Browser event is on in Settings → Results: `modal_shown`, `modal_closed`, `modal_converted`, `game_played` and `prize_won`. In an A/B test the props include `variant` (a–d).

{ name, modal, goal?, game?, prize? }

**Opening a modal from your code**

Set location.hash to #modal-{slug}. That counts as a link, so frequency and other rules don’t hold it back.

Or dispatch modal-kit:request-open on the dialog once it has data-modal-kit-ready (or after modal-kit:ready). The modal’s rules still apply unless you pass source: ‘link’.

Close it with a button set to the Close modal action, or let visitors use Esc and the close button. Focus returns to whatever opened it when you pass trigger.

JavaScript

```
const dialog = document.getElementById( 'modal-newsletter' );

dialog.addEventListener( 'modal-kit:close', ( event ) => {
  console.log( event.detail.slug, event.detail.reason );
} );

// Open it from your own script. Rules still apply.
dialog.dispatchEvent(
  new CustomEvent( 'modal-kit:request-open', {
    detail: { source: 'my-script', trigger: myButton },
  } )
);

// With Browser event on (Settings → Results).
window.addEventListener( 'modal-kit:event', ( event ) => {
  const { name, modal, ...props } = event.detail;
} );
```

REST API and WP-CLI

## Modals are posts

A modal is a post of type `mk_modal`, so the core REST API and WP-CLI already work with it. Its settings are post meta registered with a JSON schema, so WordPress rejects anything that doesn’t fit.

`/wp/v2/mk_modal`

Users who can edit modals

The core posts endpoint for modals: title, content and meta. The meta keys are _modal_kit_enabled, _modal_kit_triggers, _modal_kit_rules and _modal_kit_overrides.

`GET /modal-kit/v1/export`

Administrators

Every modal with its triggers, rules and overrides, and the plugin settings unless you pass settings=false. The same file as Settings → Tools.

`POST /modal-kit/v1/import`

Administrators

Imports that file: { data }, with replace: true to overwrite modals that have the same slug.

`wp post list --post_type=mk_modal`

WP-CLI

There are no custom WP-CLI commands. Core post and post meta commands work on modals as on any post type.

Add a scroll trigger to modal 42 (Application Password)

```
curl -X POST https://example.com/wp-json/wp/v2/mk_modal/42 \
  -u "admin:xxxx xxxx xxxx xxxx xxxx xxxx" \
  -H "Content-Type: application/json" \
  -d '{ "meta": { "_modal_kit_triggers": [
        { "type": "scroll", "percent": 50 }
      ] } }'
```

The other routes under `modal-kit/v1` and `modal-kit-pro/v1` serve the plugins’ own screens and front end. They can change between versions, so build on the ones above.

Forms · Pro

## Your own form destination

Add a class to `modal_kit_pro_providers` and it appears under Send to in the Form block. A provider either gives the browser a public address to post to, or sets the transport to `relay` and sends from your site, so any secret stays on the server.

PHP · a CRM, sent from your site

```
add_filter( 'modal_kit_pro_providers', function ( $providers ) {
  $providers[] = new class() extends \ModalKit\Pro\Providers\Provider {
    public function id() {
      return 'acme-crm';
    }

    public function label() {
      return __( 'Acme CRM', 'my-plugin' );
    }

    // Asks for an API key on Settings → Integrations.
    public function needs_key() {
      return true;
    }

    // Sent from the site, so it needs live WordPress.
    public function needs_live_site() {
      return true;
    }

    // What the page may see: no address, so the
    // browser hands the entry to your site.
    public function public_config( $form ) {
      return array(
        'url'       => '',
        'transport' => 'relay',
        'email'     => 'email',
      );
    }

    // $fields are keyed by each Field block's name.
    public function send( $form, $fields, $tags ) {
      $result = $this->api_json(
        'POST',
        'https://api.acme.example/v1/contacts',
        array( 'Authorization' => 'Bearer ' . $this->key() ),
        array(
          'email' => $fields['email'] ?? '',
          'name'  => $fields['name'] ?? '',
          'tags'  => $tags,
        )
      );

      if ( is_wp_error( $result ) ) {
        return $result;
      }

      if ( $result['code'] < 200 || $result['code'] >= 300 ) {
        return self::rejected( $result );
      }

      return true;
    }
  };

  return $providers;
} );
```

Webhook body · POST application/json

```
{
  "modal": "welcome-offer",
  "fields": {
    "email": "sam@example.com",
    "name": "Sam"
  },
  "tags": [ "welcome" ],
  "sentAt": "2026-10-26T10:31:00+00:00",
  "site": "https://example.com/"
}
```

Return true or a WP_Error from send(). Failures show in Submissions with the error, and the visitor sees the form’s “couldn’t send” message.

For a service with a public, cross-origin endpoint, return its address with transport post instead, and the browser posts straight to it, also on a static export.

Webhooks post the body above. modal is the modal’s slug and fields are keyed by each Field block’s name.

In the docs

[Test what visitors see →](https://modalkitwp.com/docs/test-what-visitors-see/)

[Open it from a link or button →](https://modalkitwp.com/docs/open-from-a-link/)

[Results and analytics →](https://modalkitwp.com/docs/results/)

## Blocks in, hooks out. Build on it.

[Download free](https://packages.cocartheadless.com/download/latest/modal-kit.zip)

[Read the docs](https://modalkitwp.com/docs/)
