Skip to main content

Is there a place here to share code snippets?

Hi Shahjahan Jewel - just wondering if you have a space here to share code snippets? I've built a number of customizations that might be helpful to others, thought i would pass them along here for anyone else who might want to use them. I've got a couple for FCRM, and a few for FluentForms... by the way, there's no space in this community for FluentForms? and FluentSMTP?

Thanks,
Dan

Assaf Manor

Hey Dan. I'm interested to hear what did you build.

Dan Linstedt

for one: here's a custom CONDITION that: allows you to use a PHP REGEX to match tags. Our business use case is: we create dynamic tags through the wooCommerce +Learndash groups + wpfusion purchase cycle, these tags are unique and match a computed group name. Using a regular "tag selector" does not work, because we need to look for patterns in the tag (any number of tags). Therefore, we use a regex to match against different types of tags, returning true when matched, false when not.

I will be posting other free code snippets on my hobby site: https://aplusplugins.com

add_action('plugins_loaded', function () {
new DVARegexCondition();
});
/* purpose: to use a regex to match patterns in any tag.
matches tags one at a time.
(C) DataVaultAlliance Holdings LLC 2025, free for public re-use, not available to make part of a product for resale unless its embedded in the core FluentCRM engine.
Written by: Dan Linstedt
website: https://aplusplugins.com
*/
class DVARegexCondition
{
public function __construct()
{
add_filter('fluentcrm_automation_condition_groups', array($this, 'addAutomationConditions'), 10, 2);
add_filter('fluentcrm_automation_conditions_assess_regex', array($this, 'assessAutomationConditions'), 10, 5);
}
public function addAutomationConditions($groups, $funnel)
{
    $customerItems = [
        [
            'value'             => 'tags_contain',
            'label'             => 'Tags Contain',
            'help'              => 'Please enter a valid PHP preg_match regex. do NOT include leading or trailing slashes. Each tag will be compared (case insensitive) to the regex pattern to return a true or false overall',
            'custom_operators' => [
                'matches'  => 'matches'
            ],
            'type'              => 'text',
            'is_singular_value' => true,
            'disabled'          => false
        ]
    ];

    $groups['regex'] = [
        'label'    => 'Regex Match',
        'value'    => 'regex',
        'children' => $customerItems,
    ];

    return $groups;
}

//    public function assessAutomationConditions($result, $conditions, $subscriber)
public function assessAutomationConditions($result, $conditions, $subscriber, $sequence, $funnelSubscriberId)
{
    foreach ($conditions as $condition) {
        $prop = $condition['data_key'];
        $operator = $condition['operator'];
        $value    = $condition['data_value'];

        if ($prop === 'tags_contain' && !empty($value)) {
            $regex = $value;
            $pattern = "/$regex/i";

            if (@preg_match($pattern, '') === false) {
                return false; // Invalid regex
            }

            $tagNames = $subscriber->tags->pluck('title')->toArray();

            foreach ($tagNames as $tagName) {
                if (preg_match($pattern, $tagName)) {
                    return true;
                }
            }

            return false; // No match found
        }
    }

    return $result; // fallback if no conditions matched
}

}