<?php
/**
 * Mailerlite API
 */

function themezaa_mailerlite_add_subscriber( $data ) {

	$mailerlite_api = curl_init();

	curl_setopt_array(
		$mailerlite_api,
		array(
			CURLOPT_URL            => 'https://api.mailerlite.com/api/v2/subscribers',
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_ENCODING       => '',
			CURLOPT_MAXREDIRS      => 10,
			CURLOPT_TIMEOUT        => 30,
			CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
			CURLOPT_CUSTOMREQUEST  => 'POST',
			CURLOPT_POSTFIELDS     => json_encode( $data ),
			CURLOPT_HTTPHEADER     => array(
				'content-type: application/json',
				'x-mailerlite-apikey:' . ml_api_key
			),
		)
	);

	$result = curl_exec( $mailerlite_api );
    return $result;
}
