240 lines
4.5 KiB
PHP
240 lines
4.5 KiB
PHP
<?php
|
|
|
|
/*
|
|
* it means someone outside wp is accessing the file, in this case kill it.
|
|
*/
|
|
if (!defined('ABSPATH')) {
|
|
die('You can not access this file!');
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
* menu plugin
|
|
*/
|
|
function cipf_plugin_menu_CIPF() {
|
|
Plgntls::debug_infos();
|
|
Plgntls::add_menu('add_plugin_content_CIPF');
|
|
}
|
|
add_action('admin_menu', 'cipf_plugin_menu_CIPF');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function add_plugin_content_CIPF() {
|
|
Plgntls::debug_infos();
|
|
$option_paypal_object = Cipf::OPTION_PAYPAL;
|
|
$option_payment_object = Cipf::OPTION_PAYMENT;
|
|
$option_emails_object = Cipf::OPTION_EMAILS;
|
|
|
|
/*
|
|
* 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);
|
|
|
|
ob_start();
|
|
include(Plgntls::root_path() . '/html/menu/cipf_menu.html');
|
|
$html = ob_get_clean();
|
|
echo $html;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function update_payment_messages_option_CIPF($request, $option_name, $option_data, $option_default) {
|
|
Plgntls::debug_infos();
|
|
|
|
/*
|
|
* success
|
|
* failure
|
|
*
|
|
*/
|
|
$success = '';
|
|
$failure = '';
|
|
$problem = '';
|
|
if (!isset($request['message_success'])) {
|
|
return;
|
|
}
|
|
if (!isset($request['message_failure'])) {
|
|
return;
|
|
}
|
|
if (!isset($request['message_problem'])) {
|
|
return;
|
|
}
|
|
$success = $request['message_success'];
|
|
$failure = $request['message_failure'];
|
|
$problem = $request['message_problem'];
|
|
|
|
|
|
/*
|
|
* update the option with new values
|
|
*
|
|
set_payment_messages_option_CIPF($success, $failure);
|
|
*/
|
|
$data = array(
|
|
'success' => $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();
|
|
|
|
//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;
|
|
}
|
|
}
|
|
//error_log("option_data after : " . json_encode($option_data));
|
|
|
|
Plgntls::update_option_safe($option_name, $option_data);
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
* utility function to update the emails
|
|
*
|
|
*/
|
|
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;
|
|
}
|
|
|
|
/*
|
|
* 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;
|
|
}
|
|
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;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|