updates acf fields const values in class to avoid errors

This commit is contained in:
asus
2024-03-08 17:57:04 +01:00
parent 789a361871
commit fc3a205359
10 changed files with 173 additions and 67 deletions

View File

@@ -26,10 +26,10 @@ function reset_some_fields_CIPF() {
$acf_price = PLGNTLS_class::ACF_CARD_PRICE_CHOICE;
$user_id = get_current_user_id();
update_field($acf_cgv , array(""), 'user_'.$user_id);
update_field($acf_payement, array(""), 'user_'.$user_id);
update_field($acf_delivery, array(""), 'user_'.$user_id);
update_field($acf_price , array(""), 'user_'.$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);
}
@@ -37,14 +37,21 @@ function reset_some_fields_CIPF() {
/*
* 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
* 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(){
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
$acf_prof_can_renew = PLGNTLS_class::ACF_PROF_CAN_RENEW;
if (!is_page($slug_renew_card))
return;
@@ -54,30 +61,36 @@ function renew_page_restrictions_CIPF(){
$base_url = home_url();
$current_user_id = get_current_user_id();
/*
if (current_user_can('professeur__professeure')) {
$user_page = get_author_posts_url($current_user_id);
wp_redirect($user_page, 301);
}
else if (current_user_can('partenaire')) {
$args = array(
'post_type' => 'post',
'author' => $current_user_id,
'posts_per_page' => 1,
);
$posts = get_posts($args);
if (empty($posts))
$redirect_url = $base_url;
else {
$query = reset($posts);
$post_id = $query->ID;
$redirect_url = get_permalink($query->ID);
}
wp_redirect($redirect_url, 301);
}
exit;
*/
$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('administrator', 'editor', 'professeur__professeure');
if (!array_intersect($allowed_roles, $current_user->roles))
return;
/*
* if prof, check card state
*
*/
if (current_user_can('professeur__professeure')) {
$can_renew = get_field($acf_prof_can_renew, $acf_id);
if ($can_renew === false) {
$redirect_url = home_url() . '/' . $slug_page_redirection;
wp_redirect($redirect_url, 301);
exit;
}
}
/*
* if prof can renew its card, reset some form fields before
*
*/
reset_some_fields_CIPF();
}
add_action('template_redirect', 'renew_page_restrictions_CIPF');
@@ -88,8 +101,13 @@ 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(){
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
@@ -103,7 +121,7 @@ function renew_page_filter_message_CIPF(){
$cipf_renew = new PLGNTLS_class();
$card_state = get_field($acf_card_state, $acf_id);
$card_state = get_field($acf_card_state['_name'], $acf_id);
error_log("card_state");
error_log($card_state);