Skip to content

Instantly share code, notes, and snippets.

@evrpress
Last active February 27, 2017 09:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save evrpress/11eb34aa37de0a6b4d81f73a790034ab to your computer and use it in GitHub Desktop.
Save evrpress/11eb34aa37de0a6b4d81f73a790034ab to your computer and use it in GitHub Desktop.
Assigns a subscriber to a certain list if a certain link has been clicked
@ioniacob
Copy link

ioniacob commented Sep 29, 2016

Your code don't work for my.
I tested with the following code for cancel subscripton for list 1 and suscribe to list 2 if the user click a button:

add_action('wp_head','mymail_change_list_segment');
function mymail_change_list_segment() {
if ( is_page(711) ) {
$userhash = isset($_COOKIE['mymail']) ? $_COOKIE['mymail'] : NULL;
$subscriber = mymail('subscribers')->get_by_hash($userhash, true);
$user_mail = $subscriber->email;
$lists = 1;
global $user_mail, $userhash, $lists, $subscriber;
$subscriber_ids = mymail('subscribers')->add(array(
'email' => $user_mail,
'status' => 1,
), $overwrite = true );
mymail('subscribers')->assign_lists($subscriber_ids, $lists, $remove_old = true);
}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment