updated plgntls options to improve default with new options

This commit is contained in:
asus
2024-04-03 22:43:05 +02:00
parent 1628eac171
commit 91a67d955b
7 changed files with 118 additions and 92 deletions

View File

@@ -167,24 +167,38 @@ 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();
//error_log("---");
//error_log("request: " . json_encode($request));
//error_log("option_data bedore: " . json_encode($option_data));
foreach ($option_data as $email_type => $email_options) {
//error_log("email_type: " . $email_type);
// if ($email_type === '_name') {
// continue;
// }
// $ret_email = update_email_by_type_CIPF($email_type, $email_options, $request);
// if ($ret_email !== false) {
// $option_data[$email_type] = $ret_email;
// }
$option_data[$email_type] = update_email_by_type_CIPF($email_type, $email_options, $request);
$ret_update = update_email_by_type_CIPF($email_type, $email_options, $request);
if ($ret_update !== false) {
$option_data[$email_type] = $ret_update;
}
}
//error_log("option_data after : " . json_encode($option_data));
Plgntls::update_option_safe($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();
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, $request);
if ($ret_update !== false) {
$new_option[$email] = $ret_update;
}
else {
$new_option[$email] = $options;
}
}
$new_option[$email]['name'] = $options['name'];
}
Plgntls::update_option_safe($option_name, $new_option);
}
@@ -195,10 +209,7 @@ function update_emails_settings_option_CIPF($request, $option_name, $option_data
*/
function update_email_by_type_CIPF($email_type, $email_options, $request) {
Plgntls::debug_infos();
//error_log("email type: " . $email_type);
//if ($email_type === '_name') {
// return false;
//}
$is_new = false;
/*
* set notification/confirmation_send to false by default,
@@ -220,19 +231,21 @@ function update_email_by_type_CIPF($email_type, $email_options, $request) {
if ($new_value === $value) {
continue;
}
$is_new = true;
if ($option === 'notification_send' || $option === 'confirmation_send') {
$email_options[$option] = true;
}
else {
// error_log("option: " . $option);
// error_log("- previous value: " . $value);
// error_log("- newvalue : " . $new_value);
$email_options[$option] = $new_value;
}
}
//error_log("email_options: " . json_encode($email_options));
return $email_options;
if ($is_new === false) {
return false;
}
else {
return $email_options;
}
}