can choose the email for registration, and wether to send one or not

This commit is contained in:
asus
2024-03-27 13:06:48 +01:00
parent 0808c83589
commit ab6d825724
11 changed files with 384 additions and 140 deletions

View File

@@ -12,13 +12,25 @@ if (!defined('ABSPATH')) {
function add_plugin_content_CIPF() {
PLGNTLS_class::debug_infos();
/*
* paypal
*
$option_paypal = PLGNTLS_class::OPTION_PAYPAL;
*/
$admin_post_paypal = PLGNTLS_class::ADMIN_POST_PAYPAL;
$nonce_paypal = PLGNTLS_class::ADMIN_MENU_NONCE_PAYPAL;
$paypal_inputs = PLGNTLS_class::ADMIN_MENU_PAYPAL_INPUTS;
$paypal_credentials = get_paypal_options_CIPF();
/*
* registration email
*
$option_email = PLGNTLS_class::OPTION_EMAIL;
*/
$admin_post_email_registration = PLGNTLS_class::ADMIN_POST_EMAIL_REGISTRATION;
$nonce_email = PLGNTLS_class::ADMIN_MENU_NONCE_EMAIL_REGISTRATION;
$email_registration = get_email_registration_option_CIPF();
ob_start();
include(PLGNTLS_class::root_path() . '/html/menu/cipf_menu.html');
$html = ob_get_clean();
@@ -27,100 +39,13 @@ function add_plugin_content_CIPF() {
/*
* use this hook 'admin_post_{$action}' to receive a form post
* https://developer.wordpress.org/reference/hooks/admin_post_action/
*
* add the url to the action atrtibute of form, and the value of the action in an hidden input
* <form method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>">
* <input type="hidden" name="action" value="<?php echo $admin_post_patches; ?>">
* this is used to redirect when handling the reception of post form
*
*/
function paypal_credentials_CIPF() {
PLGNTLS_class::debug_infos();
$nonce_paypal = PLGNTLS_class::ADMIN_MENU_NONCE_PAYPAL;
if (!isset($_POST[$nonce_paypal['_name']])) {
redirect_menu_referer_CIPF($_POST);
exit;
}
if (!wp_verify_nonce($_POST[$nonce_paypal['_name']], $nonce_paypal['_action'])) {
redirect_menu_referer_CIPF($_POST);
exit;
}
// do actions here
update_paypal_credentials_CIPF($_POST);
redirect_menu_referer_CIPF($_POST);
}
add_action('admin_post_'.PLGNTLS_class::ADMIN_POST_PAYPAL, 'paypal_credentials_CIPF');
function update_paypal_credentials_CIPF($post) {
PLGNTLS_class::debug_infos();
$paypal_inputs = PLGNTLS_class::ADMIN_MENU_PAYPAL_INPUTS;
$option_paypal = PLGNTLS_class::OPTION_PAYPAL;
error_log("received form, _POST: " . json_encode($post));
/*
* is sandbox or live ?
*
*/
$is_sandbox = false;
if (!isset($post[$paypal_inputs['sandbox_or_live']])) {
return;
}
if ($post[$paypal_inputs['sandbox_or_live']] === 'sandbox') {
$is_sandbox = true;
}
else if ($post[$paypal_inputs['sandbox_or_live']] === 'live') {
$is_sandbox = false;
}
else {
return;
}
/*
* client id
*
*/
$client_id = '';
if (!isset($post[$paypal_inputs['client_id']])) {
return;
}
else {
$client_id = $post[$paypal_inputs['client_id']];
}
/*
* client secret
*
*/
$client_secret = '';
if (!isset($post[$paypal_inputs['client_secret']])) {
return;
}
else {
$client_secret = $post[$paypal_inputs['client_secret']];
}
/*
* update the option with new credentials
*
*/
set_paypal_options_CIPF($is_sandbox, $client_id, $client_secret);
}
function redirect_menu_referer_CIPF($post) {
PLGNTLS_class::debug_infos();
if (!isset($post)) {

View File

@@ -0,0 +1,90 @@
<?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!');
}
/*
* use this hook 'admin_post_{$action}' to receive a form post
* https://developer.wordpress.org/reference/hooks/admin_post_action/
*
* add the url to the action atrtibute of form, and the value of the action in an hidden input
* <form method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>">
* <input type="hidden" name="action" value="<?php echo $admin_post_patches; ?>">
*
*/
function change_email_registration_CIPF() {
PLGNTLS_class::debug_infos();
$nonce_email = PLGNTLS_class::ADMIN_MENU_NONCE_EMAIL_REGISTRATION;
if (!isset($_POST[$nonce_email['_name']])) {
redirect_menu_referer_CIPF($_POST);
exit;
}
if (!wp_verify_nonce($_POST[$nonce_email['_name']], $nonce_email['_action'])) {
redirect_menu_referer_CIPF($_POST);
exit;
}
// do actions here
update_email_registration_option_CIPF($_POST);
redirect_menu_referer_CIPF($_POST);
}
add_action('admin_post_'.PLGNTLS_class::ADMIN_POST_EMAIL_REGISTRATION, 'change_email_registration_CIPF');
function update_email_registration_option_CIPF($post) {
PLGNTLS_class::debug_infos();
/*
* email
*
*/
$email = '';
if (!isset($post['email'])) {
return;
}
else {
$email = $post['email'];
}
/*
* is email ?
*
*/
$is_email_prof = false;
if (isset($post['is_email_prof']) && $post['is_email_prof'] === 'on') {
$is_email_prof = true;
}
$is_email_partner = false;
if (isset($post['is_email_partner']) && $post['is_email_partner'] === 'on') {
$is_email_partner = true;
}
/*
* update the option with new values
*
*/
set_email_registration_CIPF($email, $is_email_prof, $is_email_partner);
}
?>

View File

@@ -0,0 +1,106 @@
<?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!');
}
/*
* use this hook 'admin_post_{$action}' to receive a form post
* https://developer.wordpress.org/reference/hooks/admin_post_action/
*
* add the url to the action atrtibute of form, and the value of the action in an hidden input
* <form method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>">
* <input type="hidden" name="action" value="<?php echo $admin_post_patches; ?>">
*
*/
function paypal_credentials_CIPF() {
PLGNTLS_class::debug_infos();
$nonce_paypal = PLGNTLS_class::ADMIN_MENU_NONCE_PAYPAL;
if (!isset($_POST[$nonce_paypal['_name']])) {
redirect_menu_referer_CIPF($_POST);
exit;
}
if (!wp_verify_nonce($_POST[$nonce_paypal['_name']], $nonce_paypal['_action'])) {
redirect_menu_referer_CIPF($_POST);
exit;
}
// do actions here
update_paypal_credentials_CIPF($_POST);
redirect_menu_referer_CIPF($_POST);
}
add_action('admin_post_'.PLGNTLS_class::ADMIN_POST_PAYPAL, 'paypal_credentials_CIPF');
function update_paypal_credentials_CIPF($post) {
PLGNTLS_class::debug_infos();
/*
* is sandbox or live ?
*
*/
$is_sandbox = false;
if (!isset($post['sandbox_or_live'])) {
return;
}
if ($post['sandbox_or_live'] === 'sandbox') {
$is_sandbox = true;
}
else if ($post['sandbox_or_live'] === 'live') {
$is_sandbox = false;
}
else {
return;
}
/*
* client id
*
*/
$client_id = '';
if (!isset($post['client_id'])) {
return;
}
else {
$client_id = $post['client_id'];
}
/*
* client secret
*
*/
$client_secret = '';
if (!isset($post['client_secret'])) {
return;
}
else {
$client_secret = $post['client_secret'];
}
/*
* update the option with new credentials
*
*/
set_paypal_options_CIPF($is_sandbox, $client_id, $client_secret);
}
?>