__( 'Mailify', 'advanced-form-integration' ), 'tasks' => array( 'subscribe' => __( 'Subscribe To List', 'advanced-form-integration' ) ) ); return $actions; } add_filter( 'adfoin_settings_tabs', 'adfoin_mailify_settings_tab', 10, 1 ); function adfoin_mailify_settings_tab( $providers ) { $providers['mailify'] = __( 'Mailify', 'advanced-form-integration' ); return $providers; } add_action( 'adfoin_settings_view', 'adfoin_mailify_settings_view', 10, 1 ); function adfoin_mailify_settings_view( $current_tab ) { if( $current_tab != 'mailify' ) { return; } if ( ! class_exists( 'ADFOIN_Account_Manager' ) ) { require_once plugin_dir_path( __FILE__ ) . '../../includes/class-adfoin-account-manager.php'; } $fields = array( array( 'name' => 'accountNumber', 'label' => __( 'Account Number', 'advanced-form-integration' ), 'type' => 'text', 'required' => true, 'placeholder' => __( 'Enter Account Number', 'advanced-form-integration' ), 'show_in_table' => true, ), array( 'name' => 'apiKey', 'label' => __( 'API Key', 'advanced-form-integration' ), 'type' => 'text', 'required' => true, 'mask' => true, 'placeholder' => __( 'Enter API Key', 'advanced-form-integration' ), 'show_in_table' => true, ), ); $instructions = sprintf( '
  1. %s
  2. %s
  3. %s
', __( 'Go to Settings > Developer in Mailify.', 'advanced-form-integration' ), __( 'Copy your Account Number and API Key.', 'advanced-form-integration' ), __( 'Paste them here and save.', 'advanced-form-integration' ) ); ADFOIN_Account_Manager::render_settings_view( 'mailify', __( 'Mailify', 'advanced-form-integration' ), $fields, $instructions ); } add_action( 'wp_ajax_adfoin_get_mailify_credentials', 'adfoin_get_mailify_credentials', 10, 0 ); function adfoin_get_mailify_credentials() { if ( ! class_exists( 'ADFOIN_Account_Manager' ) ) { require_once plugin_dir_path( __FILE__ ) . '../../includes/class-adfoin-account-manager.php'; } ADFOIN_Account_Manager::ajax_get_credentials_list( 'mailify' ); } add_action( 'wp_ajax_adfoin_save_mailify_credentials', 'adfoin_save_mailify_credentials', 10, 0 ); function adfoin_save_mailify_credentials() { if ( ! class_exists( 'ADFOIN_Account_Manager' ) ) { require_once plugin_dir_path( __FILE__ ) . '../../includes/class-adfoin-account-manager.php'; } ADFOIN_Account_Manager::ajax_save_credentials( 'mailify', array( 'accountNumber', 'apiKey' ) ); } // Legacy single-account import: surfaces old `adfoin_mailify_*` 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( 'mailify', array( 'accountNumber' => 'adfoin_mailify_account_number', 'apiKey' => 'adfoin_mailify_key', ) ); } }, 20 ); add_action( 'adfoin_add_js_fields', 'adfoin_mailify_js_fields', 10, 1 ); function adfoin_mailify_js_fields( $field_data ) {} add_action( 'adfoin_action_fields', 'adfoin_mailify_action_fields' ); function adfoin_mailify_action_fields() { ?> $email, 'phone' => $phone, 'FIRSTNAME_ID' => $first_name, 'LASTNAME_ID' => $last_name ); $return = adfoin_mailify_request( "lists/{$list_id}/contacts", 'POST', $data, $record, $cred_id ); } return; } /* * Mailify API Request helper */ function adfoin_mailify_request( $endpoint, $method = 'GET', $data = array(), $record = array(), $cred_id = '' ) { $credentials = adfoin_get_credentials_by_id( 'mailify', $cred_id ); $account_number = isset( $credentials['accountNumber'] ) ? $credentials['accountNumber'] : ''; $api_key = isset( $credentials['apiKey'] ) ? $credentials['apiKey'] : ''; if ( ! $account_number || ! $api_key ) { $account_number = get_option( 'adfoin_mailify_account_number' ); $api_key = get_option( 'adfoin_mailify_key' ); } if ( ! $account_number || ! $api_key ) { return new WP_Error( 'missing_api_key', __( 'Mailify credentials not found', 'advanced-form-integration' ) ); } $url = 'https://mailifyapis.com/v1/' . $endpoint; $args = array( 'timeout' => 30, 'method' => $method, 'headers' => array( 'Content-Type' => 'application/json', 'Authorization' => 'Basic ' . base64_encode( $account_number . ':' . $api_key ) ) ); 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; }