Docs / Developers

Creating a custom automation action

Extend AbstractAction and it appears in the Workflows action picker.

An automation action implements get_name() (a unique action id), get_label() (shown in the action picker on Craftor → Workflows), and execute(), which receives that step's saved configuration and the trigger context (submitted fields, post/element id, source URL, and payment details for a payment_succeeded trigger).

php
final class Acme_Log_Action extends \Craftor\Workflows\Actions\AbstractAction {

	public function get_name(): string {
		return 'acme_log_submission';
	}

	public function get_label(): string {
		return 'Log Submission (Acme)';
	}

	public function execute( array $config, array $context ): array {
		// merge_fields() resolves {field_name}, {post_id}, {element_id},
		// {source_url}, and {all_fields} — the same placeholder syntax
		// every built-in action's text fields support.
		$note = $this->merge_fields(
			(string) ( $config['note'] ?? 'New submission from {source_url}' ),
			$context
		);

		error_log( $note );

		// Throw a \RuntimeException to mark the step failed — the workflow
		// stops there unless the step has "Continue on error" enabled.
		return array( 'logged' => true );
	}
}

add_action( 'craftor/register_workflow_actions', function () {
	\Craftor\Workflows\Actions\ActionRegistry::register( new Acme_Log_Action() );
} );

Whatever execute() returns is stored against that step in the workflow's execution log (Craftor → Workflows → a workflow → Logs), visible to whoever's debugging why a step did or didn't do what was expected.