Files
2024_WEBSITE_fipf/plugins/cipf_plugin/php/profs_profil.php
2024-04-02 15:45:54 +02:00

155 lines
3.0 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!');
}
/*
* actions after prof form transfert validation is processed
*
*/
function prof_after_form_transfert_validation_CIPF($form_id, $post_array, $form_type) {
Plgntls::debug_infos();
$acf_account_state = Cipf::ACF_ACCOUNT_STATE;
$form_prof_transfert_id = Cipf::FORM_PROF_TRANSFERT_ID;
if ($form_prof_transfert_id !== $form_id) {
return;
}
//$user_id = get_current_user_id();
$user_id = $post_array['ID'];
// the check is not really connected to the form, it check the acf value, whatever the form value is, the form validation is just a trigger for this check
handle_transfert_validation_CIPF($user_id);
}
add_action('df_after_process', 'prof_after_form_transfert_validation_CIPF', 10, 3);
/*
* early checks on profil page
*
*/
function prof_profil_check_CIPF() {
Plgntls::debug_infos(2);
// is an author page
if (!is_author())
return;
Plgntls::debug_infos();
// 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, handle card changes
*
*/
handle_transfert_validation_CIPF($author_id);
handle_card_expire_CIPF($author_id);
}
add_action('wp', 'prof_profil_check_CIPF', 11);
/*
* if profil needs redirection, it happens here
*
*/
function prof_profil_redirects_CIPF() {
Plgntls::debug_infos(2);
$role_fipf = Cipf::ROLE_FIPF;
$role_admin = Cipf::ROLE_ADMIN;
$role_partner = Cipf::ROLE_PARTNER;
// is an author page
if (!is_author())
return;
// don't redirect if it is the divi builder mode
if (et_fb_is_enabled()) {
return;
}
Plgntls::debug_infos();
/*
* 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();
}
/*
* if connected prof is new, redirect to form commande
*
*/
if (is_account_new_CIPF()) {
redirect_command_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::debug_infos(2);
// is an author page
if (!is_author())
return;
Plgntls::debug_infos();
// the way to find the id of the author of an author_page
$author_id = get_queried_object_id();
display_states_css_CIPF($author_id);
}
add_action('wp_enqueue_scripts', 'prof_profil_scripts_CIPF', 11);
?>