if (!empty($_POST['sailthru_email_list'])) { $lists = explode(',', $_POST['sailthru_email_list']); foreach ($lists as $key => $list) { $subscribe_to_lists[$list] = 1; } $options['lists'] = $subscribe_to_lists; } else { $options['lists'] = array('Sailthru Subscribe Widget' => 1); // subscriber is an orphan } $options['vars']['source'] = get_bloginfo('url'); $return['data'] = array('email' => $email, 'options' => $options); if ($return['error'] == false) { $sailthru = get_option('sailthru_setup_options'); $api_key = $sailthru['sailthru_api_key']; $api_secret = $sailthru['sailthru_api_secret']; $client = new Sailthru_Client($api_key, $api_secret); $res = $client->saveUser($email, $options); if ($res['ok'] != true) { $result['error'] = true; $result['message'] = "There was an error subscribing you. Please try again later."; } $return['result'] = $res; } break; default: $return['error'] = true; $return['message'] = 'No action defined. None taken.'; } echo json_encode($return); die;
<? require('_autoload.php'); $api_key = "SAILTHRU-API-KEY"; $api_secret = "SAILTHRU-API-SECRET"; $client = new Sailthru_Client($api_key, $api_secret); try { // update existing user by Sailthru ID $response = $client->saveUser("4e2879472d7acd6d97144f9e", array( 'keys' => array( 'email' => '*****@*****.**', 'twitter' => 'infynyxx', 'fb' => 726310296 ), 'lists' => array( 'list-1' => 1, 'list-2' => 1, 'list-3' => 0 ) )); //update existing user by email or create new user using email address $response = $client->saveUser('*****@*****.**', array( 'key' => 'email', 'lists' => array( 'list-1' => 0 // optout from list-1 ) )); // get user by Sailthru ID