Hooks
modal_kit_starter_settings
filter
Free
PHP
Set the triggers, display rules and overrides a starter applies to the modal when someone picks it in the template picker.
A starter can bring modal settings as well as blocks. When it’s picked, its triggers replace the modal’s and its rules and overrides are merged into what the modal has, as an edit that’s saved with the modal.
The list starts with the settings of every pattern file read with ModalKit\Patterns::load(), keyed by pattern name. The free plugin’s own starters bring none; Pro’s Popups templates bring theirs this way. The modal editor reads the list when it loads.
Parameters
Parameter
Description
$settings
array<string, array>
Pattern name => array with any of triggers (a list of triggers), rules and overrides, shaped like the modal’s meta of the same names.
Returns
array<string, array> The settings, cast to an array. Keys other than triggers, rules and overrides are ignored.
Examples
Open Parting gift on exit intent
Modal Kit’s Parting gift starter is an exit offer with no trigger of its own. This gives it one, and a 14-day wait between shows.
add_filter( 'modal_kit_starter_settings', function ( $settings ) {
$name = 'modal-kit/parting-gift';
$settings[ $name ] = array_merge(
isset( $settings[ $name ] ) ? $settings[ $name ] : array(),
array(
'triggers' => array(
array(
'type' => 'exit',
'touch' => 'scroll-up',
),
),
'rules' => array(
'frequency' => array(
'mode' => 'days',
'days' => 14,
),
),
)
);
return $settings;
} );
Settings in a pattern file
A pattern file read with ModalKit\Patterns::load() (see modal_kit_pattern_collections) can carry its settings itself. They reach this filter without any code.
// patterns/webinar-reminder.php
return array(
'slug' => 'my-plugin/webinar-reminder',
'title' => __( 'Webinar reminder', 'my-plugin' ),
'categories' => array( 'my-plugin-agency' ),
'content' => '<!-- wp:modal-kit/modal -->'
. '<!-- wp:heading --><h2 class="wp-block-heading">'
. esc_html__( 'Our webinar starts soon', 'my-plugin' )
. '</h2><!-- /wp:heading -->'
. '<!-- /wp:modal-kit/modal -->',
'settings' => array(
'triggers' => array(
array(
'type' => 'time',
'delay' => 20,
),
),
'rules' => array(
'devices' => array( 'desktop', 'tablet' ),
),
),
);
Good to know
Triggers replace the modal’s triggers. Each rule replaces the modal’s rule of the same name, except that when both are objects (such as frequency) the starter’s keys are merged into it. Overrides are merged one level deep, so an accessibility object replaces the modal’s whole accessibility override.
Values must match the modal meta schema (schema/modal-meta.json, which modal_kit_meta_schema can extend). The REST API checks them when the modal is saved.
Trigger types in the free plugin: load, scroll, exit, time, inactivity, url and element.
Applied in modal-kit/includes/Patterns.php.