changed acf field access from _name to _key
This commit is contained in:
@@ -11,9 +11,9 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
|
||||
function check_fields_CIPF($fields) {
|
||||
error_log("--- in check_fields_CIPF");
|
||||
error_log("fields");
|
||||
error_log(json_encode($fields));
|
||||
// error_log("--- in check_fields_CIPF");
|
||||
// error_log("fields");
|
||||
// error_log(json_encode($fields));
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ if (!defined('ABSPATH')) {
|
||||
* return value of an acf field, no matter if the field is set up to return label or value
|
||||
*
|
||||
*/
|
||||
function get_acf_value_CIPF($field_name, $acf_id) {
|
||||
$field_object = get_field_object($field_name, $acf_id);
|
||||
function get_acf_value_CIPF($acf_field, $acf_id) {
|
||||
$field_object = get_field_object($acf_field['_key'], $acf_id);
|
||||
$return_format = $field_object['return_format'];
|
||||
$field = get_field($field_name, $acf_id);
|
||||
$field = get_field($acf_field['_key'], $acf_id);
|
||||
|
||||
$value = null;
|
||||
if ($return_format === 'array') {
|
||||
@@ -70,8 +70,8 @@ function check_can_pay_CIPF() {
|
||||
* in case it was changed from admin pannel
|
||||
*
|
||||
*/
|
||||
$tarif = get_acf_value_CIPF($acf_card_price_choice['_name'], $acf_id);
|
||||
$livraison = get_acf_value_CIPF($acf_card_price_delivery['_name'], $acf_id);
|
||||
$tarif = get_acf_value_CIPF($acf_card_price_choice, $acf_id);
|
||||
$livraison = get_acf_value_CIPF($acf_card_price_delivery, $acf_id);
|
||||
if ($tarif !== null && $livraison !== null) {
|
||||
$price = $tarif + $livraison;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ function get_date_limit_CIPF($user_id = null) {
|
||||
* get acf date field
|
||||
*
|
||||
*/
|
||||
$date_now = date_create('today');
|
||||
$current_date_limit_object = get_field_object($acf_card_expiration['_name'], $acf_id);
|
||||
if ($current_date_limit_object === false) {
|
||||
return false;
|
||||
@@ -87,6 +86,7 @@ function card_date_diff_CIPF($user_id = null) {
|
||||
* returns diff in days
|
||||
*
|
||||
*/
|
||||
$date_now = date_create('today');
|
||||
$date_diff = date_diff($date_now, $current_date_limit);
|
||||
return (int)$date_diff->format('%R%a');
|
||||
}
|
||||
@@ -96,6 +96,7 @@ function card_date_diff_CIPF($user_id = null) {
|
||||
|
||||
/*
|
||||
* returns true if date is in paste or is empty
|
||||
* use is_card_date_exists_CIPF to check if the field is empty
|
||||
*
|
||||
*/
|
||||
function is_card_date_expired_CIPF($user_id = null) {
|
||||
@@ -126,6 +127,42 @@ function is_card_date_expired_CIPF($user_id = null) {
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* returns true if date is empty
|
||||
*
|
||||
*/
|
||||
function card_date_exists_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
|
||||
|
||||
/*
|
||||
* define ids
|
||||
*
|
||||
*/
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
|
||||
/*
|
||||
* get acf date field
|
||||
*
|
||||
*/
|
||||
$date_now = date_create('today');
|
||||
$current_date = get_field($acf_card_expiration['_name'], $acf_id);
|
||||
|
||||
if (empty($current_date)) {
|
||||
return false;
|
||||
}
|
||||
if (is_null($current_date)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* will add card_duration to card
|
||||
* card_duration is expected in a string format : https://www.php.net/manual/en/class.dateinterval.php
|
||||
|
||||
@@ -112,7 +112,7 @@ if (!defined('ABSPATH')) {
|
||||
* early checks on profil page
|
||||
*
|
||||
*/
|
||||
function check_prof_profil_CIPF() {
|
||||
function prof_profil_check_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
|
||||
// is an author page
|
||||
@@ -122,17 +122,20 @@ function check_prof_profil_CIPF() {
|
||||
// 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
|
||||
*
|
||||
*/
|
||||
if (is_card_date_expired_CIPF) {
|
||||
if (!is_account_expired_CIPF) {
|
||||
set_account_expired_CIPF;
|
||||
if (card_date_exists_CIPF()) {
|
||||
if (is_card_date_expired_CIPF()) {
|
||||
if (!is_account_expired_CIPF()) {
|
||||
set_account_expired_CIPF();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action('template_redirect', 'check_prof_page_CIPF', 11);
|
||||
add_action('wp', 'prof_profil_check_CIPF', 11);
|
||||
|
||||
|
||||
|
||||
@@ -141,7 +144,7 @@ add_action('template_redirect', 'check_prof_page_CIPF', 11);
|
||||
* if profil needs redirection, it happens here
|
||||
*
|
||||
*/
|
||||
function check_prof_page_CIPF() {
|
||||
function prof_profil_redirects_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
|
||||
// is an author page
|
||||
@@ -154,7 +157,7 @@ function check_prof_page_CIPF() {
|
||||
// redirections here
|
||||
|
||||
}
|
||||
add_action('template_redirect', 'redirect_prof_page_CIPF', 11);
|
||||
add_action('template_redirect', 'prof_profil_redirects_CIPF', 11);
|
||||
|
||||
|
||||
|
||||
@@ -163,7 +166,7 @@ add_action('template_redirect', 'redirect_prof_page_CIPF', 11);
|
||||
* time to upload some scripts and styles on prof profil page
|
||||
*
|
||||
*/
|
||||
function check_prof_profil_CIPF() {
|
||||
function prof_profil_scripts_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
|
||||
// is an author page
|
||||
@@ -174,9 +177,9 @@ function check_prof_profil_CIPF() {
|
||||
$author_id = get_queried_object_id();
|
||||
$cipf_prof = new PLGNTLS_class();
|
||||
|
||||
$cipf_renew->add_to_front();
|
||||
$cipf_prof->add_to_front();
|
||||
}
|
||||
add_action('wp_enqueue_scripts', 'check_prof_page_CIPF', 11);
|
||||
add_action('wp_enqueue_scripts', 'prof_profil_scripts_CIPF', 11);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -55,7 +55,13 @@ function is_acf_state_CIPF($user_id = null, $acf_field, $state_name) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
$acf_state = get_field($acf_field['_name'], $acf_id);
|
||||
|
||||
/*
|
||||
* when acf fields have not been initated a first time, you can't find them by name
|
||||
* so use key instead
|
||||
*
|
||||
*/
|
||||
$acf_state = get_field($acf_field['_key'], $acf_id);
|
||||
|
||||
if ($acf_state === $acf_field[$state_name]) {
|
||||
return true;
|
||||
@@ -70,7 +76,7 @@ function set_acf_state_CIPF($user_id = null, $acf_field, $state_name) {
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
|
||||
update_field($acf_field['_name'], $acf_field[$state_name], $acf_id);
|
||||
update_field($acf_field['_key'], $acf_field[$state_name], $acf_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -280,8 +286,9 @@ function set_card_number_CIPF($user_id = null) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
|
||||
$date_now = date_create('today');
|
||||
$card_id = $date_now->format('Ymd') . $user_id;
|
||||
update_field($acf_card_number['_name'], $card_id, $acf_id);
|
||||
update_field($acf_card_number['_key'], $card_id, $acf_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -60,17 +60,17 @@ class PLGNTLS_class {
|
||||
*
|
||||
*/
|
||||
// ACF
|
||||
const ACF_CARD_STATE = ['_name'=>'etat_carte', 'new'=>'Commande', 'renew'=>'Renouvellement']; // radio button
|
||||
const ACF_CARD_PAYMENT_METHOD = ['_name'=>'paiement', 'paypal'=>'Paypal', 'transfert'=>'Virement']; // radio button
|
||||
const ACF_CARD_PRICE_CHOICE = ['_name'=>'tarif', 'low'=>'10', 'high'=>'15']; // radio button
|
||||
const ACF_CARD_PRICE_DELIVERY = ['_name'=>'livraison', 'pdf'=>'PDF', 'post'=>'Fabrication']; // radio button
|
||||
const ACF_PROF_IS_ACTIV = ['_name'=>'compte-actif', 'activ'=>'Actif', 'inactiv'=>'Inactif']; // radio button
|
||||
const ACF_PROF_CGV = ['_name'=>'cgv', 'cgv'=>'cgv']; // checkbox
|
||||
const ACF_CARD_PRICE_TOTAL = ['_name'=>'somme_a_regler']; // number
|
||||
const ACF_CARD_NUMBER = ['_name'=>'numero_de_la_carte']; // number
|
||||
const ACF_CARD_EXPIRATION = ['_name'=>'fin_de_validite']; // date picker
|
||||
const ACF_CARD_PAYMENT_STATE = ['_name'=>'etat_paiement', 'started'=>'en_cours', 'success'=>'reussi', 'failure'=>'echec', 'nothing'=>'aucun']; // radio button
|
||||
const ACF_ACCOUNT_STATE = ['_name'=>'etat_compte', 'new'=>'nouveau prof', 'to_pay'=>'doit payer', 'valid'=>'carte valide', 'waiting_invalid'=>'en attente invalide', 'waiting_valid'=>'en attente valide', 'expired'=>'carte expiree', ];
|
||||
const ACF_CARD_STATE = ['_name'=>'etat_carte', 'new'=>'Commande', 'renew'=>'Renouvellement', '_key'=>'field_65d85d72c4265']; // radio button
|
||||
const ACF_CARD_PAYMENT_METHOD = ['_name'=>'paiement', 'paypal'=>'Paypal', 'transfert'=>'Virement', '_key'=>'field_65d243b9cc89d']; // radio button
|
||||
const ACF_CARD_PRICE_CHOICE = ['_name'=>'tarif', 'low'=>'10', 'high'=>'15', '_key'=>'field_65d24447cc89f']; // radio button
|
||||
const ACF_CARD_PRICE_DELIVERY = ['_name'=>'livraison', 'pdf'=>'PDF', 'post'=>'Fabrication', '_key'=>'field_65d36f6e02a9a']; // radio button
|
||||
const ACF_PROF_IS_ACTIV = ['_name'=>'compte-actif', 'activ'=>'Actif', 'inactiv'=>'Inactif', '_key'=>'field_65e8acd5c2065']; // radio button
|
||||
const ACF_PROF_CGV = ['_name'=>'cgv', 'cgv'=>'cgv', '_key'=>'field_65d2441fcc89e']; // checkbox
|
||||
const ACF_CARD_PRICE_TOTAL = ['_name'=>'somme_a_regler', '_key'=>'field_65d396876fe57']; // number
|
||||
const ACF_CARD_NUMBER = ['_name'=>'numero_de_la_carte', '_key'=>'field_65e48a0201107']; // number
|
||||
const ACF_CARD_EXPIRATION = ['_name'=>'fin_de_validite', '_key'=>'field_65d66b26ebf59']; // date picker
|
||||
const ACF_CARD_PAYMENT_STATE = ['_name'=>'etat_paiement', 'started'=>'en_cours', 'success'=>'reussi', 'failure'=>'echec', 'nothing'=>'aucun', '_key'=>'field_65eedb65227cb']; // radio button
|
||||
const ACF_ACCOUNT_STATE = ['_name'=>'etat_compte', 'new'=>'nouveau prof', 'to_pay'=>'doit payer', 'valid'=>'carte valide', 'waiting_invalid'=>'en attente invalide', 'waiting_valid'=>'en attente valide', 'expired'=>'carte expiree', '_key'=>'field_65f89fb6de318'];
|
||||
|
||||
// META
|
||||
const META_PAYEMENT_STATUS = 'cipf_payement_status';
|
||||
|
||||
Reference in New Issue
Block a user