Skip to content

Instantly share code, notes, and snippets.

@Pross
Created April 26, 2016 19:14
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save Pross/3ff9f68fea20dcdc8845919dc51de90d to your computer and use it in GitHub Desktop.
Save Pross/3ff9f68fea20dcdc8845919dc51de90d to your computer and use it in GitHub Desktop.
Add to mu-plugins folder, auto add every new user to a sendy list. Works with default WordPress and Woocommerce registrations.
<?php
add_action( 'user_register', 'add_user_to_sendy_list' );
function add_user_to_sendy_list( $user_id ) {
$list = 'SENDY_LIST_ID';
$url = 'http://SENDY_INSTALL_URL/subscribe';
$user = get_userdata( $user_id );
$email = $user->data->user_email;
$name = $user->data->user_nicename;
$args = array(
'body' => array(
'email' => $email,
'name' => $name,
'boolean' => true,
'list' => $list
)
);
$result = wp_remote_post( $url, $args );
}
@mattkaz
Copy link

mattkaz commented Mar 28, 2018

This is great, thank you!
However, I was wondering if you might have any idea on how to make it unsubscribe a user from the same Sendy mailing list, when deleting that user from the WP users? So basically, adding the reverse of what it does now.

Thank you very much!

@hozyali
Copy link

hozyali commented Aug 8, 2021

Great work, can we use it ONLY if the user has verified email upon registration in WordPress? I don't want to send an invalidated email to sendy to avoid SES health issues..

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