125 lines
2.4 KiB
PHP
125 lines
2.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* it means someone outside wp is accessing the file, in this case kill it.
|
|
*/
|
|
if (!defined('ABSPATH')) {
|
|
die('You can not access this file!');
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
* early checks on profil page
|
|
*
|
|
*/
|
|
function prof_profil_check_CIPF() {
|
|
PLGNTLS_class::debug_infos();
|
|
|
|
// is an author page
|
|
if (!is_author())
|
|
return;
|
|
|
|
// the way to find the id of the author of an author_page
|
|
$author_id = get_queried_object_id();
|
|
|
|
|
|
/*
|
|
* in case event didn't fire, change account to expire here
|
|
* also check for waiting transfert : valid -> invalid
|
|
*
|
|
*/
|
|
if (card_date_exists_CIPF($author_id)) {
|
|
if (is_card_date_expired_CIPF($author_id)) {
|
|
if (!is_account_expired_CIPF($author_id)) {
|
|
set_account_expired_CIPF($author_id);
|
|
}
|
|
if (is_account_waiting_valid_CIPF($author_id)) {
|
|
set_account_waiting_invalid_CIPF($author_id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
add_action('wp', 'prof_profil_check_CIPF', 11);
|
|
|
|
|
|
|
|
|
|
/*
|
|
* if profil needs redirection, it happens here
|
|
*
|
|
*/
|
|
function prof_profil_redirects_CIPF() {
|
|
PLGNTLS_class::debug_infos();
|
|
$role_fipf = PLGNTLS_class::ROLE_FIPF;
|
|
$role_admin = PLGNTLS_class::ROLE_ADMIN;
|
|
$role_partner = PLGNTLS_class::ROLE_PARTNER;
|
|
|
|
// is an author page
|
|
if (!is_author())
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
* check multiple user roles
|
|
* https://developer.wordpress.org/reference/functions/current_user_can/#div-comment-4083
|
|
* if user->role is found in array of allowed role, no redirection needed
|
|
*
|
|
*/
|
|
$current_user = wp_get_current_user();
|
|
$allowed_roles = array($role_admin, $role_fipf);
|
|
if (array_intersect($allowed_roles, $current_user->roles))
|
|
return;
|
|
|
|
|
|
/*
|
|
* if partner, redirect
|
|
*
|
|
*/
|
|
if (current_user_can($role_partner)) {
|
|
redirect_home_CIPF();
|
|
}
|
|
|
|
|
|
/*
|
|
* if connected user is not author, get out
|
|
*
|
|
*/
|
|
// the way to find the id of the author of an author_page
|
|
$author_id = get_queried_object_id();
|
|
$current_user_id = get_current_user_id();
|
|
if ($current_user_id != $author_id) {
|
|
redirect_home_CIPF();
|
|
}
|
|
|
|
}
|
|
add_action('template_redirect', 'prof_profil_redirects_CIPF', 11);
|
|
|
|
|
|
|
|
|
|
/*
|
|
* time to upload some scripts and styles on prof profil page
|
|
*
|
|
*/
|
|
function prof_profil_scripts_CIPF() {
|
|
PLGNTLS_class::debug_infos();
|
|
|
|
// is an author page
|
|
if (!is_author())
|
|
return;
|
|
|
|
// the way to find the id of the author of an author_page
|
|
$author_id = get_queried_object_id();
|
|
|
|
display_page_css_CIPF($author_id);
|
|
}
|
|
add_action('wp_enqueue_scripts', 'prof_profil_scripts_CIPF', 11);
|
|
|
|
|
|
|
|
|
|
?>
|