From 5be80d1566492cbb3394334182628694304918a3 Mon Sep 17 00:00:00 2001 From: asus Date: Mon, 18 Mar 2024 13:28:02 +0100 Subject: [PATCH] v 0.3.3 partner registration detected with slug using options and without referer --- plugins/cipf_plugin/cipf_plugin.php | 2 +- plugins/cipf_plugin/php/partners_register.php | 51 +++++++++++++++++-- plugins/cipf_plugin/php/reset_card_form.php | 17 ------- plugins/cipf_plugin/utils/plgntls_class.php | 4 ++ plugins/custer/custer.php | 3 +- plugins/custer/filter_mail.php | 5 -- 6 files changed, 52 insertions(+), 30 deletions(-) delete mode 100644 plugins/cipf_plugin/php/reset_card_form.php diff --git a/plugins/cipf_plugin/cipf_plugin.php b/plugins/cipf_plugin/cipf_plugin.php index 4adfad9..bef0da9 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.3.2 +Version: 0.3.3 Author URI: */ diff --git a/plugins/cipf_plugin/php/partners_register.php b/plugins/cipf_plugin/php/partners_register.php index 5832994..6a4fba3 100644 --- a/plugins/cipf_plugin/php/partners_register.php +++ b/plugins/cipf_plugin/php/partners_register.php @@ -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 diff --git a/plugins/cipf_plugin/php/reset_card_form.php b/plugins/cipf_plugin/php/reset_card_form.php deleted file mode 100644 index a0c33ab..0000000 --- a/plugins/cipf_plugin/php/reset_card_form.php +++ /dev/null @@ -1,17 +0,0 @@ - diff --git a/plugins/cipf_plugin/utils/plgntls_class.php b/plugins/cipf_plugin/utils/plgntls_class.php index 9dc40c7..7a8ca63 100644 --- a/plugins/cipf_plugin/utils/plgntls_class.php +++ b/plugins/cipf_plugin/utils/plgntls_class.php @@ -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') diff --git a/plugins/custer/custer.php b/plugins/custer/custer.php index 7d40b3e..62da05c 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.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'); diff --git a/plugins/custer/filter_mail.php b/plugins/custer/filter_mail.php index db90223..713ab39 100644 --- a/plugins/custer/filter_mail.php +++ b/plugins/custer/filter_mail.php @@ -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);