diff --git a/plugins/cipf_plugin/css/display_states/carte_commande.css b/plugins/cipf_plugin/css/display_states/carte_commande.css index 9b0d36b..af75d91 100644 --- a/plugins/cipf_plugin/css/display_states/carte_commande.css +++ b/plugins/cipf_plugin/css/display_states/carte_commande.css @@ -1,4 +1,4 @@ -[class*='cipf_display_'].cipf_display_display_carte_commande { display: block; } -[class*='cipf_display_'].cipf_display_display_carte_commande.cipf_flex { display: flex; } +[class*='cipf_display_'].cipf_display_carte_commande { display: block; } +[class*='cipf_display_'].cipf_display_carte_commande.cipf_flex { display: flex; } diff --git a/plugins/cipf_plugin/php/paypal/update_user_payment.php b/plugins/cipf_plugin/php/paypal/update_user_payment.php index 5c28d7a..ba27c1b 100644 --- a/plugins/cipf_plugin/php/paypal/update_user_payment.php +++ b/plugins/cipf_plugin/php/paypal/update_user_payment.php @@ -179,34 +179,6 @@ function success_payment_for_user_CIPF($user_id, $order_id) { -/* -* add a schedule event to delete this order_id -* after 3 days ? -* time() + 60 = one minute from now -* time() + MINUTE_IN_SECONDS = one minute from now -* -> https://codex.wordpress.org/Easier_Expression_of_Time_Constants -* -> also strtotime : https://www.php.net/manual/en/function.strtotime.php -* -function schedule_delete_orderid_CIPF($user_id, $order_id) -{ - $delay = time() + MINUTE_IN_SECONDS; - wp_schedule_single_event($delay, 'orderid_deletion_event_CIPF', array($user_id, $order_id)); -} -*/ -/* -* action hook for the scheduled event -* TODO: ne marche pas je ne sais pas pourquoi, pas urgent a resoudre -* -function delete_order_id_later_CIPF($user_id, $order_id) -{ - delete_user_meta($user_id, 'cipf_order_id', $order_id); -} -add_action('orderid_deletion_event_CIPF', 'delete_order_id_later_CIPF', 5, 2); -*/ - - - - /* @@ -241,33 +213,6 @@ function find_user_with_order_id_CIPF($current_user_id, $order_id) { else if (count($users) === 1) return reset($users); - - return false; -} - -/* -* @return mixed num - user_id -* bool false - if no match found -* -*/ -function delete_order_id_on_success_CIPF($current_user_id, $order_id) { - PLGNTLS_class::debug_infos(); - $meta_order_id = PLGNTLS_class::META_ORDER_ID; - - $del_ret = delete_user_meta($current_user_id, $meta_order_id, $order_id); - if ($del_ret === true) - return $current_user_id; - - // it means the current user didn't have this order_id - // so we look for another user - $users = get_users(); - foreach ($users as $user) { - $user_id = $user->ID; - $del_ret = delete_user_meta($user_id, $meta_order_id, $order_id); - if ($del_ret === true) - return $user_id; - } - return false; } diff --git a/plugins/cipf_plugin/php/redirections.php b/plugins/cipf_plugin/php/redirections.php index 3ed2e7a..8877be1 100644 --- a/plugins/cipf_plugin/php/redirections.php +++ b/plugins/cipf_plugin/php/redirections.php @@ -19,8 +19,10 @@ function redirection_profil_CIPF(){ PLGNTLS_class::debug_infos(); $role_prof = PLGNTLS_class::ROLE_PROF; $role_partner = PLGNTLS_class::ROLE_PARTNER; + $slug_partner_create_page = PLGNTLS_class::SLUG_PARTNER_CREATE_PAGE; $base_url = home_url(); + $partner_page_creation = home_url($slug_partner_create_page); $current_user_id = get_current_user_id(); // Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes @@ -31,20 +33,35 @@ function redirection_profil_CIPF(){ exit; } + /* + * if prof + * + */ if (current_user_can($role_prof)) { $user_page = get_author_posts_url($current_user_id); wp_redirect($user_page, 301); exit; } - else if (current_user_can($role_partner)) { + + /* + * if partner + * + */ + if (current_user_can($role_partner)) { $args = array( 'post_type' => 'post', 'author' => $current_user_id, 'posts_per_page' => 1, ); $posts = get_posts($args); + + /* + * if post exists, redirects to it + * otherwise redirects to post creation + * + */ if (empty($posts)) { - $redirect_url = $base_url; + $redirect_url = $partner_page_creation; } else { $query = reset($posts); @@ -58,14 +75,12 @@ function redirection_profil_CIPF(){ wp_redirect($base_url, 301); exit; } - exit; } /* -* version 4: * redirects when trying to access the page with SLUG_PAGE_REDIRECTION * no matter if it exists or not * @@ -88,90 +103,4 @@ add_action('template_redirect', 'redirection_page_CIPF'); -/* -* version 1: -* redirects when on the page with slug defined in SLUG_PAGE_REDIRECTION -* -*/ -//function redirection_page_CIPF(){ -// PLGNTLS_class::debug_infos(); -// $slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION; -// -// if (!is_page($slug_page_redirection)) { -// return; -// } -// -// redirection_profil_CIPF(); -//} -//add_action('template_redirect', 'redirection_page_CIPF'); - - - - - -/* -* version 2: -* redirects when a specific url is requested : SLUG_PAGE_REDIRECTION -* works even if the page actually does not exists -* -*/ -//function redirection_query_CIPF() { -// PLGNTLS_class::debug_infos(); -// $slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION; -// -// -// if (!isset($_GET['q'])) -// return; -// -// /* -// * check the request /path/ -// * for url : https://url.com/path/to/file/?query=value -// * -> $_GET: {"q":"/path/to/file/","query":"value"} -// * -// */ -// $get_path = trim($_GET['q'], '/'); -// if ($get_path !== $slug_page_redirection) -// return; -// -// /* -// * check the request ?query -// * -// if(!isset($_GET['query'])) -// return; -// */ -// -// redirection_profil_CIPF(); -//} -//add_action('template_redirect', 'redirection_query_CIPF'); -////add_action('init', 'redirection_query_CIPF'); - - - - - -/* -* version 3: -* DOES NOT WORK so far -* because to use is_user_logged_in() in redirection_profil_CIPF -* the request should include the X-WP-Nonce header, but it does not -* redirects when someone enter the url or redirection -* /wp-json/cipf_plugin/api/v1/redirection_cipf -* -function endpoint_for_redirection_CIPF() { - PLGNTLS_class::debug_infos(); - $slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION; - $base_rest_route = PLGNTLS_class::URL_BASE_REST_ROUTE; - - register_rest_route($base_rest_route, '/' . $slug_page_redirection, array( - 'methods' => 'GET', - 'callback' => 'redirection_profil_CIPF', - )); -}; -add_action('rest_api_init', 'endpoint_for_redirection_CIPF'); -*/ - - - - - ?> diff --git a/plugins/cipf_plugin/php/scheduled_events.php b/plugins/cipf_plugin/php/scheduled_events.php new file mode 100644 index 0000000..bfb285f --- /dev/null +++ b/plugins/cipf_plugin/php/scheduled_events.php @@ -0,0 +1,41 @@ + https://codex.wordpress.org/Easier_Expression_of_Time_Constants +* -> also strtotime : https://www.php.net/manual/en/function.strtotime.php +* +*/ +//function schedule_delete_orderid_CIPF($user_id, $order_id) { +// PLGNTLS_class::debug_infos(); +// $delay = time() + MINUTE_IN_SECONDS; +// wp_schedule_single_event($delay, 'orderid_deletion_event_CIPF', array($user_id, $order_id)); +//} +//function delete_order_id_later_CIPF($user_id, $order_id) { +// PLGNTLS_class::debug_infos(); +// delete_user_meta($user_id, 'cipf_order_id', $order_id); +//} +//add_action('orderid_deletion_event_CIPF', 'delete_order_id_later_CIPF', 5, 2); + + + + + + + + + + +?> diff --git a/plugins/cipf_plugin/utils/plgntls_class.php b/plugins/cipf_plugin/utils/plgntls_class.php index 253887d..2e8c4cb 100644 --- a/plugins/cipf_plugin/utils/plgntls_class.php +++ b/plugins/cipf_plugin/utils/plgntls_class.php @@ -85,8 +85,11 @@ class PLGNTLS_class { 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 = 'compte-partenaire'; + const SLUG_PARTNER_CREATE_PAGE = 'ma-page-partenaire'; + // URL const URL_BASE_REST_ROUTE = 'cipf_plugin/api/v1'; // for routes, in php/paypal/routes.php && php/admin_modif_prof.php + // QUERY // PAYPAL