Skip to content

Instantly share code, notes, and snippets.

@calogxro
Created May 20, 2017 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save calogxro/63ea66b70889b1e1d08f3efd9b204c6f to your computer and use it in GitHub Desktop.
Save calogxro/63ea66b70889b1e1d08f3efd9b204c6f to your computer and use it in GitHub Desktop.
MailPoet: subscribe and unsubscribe a list
<?php
function mailpoet_subscribe($list_ids = array()) {
$current_user = wp_get_current_user();
$helper_user = WYSIJA::get('user','helper');
$helper_user->addSubscriber([
'user' => [
'email' => $current_user->user_email,
'firstname' => $current_user->user_firstname,
'lastname' => $current_user->user_lastname
],
'user_list' => [
'list_ids' => $list_ids
]
]);
}
function mailpoet_unsubscribe($list_ids = array()) {
$current_user = wp_get_current_user();
$model_user = WYSIJA::get('user','model');
$subscriber_data = (array)$model_user->getOne(false, ['email' => $current_user->user_email]);
if (isset($subscriber_data['user_id'])) {
$helper_user = WYSIJA::get('user','helper');
$helper_user->removeFromLists($list_ids,[$subscriber_data['user_id']]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment