Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
wpMandrill $payload Filter
# You'll need PHP 5.3+ to run this code as is.
// This action fires for an ajax event. Change it to whatever hook you need.
add_action( 'wp_ajax_todo_invite_friend', function(){
// We're only going to apply the filter when this specific action is triggered
add_filter( 'mandrill_payload', function( $payload ){
$template_content = $payload['template']['content'];
# $payload['template']['content'] # Multi-dimensional array of MC tags
$template_content = array(
// this corresponds to mc:edit="title"
'name' => 'title',
// this will be the new "title" content
'content' => "You Have Been Invited!"
// Add our new template tag content to the $payload
array_push( $payload['template']['content'], $template_content );
return $payload;
} );
$email = sanitize_email( $_POST['email'] );
$sender = get_userdata( get_current_user_id() );
$sender = "{$sender->data->display_name} ({$sender->data->user_email})";
// the second argument of wp_mail is passed to mc:edit="main" in our template by default
$success = wp_mail( $email, "You've been invited!", $sender . " invited you." );
// AJAX return values
if ( $success ) {
} else {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment