- removed custom user function and put it in custer
- changed main file for cipf instead of fipfcard - reset some fields after prof form validation
This commit is contained in:
182
plugins/cipf_plugin/php/profs_form.php
Normal file
182
plugins/cipf_plugin/php/profs_form.php
Normal file
@@ -0,0 +1,182 @@
|
||||
<?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!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* when form is validated, reset some fields
|
||||
*
|
||||
*/
|
||||
function prof_form_reset_fields_CIPF($form_id, $post_array, $form_type) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_cgv = PLGNTLS_class::ACF_PROF_CGV;
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
update_field($acf_cgv['_name'], array(""), 'user_'.$user_id);
|
||||
}
|
||||
//add_action('df_before_process', 'prof_form_reset_fields_CIPF', 10, 3);
|
||||
add_action('df_after_process', 'prof_form_reset_fields_CIPF', 10, 3);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* NOT USEFUL ANYMORE :
|
||||
* it was to fix pbms in formbuilder with calculation field
|
||||
* but I made 2 better fixes (css and js)
|
||||
*
|
||||
* reset some fields for the form to buy the card
|
||||
* - cgv
|
||||
* - paiement
|
||||
* - livraison
|
||||
* - tarif
|
||||
* this action is called after redirection hook
|
||||
*
|
||||
*/
|
||||
//function reset_some_fields_CIPF() {
|
||||
// PLGNTLS_class::debug_infos();
|
||||
// $slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
||||
// $acf_cgv = PLGNTLS_class::ACF_PROF_CGV;
|
||||
// $acf_payement = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
||||
// $acf_delivery = PLGNTLS_class::ACF_CARD_PRICE_DELIVERY;
|
||||
// $acf_price = PLGNTLS_class::ACF_CARD_PRICE_CHOICE;
|
||||
//
|
||||
// if (!is_page($slug_renew_card))
|
||||
// return;
|
||||
//
|
||||
// $user_id = get_current_user_id();
|
||||
// update_field($acf_cgv['_name'] , array(""), 'user_'.$user_id);
|
||||
// update_field($acf_payement['_name'], array(""), 'user_'.$user_id);
|
||||
// update_field($acf_delivery['_name'], array(""), 'user_'.$user_id);
|
||||
// update_field($acf_price['_name'] , array(""), 'user_'.$user_id);
|
||||
//}
|
||||
//add_action('wp', 'reset_some_fields_CIPF');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* on renew page :
|
||||
* - check restrictions
|
||||
* - change some acf fields (if access granted)
|
||||
*
|
||||
* prevent users to fill the renew form if :
|
||||
* - they are not prof and logged in,
|
||||
* - and if their card is not in renewable state
|
||||
* - except admins and editor
|
||||
*
|
||||
*/
|
||||
function renew_page_restrictions_CIPF(){
|
||||
PLGNTLS_class::debug_infos();
|
||||
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
||||
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
||||
$role_prof = PLGNTLS_class::ROLE_PROF;
|
||||
$role_fipf = PLGNTLS_class::ROLE_FIPF;
|
||||
$role_admin = PLGNTLS_class::ROLE_ADMIN;
|
||||
|
||||
$base_url = home_url();
|
||||
|
||||
wp_reset_query();
|
||||
|
||||
if (!is_page('commande'))
|
||||
return;
|
||||
|
||||
/*
|
||||
* is it good ?
|
||||
* -> dont' redirect if user not logged in, because new users need to acces this page
|
||||
*
|
||||
if (!is_user_logged_in()) {
|
||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||
nocache_headers();
|
||||
wp_redirect($base_url, 301);
|
||||
exit;
|
||||
}
|
||||
*/
|
||||
|
||||
$current_user_id = get_current_user_id();
|
||||
$current_user = wp_get_current_user();
|
||||
$acf_id = 'user_'.$current_user_id;
|
||||
|
||||
|
||||
/*
|
||||
* check multiple user roles
|
||||
* https://developer.wordpress.org/reference/functions/current_user_can/#div-comment-4083
|
||||
*
|
||||
$allowed_roles = array($role_admin, $role_fipf, $role_prof);
|
||||
if (!array_intersect($allowed_roles, $current_user->roles))
|
||||
return;
|
||||
*/
|
||||
|
||||
/*
|
||||
* if prof, check card state
|
||||
* if cannot renew, redirect
|
||||
*
|
||||
if (current_user_can($role_prof)) {
|
||||
$can_renew = get_field($acf_prof_can_renew['_name'], $acf_id);
|
||||
if ($can_renew === false) {
|
||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||
nocache_headers();
|
||||
$redirect_url = home_url() . '/' . $slug_page_redirection;
|
||||
wp_redirect($redirect_url, 301);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
add_action('template_redirect', 'renew_page_restrictions_CIPF');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* on the renew card page for prof
|
||||
* output the right message, depending of the status of the card
|
||||
* 'renouveler' or 'commander'
|
||||
*
|
||||
* #cipf_prof_carte_commande -> default display: block;
|
||||
* #cipf_prof_carte_renouvellement -> default display: none;
|
||||
*
|
||||
*/
|
||||
function renew_page_filter_message_CIPF(){
|
||||
PLGNTLS_class::debug_infos();
|
||||
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
||||
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
||||
|
||||
if (!is_page($slug_renew_card))
|
||||
return;
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
$acf_id = 'user_'.$user_id;
|
||||
|
||||
$cipf_renew = new PLGNTLS_class();
|
||||
|
||||
$card_state = get_field($acf_card_state['_name'], $acf_id);
|
||||
|
||||
if ($card_state === 'Renouvellement') {
|
||||
$cipf_renew->add_to_front(array(
|
||||
array( 'css' => 'div#cipf_prof_carte_renouvellement {display: block;}' ),
|
||||
array( 'css' => 'div#cipf_prof_carte_commande {display: none;}' ),
|
||||
));
|
||||
}
|
||||
}
|
||||
add_action('wp_enqueue_scripts', 'renew_page_filter_message_CIPF');
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user