Exemplo n.º 1
0
    /**
	 * Ajax newsletter
	 *
	 * @since    1.0.0
	 */
	public function ajax_subscribe() {

		// No First Name
		if (!isset($_POST['first_name'])) {
			$_POST['first_name'] = '';
		}

		// No Last Name
		if (!isset($_POST['last_name'])) {
			$_POST['last_name'] = '';
		}

		$success_message = stripcslashes( $this->settings['subscribe']['success_message'] );

		// MailChimp
		if ($_POST['type'] == 'mailchimp') {

			require_once('includes/mailchimp/MailChimp.php');

			if (!isset($this->settings['subscribe']['mailchimp']['api_key']) || $this->settings['subscribe']['mailchimp']['api_key'] == '') {
				echo json_encode(array(
					'status'	=> 'warning',
					'message'	=> __('MailChimp account is not setup properly.'),
				));

				die();
			}

			if (!isset($this->settings['subscribe']['mailchimp']['list']) || $this->settings['subscribe']['mailchimp']['list'] == '') {
				echo json_encode(array(
					'status'	=> 'warning',
					'message'	=> __('MailChimp: No list specified.'),
				));

				die();
			}

			$MailChimp = new WPS_MailChimp($this->settings['subscribe']['mailchimp']['api_key']);
			$result = $MailChimp->call('lists/subscribe', array(
                'id'                => $this->settings['subscribe']['mailchimp']['list'],
                'email'             => array('email'=>sanitize_email( $_POST['email']) ),
                'merge_vars'        => array( 'FNAME'=> sanitize_text_field( $_POST['first_name'] ), 'LNAME'=>sanitize_text_field( $_POST['last_name'] ) ),
                'double_optin'      => true,
                'update_existing'   => false,
                'replace_interests' => false,
                'send_welcome'      => true,
            ));

            if ($result) {

	            if (isset($result['email'])) {

					echo json_encode(array(
						'status'		=> 'check',
						'message'		=> $success_message,
					));

					die();
	            }

	            else if (isset($result['status']) && $result['status'] == 'error') {
					echo json_encode(array(
						'status'		=> 'warning',
						'message'		=> $result['error'],
					));

					die();
	            }
            } else {

	            echo json_encode(array(
					'status'	=> 'warning',
					'message'	=> __('Unable to subscribe.'),
				));

				die();
            }
		}

		// Add email to aweber
		else if ($_POST['type'] == 'aweber') {

			require_once('includes/aweber/aweber_api.php');

			if (!isset($this->settings['subscribe']['aweber']['consumer_key']) || $this->settings['subscribe']['aweber']['consumer_key'] == '') {
				echo json_encode(array(
					'status'	=> 'warning',
					'message'	=> __('Aweber account is not setup properly'),
				));

				die();
			}

			$aweber = new AWeberAPI($this->settings['subscribe']['aweber']['consumer_key'], $this->settings['subscribe']['aweber']['consumer_secret']);

			try {
				$account = $aweber->getAccount($this->settings['subscribe']['aweber']['access_key'], $this->settings['subscribe']['aweber']['access_secret']);
				$list = $account->loadFromUrl('/accounts/' . $account->id . '/lists/' . $this->settings['subscribe']['aweber']['list']);

				$subscriber = array(
					'email' 	=> sanitize_email( $_POST['email'] ),
					'name'		=> sanitize_text_field( $_POST['first_name'] ) . ' ' . sanitize_text_field( $_POST['last_name'] ),
					'ip' 		=> $_SERVER['REMOTE_ADDR']
				);

				$newSubscriber = $list->subscribers->create($subscriber);

				echo json_encode(array(
					'status'		=> 'check',
					'message'		=> $success_message,
				));

				die();

			} catch (AWeberAPIException $exc) {
				echo json_encode(array(
					'status'	=> 'warning',
					'message'	=> $exc->message,
				));

				die();
			}
		}

		// Add email to Get Response
		else if ($_POST['type'] == 'getresponse') {

			require_once('includes/getresponse/jsonRPCClient.php');

			$api = new jsonRPCClient('http://api2.getresponse.com');

			try {
				$api->add_contact(
					$this->settings['subscribe']['getresponse']['api_key'],
				    array (
				        'campaign'  => $this->settings['subscribe']['getresponse']['campaign'],
				        'name'      => sanitize_text_field( $_POST['first_name'] ) . ' ' . sanitize_text_field( $_POST['last_name'] ),
				        'email'     => sanitize_email( $_POST['email'] ),
				    )
				);

				echo json_encode(array(
					'status'		=> 'check',
					'message'		=> $success_message,
				));

				die();

			} catch (RuntimeException $exc) {

				$msg = $exc->getMessage();
				$msg = substr($msg, 0, strpos($msg, ";"));

				echo json_encode(array(
					'status'	=> 'warning',
					'message'	=> $msg,
				));

				die();
			}
		}

		// Add email to Campaign Monitor
		else if ($_POST['type'] == 'campaignmonitor') {

			require_once('includes/campaignmonitor/csrest_subscribers.php');

			$wrap = new CS_REST_Subscribers($this->settings['subscribe']['campaignmonitor']['list'], $this->settings['subscribe']['campaignmonitor']['api_key']);

			// Check if subscribor is already subscribed

			$result = $wrap->get(sanitize_email( $_POST['email'] ));

			if ($result->was_successful()) {
				echo json_encode(array(
					'status'	=> 'warning',
					'message'	=> 'You are already subscribed to this list.',
				));

				die();
			}

			$result = $wrap->add(array(
				'EmailAddress' 	=> sanitize_email($_POST['email']),
				'Name' 			=> sanitize_text_field( $_POST['first_name'] ). ' ' . sanitize_text_field( $_POST['last_name'] ),
				'Resubscribe' 	=> true
			));

			if ($result->was_successful()) {

				echo json_encode(array(
					'status'		=> 'check',
					'message'		=> $success_message,
				));

				die();

			} else {

				echo json_encode(array(
					'status'	=> 'warning',
					'message'	=> $result->response->Message,
				));

				die();
			}
		}

		// Add email to Mad Mimi
		else if ($_POST['type'] == 'madmimi') {

			require_once('includes/madmimi/MadMimi.class.php');

			$mailer = new MadMimi($this->settings['subscribe']['madmimi']['username'], $this->settings['subscribe']['madmimi']['api_key']);

			// No Email

			if (!isset($_POST['email']) || $_POST['email'] == '') {
				echo json_encode(array(
					'status'	=> 'warning',
					'message'	=> 'No Email address provided.'
				));
				die();
			}

			// Invalid Email Address

			if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
				echo json_encode(array(
					'status'	=> 'warning',
					'message'	=> 'Invalid Email provided.'
				));
				die();
			}

			try {

				// Check if user is already in list

				$result = $mailer->Memberships(sanitize_email( $_POST['email']) );
				$lists  = new SimpleXMLElement($result);

				if ($lists->list) {
					foreach ($lists->list as $l) {
						if ($l->attributes()->{'name'}->{0} == $meta_values['madmimi_list']) {

							echo json_encode(array(
								'status'		=> 'check',
								'message'		=> 'You are already subscribed to this list.',
							));

							die();
						}
					}
			    }

				$result = $mailer->AddMembership($this->settings['subscribe']['madmimi']['list'], sanitize_email( $_POST['email'] ), array(
					'first_name'	=> sanitize_text_field( $_POST['first_name'] ),
					'last_name'		=> sanitize_text_field( $_POST['last_name'] ),
				));

				echo json_encode(array(
					'status'		=> 'check',
					'message'		=> $success_message,
				));

				die();

			} catch (RuntimeException $exc) {

				echo json_encode(array(
					'status'	=> 'warning',
					'message'	=> $msg,
				));

				die();
			}
		}

		die();
	}
Exemplo n.º 2
0
<?php

/*
	In this file, we're going to make some checkboxes, and auto-select which ones the user belongs to.
	Note: My execution probably isn't the prettiest, and I encourage you to modify this for your own usage,
	rather than just using it as-is.
*/
require dirname(__FILE__) . '/../MadMimi.class.php';
// There are a total of four arguments that can be used on the next line. The first two are shown here, the second two
// are optional. The first of them is a debugger, which defaults to false, and the second, allows you to print
// the transaction ID when sending a message. It also defaults to false.
$mailer = new MadMimi('YOUR USERNAME (OR E-MAIL ADDRESS)', 'YOUR API KEY');
// Get all lists for this account..
$lists = $mailer->Lists();
$memberships = $mailer->Memberships('*****@*****.**');
echo '<form name="user_lists" method="POST" action="">';
foreach ($lists as $list) {
    foreach ($memberships as $membership) {
        if ((int) $list['id'] == (int) $membership['id']) {
            echo $list['name'] . ' <input type="checkbox" name="' . $list['name'] . '" checked="true"> <br />';
        } else {
            echo $list['name'] . ' <input type="checkbox" name="' . $list['name'] . '"> <br />';
        }
    }
}
echo '<input type="submit" value="Submit">';
echo '</form>';
Exemplo n.º 3
0
<?php

require dirname(__FILE__) . '/../MadMimi.class.php';
// There are a total of four arguments that can be used on the next line. The first two are shown here, the second two
// are optional. The first of them is a debugger, which defaults to false, and the second, allows you to print
// the transaction ID when sending a message. It also defaults to false.
$mailer = new MadMimi('YOUR USERNAME (OR E-MAIL ADDRESS)', 'YOUR API KEY');
if ($mailer->Authenticate()) {
    // Get all lists for this account..
    $lists = $mailer->Lists();
    $lists = new SimpleXMLElement($lists);
    // ...and loop through them.
    foreach ($lists as $list) {
        echo $list['name'] . "<br />";
    }
    // Now, let's check a user's membership status...
    $memberships = $mailer->Memberships('*****@*****.**');
    $memberships = new SimpleXMLElement($memberships);
    foreach ($memberships as $list) {
        echo $list['name'] . "<br />";
    }
    // Maybe we just want to send a message?
    $options = array('recipients' => 'Nicholas Young <*****@*****.**>', 'promotion_name' => 'My Awesome Promotion', 'subject' => 'You Gotta Read This', 'from' => 'Mad Mailer <*****@*****.**>');
    $body = array('Greeting' => 'Hello From MadMailer!');
    $mailer->SendMessage($options, $body);
} else {
    echo 'Wrong username or api key' . '<br />' . PHP_EOL;
}
 /**
  * Record an impression made by a optin fire
  * This function is called via PHP.
  *
  * @access public
  * @static
  * @return void
  */
 function nnr_new_int_add_email_v1()
 {
     do_action('nnr_news_int_before_submission_add_email_v1');
     // No First Name
     if (!isset($_POST['first_name'])) {
         $_POST['first_name'] = '';
     }
     // No Last Name
     if (!isset($_POST['last_name'])) {
         $_POST['last_name'] = '';
     }
     // Could not find Data ID
     if (!isset($_POST['data_id']) || $_POST['data_id'] == '') {
         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('Could not find Data ID.', $_POST['text_domain'])));
         die;
     }
     // Get all newsletter data for this data instance
     $data_manager = new NNR_Data_Manager_v1($_POST['table_name']);
     $data_instance = $data_manager->get_data_from_id($_POST['data_id']);
     $success_action = isset($data_instance['args']['newsletter']['success_action']) ? stripcslashes($data_instance['args']['newsletter']['success_action']) : 'message';
     $success_mesage = isset($data_instance['args']['newsletter']['success_message']) ? stripcslashes($data_instance['args']['newsletter']['success_message']) : __('Welcome to the community!', $_POST['text_domain']);
     $success_url = isset($data_instance['args']['newsletter']['success_url']) ? stripcslashes($data_instance['args']['newsletter']['success_url']) : '';
     // No Email
     if (!isset($_POST['email']) || $_POST['email'] == '') {
         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('No Email address provided.', $_POST['text_domain'])));
         die;
     }
     // Invalid Email Address
     if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('Invalid Email provided.', $_POST['text_domain'])));
         die;
     }
     // WordPress
     if ($_POST['type'] == 'wordpress') {
         $newsletter_db = new NNR_Newsletter_Integrations_Submission_v1($_POST['news_table_name']);
         $result = $newsletter_db->add_data(array('data_id' => $_POST['data_id'], 'email' => $_POST['email'], 'first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name']));
         if ($result) {
             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
             die;
         } else {
             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'message' => __('We already have your email!', $_POST['text_domain'])));
             die;
         }
     } else {
         if ($_POST['type'] == 'mailchimp') {
             require_once dirname(dirname(__FILE__)) . '/services/mailchimp/MailChimp.php';
             if (!isset($data_instance['args']['newsletter']['mailchimp']['api_key']) || $data_instance['args']['newsletter']['mailchimp']['api_key'] == '') {
                 echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('MailChimp account is not setup properly.', $_POST['text_domain'])));
                 die;
             }
             if (!isset($data_instance['args']['newsletter']['mailchimp']['list']) || $data_instance['args']['newsletter']['mailchimp']['list'] == '') {
                 echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('MailChimp: No list specified.', $_POST['text_domain'])));
                 die;
             }
             if (!isset($data_instance['args']['newsletter']['mailchimp']['optin'])) {
                 $data_instance['args']['newsletter']['mailchimp']['optin'] = true;
             }
             $MailChimp = new NNR_New_Int_MailChimp($data_instance['args']['newsletter']['mailchimp']['api_key']);
             $result = $MailChimp->call('lists/subscribe', array('id' => $data_instance['args']['newsletter']['mailchimp']['list'], 'email' => array('email' => $_POST['email']), 'merge_vars' => array('FNAME' => $_POST['first_name'], 'LNAME' => $_POST['last_name']), 'double_optin' => $data_instance['args']['newsletter']['mailchimp']['optin'], 'update_existing' => false, 'replace_interests' => false, 'send_welcome' => true));
             if ($result) {
                 if (isset($result['email'])) {
                     echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                     die;
                 } else {
                     if (isset($result['status']) && $result['status'] == 'error') {
                         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $result['error']));
                         die;
                     }
                 }
             } else {
                 echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('Unable to subscribe.', $_POST['text_domain'])));
                 die;
             }
         } else {
             if ($_POST['type'] == 'aweber') {
                 require_once dirname(dirname(__FILE__)) . '/services/aweber/aweber_api.php';
                 $aweber = new AWeberAPI($data_instance['args']['newsletter']['aweber']['consumer_key'], $data_instance['args']['newsletter']['aweber']['consumer_secret']);
                 try {
                     $account = $aweber->getAccount($data_instance['args']['newsletter']['aweber']['access_key'], $data_instance['args']['newsletter']['aweber']['access_secret']);
                     $list = $account->loadFromUrl('/accounts/' . $account->id . '/lists/' . $data_instance['args']['newsletter']['aweber']['list_id']);
                     $subscriber = array('email' => $_POST['email'], 'name' => $_POST['first_name'] . ' ' . $_POST['last_name'], 'ip' => $_SERVER['REMOTE_ADDR']);
                     $newSubscriber = $list->subscribers->create($subscriber);
                     echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                     die;
                 } catch (AWeberAPIException $exc) {
                     echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $exc->message));
                     die;
                 }
             } else {
                 if ($_POST['type'] == 'getresponse') {
                     require_once dirname(dirname(__FILE__)) . '/services/getresponse/jsonRPCClient.php';
                     $api = new jsonRPCClient('http://api2.getresponse.com');
                     try {
                         $api->add_contact($data_instance['args']['newsletter']['getresponse']['api_key'], array('campaign' => $data_instance['args']['newsletter']['getresponse']['campaign'], 'name' => $_POST['first_name'] . ' ' . $_POST['last_name'], 'email' => $_POST['email']));
                         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                         die;
                     } catch (RuntimeException $exc) {
                         $msg = $exc->getMessage();
                         $msg = substr($msg, 0, strpos($msg, ";"));
                         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $msg));
                         die;
                     }
                 } else {
                     if ($_POST['type'] == 'campaignmonitor') {
                         require_once dirname(dirname(__FILE__)) . '/services/campaignmonitor/csrest_subscribers.php';
                         $wrap = new CS_REST_Subscribers($data_instance['args']['newsletter']['campaignmonitor']['list'], $data_instance['args']['newsletter']['campaignmonitor']['api_key']);
                         // Check if subscriber is already subscribed
                         $result = $wrap->get($_POST['email']);
                         if ($result->was_successful()) {
                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('You are already subscribed to this list.', $_POST['text_domain'])));
                             die;
                         }
                         $result = $wrap->add(array('EmailAddress' => $_POST['email'], 'Name' => $_POST['first_name'] . ' ' . $_POST['last_name'], 'Resubscribe' => true));
                         if ($result->was_successful()) {
                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                             die;
                         } else {
                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $result->response->Message));
                             die;
                         }
                     } else {
                         if ($_POST['type'] == 'madmimi') {
                             require_once dirname(dirname(__FILE__)) . '/services/madmimi/MadMimi.class.php';
                             $mailer = new MadMimi($data_instance['args']['newsletter']['madmimi']['username'], $data_instance['args']['newsletter']['madmimi']['api_key']);
                             try {
                                 // Check if user is already in list
                                 $result = $mailer->Memberships($_POST['email']);
                                 $lists = new SimpleXMLElement($result);
                                 if ($lists->list) {
                                     foreach ($lists->list as $l) {
                                         if ($l->attributes()->{'name'}->{0} == $data_instance['args']['newsletter']['madmimi']['list']) {
                                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'message' => __('You are already subscribed to this list.', $_POST['text_domain'])));
                                             die;
                                         }
                                     }
                                 }
                                 $result = $mailer->AddMembership($data_instance['args']['newsletter']['madmimi']['list'], $_POST['email'], array('first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name']));
                                 echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                                 die;
                             } catch (RuntimeException $exc) {
                                 echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $msg));
                                 die;
                             }
                         } else {
                             if ($_POST['type'] == 'infusionsoft') {
                                 require_once dirname(dirname(__FILE__)) . '/services/infusionsoft/isdk.php';
                                 try {
                                     $infusion_app = new iSDK();
                                     $infusion_app->cfgCon($data_instance['args']['newsletter']['infusionsoft']['app_id'], $data_instance['args']['newsletter']['infusionsoft']['api_key'], 'throw');
                                 } catch (iSDKException $e) {
                                     echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $e->getMessage()));
                                     die;
                                 }
                                 if (empty($error_message)) {
                                     $contact_data = $infusion_app->dsQuery('Contact', 1, 0, array('Email' => $_POST['email']), array('Id', 'Groups'));
                                     // Check if contact already exists
                                     if (0 < count($contact_data)) {
                                         if (false === strpos($contact_data[0]['Groups'], $data_instance['args']['newsletter']['infusionsoft']['list'])) {
                                             $infusion_app->grpAssign($contact_data[0]['Id'], $data_instance['args']['newsletter']['infusionsoft']['list']);
                                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                                             die;
                                         } else {
                                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'message' => __('You are already subscribed to this list.', $_POST['text_domain'])));
                                             die;
                                         }
                                     } else {
                                         $new_contact_id = $infusion_app->dsAdd('Contact', array('FirstName' => $_POST['first_name'], 'LastName' => $_POST['last_name'], 'Email' => $_POST['email']));
                                         $infusion_app->grpAssign($new_contact_id, $data_instance['args']['newsletter']['infusionsoft']['list']);
                                         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                                         die;
                                     }
                                 }
                             } else {
                                 if ($_POST['type'] == 'mymail') {
                                     // Check if plugin is activated
                                     if (!function_exists('mymail')) {
                                         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('MyMail is not activated.', $_POST['text_domain'])));
                                         die;
                                     }
                                     // Add subscriber
                                     $subscriber_id = mymail('subscribers')->add(array('email' => $_POST['email'], 'firstname' => $_POST['first_name'], 'lastname' => $_POST['last_name']), false);
                                     // Add to List
                                     if (!is_wp_error($subscriber_id)) {
                                         mymail('subscribers')->assign_lists($subscriber_id, array($data_instance['args']['newsletter']['mymail']['list']));
                                         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                                         die;
                                     } else {
                                         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'message' => __('You are already subscribed to this list.', $_POST['text_domain'])));
                                         die;
                                     }
                                 } else {
                                     if ($_POST['type'] == 'activecampaign') {
                                         require_once dirname(dirname(__FILE__)) . '/services/activecampaign/ActiveCampaign.class.php';
                                         $ac = new ActiveCampaign($data_instance['args']['newsletter']['activecampaign']['app_url'], $data_instance['args']['newsletter']['activecampaign']['api_key']);
                                         if (!(int) $ac->credentials_test()) {
                                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('Unable to to connect to Active Campaign.', $_POST['text_domain'])));
                                             die;
                                         }
                                         // Add subscriber
                                         $contact_sync = $ac->api("contact/add", array("email" => $_POST['email'], "first_name" => $_POST['first_name'], "last_name" => $_POST['last_name'], "p[" . $data_instance['args']['newsletter']['activecampaign']['list'] . "]" => $data_instance['args']['newsletter']['activecampaign']['list'], "status[" . $data_instance['args']['newsletter']['activecampaign']['list'] . "]" => 1));
                                         if ((int) $contact_sync->success) {
                                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                                             die;
                                         } else {
                                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $contact_sync->error));
                                             die;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     do_action('nnr_news_int_after_submission_add_email_v1');
     echo json_encode(apply_filters('nnr_news_int_submission_add_email_v1', array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('Unable to subscribe user. Newsletter not setup properly.', $_POST['text_domain']))));
     die;
     // this is required to terminate immediately and return a proper response
 }