protected $_short_title = 'StreamSend';
protected $_errorFlag = false;
protected $listID;
+ protected $optIn;
private static $_instance = null;
protected $streamSendFields = array(
'choices' => $lists
),
+ array(
+ 'label' => 'Enable Opt-In',
+ 'type' => 'checkbox',
+ 'name' => 'opt-in',
+ 'tooltip' => 'Enable Opt-In',
+ 'choices' => array(
+ array(
+ 'label' => '',
+ 'name' => 'opt-in'
+ ),
+ )
+ ),
array(
'name' => 'mappedFields',
'label' => esc_html__( 'Map Fields', 'StreamSend' ),
'instructions' => esc_html__( 'Process this StreamSend feed if', 'StreamSend' ),
),
+
+
)
)
);
$feedName = $feed['meta']['feedName'];
$field_map = $this->get_field_map_fields( $feed, 'mappedFields' );
$this->listID = $feed['meta']['lists']; // get the list ID from a selected list
+ $this->optIn = $feed['meta']['opt-in'];
+ if($this->optIn == 1){
+ $this->optIn = 'false';
+ } else if($this->optIn == 0){
+ $this->optIn = 'true';
+ }
$merge_vars = array();
foreach ( $field_map as $name => $field_id ) {
$merge_vars[ $name ] = $this->get_field_value( $form, $entry, $field_id );
$apiLogin = rgar( $settings, 'glm_streamsend_login' );
$apiKey = rgar( $settings, 'glm_streamsend_key' );
$audience = rgar( $settings, 'glm_streamsend_audience' );
+
+
// check the array $values to make sure it is correct
if (is_array($values) && !empty($values)) {
foreach ($this->streamSendFields as $glmName => $ssName) {
$contactData[$ssName] = $values[$glmName];
}
- if ($ret->contact) {
- $contacts = $ss->contactUpdate(
+ if(!empty($this->listID)){
+ $contacts = $ss->contactCreate(
+ $contactData,
+ $this->optIn,
+ STREAMSEND_DEFAULT_DELIVER_ACTIVATION,
+ STREAMSEND_DEFAULT_DELIVER_WELCOME,
+ $listId
+ );
+ }else if($ret->contact){
+ $contacts = $ss->contactUpdate(
$ret->contact->id,
$contactData
);
- }else if(!empty($listId)){
- $listAdd = $ss->addToList($contactData, $this->listID);
} else {
$contacts = $ss->contactCreate(
$contactData,
- STREAMSEND_DEFAULT_ACTIVATE,
+ $this->optIn,
STREAMSEND_DEFAULT_DELIVER_ACTIVATION,
STREAMSEND_DEFAULT_DELIVER_WELCOME
);
function contactCreate( $contact,
$activate = STREAMSEND_DEFAULT_ACTIVATE,
$deliver = STREAMSEND_DEFAULT_DELIVER_ACTIVATION,
- $welcome = STREAMSEND_DEFAULT_DELIVER_WELCOME )
+ $welcome = STREAMSEND_DEFAULT_DELIVER_WELCOME,
+ $listId = " "
+ )
{
$this->debug('contactCreate() called');
$this->debug('contactCreate() Call to sendRequest() failed.');
return false;
}
+ if(!empty($listId)){
+ $email = $contact['email-address'];
+ $post_data = "<membership>\n";
+ $post_data .= " <list-id>$listId</list-id>\n"
+ ." <email-address>$email</email-address>\n";
+ $post_data .= "</membership>\n";
+ $this->postData = $post_data;
+ $this->debug('contactCreate() XML POST request data<br /><table border="1"><tr><td><pre>'
+ ."\n".htmlentities($this->postData)."\n"
+ .'</pre></td></tr></table>');
+
+ /** This operation requires the "POST" Method */
+ if ($this->sendRequest('POST', 'audiences/'.STREAMSEND_AUDIENCE.'/lists/'.$listId.'/memberships') === false) {
+ $this->debug('contactCreate() Call to sendRequest() failed.');
+ return false;
+ }
+ }
/**
* Check if the response request was successful
return(clone $this);
}
- function addToList($contact, $listId)
- {
-
- $this->debug('addToList() called');
-
- $email = $contact['email-address'];
-
- $post_data = "<membership>\n";
- $post_data .= " <list-id>$listId</list-id>\n"
- ." <email-address>$email</email-address>\n";
- $post_data .= "</membership>\n";
- $this->postData = $post_data;
- $this->debug('contactCreate() XML POST request data<br /><table border="1"><tr><td><pre>'
- ."\n".htmlentities($this->postData)."\n"
- .'</pre></td></tr></table>');
-
- /** This operation requires the "POST" Method */
- if ($this->sendRequest('POST', 'audiences/'.STREAMSEND_AUDIENCE.'/lists/'.$listId.'/memberships') === false) {
- $this->debug('contactCreate() Call to sendRequest() failed.');
- return false;
- }
-
- /**
- * Check if the response request was successful
- */
- if ($this->responseError > 0) {
- $this->debug('addToList() Call to sendRequest() returned an error code.');
- } else {
- $this->debug('addToList() Received good response from sendRequest().');
- }
-
- return(clone $this);
-
- }
-
-
-
/**
* Memberships (subscription) Methods
*