Guides

Developers

Start workflows from code, register triggers and actions, hooks, filters and the REST API.

SwiftAction is extended with plain PHP functions and WordPress hooks. The built-in WooCommerce and EDD integrations use the same API described here. IDs are lowercase and namespaced with a dot, for example myplugin.ticket_closed.

Start workflows from your code

Fire a custom event

Workflows using the Custom event trigger with the same event name start. No registration needed.

php
swiftaction_fire_event( 'lead_captured', array(
    'email'  => $email,     // identifies the contact (or pass $who as the 3rd argument)
    'source' => 'webinar',  // any data: {{trigger.source}}, conditions
) );

$who can be a user ID, an email, a WP_User or a Contact. By default SwiftAction uses $data['user_id'], then $data['email'], then the current visitor. Admins can also use the WordPress hook trigger to listen to any plugin’s action hook without code.

Enroll a contact directly

php
$run = swiftaction_enroll_contact( $workflow_id, $user_id_or_contact, array( 'plan' => 'pro' ), $force = false );
if ( is_wp_error( $run ) ) {
    // Not active, blocked by the re-entry rule, ...
}

Where to register

php
add_action( 'swiftaction_register', function ( \SwiftAction\Plugin $plugin ) {
    // swiftaction_register_trigger(), swiftaction_register_action(), swiftaction_register_condition_field() ...
} );

swiftaction_register runs on init (priority 5), after the built-in integrations load.

Custom triggers

php
swiftaction_register_trigger( 'myplugin.ticket_closed', array(
    'label'       => __( 'Support ticket closed', 'myplugin' ),
    'description' => __( 'A customer’s support ticket is closed.', 'myplugin' ),
    'group'       => __( 'Support', 'myplugin' ),
    'icon'        => 'tickets-alt',                       // Dashicon name
    'fields'      => array(                               // settings on the trigger step
        array( 'key' => 'priority', 'type' => 'select', 'label' => 'Priority',
               'options' => array( '' => 'Any', 'high' => 'High', 'low' => 'Low' ) ),
    ),
    'provides'    => array( 'ticket_id' => 'Ticket ID', 'priority' => 'Priority' ),
    // Only called while an active workflow uses this trigger:
    'listen'      => function ( callable $fire ) {
        add_action( 'myplugin_ticket_closed', function ( $ticket ) use ( $fire ) {
            $contact = swiftaction_get_user_contact( (int) $ticket->user_id );
            $fire( $contact, array( 'ticket_id' => $ticket->id, 'priority' => $ticket->priority ) );
        } );
    },
    // Per workflow: does this event match the step's settings?
    'matches'     => fn( array $s, array $data ) => '' === ( $s['priority'] ?? '' ) || $s['priority'] === $data['priority'],
) );
  • Pass null as the contact when there’s no known person; no run starts.
  • Keep $data small and scalar (IDs, not objects): it’s stored with the run.
  • Re-entry rules, loop protection, pausing and versions are handled for you.

Custom actions

php
swiftaction_register_action( 'myplugin.create_ticket', array(
    'label'   => __( 'Create support ticket', 'myplugin' ),
    'group'   => __( 'Support', 'myplugin' ),
    'fields'  => array(
        array( 'key' => 'subject', 'type' => 'text', 'label' => 'Subject', 'required' => true, 'merge_tags' => true ),
    ),
    'retry'   => array( 'attempts' => 3, 'backoff' => 60 ),  // optional: retry WP_Errors after 60s, 120s, 240s
    'handler' => function ( array $settings, \SwiftAction\Engine\RunContext $context ) {
        // $settings has defaults applied and merge tags rendered.
        $id = myplugin_create_ticket( $context->contact->email, $settings['subject'] );
        if ( ! $id ) {
            return new WP_Error( 'ticket_failed', 'Could not create the ticket.' ); // logged, retried
        }
        return array(
            'ticket_id' => $id,                          // shown in Replay
            'context'   => array( 'ticket_id' => $id ),  // {{trigger.ticket_id}} in later steps
        );
        // Or: return array( 'skipped' => true, 'reason' => 'No email address' );
    },
    'dry_run' => fn( array $s ) => sprintf( 'Would create a ticket "%s"', $s['subject'] ), // shown by Simulate
) );

RunContext gives you ->contact, ->workflow, ->run, ->dry_run, ->trigger(), ->data(), ->get( $key, $default ) and ->user().

Custom condition fields

php
swiftaction_register_condition_field( 'myplugin.open_tickets', array(
    'label'   => __( 'Open support tickets', 'myplugin' ),
    'group'   => __( 'Support', 'myplugin' ),
    'type'    => 'number',   // text | number | select | multiselect | boolean | date (Unix timestamp)
    'resolve' => fn( \SwiftAction\Engine\RunContext $c ) => myplugin_count_open( $c->contact->email ),
    // 'options'  => array or callable (value => label) for select/multiselect
    // 'triggers' => array( 'myplugin.ticket_closed' )  // only offer it for these triggers
) );

Settings field types

Used by fields on triggers and actions; the builder renders the form automatically.

KeyMeaning
typetext, textarea, richtext, number, email, url, select, multiselect, checkbox, date, datetime, duration, tags, user_roles, key_value, image, hidden
label, help, placeholder, default, requiredAs expected.
optionsvalue => label array, or a callable returning one.
merge_tagstrue to allow merge tags (rendered before your handler runs); 'json' to JSON-escape values.
show_ifarray( 'field' => 'mode', 'value' => 'custom' ); value may be an array.

Custom merge tags

php
swiftaction()->merge_tags()->register_group( 'ticket', __( 'Ticket', 'myplugin' ),
    function ( string $key, \SwiftAction\Engine\RunContext $c ) {
        $ticket = myplugin_get_ticket( (int) $c->get( 'ticket_id' ) );
        return match ( $key ) {
            'subject' => $ticket?->subject,
            'url'     => $ticket ? get_permalink( $ticket->post_id ) : null,
            default   => null,   // unknown → fallback text
        };
    },
    array( 'subject' => 'Subject', 'url' => 'Link' )   // entries in the picker
);

Return new \SwiftAction\Engine\HtmlValue( $html ) to output HTML. For one-off values use the swiftaction_merge_tag_value filter.

Integrations

php
add_action( 'swiftaction_register_integrations', function () {
    swiftaction_register_integration( 'myplugin', array(
        'label'     => 'My Plugin',
        'is_active' => fn() => class_exists( 'MyPlugin' ),
        'load'      => function ( \SwiftAction\Plugin $plugin ) {
            swiftaction_register_trigger( 'myplugin.ticket_closed', array( 'integration' => 'myplugin', /* ... */ ) );
        },
    ) );
} );

Contacts, tags and fields

php
$contact = swiftaction_get_user_contact( $user_id );
$contact = swiftaction()->contacts()->identify( $email, array( 'first_name' => 'Ann' ) ); // guest by email
$contact = swiftaction()->contacts()->current();   // logged-in user or tracked guest

swiftaction_add_tag( $contact, 'VIP' );            // creates the tag if needed; fires "Tag added"
swiftaction_remove_tag( $contact, 'VIP' );
swiftaction_has_tag( $contact, 'VIP' );

swiftaction()->contacts()->meta()->set( $contact->id, 'company', 'Acme' );
swiftaction()->subscriptions()->set( $contact, 'unsubscribed', array( 'source' => 'api' ) );

Useful hooks

HookTypeUse
swiftaction_run_started / _finishedactionReact to runs (Run, Workflow, Contact).
swiftaction_step_recordedactionEvery step, including simulations (run ID 0).
swiftaction_tag_added / _removedactionContact, Tag.
swiftaction_popup_eventactionshown, clicked, dismissed, submitted for popups and banners.
swiftaction_form_submittedactionEvery stored form submission.
swiftaction_email_opened / _clickedactionTracked opens and clicks.
swiftaction_contact_unsubscribed / _resubscribedactionSubscription changes, with the source.
swiftaction_can_track_guestfilterFinal say on the guest cookie.
swiftaction_guest_consentfilterConnect your cookie banner.
swiftaction_webhook_argsfilterChange webhook requests (auth, timeouts).
swiftaction_form_valuesfilterValidate or change form answers; return WP_Error to reject.
swiftaction_email_renderedfilterChange a designed email after rendering.
swiftaction_unsubscribe_urlfilterSend unsubscribe links to your own preferences page.
swiftaction_show_popupsfilterHide automatic popups and banners on a page.

The plugin ships a complete hooks reference in docs/DEVELOPERS.md.

REST API

Namespace swiftaction/v1. Admin routes need the swiftaction_manage capability (cookie with X-WP-Nonce, or application passwords).

RoutePurpose
GET /definitionsTriggers, actions, condition fields, merge tags and tags.
GET, POST /workflows · GET, PUT, DELETE /workflows/{id}Workflows (PUT saves a draft).
POST /workflows/{id}/publish · /status · /duplicate · /validatePublish, activate or pause, duplicate, validate.
GET /workflows/{id}/live · /runsLive counts and events; runs.
GET /runs/{id}A run with its steps, graph and email results.
POST /workflows/{id}/simulateDry run for a contact.
/popups · /emails · /contact-fields · /tags · /contactsPopups and banners, emails (preview, test), custom fields, tags, contact search.

Front-end JavaScript

js
swiftaction.openPopup( 5 );  swiftaction.closePopup();
swiftaction.showBanner( 7 ); swiftaction.hideBanner( 7 );

document.addEventListener( 'swiftaction:popup:submitted', ( e ) => { /* e.detail.id, e.detail.source */ } );
// swiftaction:popup:shown|clicked|dismissed, swiftaction:banner:shown|clicked|dismissed|submitted
Note
Datetimes in SwiftAction’s tables are UTC. Use the services (swiftaction()->contacts(), ->runs(), ->emails()…) rather than querying tables: the schema can change between versions.
For SwiftAction 1.0 · Updated 5 December 2026 · Questions or corrections?