Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
wpMandrill $payload Filter
<?php
# You'll need PHP 5.3+ to run this code as is. http://php.net/manual/en/functions.anonymous.php
// 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 https://mandrill.zendesk.com/hc/en-us/articles/205582497
$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 ) {
die('success');
} else {
die('error');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment