__( 'Omnisend', 'advanced-form-integration' ), 'tasks' => array( 'add_contact' => __( 'Create New Contact', 'advanced-form-integration' ) ) ); return $actions; } add_filter( 'adfoin_settings_tabs', 'adfoin_omnisend_settings_tab', 10, 1 ); function adfoin_omnisend_settings_tab( $providers ) { $providers['omnisend'] = __( 'Omnisend', 'advanced-form-integration' ); return $providers; } add_action( 'adfoin_settings_view', 'adfoin_omnisend_settings_view', 10, 1 ); function adfoin_omnisend_settings_view( $current_tab ) { if( $current_tab != 'omnisend' ) { return; } $title = __( 'Omnisend', 'advanced-form-integration' ); $key = 'omnisend'; $arguments = wp_json_encode([ 'platform' => $key, 'fields' => [ [ 'key' => 'apiKey', 'label' => __( 'API Key', 'advanced-form-integration' ), 'hidden' => true ] ] ]); $instructions = sprintf( __( '
Go to Store Settings > Integrations & API > API Keys.
', 'advanced-form-integration' ) ); echo adfoin_platform_settings_template( $title, $key, $arguments, $instructions ); } add_action( 'wp_ajax_adfoin_get_omnisend_credentials', 'adfoin_get_omnisend_credentials', 10, 0 ); function adfoin_get_omnisend_credentials() { adfoin_verify_nonce(); $all_credentials = adfoin_read_credentials( 'omnisend' ); wp_send_json_success( $all_credentials ); } add_action( 'wp_ajax_adfoin_save_omnisend_credentials', 'adfoin_save_omnisend_credentials', 10, 0 ); /* * Get Omnisend credentials */ function adfoin_save_omnisend_credentials() { adfoin_verify_nonce(); $platform = sanitize_text_field( wp_unslash( $_POST['platform'] ) ); if( 'omnisend' == $platform ) { $data = adfoin_array_map_recursive( 'sanitize_text_field', $_POST['data'] ); adfoin_save_credentials( $platform, $data ); } wp_send_json_success(); } // Legacy single-account import: surfaces old `adfoin_omnisend_*` options // as a Legacy Account record when the new credentials store is empty. add_action( 'plugins_loaded', function() { if ( class_exists( 'ADFOIN_Account_Manager' ) ) { ADFOIN_Account_Manager::register_legacy_option_importer( 'omnisend', array( 'apiKey' => 'adfoin_omnisend_api_token', ), array( 'id' => '123456', 'title' => 'Untitled', ) ); } }, 20 ); function adfoin_omnisend_credentials_list() { $html = ''; $credentials = adfoin_read_credentials( 'omnisend' ); foreach( $credentials as $option ) { $html .= ''; } echo $html; } add_action( 'adfoin_action_fields', 'adfoin_omnisend_action_fields' ); function adfoin_omnisend_action_fields() { ?> $first_name, 'lastName' => $last_name, 'address' => $address, 'city' => $city, 'state' => $state, 'postalCode' => $zip, 'country' => $country, 'birthdate' => $birthday, 'identifiers' => array( array( 'type' => 'email', 'id' => trim( $email ), 'channels' => array( 'email' => array( 'status' => $email_status, ) ) ) ) ); if ( $country_code ) { $body['countryCode'] = strtoupper( $country_code ); } if ( $phone ) { $body['identifiers'][] = array( 'type' => 'phone', 'id' => $phone, 'channels' => array( 'sms' => array( 'status' => 'subscribed', ) ) ); } if ( $gender ) { $body['gender'] = strtolower( $gender )[0] === 'f' ? 'f' : 'm'; } $body = array_filter( $body ); $response = adfoin_omnisend_request( 'contacts', 'POST', $body, $record, $cred_id ); } return; } function adfoin_omnisend_request( $endpoint, $method = 'GET', $data = array(), $record = array(), $cred_id = '' ) { $credentials = adfoin_get_credentials_by_id( 'omnisend', $cred_id ); $api_key = isset( $credentials['apiKey'] ) ? $credentials['apiKey'] : ''; if ( ! $api_key ) { return new WP_Error( 'missing_credentials', __( 'Omnisend API credentials not found', 'advanced-form-integration' ) ); } $url = 'https://api.omnisend.com/api/' . $endpoint; $args = array( 'timeout' => 30, 'method' => $method, 'headers' => array( 'Content-Type' => 'application/json', 'Authorization' => 'Omnisend-API-Key ' . $api_key, 'Omnisend-Version' => '2026-03-15', ), ); if ( in_array( $method, array( 'POST', 'PUT', 'PATCH' ), true ) ) { $args['body'] = wp_json_encode( $data ); } $response = wp_remote_request( $url, $args ); if ( $record ) { adfoin_add_to_log( $response, $url, $args, $record ); } return $response; }