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

Added Sendgrid_NLVX::delete_recipient_from_list() #49

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
44 changes: 43 additions & 1 deletion lib/class-sendgrid-nlvx.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

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