- added debug function
- fixed issues in acf fields use
This commit is contained in:
@@ -11,6 +11,7 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
|
||||
function restrict_author_page_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
if (!is_author())
|
||||
return;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ if (!defined('ABSPATH')) {
|
||||
*
|
||||
*/
|
||||
function replace_words_CIPF($matches, $user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
if ($user_id !== null) {
|
||||
$current_user = get_user_by('id', $user_id);
|
||||
}
|
||||
@@ -66,6 +67,7 @@ function replace_words_CIPF($matches, $user_id = null) {
|
||||
*
|
||||
*/
|
||||
function filter_email_fb_CIPF($reply_body, $post_array) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$id = $post_array['ID'];
|
||||
// pattern : anything surrounded by '$$', ex : $$value$$
|
||||
$pattern = '/\$\$(.*?)\$\$/';
|
||||
@@ -92,6 +94,7 @@ add_filter('df_notification_body', 'filter_email_fb_CIPF', 10, 2); // the admini
|
||||
* or event that a different user has already logged in
|
||||
*/
|
||||
function filter_email_wp_CIPF($args) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
// pattern : anything surrounded by '$$', ex : $$value$$
|
||||
$pattern = '/\$\$(.*?)\$\$/';
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ if (!defined('ABSPATH')) {
|
||||
* hide admin bar if access a front page and is not an admin
|
||||
*/
|
||||
function hide_admin_bar_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
if (!current_user_can('administrator') && !is_admin()) {
|
||||
show_admin_bar(false);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ if (!defined('ABSPATH')) {
|
||||
* - $menu_redirect = 'www.un_autre_site.net/contact' -> https://www.un_autre_site.net/contact
|
||||
*/
|
||||
function change_menu_logout($items){
|
||||
PLGNTLS_class::debug_infos();
|
||||
$menu_title = 'special logout';
|
||||
|
||||
// quelques urls utiles :
|
||||
|
||||
@@ -20,6 +20,7 @@ if (!defined('ABSPATH')) {
|
||||
*
|
||||
*/
|
||||
function handle_orders_request_CIPF($request_data) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
|
||||
// declaring outside the try..catch scope
|
||||
$order_response = array();
|
||||
@@ -96,8 +97,8 @@ function handle_orders_request_CIPF($request_data) {
|
||||
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_create
|
||||
*
|
||||
*/
|
||||
function create_order_CIPF()
|
||||
{
|
||||
function create_order_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$paypal_api_base_url = PLGNTLS_class::PAYPAL_API_BASE_URL;
|
||||
|
||||
$access_token = generate_access_token_CIPF();
|
||||
|
||||
@@ -11,6 +11,7 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
|
||||
function handle_orders_capture_request_CIPF($request) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$order_id = $request['orderID'];
|
||||
// declaring outside the try..catch scope
|
||||
$response_json = array();
|
||||
@@ -74,6 +75,7 @@ function handle_orders_capture_request_CIPF($request) {
|
||||
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
|
||||
*/
|
||||
function capture_order_CIPF($order_id) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$paypal_api_base_url = PLGNTLS_class::PAYPAL_API_BASE_URL;
|
||||
$access_token = generate_access_token_CIPF();
|
||||
$url = $paypal_api_base_url . '/v2/checkout/orders/' . $order_id . '/capture';
|
||||
|
||||
@@ -14,6 +14,7 @@ if (!defined('ABSPATH')) {
|
||||
*
|
||||
*/
|
||||
function handle_json_response_CIPF($response, $ch) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
if ($response === false)
|
||||
throw new HttpException('cURL error: ' . curl_error($ch), 502);
|
||||
|
||||
@@ -32,6 +33,7 @@ function handle_json_response_CIPF($response, $ch) {
|
||||
);
|
||||
}
|
||||
function handle_response_CIPF($response) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
try
|
||||
{
|
||||
// Decode JSON response
|
||||
@@ -57,8 +59,8 @@ function handle_response_CIPF($response) {
|
||||
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
||||
* @see https://developer.paypal.com/api/rest/authentication/
|
||||
*/
|
||||
function generate_access_token_CIPF()
|
||||
{
|
||||
function generate_access_token_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$paypal_client_id = PLGNTLS_class::PAYPAL_CLIENT_ID;
|
||||
$paypal_client_secret = PLGNTLS_class::PAYPAL_CLIENT_SECRET;
|
||||
$paypal_api_base_url = PLGNTLS_class::PAYPAL_API_BASE_URL;
|
||||
|
||||
@@ -11,8 +11,8 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
// handling routes and endpoints
|
||||
// diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573
|
||||
function routes_endpoints_CIPF()
|
||||
{
|
||||
function routes_endpoints_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$base_rest_route = "cipf_plugin/api/v1";
|
||||
register_rest_route($base_rest_route, '/orders', array(
|
||||
'methods' => 'POST',
|
||||
|
||||
@@ -15,8 +15,8 @@ if (!defined('ABSPATH')) {
|
||||
/**
|
||||
* call to paypal_shortcode_content()
|
||||
*/
|
||||
function paypal_shortcode_content_CIPF()
|
||||
{
|
||||
function paypal_shortcode_content_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$slug_paypal_redirection_success = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_SUCCESS;
|
||||
$slug_paypal_redirection_failure = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_FAILURE;
|
||||
$paypal_client_id = PLGNTLS_class::PAYPAL_CLIENT_ID;
|
||||
@@ -55,6 +55,7 @@ add_shortcode('cipf_paypal_shortcode', 'paypal_shortcode_content_CIPF');
|
||||
|
||||
|
||||
function no_payment_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,9 @@ if (!defined('ABSPATH')) {
|
||||
*
|
||||
*/
|
||||
function update_user_pre_order_CIPF($message) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$meta_payement_status = PLGNTLS_class::META_PAYEMENT_STATUS;
|
||||
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
|
||||
|
||||
$order_id = $message->id;
|
||||
$user_id = get_current_user_id();
|
||||
@@ -46,8 +48,8 @@ function update_user_pre_order_CIPF($message) {
|
||||
* - addind order_id to cipf_order_id meta field
|
||||
*
|
||||
*/
|
||||
delete_user_meta($user_id, 'cipf_order_id');
|
||||
add_user_meta($user_id, 'cipf_order_id', $order_id);
|
||||
delete_user_meta($user_id, $meta_order_id);
|
||||
add_user_meta($user_id, $meta_order_id, $order_id);
|
||||
|
||||
/*
|
||||
* create a meta field to check states of payements on prof author page :
|
||||
@@ -69,6 +71,7 @@ function update_user_pre_order_CIPF($message) {
|
||||
*
|
||||
*/
|
||||
function update_user_post_capture_CIPF($message) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$meta_payement_status = PLGNTLS_class::META_PAYEMENT_STATUS;
|
||||
|
||||
$order_id = $message->id;
|
||||
@@ -94,7 +97,10 @@ function update_user_post_capture_CIPF($message) {
|
||||
*
|
||||
*/
|
||||
// find the user containing the order_id and delete this order_id
|
||||
find_user_with_order_id_CIPF($user_id, $order_id);
|
||||
$user_id_to_update = delete_order_id_on_success_CIPF($user_id, $order_id);
|
||||
if ($user_id_to_update === false)
|
||||
return;
|
||||
if ($status === 'COMPLETED') {
|
||||
// proceed to validate payment for user
|
||||
validate_payment_for_user_CIPF($user_id_to_update, $order_id);
|
||||
@@ -111,6 +117,7 @@ function update_user_post_capture_CIPF($message) {
|
||||
*
|
||||
*/
|
||||
function failure_payment_for_user_CIPF($user_id, $order_id) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
}
|
||||
|
||||
|
||||
@@ -119,6 +126,7 @@ function failure_payment_for_user_CIPF($user_id, $order_id) {
|
||||
*
|
||||
*/
|
||||
function validate_payment_for_user_CIPF($user_id, $order_id) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
||||
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
|
||||
$acf_prof_can_renew = PLGNTLS_class::ACF_PROF_CAN_RENEW;
|
||||
@@ -234,19 +242,61 @@ add_action('orderid_deletion_event_CIPF', 'delete_order_id_later_CIPF', 5, 2);
|
||||
* bool false - if no match found
|
||||
*
|
||||
*/
|
||||
function delete_order_id_on_success_CIPF($current_user_id, $order_id)
|
||||
{
|
||||
$del_ret = delete_user_meta($current_user_id, 'cipf_order_id', $order_id);
|
||||
function find_user_with_order_id_CIPF($current_user_id, $order_id) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
|
||||
$role_prof = PLGNTLS_class::ROLE_PROF;
|
||||
|
||||
$user_metas = get_user_meta($current_user_id, $meta_order_id, false);
|
||||
if (in_array($order_id, $user_metas)) {
|
||||
return $current_user_id;
|
||||
}
|
||||
|
||||
// it means the current user didn't have this order_id
|
||||
// so we look for another user
|
||||
// $users = get_users();
|
||||
// foreach ($users as $user) {
|
||||
// $user_id = $user->ID;
|
||||
// $del_ret = delete_user_meta($user_id, $meta_order_id, $order_id);
|
||||
// if ($del_ret === true)
|
||||
// return $user_id;
|
||||
// }
|
||||
|
||||
// https://developer.wordpress.org/reference/classes/WP_User_Query/prepare_query/
|
||||
$users = get_users(array(
|
||||
'role' => $role_prof,
|
||||
'meta_key' => $meta_order_id,
|
||||
'meta_value' => $order_id,
|
||||
'fields' => 'ID',
|
||||
));
|
||||
if (count($users) > 1)
|
||||
throw new HttpException('multiple users with same order_id', 502);
|
||||
else if (count($users) === 1)
|
||||
return reset($users);
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @return mixed num - user_id
|
||||
* bool false - if no match found
|
||||
*
|
||||
*/
|
||||
function delete_order_id_on_success_CIPF($current_user_id, $order_id) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
|
||||
|
||||
$del_ret = delete_user_meta($current_user_id, $meta_order_id, $order_id);
|
||||
if ($del_ret === true)
|
||||
return $current_user_id;
|
||||
|
||||
// it means the current user didn't have this order_id
|
||||
// so we look for another user
|
||||
$users = get_users();
|
||||
foreach ($users as $user)
|
||||
{
|
||||
foreach ($users as $user) {
|
||||
$user_id = $user->ID;
|
||||
$del_ret = delete_user_meta($user_id, 'cipf_order_id', $order_id);
|
||||
$del_ret = delete_user_meta($user_id, $meta_order_id, $order_id);
|
||||
if ($del_ret === true)
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<?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!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +17,7 @@
|
||||
*
|
||||
*/
|
||||
function check_can_pay_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_card_payment_method = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
||||
$acf_card_price_choice = PLGNTLS_class::ACF_CARD_PRICE_CHOICE;
|
||||
$acf_card_price_delivery = PLGNTLS_class::ACF_CARD_PRICE_DELIVERY;
|
||||
@@ -38,13 +47,13 @@ function check_can_pay_CIPF() {
|
||||
$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;
|
||||
update_field($acf_card_price_total, $price, $acf_id);
|
||||
update_field($acf_card_price_total['_name'], $price, $acf_id);
|
||||
|
||||
/*
|
||||
* price is not empty or 0
|
||||
*
|
||||
*/
|
||||
$price = get_field($acf_card_price_total, $acf_id);
|
||||
$price = get_field($acf_card_price_total['_name'], $acf_id);
|
||||
if (empty($price)) {
|
||||
return WP_Error('cannot_purchase', "no price selected");
|
||||
}
|
||||
@@ -52,6 +61,7 @@ function check_can_pay_CIPF() {
|
||||
return WP_Error('cannot_purchase', "price is 0, nothing to purchase");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* date validity is empty
|
||||
* or is paste
|
||||
|
||||
@@ -12,6 +12,7 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
|
||||
function handle_prof_is_activ_CIPF($author_id) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
|
||||
$slug_wait_activation = PLGNTLS_class::SLUG_PROF_INACTIV;
|
||||
|
||||
@@ -68,6 +69,7 @@ function handle_prof_is_activ_CIPF($author_id) {
|
||||
*
|
||||
*/
|
||||
function show_prof_paiement_messages_CIPF($user_id) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
|
||||
$meta_payement_status = PLGNTLS_class::META_PAYEMENT_STATUS;
|
||||
|
||||
@@ -105,6 +107,7 @@ function show_prof_paiement_messages_CIPF($user_id) {
|
||||
*
|
||||
*/
|
||||
function check_prof_page_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
// is an author page
|
||||
if (!is_author())
|
||||
return;
|
||||
|
||||
@@ -15,6 +15,7 @@ if (!defined('ABSPATH')) {
|
||||
* if partenaire -> post page || home page
|
||||
*/
|
||||
function redirection_page_CIPF(){
|
||||
PLGNTLS_class::debug_infos();
|
||||
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
||||
|
||||
if (!is_page($slug_page_redirection))
|
||||
|
||||
@@ -14,6 +14,7 @@ if (!defined('ABSPATH')) {
|
||||
*
|
||||
*/
|
||||
function add_partenaires_PLGNTLS($customer_data){
|
||||
PLGNTLS_class::debug_infos();
|
||||
$current_url = $_SERVER['HTTP_REFERER']; // not reliable to use referer, TODO: find another solution
|
||||
$path_brut = parse_url($current_url, PHP_URL_PATH);
|
||||
$path = trim($path_brut, '/');
|
||||
|
||||
@@ -20,6 +20,7 @@ if (!defined('ABSPATH')) {
|
||||
*
|
||||
*/
|
||||
function reset_some_fields_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_cgv = PLGNTLS_class::ACF_PROF_CGV;
|
||||
$acf_payement = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
||||
$acf_delivery = PLGNTLS_class::ACF_CARD_PRICE_DELIVERY;
|
||||
@@ -48,6 +49,7 @@ function reset_some_fields_CIPF() {
|
||||
*
|
||||
*/
|
||||
function renew_page_restrictions_CIPF(){
|
||||
PLGNTLS_class::debug_infos();
|
||||
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
||||
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
||||
$acf_prof_can_renew = PLGNTLS_class::ACF_PROF_CAN_RENEW;
|
||||
@@ -79,7 +81,7 @@ function renew_page_restrictions_CIPF(){
|
||||
*
|
||||
*/
|
||||
if (current_user_can('professeur__professeure')) {
|
||||
$can_renew = get_field($acf_prof_can_renew, $acf_id);
|
||||
$can_renew = get_field($acf_prof_can_renew['_name'], $acf_id);
|
||||
if ($can_renew === false) {
|
||||
$redirect_url = home_url() . '/' . $slug_page_redirection;
|
||||
wp_redirect($redirect_url, 301);
|
||||
@@ -110,6 +112,7 @@ add_action('template_redirect', 'renew_page_restrictions_CIPF');
|
||||
*
|
||||
*/
|
||||
function renew_page_filter_message_CIPF(){
|
||||
PLGNTLS_class::debug_infos();
|
||||
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
||||
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
||||
|
||||
@@ -122,8 +125,6 @@ function renew_page_filter_message_CIPF(){
|
||||
$cipf_renew = new PLGNTLS_class();
|
||||
|
||||
$card_state = get_field($acf_card_state['_name'], $acf_id);
|
||||
error_log("card_state");
|
||||
error_log($card_state);
|
||||
|
||||
if ($card_state === 'Renouvellement') {
|
||||
$cipf_renew->add_to_front(array(
|
||||
|
||||
@@ -8,12 +8,14 @@ if (!defined('ABSPATH')) {
|
||||
}
|
||||
|
||||
function extract_if_array_size_one_CIPF($value) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
if (is_array($value) && count($value) === 1)
|
||||
return reset($value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
function merge_two_arrays_CIPF($array1, $array2) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$new_array = $array1;
|
||||
foreach ($array2 as $key2 => $value2) {
|
||||
$value = extract_if_array_size_one_CIPF($value2);
|
||||
@@ -38,6 +40,7 @@ function merge_two_arrays_CIPF($array1, $array2) {
|
||||
|
||||
|
||||
function output_list_front_CIPF($array) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$output = '<ul>';
|
||||
foreach ($array as $key => $value) {
|
||||
if (str_starts_with($key, '_'))
|
||||
@@ -59,6 +62,7 @@ function output_list_front_CIPF($array) {
|
||||
|
||||
|
||||
function format_user_info_CIPF($output, $query, &$current_user, $user_id) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$output_date_format = PLGNTLS_class::USER_INFO_DATE_FORMAT;
|
||||
|
||||
$is_acf = false;
|
||||
@@ -127,6 +131,7 @@ function format_user_info_CIPF($output, $query, &$current_user, $user_id) {
|
||||
*
|
||||
*/
|
||||
function current_user_infos_CIPF($atts) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
if (!is_user_logged_in())
|
||||
return ;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user