<?
/**
 * Plugin Name: Sendy WPCF7
 * Description: Sendy integration with WP Contact Form 7
 * Author: Ryan Snowden
 * Author URI: http://crystal-asia.com
 * License: MIT
 * Version: 1.0
 */

add_action('init', 'sendywpcf_init');

/**
 * Check that WPCF is installed and add in hooks.
 *
 * @return bool
 */
function sendywpcf_init() {

	add_action( 'wpcf7_mail_sent', 'subscribe_from_cf7');
	if (!function_exists('wpcf7_add_shortcode')) {
		return false;
	}
	wpcf7_add_shortcode('sendywpcf', 'get_list_id');

	return true;
}

/**
 * Creates a hidden input with the sendy list id
 * 
 * @param mixed $args Array or string
 * @return string Hidden input with Sendy list id
 */
function get_list_id($args=[]) {

	if (!isset($args['values'][0])) {
		return false;
	}
	$content = '<input type="hidden" name="sendy_list_id" value="'.$args['values'][0].'">';

	return $content;
}

/**
 * Subscribe from WPCF Forms after the email has been sent
 *
 * @param array $args
 * @return mixed
*/
function subscribe_from_cf7($args=null) {

	$sendyUrl = "https://email.vipdevhd.com/subscribe";

	try {

		if (!isset($_POST['sendy_list_id'])) {
			throw new Exception("Missing sendy_list_id");
		}

		$postdata = http_build_query([
			'name' => $_POST['name'],
			'email' => $_POST['email'],
			'list' => $_POST['sendy_list_id'],
			'boolean' => 'true'
		]);
		$opts = ['http' => [
			'method'  => 'POST',
			'header'  => 'Content-type: application/x-www-form-urlencoded',
			'content' => $postdata
		]];
		$context  = stream_context_create($opts);
		$result = file_get_contents($sendyUrl, false, $context);

		if (!$result) {
			throw new Exception("There was a probleming adding you to the mailing list");
		}

	} catch (Exception $e) {
		echo "<script>jQuery('.wpcf7-response-output').html('".$e->getMessage();"').show(); </script>";
	}

}

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//vipdevhd.com/wp-content/plugins/wordpress-seo/css/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://vipdevhd.com/post-sitemap.xml</loc>
		<lastmod>2025-12-08T12:19:08+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://vipdevhd.com/page-sitemap.xml</loc>
		<lastmod>2026-01-27T21:58:51+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://vipdevhd.com/product-sitemap.xml</loc>
		<lastmod>2022-03-29T11:42:29+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://vipdevhd.com/category-sitemap.xml</loc>
		<lastmod>2025-12-08T12:19:08+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://vipdevhd.com/post_tag-sitemap.xml</loc>
		<lastmod>2026-01-27T21:58:51+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://vipdevhd.com/product_cat-sitemap.xml</loc>
		<lastmod>2022-03-29T11:42:29+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://vipdevhd.com/product_tag-sitemap.xml</loc>
		<lastmod>2021-02-05T11:42:02+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Yoast SEO -->