Hooks

Docs Hooks Free · PHP hooks

modal_kit_pattern_collection_types

filter

Free

PHP

Add type filters inside a template collection, such as Newsletter, Coupon or Age gate in Pro’s Popups. A starter’s type is one of its pattern categories.

When a collection is open in the template picker, its types show as a row of filters above the starters (All, then each type), so a large collection can be narrowed down. Pro uses it for its Popups collection.

A starter has a type when the type’s slug is one of its pattern categories, alongside the collection’s slug.

Parameters

Parameter

Description

$types

array<string, array<string, string>>

Collection slug => ( type slug => label ). Empty by default; Pro sets modal-kit-pro-popups at priority 10.

Returns

array<string, array<string, string>> The types, cast to an array.

Examples

Split your collection into types

Give each starter the collection’s slug and one type slug in its categories.

PHP

add_filter( 'modal_kit_pattern_collection_types', function ( $types ) {
  $types                     = (array) $types;
  $types['my-plugin-agency'] = array(
    'my-plugin-agency-lead'   => __( 'Lead capture', 'my-plugin' ),
    'my-plugin-agency-notice' => __( 'Notice', 'my-plugin' ),
  );

  return $types;
} );

add_action( 'init', function () {
  register_block_pattern(
    'my-plugin/holiday-closure',
    array(
      'title'      => __( 'Holiday closure', 'my-plugin' ),
      'categories' => array( 'my-plugin-agency', 'my-plugin-agency-notice' ),
      'postTypes'  => array( 'mk_modal' ),
      'inserter'   => false,
      'content'    => '<!-- wp:modal-kit/modal -->'
        . '<!-- wp:paragraph --><p>'
        . esc_html__( 'We are closed until 2 January.', 'my-plugin' )
        . '</p><!-- /wp:paragraph -->'
        . '<!-- /wp:modal-kit/modal -->',
    )
  );
} );

Add a type to Pro’s Popups

Pro sets its whole Popups entry at priority 10, so add yours later. Your starters then need modal-kit-pro-popups and the type in their categories.

PHP

add_filter( 'modal_kit_pattern_collection_types', function ( $types ) {
  if ( isset( $types['modal-kit-pro-popups'] ) ) {
    $types['modal-kit-pro-popups']['my-plugin-popup-quiz'] = __(
      'Quiz',
      'my-plugin'
    );
  }

  return $types;
}, 20 );

Good to know

Types keep the order you give them, and a type with no starters in the open collection is hidden.

Opening another collection resets the filter to All.

Types aren’t registered as pattern categories: they only group starters inside the picker.

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

Need a hook that isn’t here?