wip trying to force the acf id that formbuilder will use
This commit is contained in:
@@ -2,9 +2,9 @@
|
|||||||
/*
|
/*
|
||||||
Plugin Name: cipf_plugin
|
Plugin Name: cipf_plugin
|
||||||
Plugin URI:
|
Plugin URI:
|
||||||
Description:
|
Description: test avec page de redirection
|
||||||
Author: hugogogo
|
Author: hugogogo
|
||||||
Version: 0.2.7
|
Version: 0.2.7.1
|
||||||
Author URI:
|
Author URI:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,106 @@ if (!defined('ABSPATH')) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Hook into the ACF field retrieval process
|
||||||
|
/*
|
||||||
|
function test_acfs_CIPF($fields, $id) {
|
||||||
|
error_log("--- fields");
|
||||||
|
|
||||||
|
error_log("fields");
|
||||||
|
error_log(json_encode($fields));
|
||||||
|
error_log("id");
|
||||||
|
error_log($id);
|
||||||
|
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
function test_acf_CIPF($field, $id) {
|
||||||
|
error_log("--- " . $field['name']);
|
||||||
|
if ($field['name'] !== 'compte-actif')
|
||||||
|
return $field;
|
||||||
|
|
||||||
|
error_log("acf hook");
|
||||||
|
error_log("field");
|
||||||
|
error_log(json_encode($field));
|
||||||
|
error_log("_GET");
|
||||||
|
error_log(json_encode($_GET));
|
||||||
|
|
||||||
|
// // Check if we are targeting a specific ACF field and user
|
||||||
|
// if ($field_key === 'your_field_key' && isset($_GET['user_id'])) {
|
||||||
|
// $user_id = $_GET['user_id']; // Get the user ID from the query parameters
|
||||||
|
//
|
||||||
|
// // Retrieve the ACF field object for the specified user
|
||||||
|
// $user_field = get_field_object($field_key, 'user_' . $user_id);
|
||||||
|
//
|
||||||
|
// if ($user_field) {
|
||||||
|
// return $user_field; // Return the ACF field object for the specified user
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // If not targeting a specific user, return the original field
|
||||||
|
return $field;
|
||||||
|
}
|
||||||
|
add_filter('acf/pre_render_field', 'test_acf_CIPF', 10, 2);
|
||||||
|
add_filter('acf/pre_render_fields', 'test_acfs_CIPF', 10, 2);
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
add_filter('acf/load_field', 'test_acf_CIPF');
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
{"ID":40341,"key":"field_65e8acd5c2065","label":"Activation du compte","name":"compte-actif","aria-label":"","prefix":"acf","type":"radio","value":null,"menu_order":1,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":34538,"wrapper":{"width":"","class":"","id":""},"choices":{"Actif":"Actif","Inactif":"Inactif"},"default_value":"","return_format":"value","allow_null":0,"other_choice":0,"layout":"vertical","save_other_choice":0,"_name":"compte-actif","_valid":1}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function test_acf_CIPF($acf_id, $id) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
error_log("acf_id: " . $acf_id . ", id : " . $id);
|
||||||
|
if ($id === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return 'user_'.$id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function choose_acf_id_CIPF($options) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$shortcode_choose_acf_id = PLGNTLS_class::SHORTCODE_CHOOSE_ACF_ID;
|
||||||
|
|
||||||
|
$option = reset($options);
|
||||||
|
if (!is_string($option)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($option === $shortcode_choose_acf_id['logged_in']) {
|
||||||
|
$id = get_current_user_id();
|
||||||
|
}
|
||||||
|
else if ($option === $shortcode_choose_acf_id['post_creator']) {
|
||||||
|
$id = get_queried_object_id();
|
||||||
|
}
|
||||||
|
else if ($option === $shortcode_choose_acf_id['off']) {
|
||||||
|
$id = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* this filter is called by acf to find the id to use
|
||||||
|
* with functions like get_field()
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
add_filter('acf/pre_load_post_id', function($null, $acf_id) use ($id) {
|
||||||
|
return test_acf_CIPF($acf_id, $id);
|
||||||
|
}, 10, 2);
|
||||||
|
}
|
||||||
|
add_shortcode('cipf_choose_acf_id', 'choose_acf_id_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
// $new_body = preg_replace_callback($pattern, function($matches) use ($id) {
|
||||||
|
// return replace_words_CIPF($matches, $id);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* custom action in php on custom form submission
|
* custom action in php on custom form submission
|
||||||
* custom forms are not processed by divi form builder
|
* custom forms are not processed by divi form builder
|
||||||
|
|||||||
@@ -49,6 +49,15 @@ function format_user_info_CIPF($query, &$current_user, $user_id) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* try to extract a string
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
while (is_array($output) && count($output) === 1)
|
||||||
|
$output = reset($output);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if is not acf
|
* if is not acf
|
||||||
* check if is a date
|
* check if is a date
|
||||||
@@ -57,7 +66,10 @@ function format_user_info_CIPF($query, &$current_user, $user_id) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
if (!$is_acf) {
|
if (!$is_acf) {
|
||||||
|
$timestamp = false;
|
||||||
|
if (is_string($output)) {
|
||||||
$timestamp = strtotime($output);
|
$timestamp = strtotime($output);
|
||||||
|
}
|
||||||
if ($timestamp !== false) {
|
if ($timestamp !== false) {
|
||||||
$date = new DateTime('@' . $timestamp);
|
$date = new DateTime('@' . $timestamp);
|
||||||
$output = $date->format($output_date_format);
|
$output = $date->format($output_date_format);
|
||||||
@@ -65,12 +77,11 @@ function format_user_info_CIPF($query, &$current_user, $user_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return the result
|
* return the result
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
while (is_array($output) && count($output) === 1)
|
|
||||||
$output = reset($output);
|
|
||||||
if (is_array($output) && count($output) === 0)
|
if (is_array($output) && count($output) === 0)
|
||||||
$output = '';
|
$output = '';
|
||||||
if (!is_string($output))
|
if (!is_string($output))
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ function redirection_profil_CIPF(){
|
|||||||
/*
|
/*
|
||||||
* redirects when on the page with slug defined in SLUG_PAGE_REDIRECTION
|
* redirects when on the page with slug defined in SLUG_PAGE_REDIRECTION
|
||||||
*
|
*
|
||||||
|
*/
|
||||||
function redirection_page_CIPF(){
|
function redirection_page_CIPF(){
|
||||||
PLGNTLS_class::debug_infos();
|
PLGNTLS_class::debug_infos();
|
||||||
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
||||||
@@ -77,7 +78,6 @@ function redirection_page_CIPF(){
|
|||||||
redirection_profil_CIPF();
|
redirection_profil_CIPF();
|
||||||
}
|
}
|
||||||
add_action('template_redirect', 'redirection_page_CIPF');
|
add_action('template_redirect', 'redirection_page_CIPF');
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -88,34 +88,34 @@ add_action('template_redirect', 'redirection_page_CIPF');
|
|||||||
* works even if it does not exists
|
* works even if it does not exists
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function redirection_query_CIPF() {
|
//function redirection_query_CIPF() {
|
||||||
PLGNTLS_class::debug_infos();
|
// PLGNTLS_class::debug_infos();
|
||||||
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
// $slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
||||||
|
//
|
||||||
|
//
|
||||||
if (!isset($_GET['q']))
|
// if (!isset($_GET['q']))
|
||||||
return;
|
// return;
|
||||||
|
//
|
||||||
/*
|
// /*
|
||||||
* check the request /path/
|
// * check the request /path/
|
||||||
* for url : https://url.com/path/to/file/?query=value
|
// * for url : https://url.com/path/to/file/?query=value
|
||||||
* -> $_GET: {"q":"/path/to/file/","query":"value"}
|
// * -> $_GET: {"q":"/path/to/file/","query":"value"}
|
||||||
*
|
// *
|
||||||
*/
|
// */
|
||||||
$get_path = trim($_GET['q'], '/');
|
// $get_path = trim($_GET['q'], '/');
|
||||||
if ($get_path !== $slug_page_redirection)
|
// if ($get_path !== $slug_page_redirection)
|
||||||
return;
|
// return;
|
||||||
|
//
|
||||||
/*
|
// /*
|
||||||
* check the request ?query
|
// * check the request ?query
|
||||||
*
|
// *
|
||||||
if(!isset($_GET['query']))
|
// if(!isset($_GET['query']))
|
||||||
return;
|
// return;
|
||||||
*/
|
// */
|
||||||
|
//
|
||||||
redirection_profil_CIPF();
|
// redirection_profil_CIPF();
|
||||||
}
|
//}
|
||||||
add_action('init', 'redirection_query_CIPF');
|
//add_action('init', 'redirection_query_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -100,6 +100,9 @@ class PLGNTLS_class
|
|||||||
const ROLE_FIPF = 'fipf';
|
const ROLE_FIPF = 'fipf';
|
||||||
const ROLE_ADMIN = 'administrator';
|
const ROLE_ADMIN = 'administrator';
|
||||||
|
|
||||||
|
// SHORTCODES
|
||||||
|
const SHORTCODE_CHOOSE_ACF_ID = ['logged_in'=>'logged_in', 'post_creator'=>'post_creator', 'off'=>'off'];
|
||||||
|
|
||||||
// OTHER
|
// OTHER
|
||||||
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')
|
||||||
|
|||||||
2
private
2
private
Submodule private updated: 38d0c31353...1a7692205d
Reference in New Issue
Block a user