268 lines
5.5 KiB
PHP
268 lines
5.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
|
|
*
|
|
*/
|
|
//delete_option($option_paypal_object['_name']);
|
|
$option_paypal = Plgntls::get_option_safe($option_paypal_object, true);
|
|
//delete_option($option_payment_object['_name']);
|
|
$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');
|
|
$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();
|
|
|
|
if (!isset(
|
|
$request['sandbox_or_live'],
|
|
$request['live_client_id'],
|
|
$request['live_client_secret'],
|
|
$request['sandbox_client_id'],
|
|
$request['sandbox_client_secret'],
|
|
)) {
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* force price 1 cent ?
|
|
*
|
|
*/
|
|
$force_1_cent = false;
|
|
if (isset($request['force_1_cent'])) {
|
|
$force_1_cent = true;
|
|
}
|
|
|
|
/*
|
|
* is sandbox or live ?
|
|
*
|
|
*/
|
|
$is_sandbox = false;
|
|
if ($request['sandbox_or_live'] === 'sandbox') {
|
|
$is_sandbox = true;
|
|
}
|
|
else if ($request['sandbox_or_live'] === 'live') {
|
|
$is_sandbox = false;
|
|
}
|
|
|
|
|
|
/*
|
|
* ids
|
|
*
|
|
*/
|
|
$live_client_id = $request['live_client_id'];
|
|
$live_client_secret = $request['live_client_secret'];
|
|
$sandbox_client_id = $request['sandbox_client_id'];
|
|
$sandbox_client_secret = $request['sandbox_client_secret'];
|
|
|
|
|
|
/*
|
|
* update the option with new credentials
|
|
*
|
|
set_paypal_options_CIPF($is_sandbox, $client_id, $client_secret);
|
|
*/
|
|
$data = array(
|
|
'force_1_cent' => $force_1_cent,
|
|
'is_sandbox' => $is_sandbox,
|
|
'live_client_id' => $live_client_id,
|
|
'live_client_secret' => $live_client_secret,
|
|
'sandbox_client_id' => $sandbox_client_id,
|
|
'sandbox_client_secret' => $sandbox_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();
|
|
|
|
/*
|
|
* loop through saved data option
|
|
* update them
|
|
* add them to the option that will be saved
|
|
*
|
|
*/
|
|
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;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* to reorder and add new data with the default data
|
|
* also take the name of the default
|
|
*
|
|
*/
|
|
$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, $email_default_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_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;
|
|
}
|
|
else {
|
|
$email_options[$default_option] = $new_value;
|
|
}
|
|
}
|
|
|
|
if ($is_new === false) {
|
|
return false;
|
|
}
|
|
else {
|
|
return $email_options;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|