Skip to content

Instantly share code, notes, and snippets.

@kprimdal-dk
Created October 12, 2012 08:55
Show Gist options
  • Save kprimdal-dk/3878171 to your computer and use it in GitHub Desktop.
Save kprimdal-dk/3878171 to your computer and use it in GitHub Desktop.
WordPress New Users added to Mailchimp
<?php
/*
Plugin Name: Primux Mailchimp
Plugin URI: http://primux.dk/
Description: Add new users to a Mailchimp list
Version: 1.0
Author: Primux Media
Author URI: http://primux.dk/
*/
add_action( 'user_register', 'mux_mailchimp_add' );
function mux_mailchimp_add( $user_id ) {
$user = get_user_by('id', $user_id);
$apikey = '' // API Key
$listid = '' // List ID
// $merges = array('FNAME'=>'Dave', 'LNAME'=>'Gilmour'); // IF you want to add other fields
$double_optin=false;
$update_existing=false;
$replace_interests=true;
$send_welcome=false;
$email_type = 'html';
$data = array(
'email_address' => $user->user_email,
'apikey' => $apikey,
// 'merge_vars' => $merges,
'id' => $listid,
'double_optin' => $double_optin,
'update_existing' => $update_existing,
'replace_interests' => $replace_interests,
'send_welcome' => $send_welcome,
'email_type' => $email_type
);
$payload = json_encode($data);
//replace us2 with your actual datacenter
$submit_url = "http://us2.api.mailchimp.com/1.3/?method=listSubscribe";
$feedback = wp_remote_post( $submit_url, array( 'body' => $payload ) );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment