Automation is magic and FluentCRM is the magician. But anyone can be part of this. Following some steps, anyone can be part of this magic. In this article, we will show you, how you are able to add a custom action in automation.
Action
Actions are essential for initiating email marketing automation. There are a lot of actions that can start or initiate automation in FluentCRM such as Update Contact Property, Outgoing webhook, Split (A/B Testing), and many more. Using action you can track various activities in your WordPress ecosystem. Isn’t cool. Let’s dive into deep to learn, how to create a custom trigger in FluentCRM.
To make an automation action, we need to use two filters and one action hook.
Type | Hook | Description |
---|---|---|
Filter | fluentcrm_funnel_blocks | This is a filter hook and this hook will add your custom action to the automation action list. |
Filter | fluentcrm_funnel_block_fields | This is a filter hook and this hook will generate your custom action setting block. |
Action | fluentcrm_funnel_sequence_handle_{action_name} | This is an action hook and this action will be called automatically depending on the automation action setting. You can do further using this action hook. For the following trigger source code, the {action_name} is custom_action_name. |
To add a custom action in automation, I am going to tell you step by step. This example will be using composer, you can do without composer too.
Step 1
First of all, I created a class named Custom Action which will contain the full source code of this automation action.
<?php namespace Custom\Actions; class CustomAction { public function __construct() { $this->actionName = 'custom_action_name'; $this->priority = 99; add_filter('fluentcrm_funnel_blocks', array($this, 'pushBlock'), $this->priority, 2); add_filter('fluentcrm_funnel_block_fields', array($this, 'pushBlockFields'), $this->priority, 2); add_action('fluentcrm_funnel_sequence_handle_' . $this->actionName, array($this, 'handle'), 10, 4); } public function pushBlock($blocks, $funnel) { $this->funnel = $funnel; $block = $this->getBlock(); if($block) { $block['type'] = 'action'; $blocks[$this->actionName] = $block; } return $blocks; } public function pushBlockFields($fields, $funnel) { $this->funnel = $funnel; $fields[$this->actionName] = $this->getBlockFields(); return $fields; } public function getBlock() { return [ 'category' => 'My-plugin', 'title' => 'Add My-plugin note', 'description' => 'Add Note to My-plugin', 'icon' => 'fc-icon-writing', 'settings' => [ 'note' => '', 'note_type' => 'private' ] ]; } public function getBlockFields() { $formattedOptions = [ [ 'id' => 'private', 'title' => 'Private Note' ], [ 'id' => 'customer', 'title' => 'Note to Customer' ] ]; return [ 'title' => 'Add My-plugin Note', 'sub_title' => 'Add Note to My-plugin Order', 'fields' => [ 'note' => [ 'type' => 'input-text-popper', 'field_type' => 'textarea', 'label' => 'My-plugin Note', 'help' => 'Type the note that you want to add to the reference order. You can also use smart tags' ], 'note_type' => [ 'type' => 'radio', 'label' => 'New Order Status', 'help' => 'Select Note Type for the reference Order.', 'options' => $formattedOptions ] ] ]; } public function handle($subscriber, $sequence, $funnelSubscriberId, $funnelMetric) { error_log(print_r([$subscriber, $sequence, $funnelSubscriberId, $funnelMetric], 1)); } }
In the above example, you see, there is a method called pushBlockFields. This method returns an object and the object contains several fields. This object is the structure of this action’s setting page design. Let’s see the preview of this action’s setting block and discuss it.

In the above sourcecode, Target Products block is generated by getBlockFields. You see there is fields property in this method return array. There are so many field type in FluentCRM, you can find those here.
In the above example, you see, there is a method called handle. This method is called when this action is triggered. By this method you can do, what you want.
Step 2
Using the following code, You can able to add this custom action code in FluentCRM.
add_action('plugins_loaded', function () { if (defined('FLUENTCAMPAIGN_DIR_FILE')) { new \Custom\Actions\CustomAction(); } });