Hooks

Docs Hooks Free · PHP hooks

modal_kit_button_actions

filter

Free

PHP

Register a button action the front end understands, so a core Button in a modal can run your code. Pro adds step, form, cart and game actions.

Inside a modal, a core Button block gets an Action panel: Open link, Close modal or Copy text. The choice is saved as the block’s modalKitAction attribute; the saved markup doesn’t change. When the button renders, Modal Kit checks the action against this list and, if it is known, adds the runtime’s click handler.

Clicking a button with an add-on’s action doesn’t follow its link. The runtime fires a bubbling modal-kit:action event on the button, with detail.action and detail.button, for your script to handle.

Pro adds step-nav, go-to-step, submit-form, woo-add-to-cart, woo-apply-coupon and game-play this way.

Parameters

Parameter

Description

$actions

string[]

Action names. The free plugin’s are link, close and copy.

Returns

string[] Action names, cast to an array and compared strictly, so use strings. A button whose action isn’t in the list renders as it was saved.

Example

Register an action

The name is what the editor saves in modalKitAction, so it must match the value you give modalKit.buttonActions.

PHP

add_filter( 'modal_kit_button_actions', function ( $actions ) {
  $actions[] = 'my-share';

  return $actions;
} );

Good to know

This is the server side only. To let authors choose the action, add { value, label } (and an optional Settings component) with the modalKit.buttonActions editor filter. Attributes your settings save need registering on core/button in the editor.

To put data on the button for your script, use modal_kit_render_button_action.

A click on an add-on action counts as the visitor acting on the modal for its frequency rules, like any other button except Close modal.

The filter runs for every core Button rendered, with or without an action, so keep the callback cheap.

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

Need a hook that isn’t here?