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

@@ -4,7 +4,7 @@ Plugin Name: cipf_plugin
Plugin URI: Plugin URI:
Description: Description:
Author: hugogogo Author: hugogogo
Version: 0.4.1 Version: 0.4.2.1
Author URI: 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.php');
include_once(PLGNTLS_class::root_path() . 'php/admin_menu/admin_menu_toggle.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/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'); include_once(PLGNTLS_class::root_path() . 'php/paypal/paypal.php');

View File

@@ -1,6 +1,12 @@
<style> <style>
h1 {
margin-left: 15px;
margin-top: 50px;
}
form { form {
margin: 15px; margin: 15px;
border: 1px solid black;
padding: 20px;
} }
form > div { form > div {
margin: 20px 0px; margin: 20px 0px;
@@ -8,9 +14,19 @@
.define_paypal_credentials_cipf input { .define_paypal_credentials_cipf input {
width: 100%; width: 100%;
} }
form#email_registration_cipf .define_email_registration {
display: flex;
flex-direction: column;
}
form#email_registration_cipf .define_email_registration textarea {
resize: vertical;
height: 120px;
}
</style> </style>
<!-- https://developer.wordpress.org/reference/hooks/admin_post_action/ --> <!-- https://developer.wordpress.org/reference/hooks/admin_post_action/ -->
<h1>paypal credentials</h1>
<form method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>"> <form method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>">
<input type="hidden" name="action" value="<?php echo $admin_post_paypal; ?>"> <input type="hidden" name="action" value="<?php echo $admin_post_paypal; ?>">
<?php wp_nonce_field($nonce_paypal['_action'], $nonce_paypal['_name']); ?> <?php wp_nonce_field($nonce_paypal['_action'], $nonce_paypal['_name']); ?>
@@ -26,15 +42,41 @@
</div> </div>
<div class="choose_sandbox_live_cipf choose_sandbox_cipf"> <div class="choose_sandbox_live_cipf choose_sandbox_cipf">
<input type="radio" id="sandbox" name="<?php echo $paypal_inputs['sandbox_or_live']; ?>" value="sandbox" <?php if ($paypal_credentials['is_sandbox'] === true) {echo 'checked';} ?> /> <input type="radio" id="sandbox" name="sandbox_or_live" value="sandbox" <?php if ($paypal_credentials['is_sandbox'] === true) {echo 'checked';} ?> />
<label for="sandbox">sandbox</label> <label for="sandbox">sandbox</label>
</div> </div>
<div class="choose_sandbox_live_cipf choose_live_cipf"> <div class="choose_sandbox_live_cipf choose_live_cipf">
<input type="radio" id="live" name="<?php echo $paypal_inputs['sandbox_or_live']; ?>" value="live" <?php if ($paypal_credentials['is_sandbox'] === false) {echo 'checked';} ?> /> <input type="radio" id="live" name="sandbox_or_live" value="live" <?php if ($paypal_credentials['is_sandbox'] === false) {echo 'checked';} ?> />
<label for="live">live</label> <label for="live">live</label>
</div> </div>
<input type="submit" value="send"/> <input type="submit" value="send"/>
</form> </form>
<!--
-->
<h1>email a la creation de compte</h1>
<form id="email_registration_cipf" method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>">
<input type="hidden" name="action" value="<?php echo $admin_post_email_registration; ?>">
<?php wp_nonce_field($nonce_email['_action'], $nonce_email['_name']); ?>
<div class="define_email_registration">
<label for="define_email_registration_cipf">email : </label>
<textarea id="define_email_registration_cipf" name="email"><?php echo $email_registration['email']; ?></textarea>
</div>
<div class="send_email">
<input type="checkbox" id="send_email_prof_cipf" name="is_email_prof" <?php if ($email_registration['is_email_prof'] === true) {echo 'checked';} ?> />
<label for="send_email_prof_cipf">envoyer un email à l'inscription des profs ?</label>
</div>
<div class="send_email">
<input type="checkbox" id="send_email_partner_cipf" name="is_email_partner" <?php if ($email_registration['is_email_partner'] === true) {echo 'checked';} ?> />
<label for="send_email_partner_cipf">envoyer un email à l'inscription des partenaires ?</label>
</div>
<input type="submit" value="send"/>
</form>

View File

@@ -12,13 +12,25 @@ if (!defined('ABSPATH')) {
function add_plugin_content_CIPF() { function add_plugin_content_CIPF() {
PLGNTLS_class::debug_infos(); PLGNTLS_class::debug_infos();
/*
* paypal
*
$option_paypal = PLGNTLS_class::OPTION_PAYPAL; $option_paypal = PLGNTLS_class::OPTION_PAYPAL;
*/
$admin_post_paypal = PLGNTLS_class::ADMIN_POST_PAYPAL; $admin_post_paypal = PLGNTLS_class::ADMIN_POST_PAYPAL;
$nonce_paypal = PLGNTLS_class::ADMIN_MENU_NONCE_PAYPAL; $nonce_paypal = PLGNTLS_class::ADMIN_MENU_NONCE_PAYPAL;
$paypal_inputs = PLGNTLS_class::ADMIN_MENU_PAYPAL_INPUTS;
$paypal_credentials = get_paypal_options_CIPF(); $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(); ob_start();
include(PLGNTLS_class::root_path() . '/html/menu/cipf_menu.html'); include(PLGNTLS_class::root_path() . '/html/menu/cipf_menu.html');
$html = ob_get_clean(); $html = ob_get_clean();
@@ -27,100 +39,13 @@ function add_plugin_content_CIPF() {
/* /*
* use this hook 'admin_post_{$action}' to receive a form post * this is used to redirect when handling the reception of post form
* 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();
$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) { function redirect_menu_referer_CIPF($post) {
PLGNTLS_class::debug_infos(); PLGNTLS_class::debug_infos();
if (!isset($post)) { 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 <?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 : * it means someone outside wp is accessing the file, in this case kill it.
{"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":[]}
*/ */
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 * ../../../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 ); * 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) { 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)); PLGNTLS_class::debug_infos();
error_log("- user: ". json_encode($user)); $wp_new_user_notification_email['message'] = get_email_registration_CIPF();
error_log("- blogname: ". json_encode($blogname));
$wp_new_user_notification_email['message'] = 'poutpout $$nickname$$';
return $wp_new_user_notification_email; 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) { function add_fields_register_CIPF($args) {
PLGNTLS_class::debug_infos(); PLGNTLS_class::debug_infos();
// error_log("args : " . json_encode($args));
$role_partner = PLGNTLS_class::ROLE_PARTNER; $role_partner = PLGNTLS_class::ROLE_PARTNER;
$slug_partner_registration = PLGNTLS_class::SLUG_PARTNER_REGISTRATION; $slug_partner_registration = PLGNTLS_class::SLUG_PARTNER_REGISTRATION;
$input_hidden_role = PLGNTLS_class::INPUT_HIDDEN_ROLE; $input_hidden_role = PLGNTLS_class::INPUT_HIDDEN_ROLE;

View File

@@ -127,13 +127,22 @@ class PLGNTLS_class {
'client_secret'=>'EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-', '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 lidentifiant : $$user_login$$\r\n\r\nLa FIPF'],
'is_email_prof'=>true,
'is_email_partner'=>true,
];
// ADMIN MENU // ADMIN MENU
const SLUG_TOOGLE_ADMIN_MENU = ['_name'=>'toogle_admin_menu_url_cipf', 'toggle'=>'toggle', 'show'=>'show', 'hide'=>'hide']; 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 TOGGLE_ADMIN_MENU = ['_name'=>'toggle_admin_menu_option_cipf', 'show'=>'show', 'hide'=>'hide'];
const ADMIN_POST_PAYPAL = 'paypal_credentials_CIPF'; 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_NONCE_PAYPAL = ['_name'=>'nonce_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_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 // FORMS
const FORM_PROF_COMMANDE_ID = 'prof_commande'; const FORM_PROF_COMMANDE_ID = 'prof_commande';

View File

@@ -4,7 +4,7 @@ Plugin Name: custer_plugin
Plugin URI: Plugin URI:
Description: customize user : output infos on page, on email, and change current user id momentarly Description: customize user : output infos on page, on email, and change current user id momentarly
Author: hugogogo Author: hugogogo
Version: 0.1.6 Version: 0.1.7
Author URI: Author URI:
*/ */

View File

@@ -89,7 +89,6 @@ function replace_words($matches, $user_id = null) {
function filter_email_wp($args) { function filter_email_wp($args) {
// pattern : anything surrounded by '$$', ex : $$value$$ // pattern : anything surrounded by '$$', ex : $$value$$
$pattern = '/\$\$(.*?)\$\$/'; $pattern = '/\$\$(.*?)\$\$/';
error_log("args: " . json_encode($args));
$old_body = $args['message']; $old_body = $args['message'];
$new_body = preg_replace_callback($pattern, __NAMESPACE__.'\replace_words', $old_body); $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_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);
?> ?>

View File

@@ -33,9 +33,6 @@ function return_result($output) {
* if is acf, use acf default format * if is acf, use acf default format
*/ */
function format_user_info($query, $current_user, $user_id) { 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; $output_date_format = Custer::USER_INFO_DATE_FORMAT;
$is_acf = false; $is_acf = false;