From 96b274e62782589f447708b12a014303b6ea4764 Mon Sep 17 00:00:00 2001 From: Thomas Bachem Date: Wed, 19 Apr 2017 11:36:42 +0200 Subject: [PATCH] Added Sendgrid_NLVX::delete_recipient_from_list() --- lib/class-sendgrid-nlvx.php | 44 ++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/lib/class-sendgrid-nlvx.php b/lib/class-sendgrid-nlvx.php index 8d99f7d..2a037a4 100644 --- a/lib/class-sendgrid-nlvx.php +++ b/lib/class-sendgrid-nlvx.php @@ -191,4 +191,46 @@ public static function create_and_add_recipient_to_list($email, $first_name = '' return Sendgrid_NLVX::add_recipient_to_list($recipient_id, $list_id); } -} \ No newline at end of file + + /** + * Removes a recipient from the specified list + * + * @param string $recipient_id the ID of the recipient. + * @param string $list_id the ID of the list, defaults to the default list + * + * @return bool True if successful, false otherwise. + */ + public static function delete_recipient_from_list($recipient_id, $list_id = null) + { + $auth = self::get_auth_header_value(); + + if ( false == $auth ) { + return false; + } + + if ( ! $list_id ) { + $list_id = Sendgrid_Tools::get_mc_list_id(); + } + if ( false == $list_id ) { + return false; + } + + $args = array( + 'method' => 'DELETE', + 'headers' => array( + 'Authorization' => $auth + ), + 'decompress' => false + ); + + $url = Sendgrid_NLVX::NLVX_API_URL . '/lists/'. $list_id . '/recipients/' . $recipient_id; + + $response = wp_remote_post( $url, $args ); + + if ( isset( $response['response']['code'] ) && 204 == $response['response']['code'] ) { + return true; + } + + return false; + } +}