FCRM_ADD_CONTACT::process_action( $user_id,  $action_data,  $recipe_id,  $args,  $parsed )

Process our action.


Parameters Parameters

$user_id

(Required)

$action_data

(Required)

$recipe_id

(Required)

$args

(Required)

$parsed

(Required)


Top ↑

Return Return

(void)


Source Source

File: src/integrations/fluent-crm/actions/fcrm-add-contact.php

	protected function process_action( $user_id, $action_data, $recipe_id, $args, $parsed ) {
		$data['email'] = Automator()->parse->text( $action_data['meta']['FCRMUSEREMAIL'], $recipe_id, $user_id, $args );
		$subscriber    = Subscriber::where( 'email', $data['email'] )->first();

		if ( ! is_null( $subscriber ) ) {
			$action_data['do-nothing']           = true;
			$action_data['complete_with_errors'] = true;
			/* translators: Subscriber email */
			$message = sprintf( esc_html__( 'Duplicate email: %s, please use different email address.', 'uncanny-automator' ), $data['email'] );
			Automator()->complete_action( $user_id, $action_data, $recipe_id, $message );

			return;
		}

		$data['first_name']      = Automator()->parse->text( $action_data['meta']['FCRMFIRSTNAME'], $recipe_id, $user_id, $args );
		$data['last_name']       = Automator()->parse->text( $action_data['meta']['FCRMLASTNAME'], $recipe_id, $user_id, $args );
		$data['phone']           = Automator()->parse->text( $action_data['meta']['FCRMPHONE'], $recipe_id, $user_id, $args );
		$data['date_of_birth']   = Automator()->parse->text( $action_data['meta']['FCRMDATEOFBIRTH'], $recipe_id, $user_id, $args );
		$data['address_line_1']  = Automator()->parse->text( $action_data['meta']['FCRMADDRESSLINE1'], $recipe_id, $user_id, $args );
		$data['address_line_2']  = Automator()->parse->text( $action_data['meta']['FCRMADDRESSLINE2'], $recipe_id, $user_id, $args );
		$data['city']            = Automator()->parse->text( $action_data['meta']['FCRMCITY'], $recipe_id, $user_id, $args );
		$data['state']           = Automator()->parse->text( $action_data['meta']['FCRMSTATE'], $recipe_id, $user_id, $args );
		$data['postal_code']     = Automator()->parse->text( $action_data['meta']['FCRMPOSTALCODE'], $recipe_id, $user_id, $args );
		$data['country']         = Automator()->parse->text( $action_data['meta']['FCRMCOUNTRY'], $recipe_id, $user_id, $args );
		$data['status']          = Automator()->parse->text( $action_data['meta']['FCRMSTATUS'], $recipe_id, $user_id, $args );
		$data['lists']           = array_map( 'intval', json_decode( $action_data['meta']['FCRMLIST'] ) );
		$data['tags']            = array_map( 'intval', json_decode( $action_data['meta']['FCRMTAG'] ) );
		$data['query_timestamp'] = time();
		$custom_fields           = fluentcrm_get_custom_contact_fields();
		if ( $custom_fields ) {
			foreach ( $custom_fields as $k => $custom_field ) {
				switch ( $custom_field['type'] ) {
					case 'checkbox':
						$checkbox_val = array();
						foreach ( $custom_field['options'] as $option ) {
							$checkbox_value = filter_var( $action_data['meta'][ 'FLUENTCRM_CUSTOMFIELD_' . $k . '_' . $option ], FILTER_VALIDATE_BOOLEAN );
							if ( true === $checkbox_value ) {
								$checkbox_val[] = $option;
							}
						}
						$data['custom_values'][ $custom_field['slug'] ] = $checkbox_val;
						break;
					case 'select-multi':
						$data['custom_values'][ $custom_field['slug'] ] = json_decode( $action_data['meta'][ 'FLUENTCRM_CUSTOMFIELD_' . $k ] );
						break;
					default:
						$data['custom_values'][ $custom_field['slug'] ] = Automator()->parse->text( $action_data['meta'][ 'FLUENTCRM_CUSTOMFIELD_' . $k ], $recipe_id, $user_id, $args );
						break;
				}
			}
		}
		$contact = Subscriber::store( $data );
		do_action( 'fluentcrm_contact_created', $contact, $data );
		Automator()->complete_action( $user_id, $action_data, $recipe_id );
	}