Filter uncanny-automator

automator_jet_crm_validate_common_triggers_tokens_parse

Filters common Jet CRM trigger tokens before they are parsed, allowing for modifications to trigger data.

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

Description

This filter allows developers to modify the accepted common Jet Engine CRM trigger token types before they are parsed. By altering the `$pieces` array, you can add or remove trigger identifiers, influencing which Jet Engine CRM events are recognized by the automator.


Usage

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

Parameters

$pieces (mixed)
This parameter contains a list of valid Jet Crm trigger slugs that the function will process.

Return Value

The filtered value.


Examples

/**
 * Example function to filter and validate common JetCRM trigger tokens.
 *
 * This function can be used to add or remove specific JetCRM trigger types
 * from the validation process for common tokens within the Automator plugin.
 * For instance, you might want to exclude certain triggers from being processed
 * in a specific context to avoid unexpected behavior or optimize performance.
 *
 * @param array $validation_tokens An array of trigger tokens to validate.
 * @param array $args An array containing contextual information for the validation.
 *                    Expected keys: 'pieces', 'recipe_id', 'trigger_data', 'user_id'.
 * @return array The modified array of trigger tokens to validate.
 */
function my_automator_filter_jet_crm_validation_tokens( $validation_tokens, $args ) {

	// Extract arguments for easier access
	$pieces       = $args['pieces'];
	$recipe_id    = $args['recipe_id'];
	$trigger_data = $args['trigger_data'];
	$user_id      = $args['user_id'];

	// Example: If the recipe is for a specific user, maybe we want to be more restrictive
	// about which tokens are validated.
	if ( 123 === $user_id ) {
		// Remove 'JETCRM_CONTACT_STATUS_UPDATED' if it's present and this is for user ID 123
		$key = array_search( 'JETCRM_CONTACT_STATUS_UPDATED', $validation_tokens, true );
		if ( false !== $key ) {
			unset( $validation_tokens[ $key ] );
		}
	}

	// Example: Add a new validation token if a specific piece of data is present.
	// This is just an illustrative example, the actual logic would depend on the 'pieces' structure.
	if ( isset( $pieces[2] ) && 'specific_condition' === $pieces[2] ) {
		$validation_tokens[] = 'JETCRM_CUSTOM_EVENT_TRIGGER'; // Assuming this is a valid JetCRM trigger
	}

	// Ensure the array keys are re-indexed if elements were removed
	return array_values( $validation_tokens );
}
add_filter( 'automator_jet_crm_validate_common_triggers_tokens_parse', 'my_automator_filter_jet_crm_validation_tokens', 10, 2 );

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/jet-crm/tokens/jetcrm-tokens.php:363

*/
	public function parse_jetcrm_tokens( $value, $pieces, $recipe_id, $trigger_data, $user_id, $replace_args ) {

		if ( ! is_array( $pieces ) || ! isset( $pieces[1] ) || ! isset( $pieces[2] ) ) {
			return $value;
		}

		$trigger_meta_validations = apply_filters(
			'automator_jet_crm_validate_common_triggers_tokens_parse',
			array( 'JETCRM_CONTACT_CREATED', 'JETCRM_CONTACT_STATUS_UPDATED' ),
			array(
				'pieces'       => $pieces,
				'recipe_id'    => $recipe_id,
				'trigger_data' => $trigger_data,
				'user_id'      => $user_id,


Scroll to Top