From ab6d825724a1a939be47f38bdd11956a45600be8 Mon Sep 17 00:00:00 2001 From: asus Date: Wed, 27 Mar 2024 13:06:48 +0100 Subject: [PATCH] can choose the email for registration, and wether to send one or not --- plugins/cipf_plugin/cipf_plugin.php | 4 +- plugins/cipf_plugin/html/menu/cipf_menu.html | 46 ++++++- .../php/admin_menu/menu_content.php | 111 +++------------ .../cipf_plugin/php/admin_menu/post_email.php | 90 ++++++++++++ .../php/admin_menu/post_paypal.php | 106 ++++++++++++++ .../cipf_plugin/php/email_registration.php | 129 +++++++++++++----- plugins/cipf_plugin/php/partners_register.php | 1 - plugins/cipf_plugin/utils/plgntls_class.php | 13 +- plugins/custer/custer.php | 2 +- plugins/custer/filter_mail.php | 19 ++- plugins/custer/format_user_infos.php | 3 - 11 files changed, 384 insertions(+), 140 deletions(-) create mode 100644 plugins/cipf_plugin/php/admin_menu/post_email.php create mode 100644 plugins/cipf_plugin/php/admin_menu/post_paypal.php diff --git a/plugins/cipf_plugin/cipf_plugin.php b/plugins/cipf_plugin/cipf_plugin.php index a217350..be7a8d3 100644 --- a/plugins/cipf_plugin/cipf_plugin.php +++ b/plugins/cipf_plugin/cipf_plugin.php @@ -4,7 +4,7 @@ Plugin Name: cipf_plugin Plugin URI: Description: Author: hugogogo -Version: 0.4.1 +Version: 0.4.2.1 Author URI: */ @@ -31,6 +31,8 @@ include_once(PLGNTLS_class::root_path() . 'utils/console_log.php'); include_once(PLGNTLS_class::root_path() . 'php/admin_menu/admin_menu.php'); include_once(PLGNTLS_class::root_path() . 'php/admin_menu/admin_menu_toggle.php'); include_once(PLGNTLS_class::root_path() . 'php/admin_menu/menu_content.php'); +include_once(PLGNTLS_class::root_path() . 'php/admin_menu/post_paypal.php'); +include_once(PLGNTLS_class::root_path() . 'php/admin_menu/post_email.php'); include_once(PLGNTLS_class::root_path() . 'php/paypal/paypal.php'); diff --git a/plugins/cipf_plugin/html/menu/cipf_menu.html b/plugins/cipf_plugin/html/menu/cipf_menu.html index a04300d..ca05605 100644 --- a/plugins/cipf_plugin/html/menu/cipf_menu.html +++ b/plugins/cipf_plugin/html/menu/cipf_menu.html @@ -1,6 +1,12 @@ +

paypal credentials

@@ -26,15 +42,41 @@
- /> + />
- /> + />
+ + +

email a la creation de compte

+
+ + + +
+ + +
+ +
+ /> + +
+ +
+ /> + +
+ + +
+ diff --git a/plugins/cipf_plugin/php/admin_menu/menu_content.php b/plugins/cipf_plugin/php/admin_menu/menu_content.php index 1e90033..8a3822a 100644 --- a/plugins/cipf_plugin/php/admin_menu/menu_content.php +++ b/plugins/cipf_plugin/php/admin_menu/menu_content.php @@ -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 -*
-* +* 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)) { diff --git a/plugins/cipf_plugin/php/admin_menu/post_email.php b/plugins/cipf_plugin/php/admin_menu/post_email.php new file mode 100644 index 0000000..c746ad8 --- /dev/null +++ b/plugins/cipf_plugin/php/admin_menu/post_email.php @@ -0,0 +1,90 @@ +"> +* +* +*/ +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); +} + + + + + +?> diff --git a/plugins/cipf_plugin/php/admin_menu/post_paypal.php b/plugins/cipf_plugin/php/admin_menu/post_paypal.php new file mode 100644 index 0000000..111963a --- /dev/null +++ b/plugins/cipf_plugin/php/admin_menu/post_paypal.php @@ -0,0 +1,106 @@ +"> +* +* +*/ +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); +} + + + + +?> diff --git a/plugins/cipf_plugin/php/email_registration.php b/plugins/cipf_plugin/php/email_registration.php index c1ecd5b..0fe314e 100644 --- a/plugins/cipf_plugin/php/email_registration.php +++ b/plugins/cipf_plugin/php/email_registration.php @@ -1,59 +1,116 @@ \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\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 $$$$ * ../../../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']; +} + + + diff --git a/plugins/cipf_plugin/php/partners_register.php b/plugins/cipf_plugin/php/partners_register.php index fea63a5..2974d7f 100644 --- a/plugins/cipf_plugin/php/partners_register.php +++ b/plugins/cipf_plugin/php/partners_register.php @@ -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; diff --git a/plugins/cipf_plugin/utils/plgntls_class.php b/plugins/cipf_plugin/utils/plgntls_class.php index b6f38c5..cdacb5b 100644 --- a/plugins/cipf_plugin/utils/plgntls_class.php +++ b/plugins/cipf_plugin/utils/plgntls_class.php @@ -127,13 +127,22 @@ class PLGNTLS_class { 'client_secret'=>'EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-', ], ]; + const OPTION_EMAIL = [ + '_name'=>'cipf_email_registration', + '_default'=>[ + 'email'=>'Bonjour,\r\n\r\nVous venez de créer un compte sur le site carteprof.org avec l’identifiant : $$user_login$$\r\n\r\nLa FIPF'], + 'is_email_prof'=>true, + 'is_email_partner'=>true, + ]; + // ADMIN MENU const SLUG_TOOGLE_ADMIN_MENU = ['_name'=>'toogle_admin_menu_url_cipf', 'toggle'=>'toggle', 'show'=>'show', 'hide'=>'hide']; const TOGGLE_ADMIN_MENU = ['_name'=>'toggle_admin_menu_option_cipf', 'show'=>'show', 'hide'=>'hide']; const ADMIN_POST_PAYPAL = 'paypal_credentials_CIPF'; - const ADMIN_MENU_NONCE_PAYPAL = ['_name'=>'nonce_admin_menu_paypal_cipf', '_action'=>'action_admin_menu_paypal_cipf']; - const ADMIN_MENU_PAYPAL_INPUTS = ['sandbox_or_live' => 'sandbox_or_live', 'client_id' => 'client_id', 'client_secret' =>'client_secret']; + const ADMIN_MENU_NONCE_PAYPAL = ['_name'=>'nonce_paypal_cipf', '_action'=>'action_admin_menu_paypal_cipf']; + const ADMIN_POST_EMAIL_REGISTRATION = 'email_registration_message_CIPF'; + const ADMIN_MENU_NONCE_EMAIL_REGISTRATION = ['_name'=>'nonce_email_cipf', '_action'=>'action_admin_menu_email_registration_cipf']; // FORMS const FORM_PROF_COMMANDE_ID = 'prof_commande'; diff --git a/plugins/custer/custer.php b/plugins/custer/custer.php index 417f597..13fdf26 100644 --- a/plugins/custer/custer.php +++ b/plugins/custer/custer.php @@ -4,7 +4,7 @@ Plugin Name: custer_plugin Plugin URI: Description: customize user : output infos on page, on email, and change current user id momentarly Author: hugogogo -Version: 0.1.6 +Version: 0.1.7 Author URI: */ diff --git a/plugins/custer/filter_mail.php b/plugins/custer/filter_mail.php index 1950a95..61472ae 100644 --- a/plugins/custer/filter_mail.php +++ b/plugins/custer/filter_mail.php @@ -89,7 +89,6 @@ function replace_words($matches, $user_id = null) { function filter_email_wp($args) { // pattern : anything surrounded by '$$', ex : $$value$$ $pattern = '/\$\$(.*?)\$\$/'; -error_log("args: " . json_encode($args)); $old_body = $args['message']; $new_body = preg_replace_callback($pattern, __NAMESPACE__.'\replace_words', $old_body); @@ -100,6 +99,24 @@ error_log("args: " . json_encode($args)); add_filter('wp_mail', __NAMESPACE__.'\filter_email_wp', 10, 1); +/* +* add this filter specifically for the new users, since otherwise we would not have their id +* +*/ +function filter_regitration_email_CIPF($wp_new_user_notification_email, $user, $blogname) { + $user_id = $user->ID; + $pattern = '/\$\$(.*?)\$\$/'; + + $old_body = $wp_new_user_notification_email['message']; + $new_body = preg_replace_callback($pattern, function($matches) use ($user_id) { + return \CUSTER\replace_words($matches, $user_id); + }, $old_body); + $wp_new_user_notification_email['message'] = $new_body; + + return $wp_new_user_notification_email; +} +add_filter('wp_new_user_notification_email', __NAMESPACE__.'\filter_regitration_email_CIPF', 22, 3); + ?> diff --git a/plugins/custer/format_user_infos.php b/plugins/custer/format_user_infos.php index c3b0c86..1480613 100644 --- a/plugins/custer/format_user_infos.php +++ b/plugins/custer/format_user_infos.php @@ -33,9 +33,6 @@ function return_result($output) { * if is acf, use acf default format */ function format_user_info($query, $current_user, $user_id) { -error_log("query: " . json_encode($query)); -error_log("current_user: " . json_encode($current_user)); -error_log("user_id: " . json_encode($user_id)); $output_date_format = Custer::USER_INFO_DATE_FORMAT; $is_acf = false;