__( 'Mail Mint', 'advanced-form-integration' ), 'tasks' => array( 'subscribe' => __( 'Subscribe To List', 'advanced-form-integration' ), ) ); return $actions; } add_action( 'adfoin_action_fields', 'adfoin_mailmint_action_fields' ); function adfoin_mailmint_action_fields() { ?> 'email', 'value' => 'Email'], ['key' => 'first_name', 'value' => 'First Name'], ['key' => 'last_name', 'value' => 'Last Name'], // ['key' => 'date_of_birth', 'value' => 'Date of Birth'], // ['key' => 'company', 'value' => 'Company Name'], // ['key' => 'address_line_1', 'value' => 'Address Line 1'], // ['key' => 'address_line_2', 'value' => 'Address Line 2'], // ['key' => 'postal', 'value' => 'Postal Code/ Zip'], // ['key' => 'city', 'value' => 'City'], // ['key' => 'state', 'value' => 'State'], // ['key' => 'country', 'value' => 'Country'], // ['key' => 'phone_number', 'value' => 'Phone'], // ['key' => 'gender', 'value' => 'Gender'], ['key' => 'status', 'value' => 'Status', 'description' => 'pending, subscribed, unsubscribed, bounced'], ['key' => 'tags', 'value' => 'Tag IDs', 'description' => 'Enter IDs only. ' . $tags_fields], ]; wp_send_json_success( $fields ); } add_action( 'adfoin_mailmint_job_queue', 'adfoin_mailmint_job_queue', 10, 1 ); function adfoin_mailmint_job_queue( $data ) { adfoin_mailmint_send_data( $data['record'], $data['posted_data'] ); } function adfoin_mailmint_send_data( $record, $posted_data ) { $record_data = json_decode( $record["data"], true ); if ( adfoin_check_conditional_logic( $record_data['action_data']['cl'] ?? array(), $posted_data ) ) { return; } $data = $record_data["field_data"]; $task = $record["task"]; if( $task == "subscribe" ) { $list_id = isset($data["listId"]) ? $data["listId"] : ''; $tags = isset($data["tags"]) ? $data["tags"] : ''; unset( $data["listId"] ); unset( $data["tags"] ); $subscriber_data = []; foreach( $data as $key => $value ) { if( $value != "" ) { $subscriber_data[$key] = adfoin_get_parsed_values( $value, $posted_data ); } } if (class_exists('Mint\MRM\DataStores\ContactData') && class_exists('Mint\MRM\DataBase\Models\ContactModel')) { $existing_contact_id = Mint\MRM\DataBase\Models\ContactModel::is_contact_exist($subscriber_data['email']); if ($existing_contact_id) { Mint\MRM\DataBase\Models\ContactModel::update($subscriber_data, $existing_contact_id); $contact_id = $existing_contact_id; } else { $contact_id = Mint\MRM\DataBase\Models\ContactModel::insert(new Mint\MRM\DataStores\ContactData($subscriber_data['email'], $subscriber_data)); } if ($contact_id && $list_id) { Mint\MRM\DataBase\Models\ContactGroupModel::set_lists_to_contact([['id' => $list_id]], $contact_id); } if ($contact_id && $tags) { $tag_ids = explode(',', $tags); $formatted_tag_ids = []; foreach ($tag_ids as $key => $tag_id) { $formatted_tag_ids[] = ['id' => $tag_id]; } Mint\MRM\DataBase\Models\ContactGroupModel::set_tags_to_contact($formatted_tag_ids, $contact_id); } } } return; }