# fluent-community/2.8.0/Modules/Integrations/FluentCRM/CourseEnrollmentTrigger.php

FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS &amp; Online Courses, version 2.8.0. 156 lines.

- Page: https://pluginprobe.com/plugins/fluent-community/2.8.0/code/Modules/Integrations/FluentCRM/CourseEnrollmentTrigger.php
- Raw: https://pluginprobe.com/plugins/fluent-community/2.8.0/raw/Modules/Integrations/FluentCRM/CourseEnrollmentTrigger.php
- Modified: 2026-06-11T08:52:16+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-community/2.8.0/code/Modules/Integrations/FluentCRM/CourseEnrollmentTrigger.php#L10-L20`.

```php
<?php

namespace FluentCommunity\Modules\Integrations\FluentCRM;

use FluentCommunity\Modules\Course\Model\Course;
use FluentCrm\App\Services\Funnel\BaseTrigger;
use FluentCrm\App\Services\Funnel\FunnelHelper;
use FluentCrm\App\Services\Funnel\FunnelProcessor;
use FluentCrm\Framework\Support\Arr;

class CourseEnrollmentTrigger extends BaseTrigger
{
    public function __construct()
    {
        $this->triggerName = 'fluent_community/course/enrolled';
        $this->priority = 30;
        $this->actionArgNum = 2;
        parent::__construct();
    }

    public function getTrigger()
    {
        return [
            'category'    => __('Community', 'fluent-community'),
            'label'       => __('Enrolled in a course', 'fluent-community'),
            'description' => __('This automation will be initiated when a user enrolls in a course.', 'fluent-community'),
            'icon'        => 'fc-icon-wp_new_user_signup',
            'svg_icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"><rect x="3" y="4" width="16" height="14" rx="3" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><circle cx="11" cy="10" r="2" stroke="currentColor" stroke-width="2"/><path d="M7.5 15c.8-1.8 2.6-2.8 3.5-2.8s2.7 1 3.5 2.8" stroke="currentColor" stroke-width="2" stroke-linecap="round"/><circle cx="18" cy="18" r="4" fill="currentColor"/><path d="M18 16v4M16 18h4" stroke="#fff" stroke-width="2" stroke-linecap="round"/></svg>'
        ];
    }

    public function getSettingsFields($funnel)
    {
        return [
            'title'     => __('Enrolled in a course', 'fluent-community'),
            'sub_title' => __('This automation will be initiated when a user enrolls in a course.', 'fluent-community'),
            'fields'    => [
                'subscription_status'      => [
                    'type'        => 'option_selectors',
                    'option_key'  => 'editable_statuses',
                    'is_multiple' => false,
                    'label'       => __('Subscription Status', 'fluent-community'),
                    'placeholder' => __('Select Status', 'fluent-community')
                ],
                'subscription_status_info' => [
                    'type'       => 'html',
                    'info'       => '<b>' . __('An Automated double-opt-in email will be sent for new subscribers', 'fluent-community') . '</b>',
                    'dependency' => [
                        'depends_on' => 'subscription_status',
                        'operator'   => '=',
                        'value'      => 'pending'
                    ]
                ]
            ]
        ];
    }

    public function getFunnelSettingsDefaults()
    {
        return [
            'subscription_status' => 'subscribed'
        ];
    }

    public function getConditionFields($funnel)
    {
        $courses = Course::orderBy('title', 'ASC')->select(['id', 'title'])->get();

        return [
            'update_type'  => [
                'type'    => 'radio',
                'label'   => __('If Contact Already Exists?', 'fluent-community'),
                'help'    => __('Please specify what will happen if the subscriber already exists in the database', 'fluent-community'),
                'options' => FunnelHelper::getUpdateOptions()
            ],
            'course_ids'   => [
                'type'        => 'multi-select',
                'is_multiple' => true,
                'label'       => __('Targeted Courses', 'fluent-community'),
                'help'        => __('Select which courses this automation is for.', 'fluent-community'),
                'placeholder' => __('Select Courses', 'fluent-community'),
                'options'     => $courses,
                'inline_help' => __('Leave blank to run for all Courses', 'fluent-community')
            ],
            'run_multiple' => [
                'type'        => 'yes_no_check',
                'label'       => '',
                'check_label' => __('Restart the automation multiple times for a contact for this event. (Only enable this if you want to restart the automation for the same contact)', 'fluent-community'),
                'inline_help' => __('If you enable this, it will restart the automation for a contact even if they are already in the automation. Otherwise, it will skip if the contact already exists.', 'fluent-community')
            ]
        ];
    }

    public function getFunnelConditionDefaults($funnel)
    {
        return [
            'update_type'  => 'update', // skip_all_actions, skip_update_if_exist
            'course_ids'   => [],
            'run_multiple' => 'yes'
        ];
    }

    public function handle($funnel, $originalArgs)
    {
        $course = $originalArgs[0];
        $userId = $originalArgs[1];

        $user = get_user_by('ID', $userId);

        if (!$user || !$this->isProcessable($funnel, $user, $course)) {
            return false;
        }

        $subscriberData = FunnelHelper::prepareUserData($user);

        $subscriberData = wp_parse_args($subscriberData, $funnel->settings);
        $subscriberData['status'] = $subscriberData['subscription_status'];
        unset($subscriberData['subscription_status']);

        (new FunnelProcessor())->startFunnelSequence($funnel, $subscriberData, [
            'source_trigger_name' => $this->triggerName,
            'source_ref_id'       => $course->id
        ]);
    }

    private function isProcessable($funnel, $user, $course)
    {
        $conditions = $funnel->conditions;
        // check update_type
        $updateType = Arr::get($conditions, 'update_type');

        $subscriber = FunnelHelper::getSubscriber($user->user_email);
        if ($updateType == 'skip_all_if_exist' && $subscriber) {
            return false;
        }

        // check user roles
        if ($checkIds = Arr::get($conditions, 'course_ids', [])) {
            if (!in_array($course->id, $checkIds)) {
                return false;
            }
        }

        // check run_only_one
        if ($subscriber && FunnelHelper::ifAlreadyInFunnel($funnel->id, $subscriber->id)) {
            $multipleRun = Arr::get($conditions, 'run_multiple') == 'yes';
            if ($multipleRun) {
                FunnelHelper::removeSubscribersFromFunnel($funnel->id, [$subscriber->id]);
            }
            return $multipleRun;
        }

        return true;
    }
}

```
