From 4d230c0aa9c9ea380a6f6c890c9cf287744cd51e Mon Sep 17 00:00:00 2001 From: Thomas Bachem Date: Wed, 19 Apr 2017 13:44:01 +0200 Subject: [PATCH] Added Sendgrid_NLVX::delete_recipient() --- lib/class-sendgrid-nlvx.php | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/class-sendgrid-nlvx.php b/lib/class-sendgrid-nlvx.php index 8d99f7d..db14211 100644 --- a/lib/class-sendgrid-nlvx.php +++ b/lib/class-sendgrid-nlvx.php @@ -191,4 +191,38 @@ 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 SendGrid MC contact DB + * + * @param string $recipient_id the ID of the recipient. + * + * @return bool True if successful, false otherwise. + */ + public static function delete_recipient($recipient_id) + { + $auth = self::get_auth_header_value(); + + if ( false == $auth ) { + return false; + } + + $args = array( + 'method' => 'DELETE', + 'headers' => array( + 'Authorization' => $auth + ), + 'decompress' => false + ); + + $url = Sendgrid_NLVX::NLVX_API_URL . '/recipients/' . $recipient_id; + + $response = wp_remote_post( $url, $args ); + + if ( isset( $response['response']['code'] ) && 204 == $response['response']['code'] ) { + return true; + } + + return false; + } +}