-
-
Save greathmaster/d2f67a0aa183af8b34b87784570e6b3e to your computer and use it in GitHub Desktop.
MailPoet: subscribe and unsubscribe a list
This file contains 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