Skip to content

Instantly share code, notes, and snippets.

@greathmaster
Forked from calogxro/mailpoet_helpers.php
Created July 11, 2017 05:23
Show Gist options
  • Save greathmaster/d2f67a0aa183af8b34b87784570e6b3e to your computer and use it in GitHub Desktop.
Save greathmaster/d2f67a0aa183af8b34b87784570e6b3e 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