created plugin custer, and removed shortcodes change_id and user_infos from cipf plugin

This commit is contained in:
asus
2024-03-17 02:27:28 +01:00
parent 494943e4f7
commit 6ad1fb5137
13 changed files with 668 additions and 127 deletions

View File

@@ -18,60 +18,12 @@ if (!defined('ABSPATH')) {
/*
* version 4 :
* modifying directly the current user : very hardcore, and need to store it
*/
function shortcode_choose_meta_id_CIPF ($options) {
PLGNTLS_class::debug_infos();
// $role_fipf = PLGNTLS_class::ROLE_FIPF;
// $role_admin = PLGNTLS_class::ROLE_ADMIN;
//
// $current_user = wp_get_current_user();
//
// $allowed_roles = array($role_admin, $role_fipf);
// if (!array_intersect($allowed_roles, $current_user->roles))
// return;
$option = reset($options);
if (!is_string($option)) {
return;
}
if ($option === 'logged_in') {
$id = get_current_user_id();
error_log("logged_in id : " . $id);
PLGNTLS_class::set_current_user_backup();
wp_set_current_user($id);
}
else if ($option === 'post_creator') {
$id = get_queried_object_id();
error_log("post_creator id : " . $id);
PLGNTLS_class::set_current_user_backup();
wp_set_current_user($id);
}
else if ($option === 'off') {
$id = PLGNTLS_class::reset_current_user_backup();
error_log("reset id : " . $id);
wp_set_current_user($id);
}
else
return;
//add_action('set_current_user', 'force_set_user_CIPF');
}
add_shortcode('cipf_change_meta_id', 'shortcode_choose_meta_id_CIPF');
/*
* version 3 :
*
* trying with a filter on wp_get_current_user()
* used by form builder to retrieve the user before using get_metadat()
* -> somehow the filter is never called
* -> the filter is not called in most cases, if user is instance of WP_USER
*/
//function filter_user_id_CIPF($id) {
// PLGNTLS_class::debug_infos();
@@ -83,7 +35,8 @@ add_shortcode('cipf_change_meta_id', 'shortcode_choose_meta_id_CIPF');
// error_log("-in add_filter_for_user_id_CIPF"); // this is output
// add_filter('determine_current_user', 'filter_user_id_CIPF', 10, 1);
//}
//add_action('wp', 'add_filter_for_user_id_CIPF');
//add_shortcode('cipf_change_meta_id', 'add_filter_for_user_id_CIPF');
////add_action('wp', 'add_filter_for_user_id_CIPF');
@@ -114,11 +67,11 @@ add_shortcode('cipf_change_meta_id', 'shortcode_choose_meta_id_CIPF');
//
// $object_id = 117;
//
///*
//* I just copied the code of wordpress :
//* i'm not sure there is a better way
//*
//*/
// /*
// * I just copied the code of wordpress :
// * i'm not sure there is a better way
// *
// */
// $meta_cache = wp_cache_get( $object_id, $meta_type . '_meta' );
//
// if ( ! $meta_cache ) {
@@ -141,9 +94,9 @@ add_shortcode('cipf_change_meta_id', 'shortcode_choose_meta_id_CIPF');
// return array_map( 'maybe_unserialize', $meta_cache[ $meta_key ] );
// }
// }
///*
//* FIN copy
//*/
// /*
// * FIN copy
// */
//}
//function add_filter_for_user_id_CIPF($wp) {
// PLGNTLS_class::debug_infos();

View File

@@ -44,9 +44,81 @@ function check_can_pay_CIPF() {
* in case it was changed from admin pannel
*
*/
$tarif = (int)get_field($acf_card_price_choice['_name'], $acf_id);
$livraison = (int)get_field($acf_card_price_delivery['_name'], $acf_id);
$price = $tarif + $livraison;
$tarif_object = get_field_object($acf_card_price_choice['_name'], $acf_id);
error_log("tarif_object");
error_log(json_encode($tarif_object));
/*
{
"ID":34541,
"key":"field_65d24447cc89f",
"label":"Tarif",
"name":"tarif",
"aria-label":"",
"prefix":"acf",
"type":"radio",
"value":"Je suis hors r\u00e9seau FIPF et je souhaite commander la carte \u00e0 15 \u20ac",
"menu_order":3,
"instructions":"",
"required":0,
"id":"",
"class":"",
"conditional_logic":0,
"parent":34538,
"wrapper":{
"width":"",
"class":"",
"id":""
},
"choices":{
"10":"Mon association adh\u00e8re \u00e0 la FIPF, je peux commander la carte \u00e0 10 \u20ac",
"15":"Je suis hors r\u00e9seau FIPF et je souhaite commander la carte \u00e0 15 \u20ac"
},
"default_value":"",
"return_format":"label",
"allow_null":0,
"other_choice":0,
"layout":"vertical",
"save_other_choice":0,
"_name":"tarif",
"_valid":1
}
{
"ID":34541,
"key":"field_65d24447cc89f",
"label":"Tarif",
"name":"tarif",
"aria-label":"",
"prefix":"acf",
"type":"radio",
"value":"15",
"menu_order":3,
"instructions":"",
"required":0,"id":"",
"class":"",
"conditional_logic":0,
"parent":34538,
"wrapper":{"width":"","class":"","id":""},
"choices":{
"10":"Mon association adh\u00e8re \u00e0 la FIPF, je peux commander la carte \u00e0 10 \u20ac",
"15":"Je suis hors r\u00e9seau FIPF et je souhaite commander la carte \u00e0 15 \u20ac"
},
"default_value":"",
"return_format":"value",
"allow_null":0,
"other_choice":0,
"layout":"vertical",
"save_other_choice":0,
"_name":"tarif",
"_valid":1
}
*/
// $tarif_value = ;
// $tarif = (int)$tarif_value;
$livraison_object = get_field_object($acf_card_price_delivery['_name'], $acf_id);
// $livraison_value = ;
// $livraison = (int)$livraison_value;
// $price = $tarif + $livraison;
$price = 3;
update_field($acf_card_price_total['_name'], $price, $acf_id);
/*

View File

@@ -69,16 +69,16 @@ function redirection_profil_CIPF(){
* redirects when on the page with slug defined in SLUG_PAGE_REDIRECTION
*
*/
//function redirection_page_CIPF(){
// PLGNTLS_class::debug_infos();
// $slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
//
// if (!is_page($slug_page_redirection))
// return;
//
// redirection_profil_CIPF();
//}
//add_action('template_redirect', 'redirection_page_CIPF');
function redirection_page_CIPF(){
PLGNTLS_class::debug_infos();
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
if (!is_page($slug_page_redirection))
return;
redirection_profil_CIPF();
}
add_action('template_redirect', 'redirection_page_CIPF');
@@ -90,35 +90,35 @@ function redirection_profil_CIPF(){
* works even if the page actually does not exists
*
*/
function redirection_query_CIPF() {
PLGNTLS_class::debug_infos();
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
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_page_redirection)
return;
/*
* check the request ?query
*
if(!isset($_GET['query']))
return;
*/
redirection_profil_CIPF();
}
add_action('template_redirect', 'redirection_query_CIPF');
//add_action('init', 'redirection_query_CIPF');
//function redirection_query_CIPF() {
// PLGNTLS_class::debug_infos();
// $slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
//
//
// 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_page_redirection)
// return;
//
// /*
// * check the request ?query
// *
// if(!isset($_GET['query']))
// return;
// */
//
// redirection_profil_CIPF();
//}
//add_action('template_redirect', 'redirection_query_CIPF');
////add_action('init', 'redirection_query_CIPF');