Skip to content

Instantly share code, notes, and snippets.

@tribulant
Last active January 15, 2018 21:24
Show Gist options
  • Save tribulant/846400b10de1897de805 to your computer and use it in GitHub Desktop.
Save tribulant/846400b10de1897de805 to your computer and use it in GitHub Desktop.
WordPress Newsletter plugin: Initiate JSON API
<?php
$url = 'http://domain.com/wp-admin/admin-ajax.php?action=newsletters_api';
$data = array(
'api_method' => 'subscriber_add',
'api_key' => '37C1D6053E817212348E507D29CCCE49',
'api_data' => array(
'email' => "email@domain.com",
'list_id' => array(1,2,3),
)
);
$data_string = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = json_decode(curl_exec($ch));
curl_close($ch);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment