Skip to content

Instantly share code, notes, and snippets.

@magnific0
Created October 3, 2014 17:59
Show Gist options
  • Save magnific0/fd8a2f90b88f5877b463 to your computer and use it in GitHub Desktop.
Save magnific0/fd8a2f90b88f5877b463 to your computer and use it in GitHub Desktop.
Appending Arguments to Mailpoet Tracker URL Hook

Appending Arguments to Mailpoet Tracker URL Hook

In this example I append an extra argument to the Mailpoet tracker url called uidhash. This happens to be the confirmation hash used by Mailpoet. The hook should be added to functions.php.

function my_tracker_replaceusertags($email,$user){
  $urls = array();
  $results = array();// collect all links in email
  if(!preg_match_all('#href[ ]*=[ ]*"(?!mailto:|\#|ymsgr:|callto:|file:|ftp:|webcal:|skype:)([^"]+)"#Ui',$email->body,$results)) return;

  foreach($results[1] as $i => $url){
    if(isset($urls[$results[0][$i]])|| strpos($url, 'wysija-key')) continue;

    $urls[$results[0][$i]] = str_replace($url,$url . '&uidhash=' . $user->keyuser,$results[0][$i]);

  }
  $email->body = str_replace(array_keys($urls),$urls,$email->body);
  
}

add_action('wysija_replaceusertags', my_tracker_replaceusertags,12,2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment