updated email options
This commit is contained in:
@@ -4,7 +4,7 @@ Plugin Name: hggg_cipf
|
||||
Plugin URI:
|
||||
Description:
|
||||
Author: hugogogo
|
||||
Version: 0.5.8
|
||||
Version: 0.5.9
|
||||
Author URI:
|
||||
*/
|
||||
|
||||
@@ -309,6 +309,14 @@ contactez la fipf directement",
|
||||
'confirmation_subject'=>"[CIPF - offre expirée]",
|
||||
'confirmation_message'=>'votre offre a expiré, pour la renouveler rendez-vous sur $$__base_url__$$',
|
||||
],
|
||||
'cron_job'=>[
|
||||
'name'=>"cron-job - une fois par jour",
|
||||
'notification_send'=>true,
|
||||
'notification_from'=>'$$__admin_email__$$',
|
||||
'notification_to'=>'$$__admin_email__$$',
|
||||
'notification_subject'=>"[CIPF - cron job]",
|
||||
'notification_message'=>'la tache journaliere cron a bien fonctionné',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
* hide all acf fields with the class 'hide-for-fipf'
|
||||
*
|
||||
*/
|
||||
form#your-profile h2:has(+ .form-table .hide-group-for-fipf) {
|
||||
display: none;
|
||||
}
|
||||
form#your-profile .hide-for-fipf {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@@ -159,54 +159,72 @@
|
||||
|
||||
<div class="email_type_wrapper_cipf email_type_notification_wrapper_cipf">
|
||||
|
||||
<?php if (isset($email_options['notification_send'])) { ?>
|
||||
<div class="send_or_not_cipf">
|
||||
<input type="checkbox" id="<?php echo esc_html(stripslashes($name)); ?>_notification_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_notification_send" <?php if ($email_options['notification_send'] === true) {echo 'checked';} ?> />
|
||||
<input type="checkbox" id="<?php echo esc_html(stripslashes($name)); ?>_notification_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_notification_send" <?php if ($email_options['notification_send'] === 'on') {echo 'checked';} ?> />
|
||||
<label for="<?php echo esc_html(stripslashes($name)); ?>_notification_cipf">envoyer une notification ?</label>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="email_options_cipf">
|
||||
|
||||
<?php if (isset($email_options['notification_from'])) { ?>
|
||||
<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>
|
||||
<?php } ?>
|
||||
<?php if (isset($email_options['notification_to'])) { ?>
|
||||
<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'])); ?>" />
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if (isset($email_options['notification_subject'])) { ?>
|
||||
<div class="vertical_wrapper_cipf">
|
||||
<label for="<?php echo esc_html(stripslashes($name)); ?>_notification_subject_cipf">sujet : </label>
|
||||
<input type="text" id="<?php echo esc_html(stripslashes($name)); ?>_notification_subject_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_notification_subject" value="<?php echo esc_html(stripslashes($email_options['notification_subject'])); ?>" />
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if (isset($email_options['notification_message'])) { ?>
|
||||
<div class="vertical_wrapper_cipf">
|
||||
<label for="<?php echo esc_html(stripslashes($name)); ?>_notification_message_cipf">message : </label>
|
||||
<textarea id="<?php echo esc_html(stripslashes($name)); ?>_notification_message_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_notification_message"><?php echo esc_html(stripslashes($email_options['notification_message'])); ?></textarea>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="email_type_wrapper_cipf email_type_confirmation_wrapper_cipf">
|
||||
|
||||
<?php if (isset($email_options['confirmation_send'])) { ?>
|
||||
<div class="send_or_not_cipf">
|
||||
<input type="checkbox" id="<?php echo esc_html(stripslashes($name)); ?>_confirmation_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_confirmation_send" <?php if ($email_options['confirmation_send'] === true) {echo 'checked';} ?> />
|
||||
<input type="checkbox" id="<?php echo esc_html(stripslashes($name)); ?>_confirmation_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_confirmation_send" <?php if ($email_options['confirmation_send'] === 'on') {echo 'checked';} ?> />
|
||||
<label for="<?php echo esc_html(stripslashes($name)); ?>_confirmation_cipf">envoyer une confirmation ?</label>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="email_options_cipf">
|
||||
|
||||
<?php if (isset($email_options['confirmation_from'])) { ?>
|
||||
<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>
|
||||
<?php } ?>
|
||||
<?php if (isset($email_options['confirmation_subject'])) { ?>
|
||||
<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'])); ?>" />
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if (isset($email_options['confirmation_message'])) { ?>
|
||||
<div class="vertical_wrapper_cipf">
|
||||
<label for="<?php echo esc_html(stripslashes($name)); ?>_confirmation_message_cipf">message : </label>
|
||||
<textarea id="<?php echo esc_html(stripslashes($name)); ?>_confirmation_message_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_confirmation_message"><?php echo esc_html(stripslashes($email_options['confirmation_message'])); ?></textarea>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ function prepare_emails_CIPF($email_name, $user_id) {
|
||||
|
||||
|
||||
$emails = array();
|
||||
if ($email['notification_send']) {
|
||||
if (isset($email['notification_send']) && $email['notification_send'] === 'on') {
|
||||
$tmp_email = array();
|
||||
$tmp_email['to'] = $email['notification_to'];
|
||||
$tmp_email['subject'] = $email['notification_subject'];
|
||||
@@ -69,7 +69,7 @@ function prepare_emails_CIPF($email_name, $user_id) {
|
||||
}
|
||||
$emails[] = $tmp_email;
|
||||
}
|
||||
if ($email['confirmation_send']) {
|
||||
if (isset($email['confirmation_send']) && $email['confirmation_send'] === 'on') {
|
||||
$tmp_email = array();
|
||||
$tmp_email['to'] = $user_email;
|
||||
$tmp_email['subject'] = $email['confirmation_subject'];
|
||||
|
||||
@@ -70,6 +70,7 @@ function schedule_daily_checkup_CIPF() {
|
||||
add_action('init', 'schedule_daily_checkup_CIPF');
|
||||
function check_profs_and_partners_dates_CIPF() {
|
||||
Plgntls::debug_infos();
|
||||
error_log("daily cron job start...");
|
||||
|
||||
$profs_ids = get_all_profs_ids();
|
||||
foreach ($profs_ids as $prof_id) {
|
||||
@@ -83,6 +84,9 @@ function check_profs_and_partners_dates_CIPF() {
|
||||
foreach ($partner_pages_ids as $page_id) {
|
||||
handle_partner_offers_expire_CIPF($page_id);
|
||||
}
|
||||
|
||||
send_emails_CIPF('cron_job');
|
||||
error_log("...daily cron job end");
|
||||
}
|
||||
add_action('CIPF_daily_checkup', 'check_profs_and_partners_dates_CIPF');
|
||||
|
||||
|
||||
@@ -169,39 +169,18 @@ function update_emails_settings_option_CIPF($request, $option_name, $option_data
|
||||
Plgntls::debug_infos();
|
||||
|
||||
/*
|
||||
* loop through saved data option
|
||||
* update them
|
||||
* add them to the option that will be saved
|
||||
* first check if saved option has the same data as default option
|
||||
*
|
||||
*/
|
||||
foreach ($option_data as $email_type => $email_options) {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
$new_option = update_option_with_default_CIPF($option_data, $option_default);
|
||||
|
||||
|
||||
/*
|
||||
* to reorder and add new data with the default data
|
||||
* also take the name of the default
|
||||
* then update the option with the request
|
||||
*
|
||||
*/
|
||||
$new_option = array();
|
||||
foreach ($option_default as $email => $options) {
|
||||
if (isset($option_data[$email])) {
|
||||
$new_option[$email] = $option_data[$email];
|
||||
}
|
||||
else {
|
||||
// it means it was not in the saved data, but was added in the default
|
||||
$ret_update = update_email_by_type_CIPF($email, $options, $option_default[$email], $request);
|
||||
if ($ret_update !== false) {
|
||||
$new_option[$email] = $ret_update;
|
||||
}
|
||||
else {
|
||||
$new_option[$email] = $options;
|
||||
}
|
||||
}
|
||||
$new_option[$email]['name'] = $options['name'];
|
||||
foreach ($new_option as $email_type => $email_options) {
|
||||
$new_option[$email_type] = update_email_type_with_request_CIPF($email_type, $email_options, $request);
|
||||
}
|
||||
|
||||
Plgntls::update_option_safe($option_name, $new_option);
|
||||
@@ -209,59 +188,73 @@ function update_emails_settings_option_CIPF($request, $option_name, $option_data
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* utility function to update the emails
|
||||
* utility
|
||||
*
|
||||
*/
|
||||
function update_email_by_type_CIPF($email_type, $email_options, $email_default_options, $request) {
|
||||
function update_option_with_default_CIPF($option_data, $option_default) {
|
||||
Plgntls::debug_infos();
|
||||
$is_new = false;
|
||||
|
||||
/*
|
||||
* set notification/confirmation_send to false by default,
|
||||
* because the request only contains the value 'on' if checked, nothing for false
|
||||
*
|
||||
*/
|
||||
$email_options['notification_send'] = false;
|
||||
$email_options['confirmation_send'] = false;
|
||||
|
||||
/*
|
||||
* loop through all options to update them
|
||||
*
|
||||
*/
|
||||
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.'_'.$default_option];
|
||||
$value = $email_options[$default_option];
|
||||
if ($new_value === $value) {
|
||||
continue;
|
||||
}
|
||||
$is_new = true;
|
||||
if ($default_option === 'notification_send' || $default_option === 'confirmation_send') {
|
||||
$email_options[$default_option] = true;
|
||||
$new_option_values = array();
|
||||
foreach ($option_default as $email_type => $email_default_options) {
|
||||
if (!isset($option_data[$email_type])) {
|
||||
$new_option_values[$email_type] = $email_default_options;
|
||||
}
|
||||
else {
|
||||
$email_options[$default_option] = $new_value;
|
||||
$new_email_options = update_email_type_with_default_CIPF($option_data[$email_type], $email_default_options);
|
||||
$new_option_values[$email_type] = $new_email_options;
|
||||
}
|
||||
}
|
||||
return $new_option_values;
|
||||
}
|
||||
function update_email_type_with_default_CIPF($email_options, $email_default_options) {
|
||||
Plgntls::debug_infos();
|
||||
|
||||
if ($is_new === false) {
|
||||
return false;
|
||||
$new_email_type = array();
|
||||
foreach ($email_default_options as $default_key => $default_value) {
|
||||
if (!isset($email_options[$default_key])) {
|
||||
$new_email_type[$default_key] = $default_value;
|
||||
}
|
||||
else {
|
||||
$new_email_type[$default_key] = $email_options[$default_key];
|
||||
}
|
||||
}
|
||||
else {
|
||||
return $email_options;
|
||||
return $new_email_type;
|
||||
}
|
||||
function update_email_type_with_request_CIPF($email_type, $email_options, $request) {
|
||||
Plgntls::debug_infos();
|
||||
|
||||
foreach ($email_options as $email_key => $email_value) {
|
||||
/*
|
||||
* special update for notification/confirmation_send
|
||||
* default them to false, since they will only be in request if they value 'on'
|
||||
*
|
||||
*/
|
||||
if (in_array($email_key, array('notification_send', 'confirmation_send'))) {
|
||||
$email_options[$email_key] = 'off';
|
||||
}
|
||||
|
||||
/*
|
||||
* search in request needs the prefix
|
||||
*
|
||||
*/
|
||||
$request_name = $email_type.'_'.$email_key;
|
||||
if (isset($request[$request_name])) {
|
||||
$email_options[$email_key] = $request[$request_name];
|
||||
}
|
||||
}
|
||||
return $email_options;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user