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();
|
PLGNTLS_class::debug_infos();
|
||||||
$query_page_redirection = PLGNTLS_class::QUERY_REDIRECTION_PROFIL;
|
$query_page_redirection = PLGNTLS_class::QUERY_REDIRECTION_PROFIL;
|
||||||
|
|
||||||
// Check if the request contains ?QUERY_REDIRECTION_PROFIL
|
// Check if the request contains ?QUERY_REDIRECTION_PROFIL
|
||||||
if(isset($_GET[$query_page_redirection])) {
|
if(!isset($_GET[$query_page_redirection]))
|
||||||
admin_validate_prof_CIPF();
|
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
|
* redirect users to profil
|
||||||
* if prof -> author page
|
* if prof -> author page
|
||||||
* if partenaire -> post page || home page
|
* if partenaire -> post page || home page
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
function redirection_profil_page_CIPF(){
|
function redirection_profil_page_CIPF(){
|
||||||
PLGNTLS_class::debug_infos();
|
PLGNTLS_class::debug_infos();
|
||||||
@@ -22,29 +23,40 @@ function redirection_profil_page_CIPF(){
|
|||||||
$base_url = home_url();
|
$base_url = home_url();
|
||||||
$current_user_id = get_current_user_id();
|
$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
|
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||||
nocache_headers();
|
nocache_headers();
|
||||||
|
|
||||||
if (!is_user_logged_in()) {
|
if (!is_user_logged_in()) {
|
||||||
|
error_log("2");
|
||||||
wp_redirect($base_url, 301);
|
wp_redirect($base_url, 301);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_log("3");
|
||||||
if (current_user_can($role_prof)) {
|
if (current_user_can($role_prof)) {
|
||||||
|
error_log("4");
|
||||||
$user_page = get_author_posts_url($current_user_id);
|
$user_page = get_author_posts_url($current_user_id);
|
||||||
|
error_log("user_page");
|
||||||
|
error_log($user_page);
|
||||||
wp_redirect($user_page, 301);
|
wp_redirect($user_page, 301);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
else if (current_user_can($role_partner)) {
|
else if (current_user_can($role_partner)) {
|
||||||
|
error_log("5");
|
||||||
$args = array(
|
$args = array(
|
||||||
'post_type' => 'post',
|
'post_type' => 'post',
|
||||||
'author' => $current_user_id,
|
'author' => $current_user_id,
|
||||||
'posts_per_page' => 1,
|
'posts_per_page' => 1,
|
||||||
);
|
);
|
||||||
$posts = get_posts($args);
|
$posts = get_posts($args);
|
||||||
if (empty($posts))
|
if (empty($posts)) {
|
||||||
|
error_log("6");
|
||||||
$redirect_url = $base_url;
|
$redirect_url = $base_url;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
|
error_log("7");
|
||||||
$query = reset($posts);
|
$query = reset($posts);
|
||||||
$post_id = $query->ID;
|
$post_id = $query->ID;
|
||||||
$redirect_url = get_permalink($query->ID);
|
$redirect_url = get_permalink($query->ID);
|
||||||
@@ -53,9 +65,11 @@ function redirection_profil_page_CIPF(){
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
error_log("8");
|
||||||
wp_redirect($base_url, 301);
|
wp_redirect($base_url, 301);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
error_log("9");
|
||||||
exit;
|
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(){
|
function redirection_page_CIPF(){
|
||||||
PLGNTLS_class::debug_infos();
|
PLGNTLS_class::debug_infos();
|
||||||
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
||||||
@@ -76,23 +89,43 @@ function redirection_page_CIPF(){
|
|||||||
redirection_profil_page_CIPF();
|
redirection_profil_page_CIPF();
|
||||||
}
|
}
|
||||||
add_action('template_redirect', 'redirection_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() {
|
function redirection_query_CIPF() {
|
||||||
PLGNTLS_class::debug_infos();
|
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])) {
|
if (!isset($_GET['q']))
|
||||||
redirection_profil_page_CIPF();
|
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');
|
add_action('init', 'redirection_query_CIPF');
|
||||||
|
|
||||||
|
|||||||
@@ -76,17 +76,16 @@ class PLGNTLS_class
|
|||||||
const META_PAYEMENT_STATUS = 'cipf_payement_status';
|
const META_PAYEMENT_STATUS = 'cipf_payement_status';
|
||||||
const META_ORDER_ID = 'cipf_order_id';
|
const META_ORDER_ID = 'cipf_order_id';
|
||||||
|
|
||||||
// SLUG & URL & QUERY
|
// SLUG
|
||||||
const SLUG_PROF_INACTIV = 'validation-en-cours';
|
const SLUG_PROF_INACTIV = 'validation-en-cours';
|
||||||
const SLUG_RENEW_CARD = 'commande';
|
const SLUG_RENEW_CARD = 'commande';
|
||||||
const SLUG_PAGE_REDIRECTION = 'redirection_cipf';
|
const SLUG_PAGE_REDIRECTION = 'redirection_cipf';
|
||||||
// const SLUG_PAYPAL_REDIRECTION_SUCCESS = self::SLUG_PAGE_REDIRECTION;
|
const SLUG_PAYPAL_REDIRECTION_SUCCESS = self::SLUG_PAGE_REDIRECTION;
|
||||||
// const SLUG_PAYPAL_REDIRECTION_FAILURE = self::SLUG_PAGE_REDIRECTION;
|
const SLUG_PAYPAL_REDIRECTION_FAILURE = self::SLUG_PAGE_REDIRECTION;
|
||||||
const SLUG_PAYPAL_REDIRECTION_SUCCESS = '?'.self::QUERY_REDIRECTION_PROFIL;
|
// URL
|
||||||
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 URL_BASE_REST_ROUTE = 'cipf_plugin/api/v1'; // for routes, in php/paypal/routes.php && php/admin_modif_prof.php
|
// QUERY
|
||||||
const QUERY_REDIRECTION_PROFIL = 'redirection_cipf';
|
const QUERY_ADMIN_VALIDATE_PROF = 'admin_activate_prof_cipf'; // for admin_modif_prof.php
|
||||||
const QUERY_ADMIN_VALIDATE_PROF = 'admin_activate_prof_cipf'; // for admin_modif_prof.php
|
|
||||||
|
|
||||||
// PAYPAL
|
// PAYPAL
|
||||||
const PAYPAL_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl";
|
const PAYPAL_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl";
|
||||||
|
|||||||
Reference in New Issue
Block a user