170 lines
3.2 KiB
PHP
170 lines
3.2 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_class::debug_infos();
|
|
$acf_account_state = PLGNTLS_class::ACF_ACCOUNT_STATE;
|
|
$form_prof_transfert_id = PLGNTLS_class::FORM_PROF_TRANSFERT_ID;
|
|
|
|
if ($form_prof_transfert_id !== $form_id) {
|
|
return;
|
|
}
|
|
|
|
//$user_id = get_current_user_id();
|
|
$user_id = $post_array['ID'];
|
|
|
|
|
|
/*
|
|
* when transfert is validate, change card to valid
|
|
*
|
|
*/
|
|
if (is_transfert_success_CIPF($user_id)) {
|
|
set_account_valid_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_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;
|
|
// don't redirect if it is the divi builder mode
|
|
if (et_fb_is_enabled()) {
|
|
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();
|
|
}
|
|
|
|
|
|
/*
|
|
* 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_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);
|
|
|
|
|
|
|
|
|
|
?>
|