__( 'Sendy', 'advanced-form-integration' ), 'tasks' => array( 'subscribe' => __( 'Subscribe To List', 'advanced-form-integration' ) ) ); return $actions; } add_filter( 'adfoin_settings_tabs', 'adfoin_sendy_settings_tab', 10, 1 ); function adfoin_sendy_settings_tab( $providers ) { $providers['sendy'] = __( 'Sendy', 'advanced-form-integration' ); return $providers; } add_action( 'adfoin_settings_view', 'adfoin_sendy_settings_view', 10, 1 ); function adfoin_sendy_settings_view( $current_tab ) { if( $current_tab != 'sendy' ) { return; } // Load Account Manager if ( ! class_exists( 'ADFOIN_Account_Manager' ) ) { require_once plugin_dir_path( __FILE__ ) . '../../includes/class-adfoin-account-manager.php'; } // Migrate old settings if they exist and no new credentials exist $old_api_key = get_option( 'adfoin_sendy_api_key' ) ? get_option( 'adfoin_sendy_api_key' ) : ''; $old_url = get_option( 'adfoin_sendy_url' ) ? get_option( 'adfoin_sendy_url' ) : ''; $existing_creds = adfoin_read_credentials( 'sendy' ); if ( $old_api_key && $old_url && empty( $existing_creds ) ) { $new_cred = array( 'id' => wp_generate_uuid4(), 'title' => 'Default Account (Legacy)', 'api_key' => $old_api_key, 'url' => $old_url ); adfoin_save_credentials( 'sendy', array( $new_cred ) ); } $fields = array( array( 'name' => 'url', 'label' => __( 'Installation URL', 'advanced-form-integration' ), 'type' => 'text', 'required' => true, 'placeholder' => __( 'Please enter Sendy Installation URL', 'advanced-form-integration' ), 'show_in_table' => true, ), array( 'name' => 'api_key', 'label' => __( 'API Key', 'advanced-form-integration' ), 'type' => 'text', 'required' => true, 'placeholder' => __( 'Please enter API Key', 'advanced-form-integration' ), 'mask' => true, 'show_in_table' => true, ), ); $instructions = '
  1. ' . __( 'Enter your Sendy installation URL (e.g., https://yourdomain.com/sendy).', 'advanced-form-integration' ) . '
  2. ' . __( 'Go to your Sendy settings and copy your API Key.', 'advanced-form-integration' ) . '
  3. ' . __( 'Enter the credentials in the fields above.', 'advanced-form-integration' ) . '
  4. ' . __( 'Click "Add Account" and save your credentials.', 'advanced-form-integration' ) . '
'; ADFOIN_Account_Manager::render_settings_view( 'sendy', 'Sendy', $fields, $instructions ); } // AJAX Hooks for Account Manager add_action( 'wp_ajax_adfoin_get_sendy_credentials', 'adfoin_get_sendy_credentials' ); function adfoin_get_sendy_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( 'sendy' ); } add_action( 'wp_ajax_adfoin_save_sendy_credentials', 'adfoin_save_sendy_credentials' ); function adfoin_save_sendy_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( 'sendy', array( 'url' => 'url', 'api_key' => 'password' ) ); } add_action( 'wp_ajax_adfoin_get_sendy_credentials_list', 'adfoin_sendy_get_credentials_list_ajax' ); function adfoin_sendy_get_credentials_list_ajax() { adfoin_verify_nonce(); if ( ! class_exists( 'ADFOIN_Account_Manager' ) ) { require_once plugin_dir_path( __FILE__ ) . '../../includes/class-adfoin-account-manager.php'; } $fields = array( array( 'name' => 'url', 'mask' => false ), array( 'name' => 'api_key', 'mask' => true ), ); ADFOIN_Account_Manager::ajax_get_credentials_list( 'sendy', $fields ); } add_action( 'adfoin_action_fields', 'adfoin_sendy_action_fields' ); function adfoin_sendy_action_fields() { ?> $api_key, 'list' => $list_id, 'email' => $email, 'name' => $name, 'boolean' => 'true', ); if ( $gdpr === 'true' ) { $body['gdpr'] = 'true'; } $args = array( 'timeout' => 30, 'headers' => array( 'Content-Type' => 'application/x-www-form-urlencoded' ), 'body' => $body, ); $return = wp_remote_post( $ins_url . '/subscribe', $args ); adfoin_add_to_log( $return, $ins_url . '/subscribe', $args, $record ); } }