From d2b296721835ae19e1c5de80b1db64fa2593f840 Mon Sep 17 00:00:00 2001 From: asus Date: Wed, 3 Apr 2024 14:21:33 +0200 Subject: [PATCH] fixed error with automatically adding _name to option --- plugins/cipf_plugin/php/admin_menu.php | 29 ++++++++++++++------------ plugins/cipf_plugin/plgntls_class.php | 17 +++++++++++---- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/plugins/cipf_plugin/php/admin_menu.php b/plugins/cipf_plugin/php/admin_menu.php index e4fad7a..2799320 100644 --- a/plugins/cipf_plugin/php/admin_menu.php +++ b/plugins/cipf_plugin/php/admin_menu.php @@ -35,9 +35,10 @@ function add_plugin_content_CIPF() { * options * */ - $option_paypal = Plgntls::get_option_safe($option_paypal_object); - $option_payment = Plgntls::get_option_safe($option_payment_object); - $option_emails = Plgntls::get_option_safe($option_emails_object); + $option_paypal = Plgntls::get_option_safe($option_paypal_object, true); + $option_payment = Plgntls::get_option_safe($option_payment_object, true); + //delete_option($option_emails_object['_name']); + $option_emails = Plgntls::get_option_safe($option_emails_object, true); ob_start(); include(Plgntls::root_path() . '/html/menu/cipf_menu.html'); @@ -171,13 +172,15 @@ function update_emails_settings_option_CIPF($request, $option_name, $option_data //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; - } + // 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); } //error_log("option_data after : " . json_encode($option_data)); @@ -193,9 +196,9 @@ 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; - } + //if ($email_type === '_name') { + // return false; + //} /* * set notification/confirmation_send to false by default, diff --git a/plugins/cipf_plugin/plgntls_class.php b/plugins/cipf_plugin/plgntls_class.php index 96ea717..bbed4c6 100644 --- a/plugins/cipf_plugin/plgntls_class.php +++ b/plugins/cipf_plugin/plgntls_class.php @@ -1066,7 +1066,7 @@ class Plgntls { - public static function get_option_safe($option) { + public static function get_option_safe($option, $name = false) { /* * first init option, in case it was not already * it will returns the option name or false @@ -1098,11 +1098,20 @@ class Plgntls { } /* - * if option is an array and _name is not define, - * add the _name entry to the output, to facilitate the access to the name + * $name is true, + * add the _name entry to the output, + * it will overwrite any existing _name key + * if option is not an array, + * make it array and put the value into a '_value' key + * * */ - if (is_array($ret_option) && !isset($ret_option['_name'])) { + if ($name === true) { + if (!is_array($ret_option)) { + $value = $ret_option; + $ret_option = array(); + $ret_option['_value'] = $value; + } $ret_option['_name'] = $option_name; }