Filter uncanny-automator

automator_jet_crm_validate_common_companies_possible_triggers_tokens

Filters the possible trigger tokens for common JetCRM company events.

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

Description

Filters the possible trigger tokens for Jet CRM company-related actions. Developers can modify the default array of tokens like 'JETCRM_COMPANY_CREATED' to restrict or expand available options before they are displayed in the automation interface. This hook is called when generating the list of available tokens.


Usage

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

Parameters

$args (mixed)
This parameter contains an array of possible trigger codes related to company actions within JetCRM.

Return Value

The filtered value.


Examples

add_filter( 'automator_jet_crm_validate_common_companies_possible_triggers_tokens', function( $trigger_codes, $args ) {

	// Example: If the trigger code is 'JETCRM_COMPANY_CREATED',
	// and there's a specific condition in $args, we want to prevent
	// this trigger from being available by removing its code from the array.
	// In a real-world scenario, $args might contain information about
	// user roles, specific plugin settings, or other contextual data
	// that would determine trigger availability.

	if ( isset( $args['user_roles'] ) && in_array( 'administrator', $args['user_roles'] ) ) {
		// If the current user is an administrator, we might want to restrict
		// certain triggers for them in this context.
		// For this example, let's say we want to hide the 'JETCRM_COMPANY_CREATED'
		// trigger from administrators when specific arguments are present.

		// Check if 'JETCRM_COMPANY_CREATED' is in the list and if there's another condition
		if ( in_array( 'JETCRM_COMPANY_CREATED', $trigger_codes ) && isset( $args['restrict_for_admins'] ) && $args['restrict_for_admins'] ) {
			// Remove 'JETCRM_COMPANY_CREATED' from the list of valid triggers
			$trigger_codes = array_diff( $trigger_codes, array( 'JETCRM_COMPANY_CREATED' ) );
		}
	}

	// Always return the (potentially modified) array of trigger codes
	return $trigger_codes;
}, 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:222

* @param $args
	 *
	 * @return array|array[]|mixed
	 */
	public function jetcrm_companies_possible_tokens( $tokens = array(), $args = array() ) {
		$trigger_code = $args['triggers_meta']['code'];

		$trigger_meta_validations = apply_filters(
			'automator_jet_crm_validate_common_companies_possible_triggers_tokens',
			array( 'JETCRM_COMPANY_CREATED' ),
			$args
		);

		if ( in_array( $trigger_code, $trigger_meta_validations, true ) ) {

Scroll to Top