added email from

This commit is contained in:
asus
2024-04-10 22:31:43 +02:00
parent 265664537e
commit 6ecffc25f7
4 changed files with 70 additions and 12 deletions

View File

@@ -176,110 +176,132 @@ contactez la fipf directement",
'payment_success'=>[
'name'=>'prof - le paiement a réussi',
'notification_send'=>true,
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - paiement réussi]",
'notification_message'=>'paiement réussi de la part de $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>true,
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - paiement réussi]",
'confirmation_message'=>"paiement réussi",
],
'payment_echec'=>[
'name'=>'prof - le paiement a echoué',
'notification_send'=>true,
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - paiement echoué]",
'notification_message'=>'paiement echoué pour $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>true,
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - paiement echoué]",
'confirmation_message'=>"votre paiement a echoué",
],
'payment_problem'=>[
'name'=>'prof - le paiement a rencontré un problem',
'notification_send'=>true,
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - paiement probleme]",
'notification_message'=>'probleme de paiement pour $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>false,
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - paiement problème]",
'confirmation_message'=>"votre paiement a rencontré un probleme",
],
'transfert_success'=>[
'name'=>'prof - le virement a été validé',
'notification_send'=>true,
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - virement validé]",
'notification_message'=>'virement validé pour $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>true,
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - virement validé]",
'confirmation_message'=>"votre virement a été validé",
],
'change_card_success'=>[
'name'=>'prof - le paiement pour changer la carte a réussi',
'notification_send'=>true,
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - paiement changer carte reussi]",
'notification_message'=>'paiement pour changer sa carte a réussi de la part de $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>true,
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - paiement changement carte réussi]",
'confirmation_message'=>"paiement changement carte réussi",
],
'card_will_expire'=>[
'name'=>'prof - la carte va bientot expirer',
'notification_send'=>true,
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - carte va expirer]",
'notification_message'=>'la carte va expirer pour $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>true,
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - carte va expirer]",
'confirmation_message'=>'votre carte va expirer bientot, renouvellez-la sur $$__base_url__$$',
],
'card_expired'=>[
'name'=>'prof - la carte a expiré',
'notification_send'=>true,
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - carte expirée]",
'notification_message'=>'carte expirée pour $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>true,
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - carte expirée]",
'confirmation_message'=>'votre carte a expiré, renouvelez-la sur $$__base_url__$$',
],
'account_will_be_deleted'=>[
'name'=>'prof - le compte va être supprimé',
'notification_send'=>true,
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - compte bientot supprimé]",
'notification_message'=>'compte bientot supprimé pour $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>true,
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - compte bientot supprimé]",
'confirmation_message'=>'votre compte va bientot être supprimé sur $$__base_url__$$',
],
'account_deleted'=>[
'name'=>'prof - le compte a été supprimé',
'notification_send'=>true,
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - compte supprimé]",
'notification_message'=>'compte supprimé pour $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>true,
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - compte supprimé]",
'confirmation_message'=>'votre compte a été supprimé sur $$__base_url__$$',
],
'offer_will_expire'=>[
'name'=>"partenaire - l'offre arrive bientot a expiration",
'notification_send'=>true,
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /partenaire - offre va expirer]",
'notification_message'=>'offre va expirer pour $$user_login$$ : $$__user_post_url__$$',
'confirmation_send'=>true,
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - offre va expirer]",
'confirmation_message'=>'une de vos offre va expirer, rendez-vous sur $$__base_url__$$',
],
'offer_expired'=>[
'name'=>"partenaire - l'offre partenaire a expirée",
'notification_send'=>true,
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /partenaire - offre expirée]",
'notification_message'=>'offre expirée pour $$user_login$$ : $$__user_post_url__$$',
'confirmation_send'=>true,
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - offre expirée]",
'confirmation_message'=>'votre offre a expiré, pour la renouveler rendez-vous sur $$__base_url__$$',
],

View File

@@ -166,6 +166,10 @@
<div class="email_options_cipf">
<div class="vertical_wrapper_cipf">
<label for="<?php echo esc_html(stripslashes($name)); ?>_notification_from_cipf">de : </label>
<input type="text" id="<?php echo esc_html(stripslashes($name)); ?>_notification_from_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_notification_from" value="<?php echo esc_html(stripslashes($email_options['notification_from'])); ?>" />
</div>
<div class="vertical_wrapper_cipf">
<label for="<?php echo esc_html(stripslashes($name)); ?>_notification_to_cipf">destinataire : </label>
<input type="text" id="<?php echo esc_html(stripslashes($name)); ?>_notification_to_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_notification_to" value="<?php echo esc_html(stripslashes($email_options['notification_to'])); ?>" />
@@ -191,6 +195,10 @@
<div class="email_options_cipf">
<div class="vertical_wrapper_cipf">
<label for="<?php echo esc_html(stripslashes($name)); ?>_confirmation_from_cipf">de : </label>
<input type="text" id="<?php echo esc_html(stripslashes($name)); ?>_confirmation_from_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_confirmation_from" value="<?php echo esc_html(stripslashes($email_options['confirmation_from'])); ?>" />
</div>
<div class="vertical_wrapper_cipf">
<label for="<?php echo esc_html(stripslashes($name)); ?>_confirmation_subject_cipf">sujet : </label>
<input type="text" id="<?php echo esc_html(stripslashes($name)); ?>_confirmation_subject_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_confirmation_subject" value="<?php echo esc_html(stripslashes($email_options['confirmation_subject'])); ?>" />

View File

@@ -38,7 +38,7 @@ function prepare_emails_CIPF($email_name, $user_id) {
}
$user = get_user_by('id', $user_id);
$user_email = $user->user_email;
$headers = array('Content-Type: text/html; charset=UTF-8');
$header_content_type = 'Content-Type: text/html; charset=UTF-8';
$emails_option = Plgntls::get_option_safe($emails_option_object);
@@ -57,7 +57,15 @@ function prepare_emails_CIPF($email_name, $user_id) {
$tmp_email['to'] = $email['notification_to'];
$tmp_email['subject'] = $email['notification_subject'];
$tmp_email['message'] = $email['notification_message'];
$tmp_email['headers'] = $headers;
$tmp_email['headers'] = array();
$tmp_email['headers'][] = $header_content_type;
$from = $email['notification_from'];
if (empty($from)) {
$from = get_option('admin_email');
}
if (!empty($from)) {
$tmp_email['headers'][] = 'From:'.$from;
}
$emails[] = $tmp_email;
}
if ($email['confirmation_send']) {
@@ -65,7 +73,15 @@ function prepare_emails_CIPF($email_name, $user_id) {
$tmp_email['to'] = $user_email;
$tmp_email['subject'] = $email['confirmation_subject'];
$tmp_email['message'] = $email['confirmation_message'];
$tmp_email['headers'] = $headers;
$tmp_email['headers'] = array();
$tmp_email['headers'][] = $header_content_type;
$from = $email['confirmation_from'];
if (empty($from)) {
$from = get_option('admin_email');
}
if (!empty($from)) {
$tmp_email['headers'][] = 'From:'.$from;
}
$emails[] = $tmp_email;
}
return $emails;
@@ -82,6 +98,7 @@ function send_emails_CIPF($email_name, $user_id = null) {
}
foreach ($emails as $email) {
error_log('Email: ' . json_encode($email));
$sent = wp_mail($email['to'], $email['subject'], $email['message'], $email['headers']);
}
if (!$sent) {

View File

@@ -168,8 +168,14 @@ function update_paypal_credentials_CIPF($request, $option_name, $option_data, $o
function update_emails_settings_option_CIPF($request, $option_name, $option_data, $option_default) {
Plgntls::debug_infos();
/*
* loop through saved data option
* update them
* add them to the option that will be saved
*
*/
foreach ($option_data as $email_type => $email_options) {
$ret_update = update_email_by_type_CIPF($email_type, $email_options, $request);
$ret_update = update_email_by_type_CIPF($email_type, $email_options, $option_default[$email_type], $request);
if ($ret_update !== false) {
$option_data[$email_type] = $ret_update;
}
@@ -178,7 +184,6 @@ function update_emails_settings_option_CIPF($request, $option_name, $option_data
/*
* to reorder and add new data with the default data
* also take the name of the default
* not really good :p
*
*/
$new_option = array();
@@ -208,7 +213,7 @@ function update_emails_settings_option_CIPF($request, $option_name, $option_data
* utility function to update the emails
*
*/
function update_email_by_type_CIPF($email_type, $email_options, $request) {
function update_email_by_type_CIPF($email_type, $email_options, $email_default_options, $request) {
Plgntls::debug_infos();
$is_new = false;
@@ -224,20 +229,26 @@ function update_email_by_type_CIPF($email_type, $email_options, $request) {
* loop through all options to update them
*
*/
foreach ($email_options as $option => $value) {
if (!isset($request[$email_type.'_'.$option])) {
foreach ($email_default_options as $default_option => $default_value) {
if (!isset($request[$email_type.'_'.$default_option])) {
if (isset($email_options[$default_option])) {
continue;
}
$is_new = true;
$email_options[$default_option] = $default_value;
continue;
}
$new_value = $request[$email_type.'_'.$option];
$new_value = $request[$email_type.'_'.$default_option];
$value = $email_options[$default_option];
if ($new_value === $value) {
continue;
}
$is_new = true;
if ($option === 'notification_send' || $option === 'confirmation_send') {
$email_options[$option] = true;
if ($default_option === 'notification_send' || $default_option === 'confirmation_send') {
$email_options[$default_option] = true;
}
else {
$email_options[$option] = $new_value;
$email_options[$default_option] = $new_value;
}
}