xtxpatch v 0.1.1 it works fine

This commit is contained in:
asus
2024-03-31 19:59:20 +02:00
parent 995e230e32
commit 5d4be76102
10 changed files with 52 additions and 1527 deletions

View File

@@ -33,7 +33,6 @@ include_once(Plgntls::root_path() . 'php/admin_menu/admin_menu_toggle.php');
include_once(Plgntls::root_path() . 'php/admin_menu/menu_content.php');
include_once(Plgntls::root_path() . 'php/admin_menu/post_paypal.php');
include_once(Plgntls::root_path() . 'php/admin_menu/post_payment_messages.php');
include_once(Plgntls::root_path() . 'php/admin_menu/post_email.php');
include_once(Plgntls::root_path() . 'php/paypal/paypal.php');

View File

@@ -22,20 +22,12 @@ function add_plugin_content_CIPF() {
$paypal_credentials = get_paypal_options_CIPF();
/*
* registration email
* payment messages
*
*/
$admin_post_email_registration = Plgntls::ADMIN_POST_EMAIL_REGISTRATION;
$nonce_email = Plgntls::ADMIN_MENU_NONCE_EMAIL_REGISTRATION;
$email_registration = get_email_registration_option_CIPF();
/*
* registration email
*
$admin_post_payment_messages = Plgntls::ADMIN_POST_PAYMENT_MESSAGES;
$nonce_payment_messages = Plgntls::ADMIN_MENU_NONCE_PAYMENT_MESSAGES;
$payment_messages = get_payment_messages_option_CIPF();
*/
ob_start();
include(Plgntls::root_path() . '/html/menu/cipf_menu.html');

View File

@@ -1,90 +0,0 @@
<?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::debug_infos();
$nonce_email = Plgntls::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::ADMIN_POST_EMAIL_REGISTRATION, 'change_email_registration_CIPF');
function update_email_registration_option_CIPF($post) {
Plgntls::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

@@ -11,103 +11,6 @@ if (!defined('ABSPATH')) {
/*
* ../../../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::debug_infos();
$role_partner = Plgntls::ROLE_PARTNER;
$role_prof = Plgntls::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) {
Plgntls::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);
/*
* OPTIONS
*
*/
function set_email_registration_CIPF($email, $is_email_prof, $is_email_partner) {
Plgntls::debug_infos();
$option_email = Plgntls::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');
}
function get_email_registration_option_CIPF() {
Plgntls::debug_infos();
$option_email = Plgntls::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::debug_infos();
$email_option = get_email_registration_option_CIPF();
return $email_option['email'];
}
function is_email_registration_prof_CIPF() {
Plgntls::debug_infos();
$email_option = get_email_registration_option_CIPF();
return $email_option['is_email_prof'];
}
function is_email_registration_partner_CIPF() {
Plgntls::debug_infos();
$email_option = get_email_registration_option_CIPF();
return $email_option['is_email_partner'];
}

View File

@@ -28,7 +28,6 @@ function randomize_post_output_CIPF($query) {
}
Plgntls::debug_infos();
error_log("posts_per_page: " . json_encode($posts_per_page));
$query->set('orderby', 'rand');
}
add_action('pre_get_posts', 'randomize_post_output_CIPF');

View File

@@ -72,7 +72,6 @@ function redirection_profil_CIPF(){
*
*/
if (current_user_can($role_prof)) {
error_log("is prof");
$user_page = get_author_posts_url($current_user_id);
wp_redirect($user_page, 301);
exit;

View File

@@ -16,6 +16,9 @@ if (!defined('ABSPATH')) {
*
*/
class Xtxpatch {
const ROLE_PROF = 'professeur__professeure';
const ROLE_PARTNER = 'partenaire';
const OPTION_REGISTER_EMAIL = [
'_name'=>'define_email_at_register_xtxpatch',
'_callback'=>__NAMESPACE__.'\define_register_email',

View File

@@ -84,6 +84,53 @@ function define_register_email($request, $option_name, $option_value, $option_de
/*
* ../../../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($send, $user) {
$role_partner = Xtxpatch::ROLE_PARTNER;
$role_prof = Xtxpatch::ROLE_PROF;
$option_register_email = Xtxpatch::OPTION_REGISTER_EMAIL;
$email_option = \Plgntls_xtx::get_option_safe($option_register_email['_name']);
if (user_can($user, $role_prof)) {
$send = $email_option['is_email_prof'];
}
else if (user_can($user, $role_partner)) {
$send = $email_option['is_email_partner'];
}
return $send;
}
add_filter( 'wp_send_new_user_notification_to_user', __NAMESPACE__.'\send_registration_email', 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($wp_new_user_notification_email, $user, $blogname) {
$option_register_email = Xtxpatch::OPTION_REGISTER_EMAIL;
$email_option = \Plgntls_xtx::get_option_safe($option_register_email['_name']);
$wp_new_user_notification_email['message'] = $email_option['email'];
return $wp_new_user_notification_email;
}
add_filter('wp_new_user_notification_email', __NAMESPACE__.'\filter_regitration_email', 21, 3);
?>

View File

@@ -4,7 +4,7 @@ Plugin Name: hggg_xtxpatch
Plugin URI:
Description: some patchs for the xootix login/registration plugin
Author: hugogogo
Version: 0.1.0
Version: 0.1.1
Author URI:
*/