Skip to content

Instantly share code, notes, and snippets.

@agengdp
Created February 11, 2018 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agengdp/8495ef7f8605ec20467bbe4ffff2cf46 to your computer and use it in GitHub Desktop.
Save agengdp/8495ef7f8605ec20467bbe4ffff2cf46 to your computer and use it in GitHub Desktop.
Kirim EMail Wordpress Caldera Form
<?php
/**
* Plugin Name: ADP Kirim email
* Description: Caldera Forms kirim email connector
* Version: 1.0.0
* Author: agengdp
*/
// Kirim Email creds
define('ADP_USERNAME', 'username nya');
define('ADP_TOKEN', 'token nya');
define('ADP_LIST_ID', 'id dari list nya');
// Caldera Field slug
define('ADP_CF_EMAIL', 'email_address');
define('ADP_CF_NAME', 'first_name');
add_action( 'adp_kirim_email', 'adp_kirim_email');
function adp_kirim_email( $data ) {
if(isset($data[ADP_CF_NAME]) && isset($data[ADP_CF_EMAIL])){
$params = [
'full_name' => $data[ADP_CF_NAME],
'email' => $data[ADP_CF_EMAIL],
'lists' => ADP_LIST_ID,
];
$req = adp_request($params);
}
}
function adp_request($params)
{
$base_url = 'https://aplikasi.kirim.email/api/v3/subscriber/';
$time = time();
$headers = [
"Auth-Id" => ADP_USERNAME,
"Auth-Token" => hash_hmac("sha256", ADP_USERNAME."::".ADP_TOKEN."::".$time, ADP_TOKEN),
"Timestamp" => $time
];
$post = wp_remote_post($base_url, [
'method' => 'POST',
'headers' => $headers,
'body' => $params,
]);
return $post['body'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment