emails.php 2.85 KB
<?php
/**
 * Understrap emails
 *
 * @package Understrap
 */

// Exit if accessed directly.


add_filter( 'cf7_2_post_status_wpsl_stores', 'publish_new_wpsl_stores',10,3);
  /**
  * Function to change the post status of saved/submitted posts.
  * @param string $status the post status, default is 'draft'.
  * @param string $ckf7_key unique key to identify your form.
  * @param array $submitted_data complete set of data submitted in the form as an array of field-name=>value pairs.
  * @return string a valid post status ('publish'|'draft'|'pending'|'trash')
  */
  function publish_new_wpsl_stores($status, $ckf7_key, $submitted_data){

	$email     = $submitted_data['your-email'];
	$subject   = 'WYN Important Registration Information';
	$stream_opts = [
		"ssl" => [
			"verify_peer"=>false,
			"verify_peer_name"=>false,
		]
	];  

	$message   =  file_get_contents(get_site_url().'/wp-content/themes/understrap-child/inc/Registration-Confirmation.html', false, stream_context_create($stream_opts));

	$headers_customer = array('Content-Type: text/html; charset=UTF-8');
	wp_mail( $email , $subject, $message, $headers_customer);


	return 'draft';
  }


  add_action('publish_wpsl_stores','send_notification_for_publish_project',10,1);

  function send_notification_for_publish_project( $post_id ) { 
	    $notification_sent = get_post_meta($post_id, 'notification_sent_for_publish_project', 1);
		if($notification_sent != 1){
	    update_post_meta($post_id, 'notification_sent_for_publish_project', true);
		delete_autoload_map_transient();
		$email    = get_post_meta($post_id, 'wpsl_email', true);
		$subject   = 'WYN Registration Approved';

		$stream_opts = [
			"ssl" => [
				"verify_peer"=>false,
				"verify_peer_name"=>false,
			]
		];  
		$message   =  file_get_contents(get_site_url().'/wp-content/themes/understrap-child/inc/Registration-Acceptance.html', false, stream_context_create($stream_opts));

		$headers_customer = array('Content-Type: text/html; charset=UTF-8');
		wp_mail( $email , $subject, $message, $headers_customer);
		}

  }


	add_action( 'trash_wpsl_stores', 'send_notification_for_delete_project' ,10,1);

	function send_notification_for_delete_project( $post_id ) {    
		$notification_sent = get_post_meta($post_id, 'notification_sent_for_delete_project', 1);
		if($notification_sent != 1){
	    update_post_meta($post_id, 'notification_sent_for_delete_project', true);
		$email    = get_post_meta($post_id, 'wpsl_email', true);
		$subject   = 'WYN Registration Denied';
		
		$stream_opts = [
			"ssl" => [
				"verify_peer"=>false,
				"verify_peer_name"=>false,
			]
		];  
		$message   = file_get_contents(get_site_url().'/wp-content/themes/understrap-child/inc/Registration-Denied.html', false, stream_context_create($stream_opts));

		$headers_customer = array('Content-Type: text/html; charset=UTF-8');
		wp_mail( $email , $subject, $message, $headers_customer);
		}
	}