AC_TOKENS::save_token_data( mixed $args, mixed $trigger )

save_token_data


Parameters Parameters

$args

(Required)

$trigger

(Required)


Top ↑

Return Return

(void)


Source Source

File: src/integrations/active-campaign/tokens/ac-tokens.php

	public function save_token_data( $args, $trigger ) {

		if ( 'ACTIVE_CAMPAIGN' !== $trigger->get_integration() ) {
			return;
		}

		if ( ! isset( $args['trigger_args'] ) || ! isset( $args['entry_args']['code'] ) ) {
			return;
		}

		$trigger_code = $args['entry_args']['code'];

		if ( 'CONTACT_TAG_ADDED' === $trigger_code || 'CONTACT_TAG_REMOVED' === $trigger_code ) {
			$ac_event = array_shift( $args['trigger_args'] );

			$trigger_log_entry = $args['trigger_entry'];

			if ( ! empty( $ac_event['tag'] ) ) {
				Automator()->db->token->save( 'TAG', $ac_event['tag'], $trigger_log_entry );
			}

			if ( ! empty( $ac_event['contact']['email'] ) ) {
				Automator()->db->token->save( 'EMAIL', $ac_event['contact']['email'], $trigger_log_entry );
			}

			if ( ! empty( $ac_event['contact']['tags'] ) ) {
				Automator()->db->token->save( 'TAGS', $ac_event['contact']['tags'], $trigger_log_entry );
			}

			if ( ! empty( $ac_event['contact']['first_name'] ) ) {
				Automator()->db->token->save( 'FIRST_NAME', $ac_event['contact']['first_name'], $trigger_log_entry );
			}

			if ( ! empty( $ac_event['contact']['last_name'] ) ) {
				Automator()->db->token->save( 'LAST_NAME', $ac_event['contact']['last_name'], $trigger_log_entry );
			}

			if ( ! empty( $ac_event['contact']['phone'] ) ) {
				Automator()->db->token->save( 'PHONE', $ac_event['contact']['phone'], $trigger_log_entry );
			}

			if ( ! empty( $ac_event['contact']['customer_acct_name'] ) ) {
				Automator()->db->token->save( 'CUSTOMER_ACCT_NAME', $ac_event['contact']['customer_acct_name'], $trigger_log_entry );
			}
		}

	}