Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Added Sendgrid_NLVX::delete_recipient() #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion lib/class-sendgrid-nlvx.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
* 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;
}
}