MC4WP_API_v3::update_list_member PHP Method

update_list_member() public method

public update_list_member ( $list_id, $email_address, array $args ) : object
$list_id
$email_address
$args array
return object
    public function update_list_member($list_id, $email_address, array $args)
    {
        $subscriber_hash = $this->get_subscriber_hash($email_address);
        $resource = sprintf('/lists/%s/members/%s', $list_id, $subscriber_hash);
        // make sure we're sending an object as the MailChimp schema requires this
        if (isset($args['merge_fields'])) {
            $args['merge_fields'] = (object) $args['merge_fields'];
        }
        if (isset($args['interests'])) {
            $args['interests'] = (object) $args['interests'];
        }
        $data = $this->client->patch($resource, $args);
        return $data;
    }

Usage Example

 /**
  *
  * @param string $list_id
  * @param string $email_address
  *
  * @return boolean
  */
 public function list_unsubscribe($list_id, $email_address)
 {
     $this->reset_error();
     try {
         $this->api->update_list_member($list_id, $email_address, array('status' => 'unsubscribed'));
     } catch (MC4WP_API_Resource_Not_Found_Exception $e) {
         // if email wasn't even on the list: great.
         return true;
     } catch (MC4WP_API_Exception $e) {
         $this->error_code = $e->getCode();
         $this->error_message = $e;
         return false;
     }
     return true;
 }