You are here

function CMBase::subscriberAddWithCustomFields in Campaign Monitor 5.2

*

Parameters

string $email Email address.: * @param string $name User's name. * @param mixed $fields Should be a $key => $value mapping. If there are more than one items for $key, let * $value be a list of scalar values. Example: array( 'Interests' => array( 'xbox', 'wii' ) ) * @param int $list_id (Optional) A valid List ID to check against. If not given, the default class property is used. * @param boolean $resubscribe If true, does an equivalent 'AndResubscribe' API method. * @return mixed A parsed response from the server, or null if something failed. * @see http://www.campaignmonitor.com/api/Subscriber.AddWithCustomFields.aspx

2 calls to CMBase::subscriberAddWithCustomFields()
CampaignMonitor::subscriberAddAndResubscribeWithCustomFields in lib/CMBase.php
*
CMBase::subscriberAddWithCustomFieldsRedundant in lib/CMBase.php
* Same as subscriberAddRedundant() except with CustomFields. * *

File

lib/CMBase.php, line 442

Class

CMBase

Code

function subscriberAddWithCustomFields($email, $name, $fields, $list_id = null, $resubscribe = false) {
  if (!$list_id) {
    $list_id = $this->list_id;
  }
  $action = 'Subscriber.AddWithCustomFields';
  if ($resubscribe) {
    $action = 'Subscriber.AddAndResubscribeWithCustomFields';
  }
  if (!is_array($fields)) {
    $fields = array();
  }
  $_fields = array(
    'SubscriberCustomField' => array(),
  );
  foreach ($fields as $k => $v) {
    if (is_array($v)) {
      foreach ($v as $nv) {
        $_fields['SubscriberCustomField'][] = array(
          'Key' => $k,
          'Value' => $nv,
        );
      }
    }
    else {
      $_fields['SubscriberCustomField'][] = array(
        'Key' => $k,
        'Value' => $v,
      );
    }
  }
  return $this
    ->makeCall($action, array(
    'params' => array(
      'ListID' => $list_id,
      'Email' => $email,
      'Name' => $name,
      'CustomFields' => $_fields,
    ),
  ));
}