You must install and activate AffiliateWP to use AffiliateWP GetResponse Add-on

'; } if ( $affwp_plugin_data['Version'] < '1.1' ) { echo '

AffiliateWP GetResponse Add-on requires AffiliateWP 1.1 or greater. Please update AffiliateWP.

'; } } //plugin settings link public function settings_link( $links ) { $plugin_link = array( 'Settings', ); return array_merge( $plugin_link, $links ); } //affiliatewp getresponse settings public function affwp_getresponse_settings( $settings ) { $getresponse_api_key = affiliate_wp()->settings->get( 'affwp_getresponse_api_key' ); $getresponse_campaigns = $this->affwp_getresponse_get_campaigns(); if ($getresponse_campaigns === false ) { $getresponse_campaigns = array (); } if( ! empty ( $getresponse_api_key ) ){ $getresponse_campaigns = array_merge( array( '' => 'Select a campaign' ), $getresponse_campaigns ); } else{ $getresponse_campaigns = array( '' => 'Enter your GetResponse API Key and save to see your campaigns' ); } $affwp_getresponse_settings = array( 'affwp_getresponse_header' => array( 'name' => 'AffiliateWP GetResponse Settings', 'type' => 'header' ), 'affwp_enable_getresponse' => array( 'name' => 'Enable/Disable', 'type' => 'checkbox', 'desc' => 'Enable GetResponse Campaign. This will add a checkbox to the affiliate registration page.' ), 'affwp_getresponse_form_label' => array( 'name' =>'Checkbox Label', 'desc' => '
Enter the form label here, this will be displayed on the registration page.', 'type' => 'text', 'std' => 'Signup for our newsletter' ), 'affwp_getresponse_api_key' => array( 'name' =>'GetResponse API Key', 'desc' => '
Enter your GetResponse API Key here. Click here to login to GetResponse and get your API key.', 'type' => 'text', 'std' => '' ), 'affwp_getresponse_campaign_id' => array( 'name' => 'Campaign', 'desc' => '
Select the campaign you want the affiliate to be added to when they register.
To export registered Affiliates to your GetResponse campaign, click the "Tools" sub-menu.', 'type' => 'select', 'options' => $getresponse_campaigns ) ); return array_merge( $settings, $affwp_getresponse_settings ); } //add subscribe checkbox to the signup page public function affwp_getresponse_subscribe_checkbox(){ $getresponse_enabled = affiliate_wp()->settings->get( 'affwp_enable_getresponse' ); $getresponse_label = affiliate_wp()->settings->get( 'affwp_getresponse_form_label' ); $getresponse_api_key = affiliate_wp()->settings->get( 'affwp_getresponse_api_key' ); $getresponse_campaign_id = affiliate_wp()->settings->get( 'affwp_getresponse_campaign_id' ); ob_start(); if ( ! empty ( $getresponse_enabled ) && ! empty ( $getresponse_api_key ) && ! empty ( $getresponse_campaign_id ) ){ ?>

settings->get( 'affwp_enable_getresponse' ); $getresponse_label = affiliate_wp()->settings->get( 'affwp_getresponse_form_label' ); $getresponse_api_key = affiliate_wp()->settings->get( 'affwp_getresponse_api_key' ); $getresponse_campaign_id = affiliate_wp()->settings->get( 'affwp_getresponse_campaign_id' ); ob_start(); if ( ! empty ( $getresponse_enabled ) && ! empty ( $getresponse_api_key ) && ! empty ( $getresponse_campaign_id ) ){ ?>

affiliates->get_by( 'affiliate_id', $affiliate_id ); $user_id = $affiliate->user_id; $getresponse_api_key = affiliate_wp()->settings->get( 'affwp_getresponse_api_key' ); if( ! empty( $_POST['affwp_getresponse_subscribe'] ) && ! empty( $getresponse_api_key ) ) { if( is_user_logged_in() ){ global $wpdb; $user_id = get_current_user_id(); $email = $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM $wpdb->users WHERE ID = '%d'", $user_id ) ); $name = $wpdb->get_var( $wpdb->prepare( "SELECT display_name FROM $wpdb->users WHERE ID = '%d'", $user_id ) ); } else{ $name = ucwords( sanitize_text_field( $_POST['affwp_user_name'] ) ); $email = sanitize_text_field( $_POST['affwp_user_email'] ); $affiliate = affiliate_wp()->affiliates->get_by( 'affiliate_id', $affiliate_id ); $user_id = $affiliate->user_id; } $this->affwp_add_to_getresponse( $name, $email, $user_id ); } return false; } //add new affiliate to campaign from the admin add new affiliate page public function affwp_getresponse_admin_add_user_to_list( $add ){ global $wpdb; $affiliate = affiliate_wp()->affiliates->get_by( 'affiliate_id', $add ); $user_id = $affiliate->user_id; $email = $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM $wpdb->users WHERE ID = '%d'", $user_id ) ); $name = $wpdb->get_var( $wpdb->prepare( "SELECT display_name FROM $wpdb->users WHERE ID = '%d'", $user_id ) ); $getresponse_api_key = affiliate_wp()->settings->get( 'affwp_getresponse_api_key' ); if( ! empty( $_POST['affwp_getresponse_subscribe'] ) && ! empty( $getresponse_api_key ) ) { $this->affwp_add_to_getresponse( $name, $email, $user_id ); } return false; } //get getresponse campaigns public function affwp_getresponse_get_campaigns(){ if ( ! class_exists( 'jsonRPCClient' ) ) require_once( 'classes/jsonRPCClient.php' ); $api_url = 'http://api2.getresponse.com'; $client = new jsonRPCClient($api_url); try { $getresponse_api_key = affiliate_wp()->settings->get( 'affwp_getresponse_api_key' ); $getresponse_api_key = trim( $getresponse_api_key ); $getresponse_campaigns = array(); $campaigns = $client->get_campaigns( $getresponse_api_key ); foreach ($campaigns as $key => $value) { $getresponse_campaigns[ $key ] = $value[ 'name' ]; } return $getresponse_campaigns; } catch (Exception $e) { return false; } } //Add subscribe checkbox to the Affiliate settings dashboard page public function affwp_dashboard_getresponse_subscribe_checkbox( $affiliate_id, $user_id ){ $getresponse_enabled = affiliate_wp()->settings->get( 'affwp_enable_getresponse' ); $getresponse_label = affiliate_wp()->settings->get( 'affwp_getresponse_form_label' ); $getresponse_api_key = affiliate_wp()->settings->get( 'affwp_getresponse_api_key' ); $getresponse_campaign_id = affiliate_wp()->settings->get( 'affwp_getresponse_campaign_id' ); $subscribe_status = get_user_meta( $user_id, 'tbz_affwp_subscribed_to_getresponse', true ); if( ! $subscribe_status && $getresponse_enabled && $getresponse_api_key && $getresponse_campaign_id) { ob_start(); ?>

affiliates->get_by( 'affiliate_id', $affiliate_id ); $user_id = $affiliate->user_id; $email = $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM $wpdb->users WHERE ID = '%d'", $user_id ) ); $name = affiliate_wp()->affiliates->get_affiliate_name( $affiliate_id ); $getresponse_api_key = affiliate_wp()->settings->get( 'affwp_getresponse_api_key' ); if( ! empty( $_POST['affwp_getresponse_subscribe'] ) && $getresponse_api_key ) { $this->affwp_add_to_getresponse( $name, $email, $user_id ); } return false; } public function affwp_getresponse_export(){ $getresponse_api_key = affiliate_wp()->settings->get( 'affwp_getresponse_api_key' ); $getresponse_campaign_id = affiliate_wp()->settings->get( 'affwp_getresponse_campaign_id' ); if( $getresponse_api_key && $getresponse_campaign_id) { ?>

affiliates->get_affiliates( array( 'orderby' => 'date_registered', 'order' => 'ASC', 'number' => -1, 'date' => $date ) ); if( $affiliates ) { foreach( $affiliates as $affiliate ) { global $wpdb; $user_id = $affiliate->user_id; $email = $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM $wpdb->users WHERE ID = '%d'", $user_id ) ); $name = $wpdb->get_var( $wpdb->prepare( "SELECT display_name FROM $wpdb->users WHERE ID = '%d'", $user_id ) ); $subscribe_status = get_user_meta( $user_id, 'tbz_affwp_subscribed_to_getresponse', true ); $getresponse_api_key = affiliate_wp()->settings->get( 'affwp_getresponse_api_key' ); $getresponse_enabled = affiliate_wp()->settings->get( 'affwp_enable_getresponse' ); $getresponse_campaign_id = affiliate_wp()->settings->get( 'affwp_getresponse_campaign_id' ); if( ! $subscribe_status && $getresponse_enabled && $getresponse_api_key && $getresponse_campaign_id) { $this->affwp_add_to_getresponse( $name, $email, $user_id ); } } wp_safe_redirect( admin_url( 'admin.php?page=affiliate-wp-tools&affwp_notice=affiliate_exported' ) ); exit; } } public function show_notices() { $class = 'updated'; if ( isset( $_GET['affwp_notice'] ) && $_GET['affwp_notice'] ) { switch( $_GET['affwp_notice'] ) { case 'affiliate_exported' : $message = __( 'Affiliates Exported to GetResponse', 'affiliate-wp' ); break; } } if ( ! empty( $message ) ) { echo '

' . $message . '

'; } } //Add registered affiliates to GetResponse helper function public function affwp_add_to_getresponse( $name, $email, $user_id ){ if( empty( $name ) || empty( $email ) || empty( $user_id ) ) return; $getresponse_campaign_id = affiliate_wp()->settings->get( 'affwp_getresponse_campaign_id' ); $getresponse_api_key = affiliate_wp()->settings->get( 'affwp_getresponse_api_key' ); $getresponse_api_key = trim( $getresponse_api_key ); if ( ! class_exists( 'jsonRPCClient' ) ) require_once( 'classes/jsonRPCClient.php' ); $api_url = 'http://api2.getresponse.com'; $client = new jsonRPCClient($api_url); try{ $response = $client->add_contact( $getresponse_api_key, array ( 'campaign' => $getresponse_campaign_id, 'name' => $name, 'email' => $email, 'ip' => $_SERVER['REMOTE_ADDR'], 'cycle_day' => 0 ) ); update_user_meta( $user_id, 'tbz_affwp_subscribed_to_getresponse', 'yes' ); return true; } catch (Exception $e) { return false; } } } } function tbz_affwp_getresponse_addon() { return AffiliateWP_GetResponse_Add_on::get_instance(); } add_action( 'plugins_loaded', 'tbz_affwp_getresponse_addon' );