Filter uncanny-automator

automator_wholesale_suite_validate_common_lead_tokens

Filters lead creation arguments to validate common tokens, allowing for custom modifications before lead creation.

add_filter( 'automator_wholesale_suite_validate_common_lead_tokens', $callback, 10, 1 );

Description

Filters the list of lead tokens that are validated for common usage within the Wholesale Suite integration. Developers can add or remove token codes to customize which lead tokens are considered valid for specific automations.


Usage

add_filter( 'automator_wholesale_suite_validate_common_lead_tokens', 'your_function_name', 10, 1 );

Parameters

$args (mixed)
This parameter is an array containing a list of valid token types that can be processed for Wholesale Suite lead events.

Return Value

The filtered value.


Examples

add_filter( 'automator_wholesale_suite_validate_common_lead_tokens', 'my_custom_wss_lead_token_validation', 10, 2 );
/**
 * Custom validation for Wholesale Suite lead tokens.
 *
 * This example adds an additional validation rule to ensure that only leads
 * created via the "WSS_LEAD_CREATED" trigger are processed, and also checks
 * if the lead has a specific custom field value.
 *
 * @param array $trigger_meta_validations The existing list of trigger codes to validate.
 * @param array $args The arguments passed to the filter.
 * @return array The modified list of trigger codes to validate.
 */
function my_custom_wss_lead_token_validation( $trigger_meta_validations, $args ) {
	// Ensure the trigger code is "WSS_LEAD_CREATED" as per the default.
	if ( ! in_array( 'WSS_LEAD_CREATED', $trigger_meta_validations, true ) ) {
		return $trigger_meta_validations;
	}

	// Example: Check if the lead has a specific custom field value.
	// This is a hypothetical check. You'd replace 'custom_field_name'
	// and 'expected_value' with actual field names and values from your Wholesale Suite setup.
	if ( isset( $args['lead_meta']['custom_field_name'] ) && $args['lead_meta']['custom_field_name'] === 'expected_value' ) {
		// If the custom field matches, we allow this trigger code.
		// We can add it explicitly here if it wasn't already there, or simply return the existing array.
		if ( ! in_array( 'WSS_LEAD_CREATED', $trigger_meta_validations, true ) ) {
			$trigger_meta_validations[] = 'WSS_LEAD_CREATED';
		}
	} else {
		// If the custom field does not match, remove "WSS_LEAD_CREATED" from the validations
		// so it's not processed further.
		$trigger_meta_validations = array_diff( $trigger_meta_validations, array( 'WSS_LEAD_CREATED' ) );
	}

	return $trigger_meta_validations;
}

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/wholesale-suite/tokens/wss-tokens.php:172

public function wss_leads_possible_tokens( $tokens = array(), $args = array() ) {
		$trigger_code = $args['triggers_meta']['code'];

		$trigger_meta_validations = apply_filters(
			'automator_wholesale_suite_validate_common_lead_tokens',
			array( 'WSS_LEAD_CREATED' ),
			$args
		);

		if ( in_array( $trigger_code, $trigger_meta_validations, true ) ) {
			$helper     = new Wholesale_Suite_Helpers();
			$all_fields = $helper->get_all_lead_form_fields();
			$fields     = array();
			foreach ( $all_fields as $key => $field ) {
				$fields[] = array(
					'tokenId'         => $key,
					'tokenName'       => $field['label'],
					'tokenType'       => $field['type'],
					'tokenIdentifier' => $trigger_code,
				);
			}

			$tokens = array_merge( $tokens, $fields );
		}

		return $tokens;
	}

Scroll to Top