You are here

function CampaignMonitor::subscriberAddWithCustomFields in Campaign Monitor 6.2

Same name and namespace in other branches
  1. 6.3 lib/CMBase.php \CampaignMonitor::subscriberAddWithCustomFields()

*

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 CampaignMonitor::subscriberAddWithCustomFields()
CampaignMonitor::subscriberAddAndResubscribeWithCustomFields in lib/CMBase.php
*
CampaignMonitor::subscriberAddWithCustomFieldsRedundant in lib/CMBase.php
* Same as subscriberAddRedundant() except with CustomFields. * *

File

lib/CMBase.php, line 672

Class

CampaignMonitor
The new CampaignMonitor class that now extends from CMBase. This should be backwards compatible with the original (PHP5) version.

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,
    ),
  ));
}