203 lines
6.4 KiB
PHP
203 lines
6.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* it means someone outside wp is accessing the file, in this case kill it.
|
|
*/
|
|
if (!defined('ABSPATH')) {
|
|
die('You can not access this file!');
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
* events and emails :
|
|
*
|
|
* 1. profs : email : payment_success : validation payment prof reussi, send email
|
|
* 2. profs : email : payment_failure : validation payment prof echec, send email
|
|
* 3. profs : email : transfert_success : validation transfert prof reussi, send email
|
|
* 4. profs : email : transfert_failures : validation transfert prof echec, send email
|
|
* 5. partners : email : offer_expired : offres temporaires -> gerer qu'elles disparaissent apres la date de validite -> la passer en masquer
|
|
* 6. partners : email : offer_will_expire : la gestion des offres à échéance
|
|
* 7. payments : email : account_deleted : schedule event pour supprimer le compte xx temps (6 mois ?) apres fin de validite de la carte
|
|
* 8. payments : email : account_will_expire : faire rappels emails avant expiration
|
|
* 9. payments : email : account_expired : desactiver carte expiree
|
|
*
|
|
*/
|
|
|
|
|
|
function prepare_emails_CIPF($email_name, $user_id) {
|
|
Plgntls::debug_infos();
|
|
$emails_option_object = Cipf::OPTION_EMAILS;
|
|
|
|
if (!isset($emails_option_object['_default'][$email_name])) {
|
|
return false;
|
|
}
|
|
|
|
if (is_null($user_id)) {
|
|
$user_id = get_current_user_id();
|
|
}
|
|
|
|
|
|
$emails_option = Plgntls::get_option_safe($emails_option_object);
|
|
if (!$emails_option) {
|
|
return false;
|
|
}
|
|
if (!isset($emails_option[$email_name])) {
|
|
return false;
|
|
}
|
|
$email = $emails_option[$email_name];
|
|
|
|
|
|
$emails = array();
|
|
if ($email['notification_send']) {
|
|
$tmp_email = array();
|
|
$tmp_email['to'] = $email['notification_to'];
|
|
$tmp_email['subject'] = $email['notification_subject'];
|
|
$tmp_email['message'] = $email['notification_message'];
|
|
$tmp_email['headers'] = array('Content-Type: text/html; charset=UTF-8');
|
|
$emails[] = $tmp_email;
|
|
}
|
|
if ($email['confirmation_send']) {
|
|
$tmp_email = array();
|
|
$tmp_email['to'] = $user_id;
|
|
$tmp_email['subject'] = $email['confirmation_subject'];
|
|
$tmp_email['message'] = $email['confirmation_message'];
|
|
$tmp_email['headers'] = array('Content-Type: text/html; charset=UTF-8');
|
|
$emails[] = $tmp_email;
|
|
}
|
|
return $emails;
|
|
}
|
|
|
|
|
|
|
|
function send_emails_CIPF($email_name, $user_id = null) {
|
|
Plgntls::debug_infos();
|
|
$emails = prepare_emails_CIPF($email_name, $user_id);
|
|
if (false === $emails) {
|
|
error_log('Email preparing failed!: ' . json_encode($emails));
|
|
return;
|
|
}
|
|
|
|
foreach ($emails as $email) {
|
|
$sent = wp_mail($email['to'], $email['subject'], $email['message'], $email['headers']);
|
|
}
|
|
if (!$sent) {
|
|
error_log('Email sending failed!: ' . json_encode($email));
|
|
}
|
|
}
|
|
|
|
|
|
//function email_payment_success_CIPF($user_id = null) {
|
|
// Plgntls::debug_infos();
|
|
//error_log("email payment success: " . json_encode($email_payment_success));
|
|
//
|
|
// send_email_CIPF($email_payment_success, $user_id);
|
|
// $user = get_user_by('id', $user_id);
|
|
//// $to = $user->user_email;
|
|
// $to = '$$__admin_email__$$';
|
|
// $subject = 'My Custom Email Subject';
|
|
// $message = 'Hello, This is a test email sent from my WordPress plugin!';
|
|
// $headers = array('Content-Type: text/html; charset=UTF-8');
|
|
//
|
|
//
|
|
// // Check if the email was sent successfully
|
|
//}
|
|
|
|
/*
|
|
'payment_success'=>[
|
|
'notification_send'=>true,
|
|
'notification_to'=>'$$__admin_email__$$',
|
|
'notification_subject'=>"paiement réussi",
|
|
'notification_message'=>"par ici la monnaie",
|
|
'confirmation_send'=>true,
|
|
'confirmation_subject'=>"paiement réussi",
|
|
'confirmation_mesage'=>"donne l'argent",
|
|
],
|
|
// 2. profs : email : payment_failure : validation payment prof echec, send email
|
|
'payment_echec'=>[
|
|
'notification_send'=>true,
|
|
'notification_to'=>'$$__admin_email__$$',
|
|
'notification_subject'=>"",
|
|
'notification_message'=>"",
|
|
'confirmation_send'=>true,
|
|
'confirmation_subject'=>"",
|
|
'confirmation_mesage'=>"",
|
|
],
|
|
// 3. profs : email : transfert_success : validation transfert prof reussi, send email
|
|
'transfert_success'=>[
|
|
'notification_send'=>true,
|
|
'notification_to'=>'$$__admin_email__$$',
|
|
'notification_subject'=>"",
|
|
'notification_message'=>"",
|
|
'confirmation_send'=>true,
|
|
'confirmation_subject'=>"",
|
|
'confirmation_mesage'=>"",
|
|
],
|
|
// 4. profs : email : transfert_failures : validation transfert prof echec, send email
|
|
'transfert_echec'=>[
|
|
'notification_send'=>true,
|
|
'notification_to'=>'$$__admin_email__$$',
|
|
'notification_subject'=>"",
|
|
'notification_message'=>"",
|
|
'confirmation_send'=>true,
|
|
'confirmation_subject'=>"",
|
|
'confirmation_mesage'=>"",
|
|
],
|
|
// 5. partners : email : offer_expired : offres temporaires -> gerer qu'elles disparaissent apres la date de validite -> la passer en masquer
|
|
'offer_expired'=>[
|
|
'notification_send'=>true,
|
|
'notification_to'=>'$$__admin_email__$$',
|
|
'notification_subject'=>"",
|
|
'notification_message'=>"",
|
|
'confirmation_send'=>true,
|
|
'confirmation_subject'=>"",
|
|
'confirmation_mesage'=>"",
|
|
],
|
|
// 6. partners : email : offer_will_expire : la gestion des offres à échéance
|
|
'offer_will_expire'=>[
|
|
'notification_send'=>true,
|
|
'notification_to'=>'$$__admin_email__$$',
|
|
'notification_subject'=>"",
|
|
'notification_message'=>"",
|
|
'confirmation_send'=>true,
|
|
'confirmation_subject'=>"",
|
|
'confirmation_mesage'=>"",
|
|
],
|
|
// 7. payments : email : account_deleted : schedule event pour supprimer le compte xx temps (6 mois ?) apres fin de validite de la carte
|
|
'account_deleted'=>[
|
|
'notification_send'=>true,
|
|
'notification_to'=>'$$__admin_email__$$',
|
|
'notification_subject'=>"",
|
|
'notification_message'=>"",
|
|
'confirmation_send'=>true,
|
|
'confirmation_subject'=>"",
|
|
'confirmation_mesage'=>"",
|
|
],
|
|
// 8. payments : email : account_will_expire : faire rappels emails avant expiration
|
|
'eccount_will_expire'=>[
|
|
'notification_send'=>true,
|
|
'notification_to'=>'$$__admin_email__$$',
|
|
'notification_subject'=>"",
|
|
'notification_message'=>"",
|
|
'confirmation_send'=>true,
|
|
'confirmation_subject'=>"",
|
|
'confirmation_mesage'=>"",
|
|
],
|
|
// 9. payments : email : account_expired : desactiver carte expiree
|
|
'account_expired'=>[
|
|
'notification_send'=>true,
|
|
'notification_to'=>'$$__admin_email__$$',
|
|
'notification_subject'=>"",
|
|
'notification_message'=>"",
|
|
'confirmation_send'=>true,
|
|
'confirmation_subject'=>"",
|
|
'confirmation_mesage'=>"",
|
|
],
|
|
*/
|
|
|
|
|
|
|
|
|
|
?>
|