- fixed error in plgntls debug logs

- fixed button partner modification page restrictions
This commit is contained in:
asus
2024-04-04 15:06:33 +02:00
parent 6cd25725e0
commit 4948298b8a
4 changed files with 75 additions and 15 deletions

View File

@@ -75,6 +75,55 @@ function current_user_can_CIPF($capability) {
/*
* checks if current user is partner
* works as soon as 'init' hook
*
* first hook to use is...() is parse_query
* -> https://developer.wordpress.org/apis/hooks/action-reference/
* - after 'init', before 'wp'
* but 'init' already has set user, so we can recreate the functions
*
*/
function is_partner() {
Plgntls::debug_infos();
$role_partner = Cipf::ROLE_PARTNER;
if (!is_user_logged_in_CIPF()) {
return false;
}
if (!current_user_can_CIPF($role_partner)) {
return false;
}
return true;
}
/*
* checks if current user is prof
* works as soon as 'init' hook
*
* first hook to use is...() is parse_query
* -> https://developer.wordpress.org/apis/hooks/action-reference/
* - after 'init', before 'wp'
* but 'init' already has set user, so we can recreate the functions
*
*/
function is_prof() {
Plgntls::debug_infos();
$role_prof = Cipf::ROLE_PROF;
if (!is_user_logged_in_CIPF()) {
return false;
}
if (!current_user_can_CIPF($role_prof)) {
return false;
}
return true;
}

View File

@@ -143,18 +143,17 @@ add_action('template_redirect', 'redirection_page_CIPF');
* but 'init' already has set user, so we can recreate the functions
*
*/
function redirects_home_if_not_partner() {
Plgntls::debug_infos(2);
$role_partner = Cipf::ROLE_PARTNER;
if (!is_user_logged_in_CIPF()) {
redirect_home_CIPF();
}
if (!current_user_can_CIPF($role_partner)) {
redirect_home_CIPF();
}
Plgntls::debug_infos();
}
//function redirects_home_if_not_partner() {
// Plgntls::debug_infos();
// $role_partner = Cipf::ROLE_PARTNER;
//
// if (!is_user_logged_in_CIPF()) {
// redirect_home_CIPF();
// }
// if (!current_user_can_CIPF($role_partner)) {
// redirect_home_CIPF();
// }
//}

View File

@@ -20,6 +20,10 @@ function is_partner_form_creation_page_CIPF() {
/*
* only for the partner form creation page
* first available hook is parse_query
* -> https://developer.wordpress.org/apis/hooks/action-reference/
* 584 : wordpress_docker/volumes/wp_volume/wp-includes/query.php
* 4427 : wordpress_docker/volumes/wp_volume/wp-includes/class-wp-query.php
*
*/
if (!is_page($slug_partner_create_page)) {
@@ -39,7 +43,10 @@ function is_partner_form_creation_page_CIPF() {
function partner_form_creation_page_init_CIPF() {
Plgntls::debug_infos(2);
redirects_home_if_not_partner();
if (!is_partner()) {
return;
}
Plgntls::debug_infos();
// https://developer.wordpress.org/reference/functions/get_query_var/#more-information
global $wp;
@@ -57,7 +64,9 @@ add_action('init','partner_form_creation_page_init_CIPF');
function partner_form_creation_page_CIPF() {
Plgntls::debug_infos(2);
redirects_home_if_not_partner();
if (!is_partner()) {
return;
}
if (!is_partner_form_creation_page_CIPF()) {
return;
}

View File

@@ -55,8 +55,10 @@ class Plgntls {
* typical for early hooks like 'init' or 'wp', where there is a first check to see if you should 'enter' in this function, level 1 will be present after thoses checks
* 2 : output everything
*
*/
private static $_DEBUG_INFOS = 1;
private static $_DEBUG_INFOS = 2;
*/
private static $_DEBUG_INFOS = 0;
private static $_instance_count = 0;
private static $_adding_count = 0;
@@ -335,6 +337,7 @@ class Plgntls {
$function = $trace[1]['function'];
$file = $trace[0]['file'];
$line = $trace[0]['line'];
error_log("-debug: function '".$function."' (in ".$file.", line ".$line .')');
}