$success, 'failure' => $failure, 'problem' => $problem, ); Plgntls::update_option_safe($option_name, $data); } function update_paypal_credentials_CIPF($request, $option_name, $option_data, $option_default) { Plgntls::debug_infos(); /* * is sandbox or live ? * */ $is_sandbox = false; if (!isset($request['sandbox_or_live'])) { return; } if ($request['sandbox_or_live'] === 'sandbox') { $is_sandbox = true; } else if ($request['sandbox_or_live'] === 'live') { $is_sandbox = false; } else { return; } /* * client id * */ $client_id = ''; if (!isset($request['client_id'])) { return; } else { $client_id = $request['client_id']; } /* * client secret * */ $client_secret = ''; if (!isset($request['client_secret'])) { return; } else { $client_secret = $request['client_secret']; } /* * update the option with new credentials * set_paypal_options_CIPF($is_sandbox, $client_id, $client_secret); */ $data = array( 'is_sandbox' => $is_sandbox, 'client_id' => $client_id, 'client_secret' => $client_secret, ); Plgntls::update_option_safe($option_name, $data); } /* * update emails * */ function update_emails_settings_option_CIPF($request, $option_name, $option_data, $option_default) { Plgntls::debug_infos(); foreach ($option_data as $email_type => $email_options) { $ret_update = update_email_by_type_CIPF($email_type, $email_options, $request); if ($ret_update !== false) { $option_data[$email_type] = $ret_update; } } /* * 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); } /* * utility function to update the emails * */ function update_email_by_type_CIPF($email_type, $email_options, $request) { 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_options as $option => $value) { if (!isset($request[$email_type.'_'.$option])) { continue; } $new_value = $request[$email_type.'_'.$option]; if ($new_value === $value) { continue; } $is_new = true; if ($option === 'notification_send' || $option === 'confirmation_send') { $email_options[$option] = true; } else { $email_options[$option] = $new_value; } } if ($is_new === false) { return false; } else { return $email_options; } } ?>