/** * Subscribes to Infusionsoft list. Returns either "success" string or error message. * @return string */ function subscribe_infusionsoft($api_key, $app_id, $list_id, $email, $name = '', $last_name = '') { if (!function_exists('curl_init')) { return __('curl_init is not defined ', 'rapidology'); } if (!class_exists('iSDK')) { require_once RAD_RAPIDOLOGY_PLUGIN_DIR . 'subscription/infusionsoft/isdk.php'; } try { $infusion_app = new iSDK(); $infusion_app->cfgCon($app_id, $api_key, 'throw'); } catch (iSDKException $e) { $error_message = $e->getMessage(); } $contact_details = array('FirstName' => $name, 'LastName' => $last_name, 'Email' => $email); $new_contact_id = $infusion_app->addWithDupCheck($contact_details, $checkType = 'Email'); $infusion_app->optIn($contact_details['Email']); $response = $infusion_app->grpAssign($new_contact_id, $list_id); if ($response) { $error_message = 'success'; } else { $error_message = esc_html__('Already In List', 'rapidology'); } return $error_message; }