Filter uncanny-automator

automator_jet_crm_validate_common_companies_triggers_tokens_parse

Filters Jet CRM company creation triggers and tokens before parsing.

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

Description

Filters the array of JetEngine CRM company trigger tokens before they are parsed. Developers can use this hook to add, remove, or modify available company trigger tokens for automation recipes, allowing for custom trigger options based on specific CRM company events.


Usage

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

Parameters

$pieces (mixed)
This parameter contains an array of trigger types that are being validated for common company-related triggers.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to hook into the 'automator_jet_crm_validate_common_companies_triggers_tokens_parse' filter.
 * This example demonstrates how to conditionally modify the trigger metas based on the trigger type.
 *
 * @param array $trigger_metas The array of trigger metas to be validated.
 * @param array $args          An array of arguments passed to the filter.
 *                             - 'pieces': The pieces of data available for the trigger.
 *                             - 'recipe_id': The ID of the current recipe.
 *                             - 'trigger_data': The data associated with the trigger.
 *                             - 'user_id': The ID of the user performing the action.
 * @return array The modified or original trigger metas.
 */
function my_automator_jet_crm_company_trigger_validation( $trigger_metas, $args ) {

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

	// Check if we are dealing with the 'JETCRM_COMPANY_CREATED' trigger
	if ( in_array( 'JETCRM_COMPANY_CREATED', $trigger_metas ) ) {

		// Example: If the company has a specific tag associated with it in the trigger data,
		// we might want to add an additional validation or modify the trigger metas.
		// For this example, let's assume 'trigger_data' contains a 'company_tags' key.
		if ( isset( $trigger_data['company_tags'] ) && is_array( $trigger_data['company_tags'] ) ) {
			if ( in_array( 'important_client', $trigger_data['company_tags'] ) ) {
				// Add a new meta if it's an important client, for further processing.
				$trigger_metas[] = 'JETCRM_COMPANY_IS_IMPORTANT';
			}
		}

		// Another example: If the 'pieces' array contains 'company_name',
		// we can ensure that the company name is available for token replacement.
		if ( ! in_array( 'company_name', $pieces ) ) {
			// Log an error or warning if the expected piece is missing.
			// In a real-world scenario, you might want to return an empty array
			// to invalidate the trigger or throw an exception.
			error_log( "Missing 'company_name' piece for JETCRM_COMPANY_CREATED trigger in recipe ID: {$recipe_id}" );
		}
	}

	// Always return the (potentially modified) trigger metas
	return $trigger_metas;
}

// Add the filter with the correct number of accepted arguments (2 in this case)
add_filter( 'automator_jet_crm_validate_common_companies_triggers_tokens_parse', 'my_automator_jet_crm_company_trigger_validation', 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:375

'recipe_id'    => $recipe_id,
				'trigger_data' => $trigger_data,
				'user_id'      => $user_id,
				'replace_args' => $replace_args,
			)
		);

		$companies_trigger_metas = apply_filters(
			'automator_jet_crm_validate_common_companies_triggers_tokens_parse',
			array( 'JETCRM_COMPANY_CREATED' ),
			array(
				'pieces'       => $pieces,
				'recipe_id'    => $recipe_id,
				'trigger_data' => $trigger_data,
				'user_id'      => $user_id,


Scroll to Top