wip handle custom form submit
This commit is contained in:
108
2
Normal file
108
2
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* custom action in php on custom form submission
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function admin_validate_prof_CIPF($form_id, $post_array, $form_type) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$admin_validate_prof_field = PLGNTLS_class::ADMIN_VALIDATE_PROF_FIELD;
|
||||||
|
|
||||||
|
if ($form_type !== 'custom')
|
||||||
|
return;
|
||||||
|
error_log("---");
|
||||||
|
// error_log("in test_form_CIPF");
|
||||||
|
// error_log("form_id");
|
||||||
|
// error_log(json_encode($form_id));
|
||||||
|
// error_log("post_array");
|
||||||
|
// error_log(json_encode($post_array));
|
||||||
|
// error_log("form_type");
|
||||||
|
// error_log(json_encode($form_type));
|
||||||
|
|
||||||
|
$field_id = $post_array['field_id'];
|
||||||
|
$contains_id = in_array($admin_validate_prof_field, $field_id);
|
||||||
|
if ($contains_id === false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* custom action */
|
||||||
|
}
|
||||||
|
add_action('df_before_process', 'admin_validate_prof_CIPF', 10, 3);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
before :
|
||||||
|
|
||||||
|
|
||||||
|
in test_form_CIPF
|
||||||
|
form_id
|
||||||
|
""
|
||||||
|
post_array
|
||||||
|
{"field_title":["\u00c9tat du compte"],"field_name":["de_fb_compte-actif"],"field_id":["de_fb_field_1"],"form_type_confirm":""}
|
||||||
|
form_type
|
||||||
|
"custom"
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
after :
|
||||||
|
|
||||||
|
|
||||||
|
in test_form_CIPF
|
||||||
|
form_id
|
||||||
|
""
|
||||||
|
post_array
|
||||||
|
{"field_title":["\u00c9tat du compte"],"field_name":["de_fb_compte-actif"],"field_id":["de_fb_field_1"],"form_type_confirm":""}
|
||||||
|
form_type
|
||||||
|
"custom"
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
exploded view :
|
||||||
|
|
||||||
|
{
|
||||||
|
"field_title":["\u00c9tat du compte"],
|
||||||
|
"field_name":["de_fb_compte-actif"],
|
||||||
|
"field_id":["de_fb_field_1"],
|
||||||
|
"form_type_confirm":""
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
"field_title":["\u00c9tat du compte"],
|
||||||
|
"field_name":["de_fb_compte-actif"],
|
||||||
|
"field_id":["de_fb_field_1"],
|
||||||
|
"compte-actif":"Actif",
|
||||||
|
"form_type_confirm":""
|
||||||
|
}
|
||||||
|
CIPF_admin_activation_prof
|
||||||
|
{
|
||||||
|
"field_title":["\u00c9tat du compte"],
|
||||||
|
"field_name":["compte-actif"],
|
||||||
|
"field_id":["cipf_admin_activation_prof"],
|
||||||
|
"compte-actif":"Inactif",
|
||||||
|
"form_type_confirm":""
|
||||||
|
}
|
||||||
|
|
||||||
|
--- with field test :
|
||||||
|
|
||||||
|
{
|
||||||
|
"field_title":["\u00c9tat du compte","test"],
|
||||||
|
"field_name":["compte-actif","de_fb_field_3"],
|
||||||
|
"field_id":["cipf_admin_activation_prof","de_fb_field_3"],
|
||||||
|
"field_3":"",
|
||||||
|
"form_type_confirm":""
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -47,6 +47,8 @@ include_once(PLGNTLS_class::root_path() . 'php/prof_check_page.php');
|
|||||||
include_once(PLGNTLS_class::root_path() . 'php/renew_card.php');
|
include_once(PLGNTLS_class::root_path() . 'php/renew_card.php');
|
||||||
//include_once(PLGNTLS_class::root_path() . 'php/reset_card_form.php');
|
//include_once(PLGNTLS_class::root_path() . 'php/reset_card_form.php');
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/partner_check_page.php');
|
include_once(PLGNTLS_class::root_path() . 'php/partner_check_page.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/format_user_infos.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/admin_modif_prof.php');
|
||||||
|
|
||||||
|
|
||||||
// form builder patch :
|
// form builder patch :
|
||||||
|
|||||||
24
plugins/cipf_plugin/js/admin_prevent_submit.js
Normal file
24
plugins/cipf_plugin/js/admin_prevent_submit.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
cipf_admin_activate_prof_form
|
||||||
|
*/
|
||||||
|
|
||||||
|
function admin_activate_form_submit_prevent_CIPF() {
|
||||||
|
let form_activate_prof = document.querySelector('#cipf_admin_activate_prof_form form');
|
||||||
|
console.log("form:");
|
||||||
|
console.log(form_activate_prof);
|
||||||
|
if (form_activate_prof === null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
function handle_form(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
let form_data = new FormData(event.target);
|
||||||
|
for (var pair of form_data.entries()) {
|
||||||
|
console.log(pair[0]+ ': ' + pair[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
form_activate_prof.addEventListener('submit', handle_form);
|
||||||
|
}
|
||||||
|
admin_activate_form_submit_prevent_CIPF();
|
||||||
|
|
||||||
@@ -1,18 +1,23 @@
|
|||||||
|
|
||||||
/*
|
function patch_form_calculation_CIPF() {
|
||||||
* finds the input:checked in the element .calculate_field
|
let form_calculation = document.querySelector('form.fb_form.multistep');
|
||||||
* and trigger the event 'change' on it
|
if (form_calculation === null)
|
||||||
* - this event 'change' is added by form builder in divi-form-calc-min.js :
|
return;
|
||||||
* $(document).on(
|
|
||||||
* 'change',
|
/*
|
||||||
* '.calculate_field input:not([type="hidden"]), .calculate_field select',
|
* finds the input:checked in the element .calculate_field
|
||||||
* function () {
|
* and trigger the event 'change' on it
|
||||||
* ...
|
* - this event 'change' is added by form builder in divi-form-calc-min.js :
|
||||||
* }
|
* $(document).on(
|
||||||
* );
|
* 'change',
|
||||||
*
|
* '.calculate_field input:not([type="hidden"]), .calculate_field select',
|
||||||
*/
|
* function () {
|
||||||
function trigger_change_CIPF(element) {
|
* ...
|
||||||
|
* }
|
||||||
|
* );
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function trigger_change(element) {
|
||||||
/*
|
/*
|
||||||
* jquery version
|
* jquery version
|
||||||
*
|
*
|
||||||
@@ -34,21 +39,19 @@ function trigger_change_CIPF(element) {
|
|||||||
});
|
});
|
||||||
input.dispatchEvent(change_event);
|
input.dispatchEvent(change_event);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let form_CIPF = document.querySelector('form.fb_form.multistep');
|
// create an observer on form to check if child nodes are modified
|
||||||
|
const observer_form = new MutationObserver(wait_for_calculation_class);
|
||||||
// create an observer on form to check if child nodes are modified
|
observer_form.observe(form_calculation, {
|
||||||
const observer_form_CIPF = new MutationObserver(wait_for_calculation_class_CIPF);
|
|
||||||
observer_form_CIPF.observe(form_CIPF, {
|
|
||||||
subtree: true,
|
subtree: true,
|
||||||
attributes: true,
|
attributes: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// observe mutations to see if they include the addition of class .calculate_field
|
// observe mutations to see if they include the addition of class .calculate_field
|
||||||
// if the class is added, call the function that might trigger the change event on it
|
// if the class is added, call the function that might trigger the change event on it
|
||||||
function wait_for_calculation_class_CIPF(mutationsList) {
|
function wait_for_calculation_class(mutationsList) {
|
||||||
mutationsList.forEach((mutation) => {
|
mutationsList.forEach((mutation) => {
|
||||||
// check if class where added
|
// check if class where added
|
||||||
if (mutation.type !== 'attributes')
|
if (mutation.type !== 'attributes')
|
||||||
@@ -59,8 +62,10 @@ function wait_for_calculation_class_CIPF(mutationsList) {
|
|||||||
let target = mutation.target;
|
let target = mutation.target;
|
||||||
if (target.classList.contains('calculate_field')) {
|
if (target.classList.contains('calculate_field')) {
|
||||||
// If the class is added, trigger the 'change' event
|
// If the class is added, trigger the 'change' event
|
||||||
trigger_change_CIPF(target);
|
trigger_change(target);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
patch_form_calculation_CIPF();
|
||||||
|
|
||||||
|
|||||||
166
plugins/cipf_plugin/php/admin_modif_prof.php
Normal file
166
plugins/cipf_plugin/php/admin_modif_prof.php
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* custom action in php on custom form submission
|
||||||
|
* custom forms are not processed by divi form builder
|
||||||
|
* so they don't change between hooks before and after process
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function admin_validate_prof_CIPF($form_id, $post_array, $form_type) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$admin_validate_prof_field = PLGNTLS_class::ADMIN_VALIDATE_PROF_FIELD;
|
||||||
|
|
||||||
|
if ($form_type !== 'custom')
|
||||||
|
return;
|
||||||
|
error_log("---");
|
||||||
|
error_log("in test_form_CIPF");
|
||||||
|
// error_log("form_id");
|
||||||
|
// error_log(json_encode($form_id));
|
||||||
|
// error_log("post_array");
|
||||||
|
// error_log(json_encode($post_array));
|
||||||
|
// error_log("form_type");
|
||||||
|
// error_log(json_encode($form_type));
|
||||||
|
|
||||||
|
$field_id = $post_array['field_id'];
|
||||||
|
$contains_id = in_array($admin_validate_prof_field, $field_id);
|
||||||
|
if ($contains_id === false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* custom action */
|
||||||
|
}
|
||||||
|
add_action('df_before_process', 'admin_validate_prof_CIPF', 10, 3);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
before :
|
||||||
|
|
||||||
|
|
||||||
|
in test_form_CIPF
|
||||||
|
form_id
|
||||||
|
""
|
||||||
|
post_array
|
||||||
|
{"field_title":["\u00c9tat du compte"],"field_name":["de_fb_compte-actif"],"field_id":["de_fb_field_1"],"form_type_confirm":""}
|
||||||
|
form_type
|
||||||
|
"custom"
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
after :
|
||||||
|
|
||||||
|
|
||||||
|
in test_form_CIPF
|
||||||
|
form_id
|
||||||
|
""
|
||||||
|
post_array
|
||||||
|
{"field_title":["\u00c9tat du compte"],"field_name":["de_fb_compte-actif"],"field_id":["de_fb_field_1"],"form_type_confirm":""}
|
||||||
|
form_type
|
||||||
|
"custom"
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
exploded view :
|
||||||
|
|
||||||
|
{
|
||||||
|
"field_title":["\u00c9tat du compte"],
|
||||||
|
"field_name":["de_fb_compte-actif"],
|
||||||
|
"field_id":["de_fb_field_1"],
|
||||||
|
"form_type_confirm":""
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
"field_title":["\u00c9tat du compte"],
|
||||||
|
"field_name":["de_fb_compte-actif"],
|
||||||
|
"field_id":["de_fb_field_1"],
|
||||||
|
"compte-actif":"Actif",
|
||||||
|
"form_type_confirm":""
|
||||||
|
}
|
||||||
|
CIPF_admin_activation_prof
|
||||||
|
{
|
||||||
|
"field_title":["\u00c9tat du compte"],
|
||||||
|
"field_name":["compte-actif"],
|
||||||
|
"field_id":["cipf_admin_activation_prof"],
|
||||||
|
"compte-actif":"Inactif",
|
||||||
|
"form_type_confirm":""
|
||||||
|
}
|
||||||
|
|
||||||
|
--- with field test :
|
||||||
|
|
||||||
|
{
|
||||||
|
"field_title":["\u00c9tat du compte","test"],
|
||||||
|
"field_name":["compte-actif","de_fb_field_3"],
|
||||||
|
"field_id":["cipf_admin_activation_prof","de_fb_field_3"],
|
||||||
|
"field_3":"",
|
||||||
|
"form_type_confirm":""
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ABORTED
|
||||||
|
* tried to receive the form in ajax from front with wp REST API
|
||||||
|
* but then I'm not sure how to handle the front
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function admin_validate_prof_form_CIPF($request) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
error_log("-----");
|
||||||
|
error_log("inside admin_validate_prof_form_CIPF");
|
||||||
|
error_log("request");
|
||||||
|
error_log(json_encode($request));
|
||||||
|
error_log("_POST");
|
||||||
|
error_log(json_encode($_POST));
|
||||||
|
// _POST : {"field_title":["\u00c9tat du compte"],"field_name":["compte-actif"],"field_id":["cipf_admin_activate_prof"],"form_key":"40781-1","unique_id":"91eed9aa-2b92-4da7-a0b4-e94f24515223","form_type":"custom","divi-form-submit":"yes","form_id":"","form_type_confirm":""}
|
||||||
|
|
||||||
|
// maybe do a redirection here ?
|
||||||
|
// with wp_safe_redirect(home_url('/slug')); ?
|
||||||
|
// return new WP_REST_Response( array( 'message' => 'Form submitted successfully' ), 200 );
|
||||||
|
}
|
||||||
|
function endpoint_form_admin_activate_prof_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$base_rest_route = PLGNTLS_class::BASE_REST_ROUTE;
|
||||||
|
register_rest_route($base_rest_route, '/admin_prof_activate_form', array(
|
||||||
|
'methods' => 'POST',
|
||||||
|
'callback' => 'admin_validate_prof_form_CIPF',
|
||||||
|
));
|
||||||
|
};
|
||||||
|
add_action('rest_api_init', 'endpoint_form_admin_activate_prof_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ABORTED
|
||||||
|
* enqueue script that should prevent the form to submit, but does not work
|
||||||
|
*
|
||||||
|
function admin_validate_prof_prevent_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$handle = 'admin_prevent_submit';
|
||||||
|
$url = PLGNTLS_class::root_url() . 'js/admin_prevent_submit.js';
|
||||||
|
$dependencies = array();
|
||||||
|
$version = null;
|
||||||
|
$defer = true;
|
||||||
|
wp_enqueue_script($handle, $url, $dependencies, $version, $defer);
|
||||||
|
}
|
||||||
|
add_action('wp_enqueue_scripts', 'admin_validate_prof_prevent_CIPF');
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -7,6 +7,7 @@ if (!defined('ABSPATH')) {
|
|||||||
die('You can not access this file!');
|
die('You can not access this file!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/format_user_infos.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ function replace_words_CIPF($matches, $user_id = null) {
|
|||||||
}
|
}
|
||||||
else if (is_user_logged_in()) {
|
else if (is_user_logged_in()) {
|
||||||
$current_user = wp_get_current_user();
|
$current_user = wp_get_current_user();
|
||||||
|
$user_id = get_current_user_id();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return "";
|
return "";
|
||||||
@@ -31,7 +33,7 @@ function replace_words_CIPF($matches, $user_id = null) {
|
|||||||
return "";
|
return "";
|
||||||
|
|
||||||
$query = $matches[1];
|
$query = $matches[1];
|
||||||
$result = $current_user->$query;
|
$result = format_user_info_CIPF($query, $current_user, $user_id);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if result is array, take the first element (not ideal)
|
* if result is array, take the first element (not ideal)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ function add_form_calculation_patch_CIPF() {
|
|||||||
$handle = 'form_calculation_patch';
|
$handle = 'form_calculation_patch';
|
||||||
$url = PLGNTLS_class::root_url() . 'js/form_builder_patch/form_calculation.js';
|
$url = PLGNTLS_class::root_url() . 'js/form_builder_patch/form_calculation.js';
|
||||||
$dependencies = array('de_fb_calc');
|
$dependencies = array('de_fb_calc');
|
||||||
$version = '';
|
$version = null;
|
||||||
$defer = true;
|
$defer = true;
|
||||||
wp_enqueue_script( $handle, $url, $dependencies, $version, $defer);
|
wp_enqueue_script( $handle, $url, $dependencies, $version, $defer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ function add_my_jquery_patch()
|
|||||||
$handle = 'jquery_validator_url_patch';
|
$handle = 'jquery_validator_url_patch';
|
||||||
$url = PLGNTLS_class::root_url() . 'js/form_builder_patch/url_validation.js';
|
$url = PLGNTLS_class::root_url() . 'js/form_builder_patch/url_validation.js';
|
||||||
$dependencies = array('de_fb_validate');
|
$dependencies = array('de_fb_validate');
|
||||||
$version = '';
|
$version = null;
|
||||||
$defer = true;
|
$defer = true;
|
||||||
wp_enqueue_script( $handle, $url, $dependencies, $version, $defer);
|
wp_enqueue_script( $handle, $url, $dependencies, $version, $defer);
|
||||||
}
|
}
|
||||||
|
|||||||
92
plugins/cipf_plugin/php/format_user_infos.php
Normal file
92
plugins/cipf_plugin/php/format_user_infos.php
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function format_user_info_CIPF($query, &$current_user, $user_id) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$output_date_format = PLGNTLS_class::USER_INFO_DATE_FORMAT;
|
||||||
|
|
||||||
|
$is_acf = false;
|
||||||
|
$is_date = false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check if it's an acf field
|
||||||
|
* first method : check if _field exist
|
||||||
|
*
|
||||||
|
$_acf_field = '_'.$query;
|
||||||
|
$acf_field = $current_user->$_acf_field;
|
||||||
|
if (!empty($acf_field))
|
||||||
|
$is_acf = true;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check if it's an acf field, and a date
|
||||||
|
* second method : check what get_field_object() returns
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
$acf_object = get_field_object($query, $acf_id);
|
||||||
|
if ($acf_object !== false)
|
||||||
|
$is_acf = true;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if is acf, use the acf return format
|
||||||
|
* otherwise, use the default wordpress value
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if ($is_acf)
|
||||||
|
$output = get_field($query, $acf_id);
|
||||||
|
else
|
||||||
|
$output = $current_user->$query;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check if is date
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if ($is_acf) {
|
||||||
|
$acf_type = $acf_object['type'];
|
||||||
|
if ($acf_type && $acf_type === "date_picker")
|
||||||
|
$is_date = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if is date, transform format
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if ($is_date) {
|
||||||
|
$acf_date_string = $acf_object['value'];
|
||||||
|
$acf_date_format = $acf_object['return_format'];
|
||||||
|
$date = date_create_from_format($acf_date_format, $acf_date_string);
|
||||||
|
$output = $date->format($output_date_format);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return the result
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
while (is_array($output) && count($output) === 1)
|
||||||
|
$output = reset($output);
|
||||||
|
if (is_array($output) && count($output) === 0)
|
||||||
|
$output = '';
|
||||||
|
if (!is_string($output))
|
||||||
|
$output = json_encode($output, JSON_UNESCAPED_SLASHES);
|
||||||
|
return esc_html($output);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -107,7 +107,6 @@ post_array
|
|||||||
form_type
|
form_type
|
||||||
"post"
|
"post"
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
function test_partner_CIPF($form_id, $post_array) {
|
function test_partner_CIPF($form_id, $post_array) {
|
||||||
error_log("---");
|
error_log("---");
|
||||||
@@ -119,6 +118,7 @@ function test_partner_CIPF($form_id, $post_array) {
|
|||||||
}
|
}
|
||||||
add_action( 'df_before_process', 'test_partner_CIPF', 10, 2);
|
add_action( 'df_before_process', 'test_partner_CIPF', 10, 2);
|
||||||
add_action( 'df_after_process', 'test_partner_CIPF', 10, 2);
|
add_action( 'df_after_process', 'test_partner_CIPF', 10, 2);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ if (!defined('ABSPATH')) {
|
|||||||
// diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573
|
// diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573
|
||||||
function routes_endpoints_CIPF() {
|
function routes_endpoints_CIPF() {
|
||||||
PLGNTLS_class::debug_infos();
|
PLGNTLS_class::debug_infos();
|
||||||
$base_rest_route = "cipf_plugin/api/v1";
|
$base_rest_route = PLGNTLS_class::BASE_REST_ROUTE;
|
||||||
register_rest_route($base_rest_route, '/orders', array(
|
register_rest_route($base_rest_route, '/orders', array(
|
||||||
'methods' => 'POST',
|
'methods' => 'POST',
|
||||||
'callback' => 'handle_orders_request_CIPF',
|
'callback' => 'handle_orders_request_CIPF',
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ function handle_prof_is_activ_CIPF($author_id) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
$is_activ = get_field($acf_prof_is_activ['_name'], $acf_id);
|
$is_activ = get_field($acf_prof_is_activ['_name'], $acf_id);
|
||||||
if ($is_activ === 'Actif')
|
if ($is_activ === $acf_prof_is_activ['activ'])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
@@ -81,9 +81,11 @@ function show_prof_paiement_messages_CIPF($user_id) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
$is_activ = get_field($acf_prof_is_activ['_name'], $acf_id);
|
$is_activ = get_field($acf_prof_is_activ['_name'], $acf_id);
|
||||||
if (is_null($is_activ) || empty($is_activ))
|
if (is_null($is_activ))
|
||||||
return;
|
return;
|
||||||
if ($is_activ === 'Inactif')
|
if (empty($is_activ))
|
||||||
|
return;
|
||||||
|
if ($is_activ === $acf_prof_is_activ['activ'])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$cipf_prof_payement = new PLGNTLS_class();
|
$cipf_prof_payement = new PLGNTLS_class();
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ if (!defined('ABSPATH')) {
|
|||||||
die('You can not access this file!');
|
die('You can not access this file!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/format_user_infos.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function extract_if_array_size_one_CIPF($value) {
|
function extract_if_array_size_one_CIPF($value) {
|
||||||
PLGNTLS_class::debug_infos();
|
PLGNTLS_class::debug_infos();
|
||||||
if (is_array($value) && count($value) === 1)
|
if (is_array($value) && count($value) === 1)
|
||||||
@@ -59,81 +63,6 @@ function output_list_front_CIPF($array, $current_user, $user_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function format_user_info_CIPF($query, &$current_user, $user_id) {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$output_date_format = PLGNTLS_class::USER_INFO_DATE_FORMAT;
|
|
||||||
|
|
||||||
$is_acf = false;
|
|
||||||
$is_date = false;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* check if it's an acf field
|
|
||||||
* first method : check if _field exist
|
|
||||||
*
|
|
||||||
$_acf_field = '_'.$query;
|
|
||||||
$acf_field = $current_user->$_acf_field;
|
|
||||||
if (!empty($acf_field))
|
|
||||||
$is_acf = true;
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* check if it's an acf field, and a date
|
|
||||||
* second method : check what get_field_object() returns
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
$acf_id = 'user_'.$user_id;
|
|
||||||
$acf_object = get_field_object($query, $acf_id);
|
|
||||||
if ($acf_object !== false)
|
|
||||||
$is_acf = true;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* if is acf, use the acf return format
|
|
||||||
* otherwise, use the default wordpress value
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if ($is_acf)
|
|
||||||
$output = get_field($query, $acf_id);
|
|
||||||
else
|
|
||||||
$output = $current_user->$query;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* check if is date
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if ($is_acf) {
|
|
||||||
$acf_type = $acf_object['type'];
|
|
||||||
if ($acf_type && $acf_type === "date_picker")
|
|
||||||
$is_date = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* if is date, transform format
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if ($is_date) {
|
|
||||||
$acf_date_string = $acf_object['value'];
|
|
||||||
$acf_date_format = $acf_object['return_format'];
|
|
||||||
$date = date_create_from_format($acf_date_format, $acf_date_string);
|
|
||||||
$output = $date->format($output_date_format);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* return the result
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
while (is_array($output) && count($output) === 1)
|
|
||||||
$output = reset($output);
|
|
||||||
if (is_array($output) && count($output) === 0)
|
|
||||||
$output = '';
|
|
||||||
if (!is_string($output))
|
|
||||||
$output = json_encode($output, JSON_UNESCAPED_SLASHES);
|
|
||||||
return esc_html($output);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* shortcode to write user info of post author
|
* shortcode to write user info of post author
|
||||||
|
|||||||
@@ -100,6 +100,8 @@ class PLGNTLS_class
|
|||||||
const CARD_RENEW_PERIOD = 31; // int : number of days before expiration when renew card start to be possible
|
const CARD_RENEW_PERIOD = 31; // int : number of days before expiration when renew card start to be possible
|
||||||
const CARD_VALIDITY_TIME = '1 year'; // string : time of validity of the card (ex: '1 month' or '1 year' or '60 days')
|
const CARD_VALIDITY_TIME = '1 year'; // string : time of validity of the card (ex: '1 month' or '1 year' or '60 days')
|
||||||
const USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php)
|
const USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php)
|
||||||
|
const ADMIN_VALIDATE_PROF_FIELD = 'cipf_admin_activate_prof'; // for admin_modif_prof.php
|
||||||
|
const BASE_REST_ROUTE = 'cipf_plugin/api/v1'; // for routes, in php/paypal/routes.php && php/admin_modif_prof.php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
private
2
private
Submodule private updated: 56b1f351d4...de5ea3a591
Reference in New Issue
Block a user