v 0.3.3 partner registration detected with slug using options and without referer

This commit is contained in:
asus
2024-03-18 13:28:02 +01:00
parent 98dfb17bf4
commit 5be80d1566
6 changed files with 52 additions and 30 deletions

View File

@@ -4,7 +4,7 @@ Plugin Name: cipf_plugin
Plugin URI:
Description:
Author: hugogogo
Version: 0.3.2
Version: 0.3.3
Author URI:
*/

View File

@@ -9,6 +9,38 @@ if (!defined('ABSPATH')) {
function check_if_partner_registration_CIPF() {
PLGNTLS_class::debug_infos();
$slug_partner_registration = PLGNTLS_class::SLUG_PARTNER_REGISTRATION;
$option_partner_slug = PLGNTLS_class::OPTION_PARTNER_SLUG;
/*
* if does not exist, create the option
*/
if (false === get_option($option_partner_slug['_name'])) {
add_option($option_partner_slug['_name'], array());
}
global $wp;
$current_slug = $wp->request;
if ($current_slug !== $slug_partner_registration) {
update_option($option_partner_slug['_name'], $option_partner_slug['false']);
return;
}
//PLGNTLS_class::set_partner_registration();
update_option($option_partner_slug['_name'], $option_partner_slug['true']);
}
add_action('template_redirect', 'check_if_partner_registration_CIPF');
/*
* at registration, add role 'partenaire' when page url has path 'creation-du-compte-partenaire'
*
@@ -16,15 +48,24 @@ if (!defined('ABSPATH')) {
function add_partenaires_CIPF($customer_data){
PLGNTLS_class::debug_infos();
$role_partner = PLGNTLS_class::ROLE_PARTNER;
$option_partner_slug = PLGNTLS_class::OPTION_PARTNER_SLUG;
$current_url = $_SERVER['HTTP_REFERER']; // not reliable to use referer, TODO: find another solution
$path_brut = parse_url($current_url, PHP_URL_PATH);
$path = trim($path_brut, '/');
if ($path === 'creation-du-compte-partenaire')
/*
*/
$partner_slug_option = get_option($option_partner_slug['_name']);
$is_partner_slug = false;
if ($partner_slug_option === $option_partner_slug['true']) {
$is_partner_slug = true;
}
if ($is_partner_slug) {
$customer_data['role'] = $role_partner;
}
return $customer_data;
}
add_filter( 'xoo_el_register_new_customer_data', 'add_partenaires_CIPF', 10, 1 );
add_filter('xoo_el_register_new_customer_data', 'add_partenaires_CIPF', 10, 1);
/*
in add_partenaires

View File

@@ -1,17 +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!');
}
?>

View File

@@ -82,6 +82,7 @@ class PLGNTLS_class {
const SLUG_PAYPAL_REDIRECTION_SUCCESS = self::SLUG_PAGE_REDIRECTION;
const SLUG_PAYPAL_REDIRECTION_FAILURE = self::SLUG_PAGE_REDIRECTION;
const SLUG_ADMIN_VALIDATE_PROF = 'admin_activate_prof_cipf'; // for admin_modif_prof.php
const SLUG_PARTNER_REGISTRATION = 'creation-du-compte-partenaire';
// URL
const URL_BASE_REST_ROUTE = 'cipf_plugin/api/v1'; // for routes, in php/paypal/routes.php && php/admin_modif_prof.php
// QUERY
@@ -101,6 +102,9 @@ class PLGNTLS_class {
// SHORTCODES
// OPTIONS
const OPTION_PARTNER_SLUG = ['_name'=>'cipf_partner_slug', 'true'=>'true', 'false'=>'false'];
// OTHER
const CARD_RENEW_PERIOD = 31; // int : number of days before expiration when renew card start to be possible
const CARD_VALIDITY_TIME = '1 year'; // string : time of validity of the card (ex: '1 month' or '1 year' or '60 days')

View File

@@ -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.3
Version: 0.1.4
Author URI:
*/
@@ -27,7 +27,6 @@ include_once(plugin_dir_path(__FILE__) . '/filter_mail.php');
include_once(plugin_dir_path(__FILE__) . '/admin_menu.php');
include_once(plugin_dir_path(__FILE__) . '/admin_menu_toggle.php');
//add_shortcode('custer_change_id', 'CUSTER\shortcode_change_id');

View File

@@ -87,15 +87,10 @@ function filter_email_wp($args) {
// pattern : anything surrounded by '$$', ex : $$value$$
$pattern = '/\$\$(.*?)\$\$/';
error_log("inside wp_mail hook, in filter_email_wp");
$old_body = $args['message'];
$new_body = preg_replace_callback($pattern, __NAMESPACE__.'\replace_words', $old_body);
$args['message'] = $new_body;
error_log("args['message']");
error_log(json_encode($args['message']));
return $args;
}
add_filter('wp_mail', __NAMESPACE__.'\filter_email_wp', 10, 1);