Hooks

Docs Hooks Free · PHP hooks

modal_kit_styles

filter

Free

PHP

Add fixed styles: token sets of colours, fonts, radius and shadow that look the same on any theme, like the bundled Fieldnote, Harbor and Night.

Fixed styles bring their own colours and fonts, unlike Native, Soft and Editorial, which follow the theme. Each one is a block style of the Modal block (is-style-{slug}). This filter receives the bundled styles and the ones authors imported or made on the site, keyed by slug, and returns the full list.

It runs once per request, on init at priority 20, when the block styles are registered. Each style that isn’t bundled gets a .mk-style-{slug} rule of --mk-* custom properties, printed inline with the Modal block’s stylesheet on the site and in the editor canvas. Styles you add are listed on Modal Kit → Settings → Styles as “Added by a plugin”.

Parameters

Parameter

Description

$styles

array

Styles keyed by slug. Each has label, description, version, color (surface, ink, muted, line, field, accent, accent-strong, on-accent, tint, overlay, full-bg, full-ink, full-accent), font (head, body, mono, head-weight, head-tracking, head-size), radius (panel, button, field) and shadow.

Returns

array Styles keyed by slug. Each is cleaned: unknown keys are dropped, values keep only characters that can appear in a CSS value, and a style without a label or one of its required colours is left out.

Examples

Add a brand style

A complete token set, in the same shape as the bundled fieldnote.json. It uses the bundled fonts, so they load with the modal.

PHP

add_filter( 'modal_kit_styles', function ( $styles ) {
  $styles['my-brand'] = array(
    'label'       => __( 'Acme', 'my-plugin' ),
    'description' => __( 'Warm white, deep green, square', 'my-plugin' ),
    'color'       => array(
      'surface'       => '#fffdf8',
      'ink'           => '#1d2420',
      'muted'         => '#55605a',
      'line'          => '#e6e2d8',
      'field'         => '#8a918c',
      'accent'        => '#0b6e4f',
      'accent-strong' => '#07513a',
      'on-accent'     => '#ffffff',
      'tint'          => '#e6f2ed',
      'overlay'       => 'rgba(20,28,24,.5)',
      'full-bg'       => '#1d2420',
      'full-ink'      => '#f6f3ea',
      'full-accent'   => '#7fd1ae',
    ),
    'font'        => array(
      'head'          => "'Instrument Serif', serif",
      'body'          => "'Instrument Sans', sans-serif",
      'head-weight'   => 400,
      'head-tracking' => '-0.01em',
      'head-size'     => 40,
    ),
    'radius'      => array(
      'panel'  => '0',
      'button' => '0',
      'field'  => '0',
    ),
    'shadow'      => '0 24px 60px rgba(20,28,24,.25)',
  );

  return $styles;
} );

Change a bundled style’s accent

A bundled style you change is no longer treated as bundled: its rule is printed inline after the stylesheet, so your values win.

PHP

add_filter( 'modal_kit_styles', function ( $styles ) {
  if ( isset( $styles['fieldnote'] ) ) {
    $styles['fieldnote']['color']['accent']        = '#0b6e4f';
    $styles['fieldnote']['color']['accent-strong'] = '#07513a';
    $styles['fieldnote']['color']['tint']          = '#e6f2ed';
  }

  return $styles;
} );

Good to know

Add the filter before init priority 20, at plugin load or on plugins_loaded. The list is built once and kept for the request, so a filter added later has no effect.

The slugs default, soft and editorial belong to the styles that follow the theme and are skipped. Slugs go through sanitize_key().

The required colours (surface, ink, accent, on-accent, full-bg, full-ink, full-accent) must be hex or rgb()/rgba() values: the plugin works out contrast and a dark style’s field colour from them. A style with an hsl() or var() value there is dropped.

Instrument Sans, Instrument Serif and IBM Plex Mono come with the plugin and load with any modal that uses the style’s fonts. Any other font is yours to load, on the site and in the editor.

Styles saved on the site are added at priority 5, so a style you add at the default priority replaces a saved one with the same slug.

There is no editor filter to add: the editor, Settings and the setup wizard get the list from PHP.

Applied in modal-kit/includes/Styles.php.

Need a hook that isn’t here?