Filter Dynamic uncanny-automator

automator_fluentcrm_omit_custom_field-{$custom_field['slug']}

> **Note:** This is a dynamic hook. The actual hook name is constructed at runtime. Filters whether to omit a specific FluentCRM custom field during automator processes.

add_filter( 'automator_fluentcrm_omit_custom_field-{$custom_field['slug']}', $callback, 10, 1 );

Description

This filter allows developers to programmatically omit specific FluentCRM custom fields from being processed or displayed within Uncanny Automator workflows. Returning `true` for a custom field's slug will prevent it from being included. This is useful for hiding sensitive or irrelevant fields from automation triggers and actions.


Usage

add_filter( 'automator_fluentcrm_omit_custom_field-{$custom_field['slug']}', 'your_function_name', 10, 1 );

Parameters

$custom_field (mixed)
This parameter is used to determine whether the custom field should be omitted from the FluentCRM contact.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to use the automator_fluentcrm_omit_custom_field-$slug filter.
 * This filter allows you to conditionally omit specific FluentCRM custom fields
 * from being processed by Uncanny Automator.
 *
 * In this example, we'll omit any custom field with the slug 'internal_notes'
 * and also any field that has the type 'hidden'.
 *
 * @param bool        $omit           The default value is false. Return true to omit the field.
 * @param array       $custom_field   The custom field array from FluentCRM.
 * @return bool True if the field should be omitted, false otherwise.
 */
add_filter( 'automator_fluentcrm_omit_custom_field-internal_notes', 'my_automator_omit_internal_notes_field', 10, 2 );
add_filter( 'automator_fluentcrm_omit_custom_field-any_other_slug', 'my_automator_omit_hidden_type_fields', 10, 2 );

function my_automator_omit_internal_notes_field( $omit, $custom_field ) {
    // We are specifically targeting a field with the slug 'internal_notes'.
    // The hook itself handles the slug, so here we just need to confirm.
    // If the slug was not 'internal_notes', this filter wouldn't be applied anyway.
    return true; // Omit this field entirely.
}

function my_automator_omit_hidden_type_fields( $omit, $custom_field ) {
    // This function will be applied to any custom field slug that is not 'internal_notes'.
    // We check if the custom field's type is 'hidden'.
    if ( isset( $custom_field['type'] ) && 'hidden' === $custom_field['type'] ) {
        return true; // Omit fields of type 'hidden'.
    }

    return $omit; // Otherwise, return the default value (false).
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/integrations/fluent-crm/helpers/fluent-crm-helpers.php:525
src/integrations/fluent-crm/helpers/fluent-crm-helpers.php:678
src/integrations/fluent-crm/actions/fcrm-add-contact.php:91

public function get_custom_field() {
		$custom_fields = fluentcrm_get_custom_contact_fields();

		$field_types = array(
			'text'         => 'text',
			'textarea'     => 'textarea',
			'checkbox'     => 'checkbox',
			'radio'        => 'radio',
			'date'         => 'date',
			'date_time'    => 'text',
			'select-multi' => 'select',
			'select-one'   => 'select',
			'number'       => 'int',
		);

		$placeholders = array(
			'date'       => esc_html_x( 'yyyy-mm-dd', 'FluentCRM', 'uncanny-automator' ),
			'date_time'  => esc_html_x( 'yyyy-mm-dd hh:mm:ss', 'FluentCRM', 'uncanny-automator' ),
			'select-one' => esc_html_x( 'Select an option', 'FluentCRM', 'uncanny-automator' ),
		);

		$fields = array();
		foreach ( $custom_fields as $k => $custom_field ) {

			if ( apply_filters( "automator_fluentcrm_omit_custom_field-{$custom_field['slug']}", false, $custom_field ) ) { // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
				continue;
			}

			$options                  = null;
			$supports_multiple_values = false;
			if ( 'select-multi' === $custom_field['type'] ) {
				$supports_multiple_values = true;
			}

			if (
				'select-multi' === $custom_field['type'] ||
				'select-one' === $custom_field['type'] ||
				'radio' === $custom_field['type']
			) {
				$options = array();
				foreach ( $custom_field['options'] as $option ) {
					$options[ $option ] = $option;
				}
			}

			if ( 'checkbox' === $custom_field['type'] ) {
				foreach ( $custom_field['options'] as $option ) {
					$fields[] = array(
						'input_type'  => $field_types[ $custom_field['type'] ],
						'option_code' => 'FLUENTCRM_CUSTOMFIELD_' . $k . '_' . $option,
						'options'     => $option,
						'required'    => false,
						'label'       => $custom_field['label'] . ' - ' . $option,
					);
				}
			} else {

				// Set placeholders for defined field types.
				$placeholder = isset( $placeholders[ $custom_field['type'] ] ) ? $placeholders[ $custom_field['type'] ] : '';

				// Radio fields do not support custom values because they are designed to work with predefined options only.
				// Allowing custom values for radio fields could lead to inconsistent behavior and break the expected functionality.
				$supports_custom_value = 'radio' !== $custom_field['type'];

				$fields[] = array(
					'input_type'               => $field_types[ $custom_field['type'] ],
					'option_code'              => 'FLUENTCRM_CUSTOMFIELD_' . $k,
					'options'                  => $options,
					'required'                 => false,
					'label'                    => $custom_field['label'],
					'supports_tokens'          => true,
					'placeholder'              => $placeholder,
					'supports_multiple_values' => $supports_multiple_values,
					'supports_custom_value'    => $supports_custom_value,
				);
			}
		}

		return $fields;
	}

Scroll to Top