Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save timothyjensen/3f731337d49a01c83f9f to your computer and use it in GitHub Desktop.
Save timothyjensen/3f731337d49a01c83f9f to your computer and use it in GitHub Desktop.
<?php
//* The Gravity form number where the user signs up for your Dreamhost Announce list
$gf_num = 2;
//* Transmit the data to Dreamhost after the form has been submitted
add_action('gform_after_submission_' . $gf_num , 'tj_send_to_dreamhost', 10, 2);
function tj_send_to_dreamhost($entry) {
$key = 'XXXXXXXXXXX'; //* unique key obtained from Dreamhost at https://panel.dreamhost.com/?tree=home.api
$cmd = 'announcement_list-add_subscriber'; //* Commands can be found at http://wiki.dreamhost.com/API/Announcement_list_commands
$listname = 'test'; //* Modify this if your Announce list is different than [email protected]
$domain = 'example.com'; //* Modify this if your Announce list is different than [email protected]
$email = rgar($entry, '2'); //* This is the Gravity Forms form entry number
$name = rgar($entry, '1.3') . " " . rgar($entry, '1.6'); //* This is the Gravity Forms form entry number
//* Sanitize inputs for security
$sanitized_email = sanitize_email( $email );
$sanitized_name = sanitize_user( $name , $strict = true );
//* Post the submitted information to Dreamhost
$url = 'https://api.dreamhost.com/';
$body = array(
'key' => $key,
'cmd' => $cmd,
'listname' => $listname,
'domain' => $domain,
'name' => $sanitized_name,
'email' => $sanitized_email,
//'format' => 'php',
);
// * Send the array to Dreamhost, https://api.dreamhost.com
$response = wp_remote_post( $url, array( 'body' => $body ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment