fixed dates format error
This commit is contained in:
@@ -4,7 +4,7 @@ Plugin Name: cipf_plugin
|
||||
Plugin URI:
|
||||
Description:
|
||||
Author: hugogogo
|
||||
Version: 0.2.6
|
||||
Version: 0.2.7
|
||||
Author URI:
|
||||
*/
|
||||
|
||||
@@ -37,7 +37,7 @@ include_once(PLGNTLS_class::root_path() . 'php/admin_menu/example_menu.php');
|
||||
include_once(PLGNTLS_class::root_path() . 'php/paypal/paypal.php');
|
||||
|
||||
include_once(PLGNTLS_class::root_path() . '/php/user_infos.php');
|
||||
//include_once(PLGNTLS_class::root_path() . '/php/hide_admin.php');
|
||||
include_once(PLGNTLS_class::root_path() . '/php/hide_admin.php');
|
||||
//include_once(PLGNTLS_class::root_path() . '/php/menus.php');
|
||||
include_once(PLGNTLS_class::root_path() . 'php/register_partenaires.php');
|
||||
include_once(PLGNTLS_class::root_path() . 'php/redirections.php');
|
||||
|
||||
@@ -18,9 +18,23 @@ if (!defined('ABSPATH')) {
|
||||
* so they don't change between hooks before and after process
|
||||
*
|
||||
*/
|
||||
function admin_validate_prof_CIPF() {
|
||||
function admin_validate_prof_CIPF($data) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
|
||||
|
||||
if (empty($data))
|
||||
redirection_profil_CIPF();
|
||||
|
||||
error_log("---");
|
||||
error_log("data");
|
||||
error_log(json_encode($data));
|
||||
|
||||
if (!isset($data[$acf_prof_is_activ['_name']]))
|
||||
redirection_profil_CIPF();
|
||||
|
||||
$is_activ = $data[$acf_prof_is_activ['_name']];
|
||||
error_log("is_activ");
|
||||
error_log($is_activ);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,177 +42,142 @@ function admin_validate_prof_CIPF() {
|
||||
|
||||
|
||||
/*
|
||||
* version 3 : ABANDONNED
|
||||
* calling the action to validate from the FormBuilder hook
|
||||
*
|
||||
*/
|
||||
function custom_form_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;
|
||||
|
||||
admin_validate_prof_CIPF();
|
||||
admin_validate_prof_CIPF($post_array);
|
||||
}
|
||||
add_action('df_before_process', 'custom_form_admin_validate_prof_CIPF', 10, 3);
|
||||
|
||||
|
||||
/*
|
||||
* calling the action to validate from the url query
|
||||
*
|
||||
function url_custom_form_admin_validate_prof_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$query_page_redirection = PLGNTLS_class::QUERY_REDIRECTION_PROFIL;
|
||||
|
||||
// Check if the request contains ?QUERY_REDIRECTION_PROFIL
|
||||
if(!isset($_GET[$query_page_redirection]))
|
||||
return;
|
||||
admin_validate_prof_CIPF();
|
||||
}
|
||||
add_action('init', 'url_custom_form_admin_validate_prof_CIPF');
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* version 4 :
|
||||
* calling the action to validate from the url query
|
||||
*
|
||||
*/
|
||||
//function url_custom_form_admin_validate_prof_CIPF() {
|
||||
// PLGNTLS_class::debug_infos();
|
||||
// $slug_admin_validate_prof = PLGNTLS_class::SLUG_ADMIN_VALIDATE_PROF;
|
||||
//
|
||||
// if (!isset($_GET['q']))
|
||||
// return;
|
||||
//
|
||||
// /*
|
||||
// * check the request /path/
|
||||
// * for url : https://url.com/path/to/file/?query=value
|
||||
// * -> $_GET: {"q":"/path/to/file/","query":"value"}
|
||||
// *
|
||||
// */
|
||||
// $get_path = trim($_GET['q'], '/');
|
||||
// if ($get_path !== $slug_admin_validate_prof)
|
||||
// return;
|
||||
//
|
||||
// admin_validate_prof_CIPF($_POST);
|
||||
//}
|
||||
//add_action('init', 'url_custom_form_admin_validate_prof_CIPF');
|
||||
|
||||
|
||||
|
||||
/*
|
||||
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
|
||||
_POST :
|
||||
{"field_title":["\u00c9tat du compte"],"field_name":["compte-actif"],"field_id":["cipf_admin_activate_prof"],"compte-actif":"Inactif","form_key":"40781-1","unique_id":"91eed9aa-2b92-4da7-a0b4-e94f24515223","form_type":"custom","divi-form-submit":"yes","form_id":"","form_type_confirm":""}
|
||||
{
|
||||
"field_title":["\u00c9tat du compte"],
|
||||
"field_name":["compte-actif"],
|
||||
"field_id":["cipf_admin_activation_prof"],
|
||||
"field_id":["cipf_admin_activate_prof"],
|
||||
"compte-actif":"Inactif",
|
||||
- "form_key":"40781-1",
|
||||
- "unique_id":"91eed9aa-2b92-4da7-a0b4-e94f24515223",
|
||||
- "form_type":"custom",
|
||||
- "divi-form-submit":"yes",
|
||||
- "form_id":"",
|
||||
"form_type_confirm":""
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
post_array :
|
||||
{"field_title":["\u00c9tat du compte"],"field_name":["compte-actif"],"field_id":["cipf_admin_activate_prof"],"compte-actif":"Inactif","form_type_confirm":""}
|
||||
{
|
||||
"field_title":["\u00c9tat du compte"],
|
||||
"field_name":["compte-actif"],
|
||||
"field_id":["cipf_admin_activate_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
|
||||
* version 2 : ABANDONNED
|
||||
* tried to receive the form in ajax from front with wp REST API
|
||||
* but I cannot verify if the user is logged in
|
||||
* so it does not work
|
||||
*
|
||||
function admin_validate_prof_form_CIPF($request) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
||||
|
||||
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":""}
|
||||
|
||||
// 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;
|
||||
}
|
||||
function endpoint_form_admin_activate_prof_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$base_rest_route = PLGNTLS_class::URL_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');
|
||||
*/
|
||||
//function admin_validate_prof_form_CIPF($request) {
|
||||
// PLGNTLS_class::debug_infos();
|
||||
// $slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
||||
//
|
||||
// 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":""}
|
||||
//
|
||||
// // 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;
|
||||
//}
|
||||
//function endpoint_form_admin_activate_prof_CIPF() {
|
||||
// PLGNTLS_class::debug_infos();
|
||||
// $base_rest_route = PLGNTLS_class::URL_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
|
||||
* version 1 : ABANDONNED
|
||||
* 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');
|
||||
*/
|
||||
//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');
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ function format_user_info_CIPF($query, &$current_user, $user_id) {
|
||||
$output_date_format = PLGNTLS_class::USER_INFO_DATE_FORMAT;
|
||||
|
||||
$is_acf = false;
|
||||
$is_date = false;
|
||||
|
||||
/*
|
||||
* check if it's an acf field
|
||||
@@ -49,26 +48,20 @@ function format_user_info_CIPF($query, &$current_user, $user_id) {
|
||||
$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 not acf
|
||||
* check if is a date
|
||||
* and format it
|
||||
* to create a DateTime from a time stamp : https://stackoverflow.com/a/12039058/9497573
|
||||
*
|
||||
*/
|
||||
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);
|
||||
if (!$is_acf) {
|
||||
$timestamp = strtotime($output);
|
||||
if ($timestamp !== false) {
|
||||
$date = new DateTime('@' . $timestamp);
|
||||
$output = $date->format($output_date_format);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ if (!defined('ABSPATH')) {
|
||||
* if partenaire -> post page || home page
|
||||
*
|
||||
*/
|
||||
function redirection_profil_page_CIPF(){
|
||||
function redirection_profil_CIPF(){
|
||||
PLGNTLS_class::debug_infos();
|
||||
$role_prof = PLGNTLS_class::ROLE_PROF;
|
||||
$role_partner = PLGNTLS_class::ROLE_PARTNER;
|
||||
@@ -23,28 +23,20 @@ function redirection_profil_page_CIPF(){
|
||||
$base_url = home_url();
|
||||
$current_user_id = get_current_user_id();
|
||||
|
||||
error_log("1");
|
||||
|
||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||
nocache_headers();
|
||||
|
||||
if (!is_user_logged_in()) {
|
||||
error_log("2");
|
||||
wp_redirect($base_url, 301);
|
||||
exit;
|
||||
}
|
||||
|
||||
error_log("3");
|
||||
if (current_user_can($role_prof)) {
|
||||
error_log("4");
|
||||
$user_page = get_author_posts_url($current_user_id);
|
||||
error_log("user_page");
|
||||
error_log($user_page);
|
||||
wp_redirect($user_page, 301);
|
||||
exit;
|
||||
}
|
||||
else if (current_user_can($role_partner)) {
|
||||
error_log("5");
|
||||
$args = array(
|
||||
'post_type' => 'post',
|
||||
'author' => $current_user_id,
|
||||
@@ -52,11 +44,9 @@ error_log("5");
|
||||
);
|
||||
$posts = get_posts($args);
|
||||
if (empty($posts)) {
|
||||
error_log("6");
|
||||
$redirect_url = $base_url;
|
||||
}
|
||||
else {
|
||||
error_log("7");
|
||||
$query = reset($posts);
|
||||
$post_id = $query->ID;
|
||||
$redirect_url = get_permalink($query->ID);
|
||||
@@ -65,11 +55,9 @@ error_log("7");
|
||||
exit;
|
||||
}
|
||||
else {
|
||||
error_log("8");
|
||||
wp_redirect($base_url, 301);
|
||||
exit;
|
||||
}
|
||||
error_log("9");
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -86,7 +74,7 @@ function redirection_page_CIPF(){
|
||||
if (!is_page($slug_page_redirection))
|
||||
return;
|
||||
|
||||
redirection_profil_page_CIPF();
|
||||
redirection_profil_CIPF();
|
||||
}
|
||||
add_action('template_redirect', 'redirection_page_CIPF');
|
||||
*/
|
||||
@@ -125,7 +113,7 @@ function redirection_query_CIPF() {
|
||||
return;
|
||||
*/
|
||||
|
||||
redirection_profil_page_CIPF();
|
||||
redirection_profil_CIPF();
|
||||
}
|
||||
add_action('init', 'redirection_query_CIPF');
|
||||
|
||||
@@ -135,7 +123,7 @@ add_action('init', 'redirection_query_CIPF');
|
||||
|
||||
/*
|
||||
* DOES NOT WORK so far
|
||||
* because to use is_user_logged_in() in redirection_profil_page_CIPF
|
||||
* because to use is_user_logged_in() in redirection_profil_CIPF
|
||||
* the request should include the X-WP-Nonce header, but it does not
|
||||
* redirects when someone enter the url or redirection
|
||||
* /wp-json/cipf_plugin/api/v1/redirection_cipf
|
||||
@@ -147,7 +135,7 @@ function endpoint_for_redirection_CIPF() {
|
||||
|
||||
register_rest_route($base_rest_route, '/' . $slug_page_redirection, array(
|
||||
'methods' => 'GET',
|
||||
'callback' => 'redirection_profil_page_CIPF',
|
||||
'callback' => 'redirection_profil_CIPF',
|
||||
));
|
||||
};
|
||||
add_action('rest_api_init', 'endpoint_for_redirection_CIPF');
|
||||
|
||||
@@ -82,10 +82,10 @@ class PLGNTLS_class
|
||||
const SLUG_PAGE_REDIRECTION = 'redirection_cipf';
|
||||
const SLUG_PAYPAL_REDIRECTION_SUCCESS = self::SLUG_PAGE_REDIRECTION;
|
||||
const SLUG_PAYPAL_REDIRECTION_FAILURE = self::SLUG_PAGE_REDIRECTION;
|
||||
const SLUG_ADMIN_VALIDATE_PROF = 'admin_activate_prof_cipf'; // for admin_modif_prof.php
|
||||
// URL
|
||||
const URL_BASE_REST_ROUTE = 'cipf_plugin/api/v1'; // for routes, in php/paypal/routes.php && php/admin_modif_prof.php
|
||||
// QUERY
|
||||
const QUERY_ADMIN_VALIDATE_PROF = 'admin_activate_prof_cipf'; // for admin_modif_prof.php
|
||||
|
||||
// PAYPAL
|
||||
const PAYPAL_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl";
|
||||
@@ -108,7 +108,7 @@ class PLGNTLS_class
|
||||
|
||||
|
||||
|
||||
private static $_DEBUG_INFOS = true;
|
||||
private static $_DEBUG_INFOS = false;
|
||||
private static $_plugin_dir_path;
|
||||
private static $_plugin_name;
|
||||
private static $_file_dir_path;
|
||||
|
||||
Reference in New Issue
Block a user