From 6c7b269052a3440ff7bac50ff8dcebf648e18614 Mon Sep 17 00:00:00 2001 From: asus Date: Fri, 15 Mar 2024 09:18:39 +0100 Subject: [PATCH] tried a fix on redirection without real page, by using template-redirection hook instead of init --- plugins/cipf_plugin/php/redirections.php | 79 ++++++++++++------------ 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/plugins/cipf_plugin/php/redirections.php b/plugins/cipf_plugin/php/redirections.php index 4f1abcf..25f99e1 100644 --- a/plugins/cipf_plugin/php/redirections.php +++ b/plugins/cipf_plugin/php/redirections.php @@ -65,56 +65,59 @@ function redirection_profil_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'); +//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 it does not exists +* 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(); -//} +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');