changed profil redirection so it does not need a real page anymore
This commit is contained in:
@@ -57,18 +57,18 @@ add_action('df_before_process', 'custom_form_admin_validate_prof_CIPF', 10, 3);
|
||||
|
||||
|
||||
/*
|
||||
* calling the action to validate from the
|
||||
* calling the action to validate from the url query
|
||||
*
|
||||
function custom_link_intercept() {
|
||||
function url_custom_form_admin_validate_prof_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$query_page_redirection = PLGNTLS_class::QUERY_REDIRECTION_PROFIL;
|
||||
|
||||
// Check if the request contains ?QUERY_REDIRECTION_PROFIL
|
||||
if(isset($_GET[$query_page_redirection])) {
|
||||
admin_validate_prof_CIPF();
|
||||
}
|
||||
if(!isset($_GET[$query_page_redirection]))
|
||||
return;
|
||||
admin_validate_prof_CIPF();
|
||||
}
|
||||
add_action('init', 'custom_link_intercept');
|
||||
add_action('init', 'url_custom_form_admin_validate_prof_CIPF');
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ if (!defined('ABSPATH')) {
|
||||
* redirect users to profil
|
||||
* if prof -> author page
|
||||
* if partenaire -> post page || home page
|
||||
*
|
||||
*/
|
||||
function redirection_profil_page_CIPF(){
|
||||
PLGNTLS_class::debug_infos();
|
||||
@@ -22,29 +23,40 @@ function redirection_profil_page_CIPF(){
|
||||
$base_url = home_url();
|
||||
$current_user_id = get_current_user_id();
|
||||
|
||||
error_log("1");
|
||||
|
||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||
nocache_headers();
|
||||
|
||||
if (!is_user_logged_in()) {
|
||||
error_log("2");
|
||||
wp_redirect($base_url, 301);
|
||||
exit;
|
||||
}
|
||||
|
||||
error_log("3");
|
||||
if (current_user_can($role_prof)) {
|
||||
error_log("4");
|
||||
$user_page = get_author_posts_url($current_user_id);
|
||||
error_log("user_page");
|
||||
error_log($user_page);
|
||||
wp_redirect($user_page, 301);
|
||||
exit;
|
||||
}
|
||||
else if (current_user_can($role_partner)) {
|
||||
error_log("5");
|
||||
$args = array(
|
||||
'post_type' => 'post',
|
||||
'author' => $current_user_id,
|
||||
'posts_per_page' => 1,
|
||||
);
|
||||
$posts = get_posts($args);
|
||||
if (empty($posts))
|
||||
if (empty($posts)) {
|
||||
error_log("6");
|
||||
$redirect_url = $base_url;
|
||||
}
|
||||
else {
|
||||
error_log("7");
|
||||
$query = reset($posts);
|
||||
$post_id = $query->ID;
|
||||
$redirect_url = get_permalink($query->ID);
|
||||
@@ -53,9 +65,11 @@ function redirection_profil_page_CIPF(){
|
||||
exit;
|
||||
}
|
||||
else {
|
||||
error_log("8");
|
||||
wp_redirect($base_url, 301);
|
||||
exit;
|
||||
}
|
||||
error_log("9");
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -63,9 +77,8 @@ function redirection_profil_page_CIPF(){
|
||||
|
||||
|
||||
/*
|
||||
* redirects when someone reaches the page with slug defined in SLUG_PAGE_REDIRECTION
|
||||
* 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;
|
||||
@@ -76,23 +89,43 @@ function redirection_page_CIPF(){
|
||||
redirection_profil_page_CIPF();
|
||||
}
|
||||
add_action('template_redirect', 'redirection_page_CIPF');
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* redirects when someone reaches the page with query ?QUERY_REDIRECTION_PROFIL
|
||||
* redirects when a specific url is requested : SLUG_PAGE_REDIRECTION
|
||||
* works even if it does not exists
|
||||
*
|
||||
*/
|
||||
function redirection_query_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$query_redirection = PLGNTLS_class::QUERY_REDIRECTION_PROFIL;
|
||||
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
||||
|
||||
// Check if the request contains ?QUERY_REDIRECTION_PROFIL
|
||||
if(isset($_GET[$query_redirection])) {
|
||||
redirection_profil_page_CIPF();
|
||||
}
|
||||
|
||||
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_page_CIPF();
|
||||
}
|
||||
add_action('init', 'redirection_query_CIPF');
|
||||
|
||||
|
||||
@@ -76,17 +76,16 @@ class PLGNTLS_class
|
||||
const META_PAYEMENT_STATUS = 'cipf_payement_status';
|
||||
const META_ORDER_ID = 'cipf_order_id';
|
||||
|
||||
// SLUG & URL & QUERY
|
||||
// SLUG
|
||||
const SLUG_PROF_INACTIV = 'validation-en-cours';
|
||||
const SLUG_RENEW_CARD = 'commande';
|
||||
const SLUG_PAGE_REDIRECTION = 'redirection_cipf';
|
||||
// const SLUG_PAYPAL_REDIRECTION_SUCCESS = self::SLUG_PAGE_REDIRECTION;
|
||||
// const SLUG_PAYPAL_REDIRECTION_FAILURE = self::SLUG_PAGE_REDIRECTION;
|
||||
const SLUG_PAYPAL_REDIRECTION_SUCCESS = '?'.self::QUERY_REDIRECTION_PROFIL;
|
||||
const SLUG_PAYPAL_REDIRECTION_FAILURE = '?'.self::QUERY_REDIRECTION_PROFIL;
|
||||
const URL_BASE_REST_ROUTE = 'cipf_plugin/api/v1'; // for routes, in php/paypal/routes.php && php/admin_modif_prof.php
|
||||
const QUERY_REDIRECTION_PROFIL = 'redirection_cipf';
|
||||
const QUERY_ADMIN_VALIDATE_PROF = 'admin_activate_prof_cipf'; // for admin_modif_prof.php
|
||||
const SLUG_PAYPAL_REDIRECTION_SUCCESS = self::SLUG_PAGE_REDIRECTION;
|
||||
const SLUG_PAYPAL_REDIRECTION_FAILURE = self::SLUG_PAGE_REDIRECTION;
|
||||
// URL
|
||||
const URL_BASE_REST_ROUTE = 'cipf_plugin/api/v1'; // for routes, in php/paypal/routes.php && php/admin_modif_prof.php
|
||||
// QUERY
|
||||
const QUERY_ADMIN_VALIDATE_PROF = 'admin_activate_prof_cipf'; // for admin_modif_prof.php
|
||||
|
||||
// PAYPAL
|
||||
const PAYPAL_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl";
|
||||
|
||||
Reference in New Issue
Block a user