Files
2024_WEBSITE_fipf/plugins/cipf_plugin/php/profs_form.php
asus 33adb095e5 - creates redirect-home function
- restrict prof form to profs
- restrict paypal page for prof only
2024-03-20 01:02:46 +01:00

112 lines
2.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 is validated
*
*/
function prof_after_form_CIPF($form_id, $post_array, $form_type) {
PLGNTLS_class::debug_infos();
$acf_account_state = PLGNTLS_class::ACF_ACCOUNT_STATE;
//$user_id = get_current_user_id();
$user_id = $post_array['ID'];
/*
* reset cgv
*
*/
reset_acf_cgv_CIPF($user_id);
/*
* change status to :
* if paypal & new prof : 'to pay'
* if paypal & expired card : 'to_pay'
* if transfert $ expired card : 'waiting_invalid'
* if transfert $ valid card : 'waiting_valid'
*
*/
if (is_payment_method_paypal_CIPF($user_id)) {
if (is_account_new_CIPF($user_id)) {
set_account_to_pay_CIPF($user_id);
}
if (is_account_expired_CIPF($user_id)) {
set_account_to_pay_CIPF($user_id);
}
}
else if (is_payment_method_transfert_CIPF($user_id)) {
if (is_account_expired_CIPF($user_id)) {
set_account_waiting_invalid_CIPF($user_id);
}
else if (is_account_valid_CIPF($user_id)) {
set_account_waiting_valid_CIPF($user_id);
}
}
}
add_action('df_after_process', 'prof_after_form_CIPF', 10, 3);
/*
* only profs can access this form
*
*/
function prof_form_restrictions_CIPF(){
PLGNTLS_class::debug_infos();
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
$role_prof = PLGNTLS_class::ROLE_PROF;
if (!is_page($slug_renew_card)) {
return;
}
/*
* if prof, don't redirect
* for everyone else, redirect
*
*/
if (current_user_can($role_prof)) {
return;
}
redirect_home_CIPF();
}
add_action('template_redirect', 'prof_form_restrictions_CIPF');
/*
* enqueue scripts and styles on page prof
*
*/
function renew_page_filter_message_CIPF(){
PLGNTLS_class::debug_infos();
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
if (!is_page($slug_renew_card))
return;
$user_id = get_current_user_id();
display_page_css_CIPF($user_id);
}
add_action('wp_enqueue_scripts', 'renew_page_filter_message_CIPF');
?>