Skip to content

Instantly share code, notes, and snippets.

@igmoweb
Last active July 6, 2016 17:26
Show Gist options
  • Save igmoweb/5ad5b75d7c356feb6c1d12c46154705e to your computer and use it in GitHub Desktop.
Save igmoweb/5ad5b75d7c356feb6c1d12c46154705e to your computer and use it in GitHub Desktop.
Adds a link at the end of all emails with a link to unsubscribe page
<?php
add_filter( 'wp_mail', 'ltu_add_unsubscribe_links' );
function ltu_add_unsubscribe_links( $args ) {
if ( ! class_exists( 'IW_LTU' ) ) {
// Let Them Unsubscribe is not active
return $args;
}
$email = $args['to'];
$user = get_user_by( 'email', $email );
if ( $user && function_exists( 'iw_ltu_user_can_unsubscribe' ) && iw_ltu_user_can_unsubscribe( $user->ID ) ) {
// The user is allowed to delete its own profile
$url = admin_url( 'profile.php' );
$url = add_query_arg( 'page', 'ltu_unsubscribe', $url );
// Add this text at the end of the email
$args['message'] .= <<<EOD
Delete your profile here:
$url
EOD;
}
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment