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);
}
?>

View File

@@ -1,59 +1,116 @@
<?php
function filter_email_wp_CIPF($args) {
PLGNTLS_class::debug_infos();
error_log("---args: " . json_encode($args));
return $args;
}
//add_filter('wp_mail', 'filter_email_wp_CIPF', 10, 1);
/*
prof registration :
{"to":"setrujegno@gufum.com","subject":"[La carte internationale des professeurs de fran\u00e7ais] Login Details","message":"Username: setrujegno\r\n\r\nTo set your password, visit the following address:\r\n\r\n<https:\/\/local-cipf-plugin.com\/?action=reset_password&key=1VB2c9x9IKrWqhlVFwlY&login=setrujegno>\r\n","headers":"","attachments":[]}
prof login :
-nothing-
prof reset password :
{"to":"setrujegno@gufum.com","subject":"[La carte internationale des professeurs de fran\u00e7ais] Password Reset","message":"Someone has requested a password reset for the following account:\r\n\r\nSite Name: La carte internationale des professeurs de fran\u00e7ais\r\n\r\nUsername: setrujegno\r\n\r\nIf this was a mistake, just ignore this email and nothing will happen.\r\n\r\nTo reset your password, visit the following address:\r\n\r\nhttps:\/\/local-cipf-plugin.com\/?action=reset_password&key=COiFnR4qJvyaSSky8FZt&login=setrujegno\r\n","headers":"","attachments":[]}
partenaire register :
{"to":"justatodra@gufum.com","subject":"[La carte internationale des professeurs de fran\u00e7ais] Login Details","message":"Username: justatodra\r\n\r\nTo set your password, visit the following address:\r\n\r\n<https:\/\/local-cipf-plugin.com\/?action=reset_password&key=K3rT3VQ0vlQrVnicjTJ7&login=justatodra>\r\n","headers":"","attachments":[]}
* it means someone outside wp is accessing the file, in this case kill it.
*/
if (!defined('ABSPATH')) {
die('You can not access this file!');
}
/*
* ../../../wordpress_docker/volumes/wp_volume/wp-includes/pluggable.php
* 2210 : $send_notification_to_user = apply_filters( 'wp_send_new_user_notification_to_user', true, $user );
*
*/
function send_registration_email_CIPF($send, $user) {
PLGNTLS_class::debug_infos();
$role_partner = PLGNTLS_class::ROLE_PARTNER;
$role_prof = PLGNTLS_class::ROLE_PROF;
if (user_can($user, $role_prof)) {
$send = is_email_registration_prof_CIPF();
}
else if (user_can($user, $role_partner)) {
$send = is_email_registration_partner_CIPF();
}
return $send;
}
add_filter( 'wp_send_new_user_notification_to_user', 'send_registration_email_CIPF', 10, 2);
/*
* use this filter to modify the message of the notification email
* you can use the specials custer expansions as $$<field>$$
* ../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/easy-login-woocommerce/includes/class-xoo-el-form-handler.php
* 24 : add_filter( 'wp_new_user_notification_email', array( __CLASS__, 'newuser_notification_email' ), 20, 3 );
*
*/
function filter_regitration_email_CIPF($wp_new_user_notification_email, $user, $blogname) {
error_log("- wp_new_user_notification_email: ". json_encode($wp_new_user_notification_email));
error_log("- user: ". json_encode($user));
error_log("- blogname: ". json_encode($blogname));
$wp_new_user_notification_email['message'] = 'poutpout $$nickname$$';
PLGNTLS_class::debug_infos();
$wp_new_user_notification_email['message'] = get_email_registration_CIPF();
return $wp_new_user_notification_email;
}
//add_filter('wp_new_user_notification_email', 'filter_regitration_email_CIPF', 21, 3);
add_filter('wp_new_user_notification_email', 'filter_regitration_email_CIPF', 21, 3);
/*
prof register :
- wp_new_user_notification_email: {
"to":"derzudospi@gufum.com",
"subject":"[%s] Login Details",
"message":"Username: derzudospi\r\n\r\nTo set your password, visit the following address:\r\n\r\nhttps:\/\/local-cipf-plugin.com\/wp-login.php?action=rp&key=NxtYeVuMfdQdcb1t2fD4&login=derzudospi\r\n\r\nhttps:\/\/local-cipf-plugin.com\/wp-login.php\r\n",
"headers":""
function set_email_registration_CIPF($email, $is_email_prof, $is_email_partner) {
PLGNTLS_class::debug_infos();
$option_email = PLGNTLS_class::OPTION_EMAIL;
$option_data = array();
$option_data['email'] = $email;
$option_data['is_email_prof'] = $is_email_prof;
$option_data['is_email_partner'] = $is_email_partner;
update_option($option_email['_name'], serialize($option_data), '', 'no');
}
- user: {
"data":{"ID":"221","user_login":"derzudospi","user_pass":"$P$BqmuxKGayo4bNTaGasmrwn46mXP6gv.","user_nicename":"derzudospi","user_email":"derzudospi@gufum.com","user_url":"","user_registered":"2024-03-26 21:32:32","user_activation_key":"","user_status":"0","display_name":"derzudospi"},"ID":221,"caps":{"professeur__professeure":true},"cap_key":"wp_503463_capabilities","roles":["professeur__professeure"],"allcaps":{"unfiltered_html":true,"upload_files":true,"campaign_form_submit":true,"copy_posts":true,"delete_others_posts":true,"delete_posts":true,"delete_private_posts":true,"delete_published_posts":true,"edit_others_posts":true,"edit_posts":true,"edit_private_posts":true,"edit_published_posts":true,"manage_links":true,"publish_posts":true,"read_private_posts":true,"delete_others_pages":true,"delete_pages":true,"delete_private_pages":true,"delete_published_pages":true,"edit_others_pages":true,"edit_pages":true,"edit_private_pages":true,"edit_published_pages":true,"manage_categories":true,"publish_pages":true,"read_private_pages":true,"e2pdf":true,"e2pdf_templates":true,"e2pdf_settings":true,"e2pdf_license":true,"e2pdf_debug":true,"professeur__professeure":true},"filter":null}
- blogname: "La carte internationale des professeurs de fran\u00e7ais"
*/
function get_email_registration_option_CIPF() {
PLGNTLS_class::debug_infos();
$option_email = PLGNTLS_class::OPTION_EMAIL;
$email_option_serialized = get_option($option_email['_name']);
if (false === $email_option_serialized) {
add_option($option_email['_name'], serialize($option_email['_default']), '', 'no');
$email_option_serialized = get_option($option_email['_name']);
}
return unserialize($email_option_serialized);
}
function get_email_registration_CIPF() {
PLGNTLS_class::debug_infos();
$email_option = get_email_registration_option_CIPF();
return $email_option['email'];
}
function is_email_registration_prof_CIPF() {
PLGNTLS_class::debug_infos();
$email_option = get_email_registration_option_CIPF();
return $email_option['is_email_prof'];
}
function is_email_registration_partner_CIPF() {
PLGNTLS_class::debug_infos();
$email_option = get_email_registration_option_CIPF();
return $email_option['is_email_partner'];
}

View File

@@ -19,7 +19,6 @@ if (!defined('ABSPATH')) {
*/
function add_fields_register_CIPF($args) {
PLGNTLS_class::debug_infos();
// error_log("args : " . json_encode($args));
$role_partner = PLGNTLS_class::ROLE_PARTNER;
$slug_partner_registration = PLGNTLS_class::SLUG_PARTNER_REGISTRATION;
$input_hidden_role = PLGNTLS_class::INPUT_HIDDEN_ROLE;