Created
May 20, 2017 17:03
-
-
Save calogxro/63ea66b70889b1e1d08f3efd9b204c6f to your computer and use it in GitHub Desktop.
MailPoet: subscribe and unsubscribe a list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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